Pages: [1]   Go Down
Author Topic: measuring the time between two interrupts  (Read 1709 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


i want to design the speedometer but i have some problems.first; i don't know how to measure the time  in two interrupts.Which functions is useful my project.I read some sites.They says "you should use detach interrupt for two interrupts in same function".  What's yours idea ?

Manchester (England England)
Offline Offline
Brattain Member
Karma: 634
Posts: 34541
Solder is electric glue
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What's yours idea
On each call into the ISR read the millis() timer and put it into a variable. On odd calls put it into one variable and on even calls put it into another variable.
Then in the main routine subtract the two variables to give you the time.

You should have a counter that is incremented on each ISR call then the least significant bit is the odd / even indicator. You should also have a flag that shows two readings have been taken. The main routine will only do the subtraction once this flag is set. After the subtraction the flag should be cleared. The ISR will, as it's first task, check the flag and exit immediately if this flag is set.

Don't bother with the detach interrupts especially inside an ISR. The millis() timer does not advance inside an ISR.

Pages: [1]   Go Up
Jump to: