Go Down

Topic: measuring the time between two interrupts (Read 3053 times) previous topic - next topic



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 ?


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.

Go Up