Why is the ticker not ticking?

13 Oct 2010 . Edited: 13 Oct 2010

A found something what looks like a bug, but maybe i'm missing something.
Could somebody please look to the code and tell me why my attached functions are never fired?

 

 

#include "mbed.h"
#include "TextLCD.h"
#include "EthernetNetIf.h"
#include "NTPClient.h"

Ticker NTPTimer, RTCTimer;
EthernetNetIf eth;
NTPClient ntp;

DigitalOut myled1(LED1), myled4(LED4);
TextLCD lcd(p24, p25, p26, p27, p28, p29, TextLCD::LCD20x2); // rs, e, d0, d1, d2, d3

time_t epoch;
uint32_t timediff = (60*60*2);

void RTCThick() {
    myled1 = !myled1;

    lcd.cls();
    epoch = time(NULL) + timediff;
    lcd.printf("Current time is: %s", ctime(&epoch));
}

void NtpThick() {
    Host ntpserver(IpAddr(), 123, "time.xs4all.nl");
    ntp.setTime(ntpserver);
}

int main() {
    wait(1);
    lcd.cls();

    lcd.printf("MBED Started");

    eth.setup();

    NtpThick();
    RTCThick();

    NTPTimer.attach(&NtpThick, (60*60*6));
    RTCTimer.attach(&RTCThick, 1);

    while (1) {
        wait(1);
        myled4 = !myled4;
    }
}

 

 

RTCThick should be invoked every second. But led1 never blinks (goes to on due to RTCThick() in the main and stays on).
I also added a while (1) loop, with a change on led4 as could imagine that I was'nt creating enough IRQs.

 

Thankx in advance.

14 Oct 2010

Hi Henry,

try "RTCTimer.attach(&RTCThick, 1.0)" or "...(..., 1f)".
Accordingly for the second timer try "NTPTimer.attach(&NtpThick, (float)(60*60*6))"

Best regards
Nenad

15 Oct 2010

I tested this, but does'nt work.

I did some more research and what I found is when I use only 1 ticker it is working.
But when I use 2 (or more?) it isnt working anymore.

15 Oct 2010

Ok, i just did a test myself with the following small program:

#include "mbed.h"

DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
DigitalOut myled3(LED3);
DigitalOut myled4(LED4);

Ticker tick1;
Ticker tick2;
Ticker tick3;
Ticker tick4;

void tick1_func(void) {
    myled1 = !myled1;
}

void tick2_func(void) {
    myled2 = !myled2;
}

void tick3_func(void) {
    myled3 = !myled3;
}

void tick4_func(void) {
    myled4 = !myled4;
}

int main() {
    tick1.attach(&tick1_func, 2.0);
    tick2.attach(&tick2_func, 1.0);
    tick3.attach(&tick3_func, 0.5);
    tick4.attach(&tick4_func, 0.25);
    while(1) {
    }
}

This works without any problems on my mbed. So the number of ticker objects is certainly not the issue. I can only assume that some of the additional libraries you are using may interact with the ticker somehow. Or maybe the interval-value of your NTPTimer is just too large (60 * 60 * 6 = 21600 seconds) for ticker objects and is then disturbing also the function of RTCTimer (all ticker objects share one LPC1768-Hardware-Timer: Timer3).

Best regards
Nenad