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.
10 years, 11 months ago.
Ticker stops working?
I am using a program which uses a ticker to call a function every second, I've noticed a problem that it stops working after a few hours. For example in this simple program led2 stops working after a few hours but led1 still flashes when the button is pressed:
#include "mbed.h"
DigitalOut led(PC_10);
DigitalOut led2(PC_12);
DigitalIn butPush(PB_2);
Ticker led1on;
Timeout led1off;
Timeout to1;
Timeout to2;
void routine(int x, float y)
{
for(int i = 0; i <= x; i++)
{
led = 1;
wait(y);
led = 0;
wait(y);
}
}
void led1off_cb(void)
{
led2 = 0;
}
void led1on_cb(void)
{
led2 = 1;
led1off.detach();
led1off.attach(&led1off_cb, 0.05);
}
int main()
{
led2 = 1;
led1off.attach(&led1on_cb, 0.05);
led1on.attach(&led1on_cb, 1);
while(1)
{
if(butPush.read() == 0)
{
routine(10, 0.2);
}
}
}
I've tested it in different programs with the same results, I've seen reference to using RTC for long intervals but does that apply to calling every second for a long time? I'm using the Nucleo F401 and have updated all the libraries, is there a problem for these timing routines for this board?
1 Answer
10 years, 11 months ago.
The problem is you updated all your libraries ;).
Option 1: Downgrade mbed lib two versions (IIRC to 89). You can do this from the revision window.
Option 2: Remove your mbed library and import mbed-src (http://developer.mbed.org/users/mbed_official/code/mbed-src/).
In the most recent mbed version a bug was introduced in the Ticker code. This bug has been fixed since then (which is why it works fine in the mbed-src), in the next mbed version it will be fixed again.