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.

Battery monitoring

Other Parts Discussed in Thread: CC2540, CC2541, TPS62730

Hi, I want to add the battery service to my project. To see how it works I have flashed the keyfob with the demo slave hex and connected it to my iPhone and the battery level characteristic is reported as 22. This is when running power off the debugger. If I remove the debugger and use a battery that hasn't had much use, it also reports 22.

This seems a bit strange and i'm thinking maybe something's wrong with the code and 100% is being reported as 22?

Thanks

  • Hello,

    Did you investigate our battMeasure(..) functions in the KeyFobDemo project? I assume you are referring to the level that is reported as notification if there is any change since the last measurement

    Did you check your battery voltage with respect to the explantion on how the precentage is calculated?

      /**
       * Battery level conversion from ADC to a percentage:
       *
       * The maximum ADC value for the battery voltage level is 511 for a
       * 10-bit conversion.  The ADC value is references vs. 1.25v and
       * this maximum value corresponds to a voltage of 3.75v.
       *
       * For a coin cell battery 3.0v = 100%.  The minimum operating
       * voltage of the CC2540 is 2.0v so 2.0v = 0%.
       *
       * To convert a voltage to an ADC value use:
       *
       *   (v/3)/1.25 * 511 = adc
       *
       * 3.0v = 409 ADC
       * 2.0v = 273 ADC
       *
       * We need to map ADC values from 409-273 to 100%-0%.
       *
       * Normalize the ADC values to zero:
       *
       * 409 - 273 = 136
       *
       * And convert ADC range to percentage range:
       *
       * percent/adc = 100/136 = 25/34
       *
       * Resulting in the final equation, with round:
       *
       * percent = ((adc - 273) * 25) + 33 / 34
       */

    LPRF Rocks the World

  • I am referring to the characteristic value for the battery characteristic.

    The same is reported by the TI iPhone app as 22% battery.

  • I've just received my second mini dev kit (2540) and it seems the 2540 key fob reports 100 correctly as expected, however the 2541 reports 23. This is with both connected to the debugger power.

    Could something be wrong in the 2541 code?

  • I've done more testing and it does seem the CC2541MiniDkDemoSlave.hex on the CC2541 keyfob reports the wrong figure.

    Using the code in my own project, or using the CC2540 versions of hex and hardware report 100.

     

    Can I please also get clarification on 1 thing. If I watch the power level drop from 100 to 99 then 98, then I take the battery out and put it back in, the reporting goes back up to 100. I this meant to happen? Does it take a reference from when it's inserted to measure in future?

     

    Thanks

  • Hi Darren,

    Just a quick thought: The CC2541 Keyfob (reference design here) has a TPS62730 DCDC converter which I suppose could mess up the readings. You can disable it (actually bypass it) by removing the DC_DC_P0_7 define in the KeyfobDemo Project options.

    Best Regards

  • Hi Nick,

    I have just tested it and yes you are correct. Removing that define gives a reading of 100 and not 23.

    Can you please just clarify my other point? Am I right that the battery will read 100 as a reference when first inserted and powered on?

  • Hi Darren,

    Darren Jones1 said:
    Can I please also get clarification on 1 thing. If I watch the power level drop from 100 to 99 then 98, then I take the battery out and put it back in, the reporting goes back up to 100. I this meant to happen? Does it take a reference from when it's inserted to measure in future?

    No, it should reflect amount of capacity left in the battery. 

    Best Regards

  • Ok, maybe the battery just has too much charge at the moment and it may just fluctuate to 98 (I notice in the code it shows worse case scenario).

  • Hi Darren,

    The ADC reads out the voltage at the VDD input pin. This voltage is a function of the internal workings of the battery. For instance, a current draw will make the voltage drop. The more depleted the battery is, the longer it will take to return to its "nominal" voltage level after a current peak, and the voltage will drop lower for a given current draw the more depleted the battery is.

    When you take the battery out and reinsert it, you give it time to do whatever it is batteries do internally with regards to their chemistry.

    See the pulse characteristic on Energizers datasheet on CR2032. http://data.energizer.com/PDFs/cr2032.pdf

    Best regards,
    Aslak 

  • Thank you for that explanation.

    Everything seems to be working fine now that the battery has been drained a bit.

  • Hi,

    I was having the same issue and commenting out the following code (see below) in KeyFobApp_Init does give me the percentage battery level. My question is does this mean that by commenting out we are not using the power saving feature of TPS62730?


    #if defined ( DC_DC_P0_7 )

      // Enable stack to toggle bypass control on TPS62730 (DC/DC converter)
      HCI_EXT_MapPmIoPortCmd( HCI_EXT_PM_IO_PORT_P0, HCI_EXT_PM_IO_PORT_PIN7 );

    #endif // defined ( DC_DC_P0_7 )

    Many thanks,

    Anas

  • Hi Anas,

    By commenting out that you remove the stacks ability to control the DC/DC regulator. Wether the DC/DC is on or in bypass depends on how you have configured P0_7. If you have not done anything to the pin it will be in its default configuration which is input with pull-up and the regulator will thus be on.

    The correct thing to do here would be to let the stack control the regulator, but you must alter the battery monitoring routine so that the regulator is put in bypass mode before reading the battery voltage (and then turned on again when the battery read is completed).

    Cheers,
    Fredrik

  • Hi Fredrik,

    Thanks for your reply. So by commenting out in default configuration the voltage is still regulated by the DC/DC regulator.

    But for a correct solution I should enable stack to toggle bypass control in KeyFobApp_Init() and additionally include this in KeyFobApp_ProcessEvent() where battery level is checked. So can I repeat the same function of toggling bypass control before and after the battery check, for example:


      if ( events & KFD_BATTERY_CHECK_EVT )
      {
        // Restart timer
        if ( BATTERY_CHECK_PERIOD )
        {

    // Toggle the bypass conntrol (DC/DC regulator OFF)

    #if defined ( DC_DC_P0_7 )

      // Enable stack to toggle bypass control on TPS62730 (DC/DC converter)
         HCI_EXT_MapPmIoPortCmd( HCI_EXT_PM_IO_PORT_P0, HCI_EXT_PM_IO_PORT_PIN7 );

    #endif // defined ( DC_DC_P0_7 )


          osal_start_timerEx( keyfobapp_TaskID, KFD_BATTERY_CHECK_EVT, BATTERY_CHECK_PERIOD );
        }

        // perform battery level check
        Batt_MeasLevel( );

    // Toggle the bypass control (DC/DC regulator ON)

    #if defined ( DC_DC_P0_7 )

      // Enable stack to toggle bypass control on TPS62730 (DC/DC converter)
         HCI_EXT_MapPmIoPortCmd( HCI_EXT_PM_IO_PORT_P0, HCI_EXT_PM_IO_PORT_PIN7 );

    #endif // defined ( DC_DC_P0_7 )

        return (events ^ KFD_BATTERY_CHECK_EVT);
      }

    Best regards.

  • I tried disabling and enabling the bypass control on TPS62730 (DC/DC converter) in the KeyFob demo project, but it didn't work. I have updated the KFD_BATTERY_CHECK_EVT as:

      if ( events & KFD_BATTERY_CHECK_EVT )
      {
        
        // Disable stack to toggle bypass control on TPS62730 (DC/DC converter)
        HCI_EXT_MapPmIoPortCmd( HCI_EXT_PM_IO_PORT_NONE, HCI_EXT_PM_IO_PORT_PIN7 );
        
        // Restart timer
        if ( BATTERY_CHECK_PERIOD )
        {
          osal_start_timerEx( keyfobapp_TaskID, KFD_BATTERY_CHECK_EVT, BATTERY_CHECK_PERIOD );
        }

        // perform battery level check
        Batt_MeasLevel( );       

        // Enable stack to toggle bypass control on TPS62730 (DC/DC converter)
        HCI_EXT_MapPmIoPortCmd( HCI_EXT_PM_IO_PORT_P0, HCI_EXT_PM_IO_PORT_PIN7 );

        return (events ^ KFD_BATTERY_CHECK_EVT);
      }

  • Hi Anas/Fedrik,

    I am facing the same problem on the battery level reading, I tried to change the battery reading routine to disable and enable the DC/DC converter as you suggested as above but it didn't work as well. 

    May I know what is the correct way to read the actual battery level?

    thanks,

    PL

  • Same problem here, disable-measure-enable does not work on my setup. Anybody?

  • The following method works for me:

    1. disable PM IO port

    2. Set the io port P0.7 to low (CC2541)

    3. Call battMeasure()

    4. Set io port P0.7 to high

    5. Enable PM IO port

  • Thanks. I tried this approach and it works well. Happy holidays and happy new year. :)

  • Hi Poh,

    What do you mean for: "disable PM IO port" ?

    Thanks

  • Hi All ,

    I have an issue with Battery level measurement

    I took keyfobdemo project as reference to my own project here I want to implement battery level measurement According keyfobdemo project I made all changes in my project also but still in sensortag App (ios based ti app) the battery level showing always 0% ( Zero Percentage )

     

    can anyone helpout how to resolve this issue

     

    Thanks in Advance

  • Dear Poh ,

    I have same problem my code always showing battery level as 18%

    where we need to do this steps . I mean which file... can you say it clearly

  • Hi Kadari,

    Were you about to resolve this issue? My code always shows battery level as 0%...

  • Hi Adam,

    The changes should be made in keyfobdemo, i hope u already know.

    One more suggestions like, without touching Power manager,

    **Make Power reader pin low( P0_0=0;)

    **Call battery measure function: Batt_MeasLevel();

    **Make Power reader pin High( P0_0=1;)

    Note: Here PIN 0 of PORT 0 is connected with TPS62730 Bypass PIN.

    Its Perfectly Working for me.

    Best Wishes with Thanks,

    MANO MM.

  • Hi~
    I want to read the ADC when battery is about to notify the battery level for CC2541. Could anybody plz lemme know, where can I use the "ADC read function" for that ? Thanks