RPM COUNTER

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

Moderators: Benj, Mods

Post Reply
rotlen
Posts: 11
Joined: Wed Oct 03, 2007 8:00 pm
Contact:

RPM COUNTER

Post by rotlen »

i need to create a RPM counter for the bike, anybody has any example in flowcode?

thanks :D

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 »

The best way to do this is to start the timer0 interrupt with a fairly low interrupt frequency.

Then use an int variable to count the interrupts. Using the interrupt frequency you can calculate how many timer0 interrupts occur in a minute.

While the timer0 is counting you can count pulses in your main program to detect the revolutions on the wheel. Each time that a minute has occured you will need to display the revs and then reset the rev counter.

To get refresh rates of less then 1 minute you can count say a second of timer0 interrupts and then times that value by 60.

rotlen
Posts: 11
Joined: Wed Oct 03, 2007 8:00 pm
Contact:

Post by rotlen »

Thanks Benj, but the algoritm is simple
RPM = RPS * 60

but i have 3 problems when de program run in the Pic 16F648A

1 Problem
Im determine the clk Freq TMR0 inf 76hz (1sec = 76) but in the pic the run too fast ..!!

Image

2 Problem
when TMR0 interrupt im disabled while calc the RPS and RPM. and enabled when finish, this is correct?

Image

3 Problem
Im conected a reed switch to RB0/INT and i have a problem with the edge, im use a Flag to not count until the edge change to 0 to 1 and not count when the RB0 mainteined a 1, but in simulate run ok , but in the micro no.!

Image


Thanks :D

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

1) Do your clock settings in Flowcode match your hardware crystal speed.

2) You should not have to disable the timer interrupt. Every time you disable and re-enable the interrupt you will gain time as the timer0 is reset every time it is enabled.

3) Are you sure that your hardware is working as expected. Remember that you need either a pull up or pull down resistor so that the I/O pin is not floating when the switch is not active.

rotlen
Posts: 11
Joined: Wed Oct 03, 2007 8:00 pm
Contact:

Post by rotlen »

Benj thank you.

Could you post a simple demo with TMR0 INT
Clock 10Mhz HS
Time Int 1 sec

Thank you

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

I have posted an example here.

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

You cannot acheive an exact devision into a second when using the 10MHz crystal.

current second delay = 1.147 seconds

If you need an exact second measurement then you will have to use a timing crystal such as 32KHz or 19.6608MHz to allow the interrupt to devide exactly into a multiple of 1Hz.

rotlen
Posts: 11
Joined: Wed Oct 03, 2007 8:00 pm
Contact:

Post by rotlen »

Thank you benj, the problem was the Watch Dog... :D

but now i have a new problem, i need to use TMR0 and RS232 Tx, and if WDTE is enabled dont run the rs232 and if WDTE is disabled dont run TMR0.

what can i do? :shock:

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 Rotlen

Both the RS232 and the TMR0 should run when the watchdog is disabled. If you are haiving problems then please send me your program and I will take a look for you.

rotlen
Posts: 11
Joined: Wed Oct 03, 2007 8:00 pm
Contact:

Post by rotlen »

Benj the problem is in TMR0.clock source select .!!

sorry :(

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 »

Ah brilliant so it is.

Glad you have it sorted now.

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

Post by kirstom14 »

Hi,
I want to create a rpm counter for an anemometer, and then i must convert the rpm to m/s. I am using a 16F877A microprocessor. Can you tell how how I can do it using Flowcode? Thanks

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 Kirstom14

Have you had a look at the above flowcode example program.

arnaud
Posts: 5
Joined: Wed Dec 05, 2007 10:59 pm
Contact:

Post by arnaud »

quote="Benj"]Hello Kirstom14

Hi Benj,
I try to write in good english. But sorry for difficulties to read me.
I made a little prog with timer0 overflow , i can to generate the C program. But when i want to try my prog in picmicro V3, it doesn't work ....
i don't know why and i don't see why too.

Could you help me, please.

I would like to send you my flowcode prog but how?

:roll:

Thanks

arnaud
Return code = 1 Have you had a look at the above flowcode example program.[/quote]

    User avatar
    Steve
    Matrix Staff
    Posts: 3427
    Joined: Tue Jan 03, 2006 3:59 pm
    Has thanked: 114 times
    Been thanked: 422 times
    Contact:

    Post by Steve »

    Hello Arnaud,

    Please paste the "compiler messages" error text in a message on this forum and we'll have a look.

    arnaud
    Posts: 5
    Joined: Wed Dec 05, 2007 10:59 pm
    Contact:

    my project

    Post by arnaud »

    Hello Steve,
    My file is converted but when I transfer it, it doesn't work on the picmicro V3;

    Could I send you my file or printscreans of my program?

    Thanks

    Arnaud

    User avatar
    Steve
    Matrix Staff
    Posts: 3427
    Joined: Tue Jan 03, 2006 3:59 pm
    Has thanked: 114 times
    Been thanked: 422 times
    Contact:

    Post by Steve »

    We can't really offer support for your own programs. Have you been able to send a very simple program to your chip?

    Common errors when programs don't run on the chip are:
    * inappropriate configuration options, especially the clock setting and WDT
    * wrong timing calculations

    Post Reply