10 years, 2 months ago.

nRF51822 Ticker

Hi,

I'm working with nRF51822-EK and I want to use Tickers in my project. When i'm using only one ticker then it works fine. But when I'm using two tickers then my program hang after executing first ticker callback. Here is example code:

#include "mbed.h"

DigitalOut led1(LED1);
DigitalOut led2(LED2);

void periodicCallback1(void)
{
    led1 = !led1;
}

void periodicCallback2(void)
{
    led2 = !led2;
}

int main()
{
    led1 = 0;
    led2 = 0;
    Ticker ticker_led1;
    ticker_led1.attach(periodicCallback1, 1);
    Ticker ticker_led2;
    ticker_led2.attach(periodicCallback2, 1);

    while(1);
}

It seems that my prevous question was related to ticker problem issue because I have in my program one ticker and one more ticker was used by PinDetect. Is there a way to fix tickers code?

If I create tickers outside of main then it works fine and don't hang.

posted by Nikita Polotnyanko 30 Aug 2014

Getting problems here also when I have more than 2 Tickers. See code below. Note: I am not using one of the published nRF51822 platforms at the moment. My board has no mbed interface. Programming is done through SWD. The board does have a lot of LEDs which have been tested and work fine.

#include "mbed.h"

//Ticker test

DigitalOut heartbeatLED(P0_28);

DigitalOut buz(P0_29);

DigitalOut led0_7(P0_7);
DigitalOut led0_8(P0_8);
DigitalOut led0_9(P0_9);
DigitalOut led0_10(P0_10);
DigitalOut led0_11(P0_11);
DigitalOut led0_12(P0_12);
DigitalOut led0_13(P0_13);
DigitalOut led0_14(P0_14);
DigitalOut led0_15(P0_15);
DigitalOut led0_16(P0_16);

Ticker t1;
void tick1() {
  led0_7 = !led0_7;
}

Ticker t2;
void tick2() {
  led0_8 = !led0_8;
}


Ticker t3;
void tick3() {
  led0_9 = !led0_9;
}

int main(void)
{ 
   t1.attach(&tick1, 0.1);   // Ok
   t2.attach(&tick2, 0.5);   // Sofar so good..

   //t3.attach(&tick3, 0.9); // Adding this ticker will result in crash
   //t3.attach(&tick3, 2.5); // Adding this ticker will also result in crash after about 2.5s
   t3.attach(&tick3, 5.0); // Adding this ticker will also result in crash after about 5s
         
  while (1) {
    led0_16=1;
    wait(0.1);
    led0_16=0; 
    wait(0.4);          
  }
}
posted by Wim Huiskamp 07 Oct 2014
Be the first to answer this question.