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.

How to use the sleep timer as capture timer with ble stack

Other Parts Discussed in Thread: CC2541

I want to calculate the heart rate and transmit the heart rate to ios phone, my heart rate sensor will give cc2541 pulse when it work, and the whole current should be less than 300uA when ble connected with phone. So I want to use a pin interrupt and the sleep timer, but the sleep timer seems has been used by bluetooth stack itself. So How Can I use it for capture the time between pulse but not influence the bluetooth stack?

Thanks,

Chris

  • Can I get this time through ll_McuPrecisionCount function? Is it free running.

    For example, when the first edge arrive, I get and store the time, then when second edge arrive ,get the second time,then just sub these two value?

  • Hi Chris, 

    What's the resolution you're looking for? Using the same timing as for the radio is probably the best way to go. 

    However, OSAL does not use the capture channel of the sleep timer, so you should be able to use that as well. Some modification would probably have to be made to hal_sleep.c since you'll be re-using the sleep timer interrupt for another purpose as well. 

    Peder

  • Thanks, Peder .

       I think 1.25ms is enough for me, so may be the 625us free running timer is convenient. There is no capture channel example available from TI, so I think it is difficult for me to modify the hal_sleep.c. Thanks!

    Chris

  • Confused by osalTimeUpdate:

    seems can not get the correct time?

    I jsut copy the osalTimeUpdate1,and call it in key down notify function:

    void osalTimeUpdate1( void )
    {
      uint16 tmp;
      uint16 ticks625us;
      uint16 elapsedMSec = 0;

      // Get the free-running count of 625us timer ticks
      tmp = ll_McuPrecisionCount();

      if ( tmp != previousLLTimerTick1 )
      {
        // Calculate the elapsed ticks of the free-running timer.
        ticks625us = tmp - previousLLTimerTick1;

        // Store the LL Timer tick count for the next time through this function.
        previousLLTimerTick1 = tmp;

        /* It is necessary to loop to convert the usecs to msecs in increments so as
         * not to overflow the 16-bit variables.
         */
        while ( ticks625us > MAXCALCTICKS )
        {
          ticks625us -= MAXCALCTICKS;
          elapsedMSec += MAXCALCTICKS * 5 / 8;
          remUsTicks1 += MAXCALCTICKS * 5 % 8;
        }

        // update converted number with remaining ticks from loop and the
        // accumulated remainder from loop
        tmp = (ticks625us * 5) + remUsTicks1;

        // Convert the 625 us ticks into milliseconds and a remainder
        elapsedMSec += tmp / 8;
        remUsTicks1 = tmp % 8;

        // Update OSAL Clock and Timers
        if ( elapsedMSec )
        {
          //osalClockUpdate( elapsedMSec );
          //osalTimerUpdate( elapsedMSec );
       time = elapsedMSec;
        }
      }
    }


    static void simpleBLEPeripheral_HandleKeys( uint8 shift, uint8 keys )
    {
      uint8 SK_Keys = 0;
     extern uint32 time;

      VOID shift;  // Intentionally unreferenced parameter

      if ( keys & HAL_KEY_SW_1 )
      {
        SK_Keys |= SK_KEY_LEFT;
      }

      if ( keys & HAL_KEY_SW_2 )
      {
     osalTimeUpdate1();
     
     Pulse_Width= time-cTime;
     cTime = time;
     Pulse_Data_Save[DP]=Pulse_Width;          
     DP++;
     
     if(DP>10){
     }
     }
    }