Sleep wake using BLE timer

Learn MoreFAQsTutorials

9个帖子/ 0新
Last post
巴拉吉
Offline
Last seen:1个月10小时前
Joined:2019-12-06 06:48
Sleep wake using BLE timer

Hi,

I'm using USB development kit , To minimize power consumption we are trying to incorporate one of sleep modes from following link

http://lpccs-docs.dialog-semiconductor.com/DA14531_Sleep_Mode+/introduct...

My requiremets are,

1.在每100毫秒循环中,它应该睡50毫秒。(剩下50毫秒,它将DO读取和更新到BLE)

2. ThroughBLE timerit should wake up.

Can you provide me some example with above constraints.

Thanks in advance

Balaji.

MHv_Dialog
Offline
Last seen:1 week 5 days ago
Staff
Joined:2013-12-06 15:10
嗨巴拉吉,

嗨巴拉吉,

The SDK6 manages sleepmode after you select one of threee different modes. In your case the optimal mode will be extended sleep. When this mode is set (as per the Sleepmode Tutorial) the device will automatically wake up to perform any BLE transactions - you will not have to do anything in your code to ensure proper BLE wakeups.

As far as your regular ADC activity, you have the option to either use the app_easy_timer to trigger readings or you can tie your ADC reads to the tail of every BLE event. You can find instructions on how to use the app_easy_timer here:http://lpccs-docs.dialog-semiciondiond.com/tutorial_sdk6/timer.html.

Tying the ADC readings to the end of every BLE event can be slightly more energy efficient because it limits the amount of wakeups. You can define a macro function in your main header file such as user_myproj.h:

#define DLG_EVENT_HANDLER_EXIT() (ble_event_ended())

In this file also add a prototype to the function:

void ble_event_ended(void);

Finally in user_myproj.c, implement your ADC read in this function.

I hope this helps.

/MHv

巴拉吉
Offline
Last seen:1个月10小时前
Joined:2019-12-06 06:48
Hi MHv,

Hi MHv,

Thanks for your quick reply , i will try to look into it , just a follow up query I need to acheive same adc operation for every 100 ms when BLE isnot connected.My advertising interval is 687.5ms and advertising timeout is 3 mins.The advertising cycle restarts only if user press a push button,till then the radio should remain off. Is is it possible to go with "Extended sleep" if BLE is connected as you mentioned above and "沉睡" when BLE is not connected.Any alternate suggestion for the same.

Thanks in advance!

Br,

BALAJI.

MHv_Dialog
Offline
Last seen:1 week 5 days ago
Staff
Joined:2013-12-06 15:10
嗨巴拉吉,

嗨巴拉吉,

这使得你app_easy_timer easiest one to implement. Extended sleep is the lowest power solution for a device that needs to wake up every 100ms (to perform the ADC readings in your case). Waking up from deep sleep requires additional energy for every wakeup in order to copy from OTP to RAM foir execution. If your application code is in flash, then deep sleep would only be useful for sleep duration of days or weeks.

And remember that sleep is managed by the SDK. The device will go to sleep unless:

  1. The Bluetooth radio needs to be active
  2. The default sleep mode is set to ARCH_SLEEP_OFF
  3. Your application is active doing something (such as reading the ADC)
  4. 这么快就下一个预定的事件发生,释放埃拉gy would be wasted by going to sleep

/MHv

巴拉吉
Offline
Last seen:1个月10小时前
Joined:2019-12-06 06:48
Hi MHv,

Hi MHv,

我拍了BLE_APP_SLEEPMODE项目,并配置了APP_EASY TIMERuser_sleepmode.c

void user_app_adv_undirect_complete(uint8_t status) { app_awake_timer_used = EASY_TIMER_INVALID_TIMER; // Disable wakeup for BLE and timer events. Only external (GPIO) wakeup events can wakeup processor. if (status == GAP_ERR_CANCELED) { #ifdef GPIO_WAKE arch_ble_ext_wakeup_on(); // Configure wakeup button app_button_enable(); #endif #ifdef BLE_TIMER_WAKE arch_ble_ext_wakeup_off(); ble_timer_wake(); #endif } }

Inside this ble_timer_wake()

static void ble_timer_wake(void) { app_easy_wakeup_set(app_wakeup_cb); if(!app_awake_timer_used) { app_awake_timer_used = app_easy_timer(APP_WAKE_UP_TIMER,app_ble_wkp_cb); GPIO_SetActive(GPIO_LED_PORT,GPIO_LED_PIN);// to check whether sleep is working I turned on led } } // BLE TIMER CALLBACK FUNCTION static void app_ble_wkp_cb(void) { #if !defined (__DA14531__) if (GetBits16(SYS_STAT_REG, PER_IS_DOWN)) #endif { periph_init(); } if (!arch_ble_ext_wakeup_get()) { arch_set_sleep_mode(app_default_sleep_mode); arch_ble_force_wakeup(); arch_ble_ext_wakeup_off(); app_easy_wakeup(); GPIO_SetInactive(GPIO_LED_PORT,GPIO_LED_PIN); // TURNED OFF LED AFTER WAKEUP } }

I made ble adv timeout of 5 sec , sleep time is 10 sec , and after wakeup. It worked as expected.

Now I have a user application task which is configured in following user_app_callback

.app_on_set_dev_config_complete = user_on_set_dev_config_complete

创建的功能原型和定义如下

void user_on_set_dev_config_complete(void); void user_on_set_dev_config_complete() { // configure a user ble timer user_app_timer_used = app_easy_timer(USER_APP_TIMER, user_app_timer_cb); // 1 second timer default_app_on_set_dev_config_complete(); } // In callback I'm toggling a gpio for every 1 sec static void user_app_timer_cb() { if(usr_adv_flag == 0) { GPIO_SetActive(GPIO_LED_PORT,GPIO_LED_PIN); // this pin is different from LED pin usr_adv_flag = 1; // arch_printf(" Led On \n"); } else { GPIO_SetInactive(GPIO_LED_PORT,GPIO_LED_PIN); usr_adv_flag = 0; // arch_printf("Led Off \n"); } }

My concern is if app is advertising there is a delay in execution of above task , but when ble is in exteneded sleep it woks as expected.What might be the possible mistake.

I need to know how sleep is acheived once adv is stopped,从下面的片段中推荐。

static void adv_data_update_timer_cb() { // If mnd_data_index has MSB set, manufacturer data is stored in scan response uint8_t *mnf_data_storage = (mnf_data_index & 0x80) ? stored_scan_rsp_data : stored_adv_data; // Update manufacturer data mnf_data_update(); // Update the selected fields of the advertising data (manufacturer data) memcpy(mnf_data_storage + (mnf_data_index & 0x7F), &mnf_data, sizeof(struct mnf_specific_data_ad_structure)); // Update advertising data on the fly app_easy_gap_update_adv_data(stored_adv_data, stored_adv_data_len, stored_scan_rsp_data, stored_scan_rsp_data_len); // Stop advertising air operation - a button press will wake-up the system app_easy_gap_advertise_stop(); }

1 . How the main loop set sleep mode ?

2. where BLE_APP_PRESENT is disabled for app to enter sleep ?

Thanks in advance,

Br,

Balaji.

MHv_Dialog
Offline
Last seen:1 week 5 days ago
Staff
Joined:2013-12-06 15:10
Hi Belaji,

Hi Belaji,

Bluetooth activity has higher priority than any of your user application. This means that sometimes your app_easy_timer will trigger a little later. The only way to acheieve near realtime execution is to stop all Bluetooth LE activity (no advertising, no connections).

The sleep implementation is the most complex part of the SDK, and is completely abstracted from the user for that reason. It is beyond the scope of the forum to explain the intricate details of this. As mentioned in the previous reply, all you need to know about sleep is that you can set the default mode of operation and the device will sleep when it can. Please take a look at the "getting Started with SDK6" tutorial I referred to earlier. In that tutorial you can find everything you need to know about sleep mode.

undefining ble_app_present仅在gtl模式(您不是)中使用的设备时相关,因此请留下。

/MHv

巴拉吉
Offline
Last seen:1个月10小时前
Joined:2019-12-06 06:48
Hi MHv,

Hi MHv,

Thanks for your detailed response. As you said when there is no advertisment or app not connected. The user application is executed as expected.But Our product requirements are not met. My mail id :巴拉吉.s@pmsind.com. I can share our requirements , After 4 months of development we got stuck up here. We need support in slight modification of SDK . we are forced to change our BLE module, if this issue is not resolved. Till now your product is awesome , keep in mind we have our smartcane product ( for which we opted for ble design using da14531) sold 100K units so far. Kindly consider my request and revert back at earliest.

Thanks in advance

Br

Balaji

巴拉吉
Offline
Last seen:1个月10小时前
Joined:2019-12-06 06:48
Hi MHv,

Hi MHv,

When I set sleep mode as

static const sleep_state_t app_default_sleep_mode = ARCH_EXT_SLEEP_ON;

in user_config.h and project file isble_sleepmode projectfrom SDK.

After timeout it entered sleep (asPD_SYS is Off), as mentioned in documentation we can use multiple option for wakeup so I prefered BLE timer

我在user_app_callbacks内配置了一个ble timer

static const struct app_callbacks user_app_callbacks = { .app_on_set_dev_config_complete = user_on_set_dev_config_complete, }; void user_on_set_dev_config_complete() { app_easy_wakeup_set(app_wakeup_cb); app_awake_timer_used = app_easy_timer(APP_WAKE_UP_TIMER,app_ble_wkp_cb); // after 5 sec wakeup default_app_on_set_dev_config_complete(); }

Device goes to sleep but didnt wake up from sleep. How to wake up using RTC / Timer 1 / BLE Timer . share me a small snippet for the same.

Does user app timers are cancelled when device enter sleep ?

Thanks in advance

Br,

BALAJI

PM_Dialog
Offline
Last seen:12 hours 3 min ago
Staff
Joined:2018-02-08 11:03
嗨巴拉吉,

嗨巴拉吉,

I read the whole conversation and regarding this statement:

>>当BLE未连接时,我需要为每100毫秒达到相同的ADC操作。我的广告间隔是687.5ms,广告超时是3分钟。

当设备配置为扩展睡眠模式时,它将在间隔(广告或连接间隔)之间睡眠。在睡眠模式下,所有外围域都断电,以便系统消耗较低的功率。因此,如果系统处于扩展睡眠模式,这意味着不可能使用包括ADC的任何外围块。

As MHv_Dialog mentioned, in order to wake-it up periodically, the app_easy_timer() should be used. This API is using the BLE timer, so it is valid in extended sleep mode. Can you please check if the callback registered in the app_easy_timer() is getting triggred?

>>> Device goes to sleep but didnt wake up from sleep. How to wake up using RTC / Timer 1 / BLE Timer .

Which is the sleep mode? Is it the extended sleep?

Thanks, PM_Dialog