⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.xmece.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
6 posts / 0 new
Last post
DavidW
Offline
Last seen:2 years 5 months ago
Joined:2017-11-17 08:35
BLE-Timer

Hello Dialog,

I'm continuing work on an application based on the ble_app_peripheral example. I did a few current measurements and have a few questions about the ble-timer.
In my application i want to sample with different frequences. For example every 40 ms. After one second i want to send it to the computer.
The code works and i get the right values.
If there is a connection intervall, sometimes the timer for the adc measurement interrupt early than expected. On the picture you can see the issue. Actually the adc measuement should be after the connection event, but it is 10 seconds earlier. After that the time between to measurements is right again. This happens a few times and thats the reason why i get more values in a second that i want.
Do you have any idea how i can solve this problem.

And another question: What is the resolution of an timer interval? Is there a possibility to get an interval of for example 65ms. At the moment i have only a resolution of 10ms. It's important for me to work with the ble-timer because between two measurements a want to sleep.

Regards
David

Attachment:
Device:
MT_dialog
Offline
Last seen:2 months 3 days ago
Staff
Joined:2015-06-08 11:34
Hi DavidW,

Hi DavidW,

Well the ble timer have an accurancy of 10 ms and this is a minimum interval that you can set, so no you cannot have a timer of 65ms. Regarding the fact that the timer will trigger sometimes a bit earlier, like 10 ms or less this is observed in two cases:

  1. Either the ble timer is set during an asyncronous event, for example at time t the expiration will happen at t-10ms to t. The reason for that is because the kernel timer is based on the BLE_GROSSTGTIM timer, which has a precesion of 10 ms. That means that the kernel timer can count ticks based on the BLE_GROSSTGTIM and timers initiated in between the period of 2 ticks will not be accurate.
  2. A timer can expire one tick earlier, when another timer expires on that tick, due to stack design.

But on the screenshot that you have attached it seems that what you are indicating is not a kernel timer (the second activity that you have marked as m2) this seems to be a connection event, and not a wake up due to a timer event.

Thanks MT_dialog

DavidW
Offline
Last seen:2 years 5 months ago
Joined:2017-11-17 08:35
Hi MT_dialog,

Hi MT_dialog,

thanks for the quick response.
Yes you're right with the connection event at M2.
So if I understood you correctly in my case the timer is set during an asyncronous event and cause of that i have this inaccuracy. Do you have any idea or is there a possibility to wait a time that i can set the timer not between two ticks?

这个问题只发生如果有连接电动汽车ent near the adc measurement. If you say the connection event has nothing to do with the kernel timer, why doesn't the wake up(adc measurement) happens directly after the connection event?

Regards

David

MT_dialog
Offline
Last seen:2 months 3 days ago
Staff
Joined:2015-06-08 11:34
Hi DavidW,

Hi DavidW,

Actually what you are experiencing is mostly the second point i ve mentioned, the expiry of a timer is quite identical with a connection event (they both are events from the BLE core), i mean that if the timer happens to co-exist with a connection interval at some point the stack will execute both while the device is awake but in your case the connection interval occurs and the timer will go of in approximatelly 10 ms, so the scheduler will execute again both in order not to waste power in order to wake up again in order to execute the callback.

Thanks MT_dialog

DavidW
Offline
Last seen:2 years 5 months ago
Joined:2017-11-17 08:35
Hi MT_dialog,

Hi MT_dialog,

okay. thanks for the good answer.
Is there a possibility to get the ble-timer from the connection intervall. Then i know if my adc and connection event timer will interrupt at the same time.
I prefer to do the measurement after the connection event, so i want to set the timer delay to x+1.

Regards,

DavidW

MT_dialog
Offline
Last seen:2 months 3 days ago
Staff
Joined:2015-06-08 11:34
Hi DavidW,

Hi DavidW,

我不了解的一种方式avoid this from happening, even if you provide a value which is not a direct multiple of the connection interval, in time this event will eventually occur. An idea would also be to perform the adc measurement right after the connection interval by catching the BLE_EVT_END of each connection interval without using a timer. Please check the beacon implementation for catching the specific event in the user_on_ble_powered(), but this implementation will limit your sampling period on your connection interval.

Thanks MT_dialog