This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Make the RTC count every 1 ms

Hi everybody! I am here again bothering you with probably silly questions. I have, on my smart beacon kit, an application that uses an ADC and then sends the converted value; i want it convert at 1 kHz, that is to say make the RTC i am currently using count every ms. The problem is that if i put:

APP_TIMER_TICKS(1,0)

as wrote in the example code from which i started, it seems not to respond correctly (i lose samples and at some point it doesn't even sends samples anymore) while from 2 ms and upper, there is no problem. It seems that it has really a problem with 1 ms. I first thought that it could not reach the minimum of 5 ticks required; if i understood correctly, the RTC uses the 32.768 kHz oscillator, so every tick with 0 prescaler should be around 30.5 microseconds and the minimum of 5 ticks should be largely respected! I am a bit confused, can you help me fix this?

main.c

Parents
  • Ok, i don't think you are able to keep 1kHz like that. You are using app_timer with scheduler, and later update BLE characteristics from IRQ - i don't think this is good idea. What I could suggest is to buffer more than one ADC sample, (ex. buffer up to 20 bytes), and then send it, and in the meantime just take samples (and nothing more, to have IRQ as short as possible). And maybe you have to get rid of app timer or at least move it out from scheduler, so it could really keep 1khZ. But still i am not sure you will have your frequency - softdevice has quite large timing overhead...

Reply
  • Ok, i don't think you are able to keep 1kHz like that. You are using app_timer with scheduler, and later update BLE characteristics from IRQ - i don't think this is good idea. What I could suggest is to buffer more than one ADC sample, (ex. buffer up to 20 bytes), and then send it, and in the meantime just take samples (and nothing more, to have IRQ as short as possible). And maybe you have to get rid of app timer or at least move it out from scheduler, so it could really keep 1khZ. But still i am not sure you will have your frequency - softdevice has quite large timing overhead...

Children
No Data
Related