Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 5 months ago. This question has been closed. Reason: Opinion based - no single answer
Ticker freezing
Ticker freezes when a delay (wait) greater than 22mS is introduced in the call back routine, remove the delay and it runs.
This example runs using the LPC1768 mbed.
Same problem with LowPowerTicker
example
#include "mbed.h" //EFM32 DigitalOut seca(PD0); DigitalOut secb(PD1); DigitalOut mina(PD2); DigitalOut minb(PD3); //LPC1768 //DigitalOut seca(p24); //DigitalOut secb(p23); //DigitalOut mina(p22); //DigitalOut minb(p21); DigitalOut myled(LED1); //LowPowerTicker toggleTicker; Ticker toggleTicker; int flipsec; void second_drive(void) { seca=flipsec; secb=!flipsec; wait_ms(30); // adding this delay freezes the MCU seca=0;secb=0; flipsec=!flipsec; myled = !myled; } int main() { toggleTicker.attach(&second_drive, 1.0f); while(1) { //sleep(); } }
Simple solution: Never call wait() from inside an interrupt. It can cause all sorts of problems.
If you want to do something 30ms later set a Timeout to trigger in 30ms and use that.
posted by Andy A 23 Jun 2015Yes you are correct Andy, I generally just set flags in my interrupt call backs and test these in my main program. Particularly with the Freescale targets if using sleep modes. I was using the LPC1768 in the first place that worked then changed targets, I didn't have my thinking head on :)
In case anyone comes here, here's a solution that works with the low power Ticker that drive's a clock mechanism stepping motor, sleep period is around 8uA average:
Working