Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Combination of ble_beacon and timer examples results in rapidly toggling LEDs

Hi everyone,

I'm trying to implement a simple bluetooth beacon which broadcasts / advertises the number of button presses and the time in seconds after the last button press.

So far I managed to combine (using copy and paste, and fixing missing #include's) the ble_peripheral/ble_beacon and peripheral/pin_change_int examples to count the button presses and use advertisement messages to broadcast the counter.

I'm currently stuck at integrating the peripheral/timer example (to measure the time since the last button press): when I copy the code of the example into my existing approach, the LEDs were lit at all times. When I attached an oscilloscope I noticed that the LEDs were toggled in rapid succession (for the first integration I aim for 1s intervalls). As suggested in this post I switched the used timer to TIMER1 and later TIMER2 but to no avail (I think I have configured them properly in the sdk_config.h header).

I'm using the PCA10040 board, SDK v15.0.0, and SoftDevice S132 v6.0.

Are there any pointers about what goes wrong?

Best,

lhochstetter

Parents
  • I assume there are many ways this can be done, but the simplest may just be to setup a app_timer with 5ms tick and increment a global counter. Then the button handler may just check the counter each time a GPIO change value, and thereby you also know how long it was pressed or released.  Using a 5ms tick will make sure the accuracy of the button press is <10ms. You may increase or decrease the wakeup tick for better accuracy. There are other ways of doing this, but for instance using a TIMER will keep the HFCLK on, which will cause considerably higher current consumption.

Reply
  • I assume there are many ways this can be done, but the simplest may just be to setup a app_timer with 5ms tick and increment a global counter. Then the button handler may just check the counter each time a GPIO change value, and thereby you also know how long it was pressed or released.  Using a 5ms tick will make sure the accuracy of the button press is <10ms. You may increase or decrease the wakeup tick for better accuracy. There are other ways of doing this, but for instance using a TIMER will keep the HFCLK on, which will cause considerably higher current consumption.

Children
Related