Calculating the time of a positive pulse

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
kirstom14
Posts: 40
Joined: Thu Nov 15, 2007 9:13 am

Calculating the time of a positive pulse

Post by kirstom14 »

I want to build a tachometer. I think that by calculating the time of the positive part of a pulse, I can find the rpm. I was going to use the formula w=rad/s, where w is rev/sec, rad is the angle and s the time. I know the angle and if I can calculate the time I could find the rpm then by w*60sec.
I am new to flowcode. Can you pls tell me how can I do it, I taught of using the PWM, but I don't know how to use it!?

User avatar
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:

Post by Benj »

Hello

If the pulse is occurring every cycle then it may be easier to use a frequency counter program. I have created an example of this which can be downloaded from the following location.

http://www.matrixmultimedia.com/softwar ... ounter.fcf

If you are not using a 19.6608MHz crystal then let me know and I will post the modifications that must be made to allow the counter to work correctly.

kirstom14
Posts: 40
Joined: Thu Nov 15, 2007 9:13 am

Post by kirstom14 »

Yes, the pulse is occurring every cycle, but it is variable, that is the pulse can be more than one in one second. I want to show the speed, so if the speed is high then the pulses will be frequent and if slow the pulse will not be that frequent. I am going to use it as speed detector so the output must be variable, it does not increase with every pulse. The program must show the real speed of a rotating disk.
Currently, I am using the 16MHz.
Thanks very much

User avatar
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:

Post by Benj »

Hello

To allow you to use the 16MHz crystal you will have to make the following changes to the example file.

1. Click on Chip and Clock Speed and set this to 16000000

2. Double click the Enable TMR0 icon in the Main.

3. Click on properties and make sure that the interrupt frequency has updated to 61.0352Hz

4. In the TMR_INT marco change the value in the decision icon to count < 61

This should be all you need to do to get an accurate reading. The only problem may be in you want pulses that are under 1hz. This can be achieved by creating an RPM counter. To do this simply add a second decision icon into the TMR_INT macro which will count seconds up to 60. Be sure to note that this will mean that higher freqency signals will overflow the int variable.

kirstom14
Posts: 40
Joined: Thu Nov 15, 2007 9:13 am

Post by kirstom14 »

Hi Benj,

Sorry for my delayed reply. I did the counter that will count from 0to 60sec and it works ok. But the problem is when I am adding the decision in the TMR_INT macro. The interrupts are still being incremented by 1, but the sec_cont [i.e. the 0sec-60sec] isn't being incremented. I added the decision box before the decision "If count<61 then"

Post Reply