4 years, 3 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();
    }
}


Question relating to:

Silicon Labs' EFM32™ Wonder Gecko ARM® Cortex®-M4 based 32-bit microcontrollers (MCUs) provide flash memory configurations up to 256 kB, 32 kB of RAM and CPU speeds up to 48 MHz, ...

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 2015

Yes 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

LowPowerTicker toggleTicker;

int flipsec,triggerdrive;

void second_drive() {
    seca=flipsec;
    secb=!flipsec;    
    wait_ms(30);      
    seca=0;secb=0;  
    flipsec=!flipsec;
    //myled = !myled;  // removed to reduce power
    triggerdrive=0;
}

void callback()
{
triggerdrive=1; 
}
 
int main() {
    
    toggleTicker.attach(&callback, 1.0f);
    
    while(1){
        
        if(triggerdrive==1){
              second_drive();
              }          
            else{
                sleep();
                }
    }
}

posted by Paul Staron 23 Jun 2015