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.

Accurate pwm in CC2540

Other Parts Discussed in Thread: CC2540

Hello! I am working with SimpleBLEPeripheral, trying to interface a servo motor by sending 1-2ms pulses every 20ms using osal events and timer 1. Every 20ms an event is triggered (this timing is not critical), and timer 1 is started for, lets say, 1.5ms (critical). Observing this signal it turns out the 1.5ms pulse will some times be up to 3ms due to some halts within the stack which I cannot control. What would be the correct way to implement a time critical output?

  • Hi

    If I understand this right, the 1.5mS pulse generated by timer1 and shouldn't be affected by

    stack if. Just check in the stack (probably application) that timer1 isn't used to operate other

    devices, such as buzzer, or something.

  • Correct, I am using the channel 1 output of timer 1 (P0_3) on the usb dongle from the mini development kit.

    As far as I have been told the stack halts the CPU when the radio is on, so if a connection event occurs during my pulse, the timer will be momentarily halted and the pulse will be longer.

    I found this out by digging down through the initialization calls of the example - if i comment out the call to GAP_ParamsInit() in gap.c, the pwm works fine.

  • Hi Albert,

    Timers (T1, T3 and T4) are autonomous units, so unless the device is in power mode PM2 or PM3

    (cc253x/4x User's Guide, section 4.1) timers should keep on running as configured regardless of

    CPU and/or Radio activity.

    May be what you see there is cc2540 switching to PM2 or PM3 and timers are halted.

  • Sorry, I was editing my last post while you answered, let me say again that: I found this out by digging down through the initialization calls of the example - if i comment out the call to GAP_ParamsInit() in gap.c, the pwm works fine.

    Igor Sherer said:

    Timers (T1, T3 and T4) are autonomous units, so unless the device is in power mode PM2 or PM3

    (cc253x/4x User's Guide, section 4.1) timers should keep on working as configured regardless of

    CPU and Radio activity.

    May be what you see there is cc2540 switching to PM2 or PM3 and timers are halted.

    Yes, PM2 or PM3 is what i believe is happening. I just got an idea, perhaps the code is expecting a sleep crystal which the usb dongle does not have, SimpleBLEPeripheral was not exactly written for it..

  • Well, unfortunately I'm not familiar with BLE, nor with CC254x based EMs, dongles etc.

    So I can't tell you what is exactly happening there :)

  • Igor Sherer said:

    Well, unfortunately I'm not familiar with BLE, nor with CC254x based EMs, dongles etc.

    So I can't tell you what is exactly happening there :)

    Thanks anyway! I was debugging this for quite some time until we discovered it is not even possible to get a simple square wave from the timer output without disabling parts of the stack. So yes, it's a rather specific BLE/cc254x issue i would say..

  • I believe I found the fix for my problem! It is spelled

      HCI_EXT_ClkDivOnHaltCmd( HCI_EXT_ENABLE_CLK_DIVIDE_ON_HALT );

    Working with a copy of SimpleBLEPeripheral this was left in the SimpleBLEPeripheral_Init() function of simpleBLEPeripheral.c...

    Changing it to DISABLED during the timer operation fixed the whole issue!

  • Did you find any  "real" solution for the problem?

    I guess i have similar problem but it didnt help me:  

    http://e2e.ti.com/support/low_power_rf/f/538/t/319822.aspx

  • Thank you Albert. Your post helped me a lot!

    Regards Pavel .