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.

BLE OSAL and Timers, can they be friends?

Other Parts Discussed in Thread: CC2541

Doing project on CC2541 using BLE. So I use OSAL and other pre-made goodies from TI. I now try to generate IR signals on P1_0 using Timer 0 channel 2 and never got it working properly. Including many other problems I observe output with ghost delays like shown on this oscillogram:

This all makes me think that BLE stack or OSAL is trying to use Timer 1 too. Meanwhile I found no information what timers are used by OSAL and what are pitfalls. Relevant code is included. I run Timer 1 from system clock divided by 8. T1CC0 is 100. This all should give 25kHz clock I think. I actually get 38kHz and very weird but cycle length is "floating" on oscilloscope screen. 

void HalIrSendInit( void ) {
/* Set pin direction to Output */
P1DIR |= BV(0); // 0 is input, ->1<- is output
PERCFG |= BV(6); // Timer 1 alternative location 2
P2DIR |= BV(6) | BV(7); // PRIP0 to 11, 1st priority: Timer 1 channels 2-3
P2SEL |= BV(3); // Timer1 priority over USART0
P2SEL &= ~BV(4); // Timer1 priority over Timer4
P1SEL |= BV(0); // P1_0 is peripheral, not GPIO

T1CTL |= BV(2); // Timer 1 is system clock divided by 8
T1CTL |= BV(1) | BV(0);// Up, down mode
T1CCTL2 |= BV(2); // Compare mode, channel 2
T1CCTL2 |= BV(5) | BV(4); // -----Toggle output
T1CCTL2 |= BV(6); // Enable interrupt for Timer 1, channel 2

/* Double this number, impulse get double longer too. */
const uint16 period=80;
const uint16 periodhalf=period/2;
 const uint8 PERIODL=(period & 0xFF);
const uint8 PERIODH=(period >> 8);
 const uint8 PERIODLhalf=(periodhalf & 0xFF);
const uint8 PERIODHhalf=(periodhalf >> 8);
 // L must be written first and H after.
T1CC0L=PERIODL; //
T1CC0H=PERIODH; // These two register define lenght of cycle. 100% of time

T1CC2L = PERIODLhalf; // PWM signal period
T1CC2H = PERIODHhalf; //

}
I think gurus here know what I do wrong or can recommend what part of documentation I missed.
  • Hi Tonu

    Did you ever get to the bottom of this. I am seeing a similar issue using PWM's. As you've mentioned nothing seems to indicate what timers resources are in use. I actually think its something todo with the processor going into to a low power mode (which I've tried to disable everywhere!), as that what turn off the primary clock being used by the timers.

    Interested to know how you got on with your project.

    Regards

    Rob
  • Timer 1, 3 and 4 are free to use.
    But be default the system clocks are stopped during Rf radio use!

    You have to put these in the initialization ( like in void SimpleBLEPeripheral_Init( uint8 task_id ) ) to stop that:

    LL_EXT_HaltDuringRf(LL_EXT_HALT_DURING_RF_DISABLE) ; // turn off RF CPU halt
    HCI_EXT_ClkDivOnHaltCmd( HCI_EXT_DISABLE_CLK_DIVIDE_ON_HALT );

    That probably fixes your problem.

    BUT if your trying to handle interrupts, OSAL TURNS OFF interrupts for up to something like 125us, and I haven't worked out how to get around that in a real-time system.

    This means you get lost/ delayed interrupts when trying to use the low level timers for timing! If you can stick with OSAL events and can cope with the jitter of 1ms or more, you will be better off.
  • You're a life-saver, Adrian.

    I have been searching three days for a solution for my problem with irregular tones generated by timer 1. The line:
    HCI_EXT_ClkDivOnHaltCmd( HCI_EXT_DISABLE_CLK_DIVIDE_ON_HALT );
    solved it.

    Big thanks!
    René