Getting time since start?

⚠️
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.wsdof.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
4 posts / 0 new
Last post
oren
Offline
Last seen:1 year 7 months ago
Expert
加入:2014-06-28 22:03
Getting time since start?

Hi,
we are using DA14580 SDK 5.0.4.
We need a way to get a global timestamp since start in seconds.
The easy way is to set a timer to run every minute and increase a counter by 60 - and getting an inaccurate measurement (accuracy of minutes).
What if we need the timestamp in accuracy of seconds? Do we need to wake up every second?
有一些注册\我吗mory-address to just read a timestamp (in some units)?
If we just woke up from a timer this would be easy - if the timer is X seconds we would increase the counter by X every time we wake up.
However, we also wake up from a button, and need to get the timestamp.

I see that the systick timer has a a systick_value() function to get the amount of time left, but the systick timer is not recommended for use.
Do the app_easy_timers have a similar "value" function? Getting the amount of time left? This could solve my problem - create a repeating 5 minutes timer to increase a counter, and whenever the button is clicked get the current time from: counter * 5minutes + (5minutes - time_left_to_timer).

Regards,
Oren

Device:
MT_dialog
Offline
Last seen:2 months 3 weeks ago
Staff
加入:2015-06-08 11:34
Hi oren,

Hi oren,

Regarding the systick timer be aware that in order to use the timer the device needs to be awake, if the device goes to sleep the timer will stop counting, regarding the app_easy_timers() they dont have a functionallity where you can check the time that its left in order to elapse. What the 580 has available and you can use (off course this depends on the accurancy that you would like on your timestamp) is the lld_evt_time_get(), this function returns the value of the BASETIMECNT which is a value of the time that the device is up and running in 625us timebase. So by reading this counter you will be able to calculate how long your device is running, so when the device is sleeping when you hit a button and the device wakes up you could just poll that register and convert its timebase into seconds. Also be aware that in order to get a valid value from that register the BLE should be up and running, so read the register in the app_on_ble_powered callback, and not in the timer callback.

Thanks MT_dialog

oren
Offline
Last seen:1 year 7 months ago
Expert
加入:2014-06-28 22:03
Not sure what "time that

Not sure what "time that device is up and running" means.
例如,如果我的程序首先广告for 10 seconds, then stops advertising and goes to sleep (deep-sleep\extended-sleep) for 10 seconds, then wakes up from timer callback and calls: lld_evt_time_get().
Will the value be 32000? (32000 * 625us = 20000000us = 20seconds).

I am also not sure why it mattes if I call it inside app_on_ble_powered callback and not in the easy-timer callback. I also need to be able to call the function when the program is not advertising -
i.e. not advertising in a repeating deep-sleep mode that wakes up every 5 minutes for some calculations and also waits for external wakeups (button). I need to be able to get the exact timestamp when I wake up from the button.

Regards,
Oren

MT_dialog
Offline
Last seen:2 months 3 weeks ago
Staff
加入:2015-06-08 11:34
Hi oren,

Hi oren,

The register that is read by the lld_evt_time_get() is counting as soon as the device boots up your fw, yes the value you should get should be approximatelly 20 seconds.

Regarding why you should place the function in the app_on_ble_powered callback i think that i ve mentioned in my previous post that in order to get a valid value from that register the BLE core needs to be up and running, so in order to ensure that you should place the function in the callback i ve mentioned. If you are using the app_easy_timer() API you should not have an issue, but i assume that you will when the device is waking up via the wake up timer. You can call the function when the device is not advertising, you will just have to wake it up, either through a BLE timer and poll that register or via the wake up interrupt.

Since you are going to use the wake up interrupt, you will have to force the BLE to wake up with the corresponding function arch_ble_force_wakeup(); the problem is that when you do that the BLE wont wake up instantly and in order to ensure that it is awake you will have to place the reading of the register in the mentioned callback. Or if you dont want to do that you can try using the app_easy_wakeup_set() API in order to set the waking up callback. You will be able to find an example in the ble_app_sleepmode on how to use that API.

Thanks MT_dialog