Timers are based on 32-bit int microsecond counters, so they can only time up to a maximum of 2^31-1 microseconds i.e. 30 minutes.
That means your Timer code could run into a freeze situation when the timer overflows and your saved 'lasttime' was sampled just before the overflow occurred.
The main code in your second example may not run as expected because it may finish and stop.
int main() {
//initialization procedures
rc.attach(&rx,0.02); // 20ms ticker
t.attach(&FlightControl,0.005); // 5ms ticker
}
Try this instead:
int main() {
//initialization procedures
rc.attach(&rx,0.02); // 20ms ticker
t.attach(&FlightControl,0.005); // 5ms ticker
while (1) {}; // endless loop
}
Also note that things go wrong when the called functions take longer than the tickerrate
Could getcmd() take longer than 20ms to complete?
The two functions might also interfere: the 5ms call overlaps with the 20ms interrupt every so often.
Hello Everyone
I'm having trouble with sampling PPM signals properly. I'm already sampling my sensors at a 5ms rate using a ticker and there is no problem with that, but sampling PPM signals at that rate allows noise to massively disrupt my signals so i thought i'd create another ticker to sample it at 50Hz but after modifying my code to do that i found out that it's sampled at the same rate as my sensors although it has a different ticker with a different interrupt rate. so i had another idea to use a timer in a while loop and update both methods accordingly. This worked..... but after a while my mbed freezes.
so could someone tell me what i'm doing wrong
My code with Timer :
my Code With Ticker :