This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2541: Power saving mode setup issue on Simple BLE peripheral example

Part Number: CC2541

Hi,

     I have a custom application built using the Simple BLE peripheral example. It has two main application tasks happening. 

1) The SimpleBLE peripheral task that happens every 5s to advertise.

2) The Custom sensor sampling task that I have setup which happens every 1s.

I would like the system to go to sleep and wake up based on the specific sensor value. I have enabled the power saving option on the preprocessor. And my assumption is that the power saver driver automatically puts the system to sleep when there are no application task/task timers running. Please correct me if I am wrong. 

And hence based on a senor value I am currently turning off the timers for the SimpleBLE peripheral task and custom sensor task. But I do not see the power consumption going down. 

I would to like the device to be in sleep when I stop these tasks and wake up back on an interrupt. I am not currently modifying the Sleep mode registers myself. Is that the right way to proceed or to stick with the power saving driver?

Thanks,

Venkat

  • In SimpleBLEPeripheral example, it defines POWER_SAVING in predefined symbols and it should enter sleeping mode by default when there is nothing to do in your osal task queue. You can define DEBUG_GPIO in predefined symbols and it will use P1_0 to toggle GPO signal when it enters/leaves sleeping mode to check if your device enter sleeping.

  • Hi,

    Venkatraman Balakrishnan said:
    my assumption is that the power saver driver automatically puts the system to sleep when there are no application task/task timers running

    Correct.

    Venkatraman Balakrishnan said:
    wake up back on an interrupt

    Is there an external sensor that will trigger the interrupt?

  • Hi lindh,

                     Thank you for the response.  Yes i re start the application task timers on the external sensor interrupt which should wake up the processor again ?

    But first of all the processor does not go to sleep or low power mode at all when I stop the application task timers. It still looks like the radio is listening every second and I see a spike of 18 mA of current every second.

    Please let me know if I am doing anything wrong or missing anything with the sleep setup.

    Thanks,

    Venkat

  • Hi Chen,

                  Thank you for the advice, it helps to debug the issue better. I enabled the DEBUG_GPIO and connected that pin to a LED. The behavior I am seeing is different. I see the LED being toggled between microseconds with continuous flickers and when I reset the device the LED stops flickering. Both of  this behavior does not make sense to me. It s hard to believe the power saving mode is toggled within micro seconds and once reset power saving mode is not working anymore. Please let me know if there is anything I am doing wrong.

    Thanks again,

    Venkat

  • I would suggest you to revise DEBUG_GPIO related code to make the GPO output high when device enters sleeping and output low when device wakes up. In this way, it’s easier to use scope check how long your device is in sleeping mode.

  • Hi Venkat,

    Venkatraman Balakrishnan said:
    I see a spike of 18 mA

    What are you measuring with? Only the radio will draw this kind of current in TX mode. Sounds like the device is advertising or is in a connection.

  • Yes, I will try that thanks.

  • I am measuring using a power supply with a scope integrated in it. Yes I suspect the same. I too believe the device is either listening or advertising. I am currently reviewing the code to see if I am turning off the radio properly. I will keep you guys posted. 

    Thanks again,

    Venkat

  • Hi guys,

                 I was able to turn off advertising and the 18mA spike stopped. But when I turn advertising back on, I do not see the 18mA spike again. But I can still receive advertisements on other devices. So was the spike due to radio listening and its not turned back on after turn on advertising?

    Also when I shut down timers for all application tasks I still see halsleep() function and timers running every milliseconds and also I see a current draw of 8 mA consistently even when I shut down timers for all tasks and when it is supposed to go to sleep. I am pretty sure the functions HAL_SET_SLEEP_MODE and CLEAR_SLEEP_MODE are called consistently within milli seconds. Is there a way to put the system to deep sleep mode of PM3 whenever I stop the task timers?

    Thanks,

    Venkat

  • Hi Venkat,

    The way the task handler works is if there is no scheduled future events (i.e. software timers, radio events etc) it will enter deep sleep (PM3). You are probably not disabling everything properly. Remember to clear event flags for events when disabling them.

  • Thank you  Joekim. I appreciate the help. I will look into my events and verify the disabling. Also just an additional confirmation.  This is my task array.

    const pTaskEventHandlerFn tasksArr[] =
    {
      LL_ProcessEvent,                                                  // task 0
      Hal_ProcessEvent,                                                 // task 1
      HCI_ProcessEvent,                                                 // task 2
    #if defined ( OSAL_CBTIMER_NUM_TASKS )
      OSAL_CBTIMER_PROCESS_EVENT( osal_CbTimerProcessEvent ),           // task 3
    #endif
      L2CAP_ProcessEvent,                                               // task 4
      GAP_ProcessEvent,                                                 // task 5
      SM_ProcessEvent,                                                  // task 6
      GATT_ProcessEvent,                                                // task 7
      GAPRole_ProcessEvent,                                             // task 8
      GAPBondMgr_ProcessEvent,                                          // task 9
      GATTServApp_ProcessEvent,                                         // task 10
      SimpleBLEPeripheral_ProcessEvent,                                  // task 11
      Sensor_ProcessEvent                                               // task 12
    };

    SimpleBLEPeripeheral ProcessEvent and Sesnor ProcessEvent(task 11 and 12) are the only application tasks and related events I assume I need to turnoff. Do I need to worry about disabling events/timers for the other tasks as well.?

    Thanks again,

    Venkat

  • Hi Venkat,

    Don't worry about any other events from task 10 and below.

  • Hey Joakim,

                         Thank you so much for clarifying that. I figured out what the issue is. Looks like I am disabling the application events properly but for some reason pwrmgr_attribute.pwrmgr_task_state is set to 2 after initialization (it is first initialized to 0 i.e. power conserve and then changed to 2) which means all tasks do not agree for power conserve. And that is why it is never entering the sleep mode. I removed my application tasks and it still happens, so I am sure it is none of application tasks that is setting pwrmgr_attribute.pwrmgr_task_state to 2. Do you have any idea if any of the other init/HAL tasks might do this?? I am not able to debug this issue efficiently. Please let me know if you have any suggestions.

    Thanks again,

    Venkat

  • Hey Joakim,

    To add to the previous message. On further investigation. I figured out that the osal_mem_kick is messing with the pwrmgr_attribute.pwrmgr_task_state specifically the line osalMemHdr_t *tmp = osal_mem_alloc(1); And I believe I do not want to mess with this section of the code. 

    Thanks,

    Venkat