frequency counter & generator
-
- Posts: 6
- Joined: Tue Feb 19, 2008 12:01 pm
frequency counter & generator
Hi,
Im trying to work out a way to measure a frequency and at the same time output a frequency,
the input being a variable engine tacho signal, i want to somehow use this input to influence the output
so that it can be increased or decreased relative to the input?
how might i do this with flowcode
thanks.
Im trying to work out a way to measure a frequency and at the same time output a frequency,
the input being a variable engine tacho signal, i want to somehow use this input to influence the output
so that it can be increased or decreased relative to the input?
how might i do this with flowcode
thanks.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: frequency counter & generator
Hello
Have you looked at the frequency counter example flowcode file available from here.
http://www.matrixmultimedia.com/Flowcode_Examples.php
Hopefully this should help you to get started.
Have you looked at the frequency counter example flowcode file available from here.
http://www.matrixmultimedia.com/Flowcode_Examples.php
Hopefully this should help you to get started.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 6
- Joined: Tue Feb 19, 2008 12:01 pm
Re: frequency counter & generator
yes, i have looked at the freq_counter file and i understand how it works, but how could i use the value stored in freq to generate that freq,
ideally i would like to do some math to change the value and then output it as a new frequency
ideally i would like to do some math to change the value and then output it as a new frequency
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: frequency counter & generator
Hello
You should be able to modify the timer interrupt so that it will output a 1 or a 0 to a pin depending on a count variable.
Eg if count < 50
output 0
if count >50
output 1
if count = 150
count = 0
you can then use the main to control the control variables rather then being constants as shown above.
You should be able to modify the timer interrupt so that it will output a 1 or a 0 to a pin depending on a count variable.
Eg if count < 50
output 0
if count >50
output 1
if count = 150
count = 0
you can then use the main to control the control variables rather then being constants as shown above.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 6
- Joined: Tue Feb 19, 2008 12:01 pm
Re: frequency counter & generator
good solution, meanwhile is there a good way to do math with flowcode that can convert the measured frequency to rpm value for a display?
- goldwingers
- Posts: 118
- Joined: Wed Sep 06, 2006 1:22 pm
- Location: London
- Been thanked: 1 time
- Contact:
Re: frequency counter & generator
Hi,
You would need to know where your signal is coming from, if its electronic it may counting the revs per rotation or for argument sake. On my motorcycle, i have 2 sensors so i would have to divide the total by 2 to get 1 full revolution. You would then need to clock the incoming frequency count for 1 second and then multiply that result by 60 to give you revs per minute ie
engine speed per sec = 100 * 60 = 6000rpm
You would need to know where your signal is coming from, if its electronic it may counting the revs per rotation or for argument sake. On my motorcycle, i have 2 sensors so i would have to divide the total by 2 to get 1 full revolution. You would then need to clock the incoming frequency count for 1 second and then multiply that result by 60 to give you revs per minute ie
engine speed per sec = 100 * 60 = 6000rpm
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: frequency counter & generator
Dear Benj.
I am looking at the frequency conter example but it doesn't seem to simulate properly but I sort of know what it is doing.
However I would like to know how to work out the code to count the frequency as follows:
Look at a pin to go high. Start a counter at say 5MHz and stop it when the next pin high condition occurs. Convert the clock ticks to a frequency and display.
Do you have any examples of this in flowcode?
Regds...Jules
I am looking at the frequency conter example but it doesn't seem to simulate properly but I sort of know what it is doing.
However I would like to know how to work out the code to count the frequency as follows:
Look at a pin to go high. Start a counter at say 5MHz and stop it when the next pin high condition occurs. Convert the clock ticks to a frequency and display.
Do you have any examples of this in flowcode?
Regds...Jules
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: frequency counter & generator
Hello Jules
The example may not simulate properly. There is a bug with the timer0 interrupt simulation that means it will sometimes not run correctly. It will however always work correctly onboard the chip. If you ever have any problems check that the clock input for the timer is set to CLKI and not T0CKI. This setting is available inside the timer interrupt enable icon properties.
Ok to do what you are asking would require a little modification to my frequency counting example.
1 ) Clear your count variable
2 ) Loop until pin goes high
3 ) Start the timer running - Low prescalar / high interrupt frequency
4 ) Inside the interrupt routine increment your count variable.
5 ) in your main program loop until pin goes low
6 ) loop until pin goes high
7 ) disable the timer interrupt
8 ) Collect the count variable
9 ) pulse frequency is equal to interrupt frequency / count
10) using floating point maths you can also calculate the period length = 1 / pulse frequency
This method is ok but the method used in my frequency counter example is more precise. This method will only give answers in the range of interrupt frequency / n, where as my example will provide any whole integer frequency count.
The example may not simulate properly. There is a bug with the timer0 interrupt simulation that means it will sometimes not run correctly. It will however always work correctly onboard the chip. If you ever have any problems check that the clock input for the timer is set to CLKI and not T0CKI. This setting is available inside the timer interrupt enable icon properties.
Ok to do what you are asking would require a little modification to my frequency counting example.
1 ) Clear your count variable
2 ) Loop until pin goes high
3 ) Start the timer running - Low prescalar / high interrupt frequency
4 ) Inside the interrupt routine increment your count variable.
5 ) in your main program loop until pin goes low
6 ) loop until pin goes high
7 ) disable the timer interrupt
8 ) Collect the count variable
9 ) pulse frequency is equal to interrupt frequency / count
10) using floating point maths you can also calculate the period length = 1 / pulse frequency
This method is ok but the method used in my frequency counter example is more precise. This method will only give answers in the range of interrupt frequency / n, where as my example will provide any whole integer frequency count.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: frequency counter & generator
Hello
Several examples don't open in the flowcode, besides of the "frequency counter." I have the professional version of the flowcode 3. What should make?
Hugs,
Rudolfo
Several examples don't open in the flowcode, besides of the "frequency counter." I have the professional version of the flowcode 3. What should make?
Hugs,
Rudolfo
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: frequency counter & generator
Hello
Which version of Flowcode are you using PIC, AVR, ARM? Have you tried using the File -> Import feature.
Which version of Flowcode are you using PIC, AVR, ARM? Have you tried using the File -> Import feature.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: frequency counter & generator
uso a versΓ£o profissional flowcode 4, necessito construir um cronometro que conte atΓ© 9,999 segundos, contando de 1 em 1 ms, ou mΓ΅ximo de 10 em 10 ms. Pede me ajudar?
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: frequency counter & generator
veedubmachine & rudolfo
I know original post is well over a year old . If this is too late to help, then maybe it will benefit others who would like to control a MOTOR or two by PWM.
I had a similar requirement to you. i.e I have two EC motors, both require PWM i/p and both have a taco o/p. Flowchart was created by 1st an initial function spec. e.g when I adjust the speed control, an ADC reads pot setting, uses a lookup table to retrieve required RPM, calculate an approximate PWM duty to control both motors. after a set time, port B and timer interrupts are enabled. Two separate Port B interrupts are triggered by both tacos. Port B interrupt is triggered every time a Taco pulse is detected. In my case there was two motors, so two taco pulses. I had to determine which interrupt was fired. Taco count variable was incremented by on a pulse detection. Timer interrupt is set for a low frequency e.g 61Hz, Then you can use a count variable to count +1 every time timer INT macro is triggered, then when count is >60 , 1 second has passed. Then RPM of motor is determined by taco count X 60 (since there is only 1 magnet in the EC motor). At this point , all taco and timer count variable are set to 0 and the whole process is started again.
If after a calculation of rpm, the motor speed requires altering, then it is best for both portB and Timer interrupts to be disabled, calculate if motors are too slow or too fast, adjust PWM, wait for motors settling time, then re-enable both interrupts.
Tested and works on real hardware.
General Advice:
Do not put any delays in interrupt routines, they should be kept as small as possible, so they as exited as fast as possible.
Use a spare pin to output a 1, then 0 for a short period each time a taco pulse is detected, then use a frequency counter and make sure both spare pin and taco detected form the motor are both the same frequencies.
Test a function at a time. E.G make sure PWM is giving correct duty, then when check taco is triggered OK. Make sure PWM is increased when motor is too slow etc.
Use 10 bit PWM not default 8bit
use int variable, not byte to control duty. E.G using with my setup. PIC Clock frequency at 4MHz . In PWM properties: Period register set at 249, Clock source /4 PWM frequency =1KHz
PWM duty is now = Duty variable /10. EG, id you set duty variable with a value of 300, then actual duty from chip PWM = 30%
Hope this will help. Good luck
I know original post is well over a year old . If this is too late to help, then maybe it will benefit others who would like to control a MOTOR or two by PWM.
I had a similar requirement to you. i.e I have two EC motors, both require PWM i/p and both have a taco o/p. Flowchart was created by 1st an initial function spec. e.g when I adjust the speed control, an ADC reads pot setting, uses a lookup table to retrieve required RPM, calculate an approximate PWM duty to control both motors. after a set time, port B and timer interrupts are enabled. Two separate Port B interrupts are triggered by both tacos. Port B interrupt is triggered every time a Taco pulse is detected. In my case there was two motors, so two taco pulses. I had to determine which interrupt was fired. Taco count variable was incremented by on a pulse detection. Timer interrupt is set for a low frequency e.g 61Hz, Then you can use a count variable to count +1 every time timer INT macro is triggered, then when count is >60 , 1 second has passed. Then RPM of motor is determined by taco count X 60 (since there is only 1 magnet in the EC motor). At this point , all taco and timer count variable are set to 0 and the whole process is started again.
If after a calculation of rpm, the motor speed requires altering, then it is best for both portB and Timer interrupts to be disabled, calculate if motors are too slow or too fast, adjust PWM, wait for motors settling time, then re-enable both interrupts.
Tested and works on real hardware.
General Advice:
Do not put any delays in interrupt routines, they should be kept as small as possible, so they as exited as fast as possible.
Use a spare pin to output a 1, then 0 for a short period each time a taco pulse is detected, then use a frequency counter and make sure both spare pin and taco detected form the motor are both the same frequencies.
Test a function at a time. E.G make sure PWM is giving correct duty, then when check taco is triggered OK. Make sure PWM is increased when motor is too slow etc.
Use 10 bit PWM not default 8bit
use int variable, not byte to control duty. E.G using with my setup. PIC Clock frequency at 4MHz . In PWM properties: Period register set at 249, Clock source /4 PWM frequency =1KHz
PWM duty is now = Duty variable /10. EG, id you set duty variable with a value of 300, then actual duty from chip PWM = 30%
Hope this will help. Good luck
Martin