Hey - first time posting. It has been a while since doing any micro-controller stuff and the teensy4 has so much power I am in awe. 600Mhz!! zoinkers so amazing.
1) Is it OK to modify the elapsedMicros in an interrupt?
I used to have it within the interrupt but then wasn't sure about "volatile" and if I could change the value inside the interrupt.
My current code is attached. It is an optical tach good for RPM's from 500-3500RPM with one pulse per revolution...
2) how much code is "ok" to put in the interrupt?
I used to have most of the RPM calculation in the interrupt(and moved it to the first IF statement in my loop), but had some other issues and moved it out when I was trying to figure it out. But I think the code would look cleaner if I could just do the RPM calculation in the interrupt-- so if it is OK to modify elapsedMicros inside of the Interrupt.
So the pseudo code is something like:
Interrupt_on_Falling edge { set a flag saying saw the interrupt}
loop {
is flag set and debounced?
- use elapsedMicros to find difference from last time
- set elapsedMIcros back to zero
- calc RPM
- reset flag
DisplayEverySoOften
- send average of RPM's since last display to the display
}
I do have some code to wait 250uS as a "debounce"-- but I don't think I actually need it anymore so may take it out.
Anyway, the real question I have is if it is OK to reset the elapsedMicros within an interrupt or if that would be bad. And if it is ok, should I move the RPM calculation stuff into the interrupt as well.
Thank you!
Lincoln
1) Is it OK to modify the elapsedMicros in an interrupt?
I used to have it within the interrupt but then wasn't sure about "volatile" and if I could change the value inside the interrupt.
My current code is attached. It is an optical tach good for RPM's from 500-3500RPM with one pulse per revolution...
2) how much code is "ok" to put in the interrupt?
I used to have most of the RPM calculation in the interrupt(and moved it to the first IF statement in my loop), but had some other issues and moved it out when I was trying to figure it out. But I think the code would look cleaner if I could just do the RPM calculation in the interrupt-- so if it is OK to modify elapsedMicros inside of the Interrupt.
So the pseudo code is something like:
Interrupt_on_Falling edge { set a flag saying saw the interrupt}
loop {
is flag set and debounced?
- use elapsedMicros to find difference from last time
- set elapsedMIcros back to zero
- calc RPM
- reset flag
DisplayEverySoOften
- send average of RPM's since last display to the display
}
I do have some code to wait 250uS as a "debounce"-- but I don't think I actually need it anymore so may take it out.
Anyway, the real question I have is if it is OK to reset the elapsedMicros within an interrupt or if that would be bad. And if it is ok, should I move the RPM calculation stuff into the interrupt as well.
Thank you!
Lincoln