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.

CC2540 Timer1 Jittering

Other Parts Discussed in Thread: CC2540

Hello TI community,

I'm working on a RC servo control code and stuck on the PPM servo signal generation. 
I'm using timer1 to generating interrupts between 1000-2000us

Here is the timer initialize code:

 CLKCONCMD |= 0x38;

 T1CTL = 0x0A;
 T1CCTL0 = 0x54;
 T1CC0L = 0xE8;
 T1CC0H = 0x03;
 T1IE = 1;

and timer set code 

  T1CC0L = LO_UINT16(1500]);
  T1CC0H = HI_UINT16(1500); 
  T1CNTL = 0;                 // Reset timer to 0;

%90 of the time output is 1500us but jumping to higher values few times in a second. going to worst after BLE connection.
I read this blog posts but didnt help me. 

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

http://e2e.ti.com/support/low_power_rf/f/538/p/196614/701217.aspx#701217

Please help.

  • Hi Melih,

    Have you tried defining the following during the initialization of the application:

    HCI_EXT_ClkDivOnHaltCmd( HCI_EXT_DISABLE_CLK_DIVIDE_ON_HALT );
    HCI_EXT_HaltDuringRfCmd( HCI_EXT_HALT_DURING_RF_DISABLE );

    Those two commands allow the MCU to operate properly regarding timers during RF events.

    Best Regards

    Joakim

  • Hello Joakim,

    I was using HCI_EXT_ClkDivOnHaltCmd( HCI_EXT_DISABLE_CLK_DIVIDE_ON_HALT ); I didnt recognize any effect on the problem.

    Now I added HCI_EXT_HaltDuringRfCmd( HCI_EXT_HALT_DURING_RF_DISABLE ); and this command resolved big jitters (2 times longer), thanks for that.

    But small jitters already there. I set the timer for 1500uS and I can see 10-50uS longer interrupts sometimes. 

    Thank you for your help, I guess my hardware based jitter problem resolved and current problem depends my code or compiler side.

    here is the current code:

    void MyTimerInit(void)
    {
     CLKCONCMD |= 0x28;
    
        T1CTL = 0x0A;
        T1CCTL0 = 0x54;
        T1CC0L = 0xE8;
        T1CC0H = 0x03;
        T1IE = 1;
        
        
        
      HCI_EXT_ClkDivOnHaltCmd( HCI_EXT_DISABLE_CLK_DIVIDE_ON_HALT );
      HCI_EXT_HaltDuringRfCmd( HCI_EXT_HALT_DURING_RF_DISABLE);
    
    }
    
    void handleTimer1()
    {
    
      T1CC0L = LO_UINT16(1500);
      T1CC0H = HI_UINT16(1500); 
      P1_O != P1_O; 
      T1CNTL = 0;                 // Reset timer to 0;
    
    }
    
    
    #pragma vector=T1_VECTOR
    __interrupt void T1_ISR (void)
    {
        handleTimer1();
    }

    Do you have any suggestion?

    I moved the handleTimer1 function into the T1_ISR interrupt to avoiding from other possible interrupt calls but didnt help. 

    Thank you very much

    Melih

     

  • Hi Melih,

    I do not know any other additional things you could try. Are you using a TI design or your own custom board? I suppose it could be related to design.

    Best Regards

    Joakim

  • I'm using different board but only active part is CC2540 , other components is RF antenna matching circuit and 2 xtal as TI suggested in the datasheet.

    I'm measuring the P0 ports directly and power supply is precisely regulated 3.3 volts.


    Do you have any sample source code that basically generating a square wave with a timer interrupt?
    I checked the forum, a lot of people talking about the timers and their weird precision timing problems and weird jitters. I think TI must be share a basic flip-flop code that working over timer interrupts when BLE enabled/connected. Because I didnt find any success story about that :(

     

  • Hi Melih,

    Unfortunately, I do not have any Timer code myself. Have you tried running your software on a TI Board just to make sure it's not bad PCB Design? (No offence)

    Best Regards

    Joakim Lindh

  • Hello Joakim,

    I cant see any pcb design reason to affect the timer interrupts only. All BLE functions working properly and I'm using same board for different applications without any problem. The Timer interrupt working precisely %90 of times except %10. I'm strongly suspecting about BLE core functions more important than timer interrupts and CPU blocking the interrupts or something like that. 

    I have USB CC2540 board from TI, I can load the code and test it to night. Please keep in contact.

    Do you know any sample code with timer interrupt in BLE Stack samples?

  • Hi Melih,

    Since the BLE stack uses interrupts for its own purposes, you simply can't depend on ISR for accurate timing.

    My suggestion would be to set Timer1 or Timer3 to output a PWM signal. For Timer3, see the buzzer.c driver in our keyfob example.

    For Timer1, see the datasheet. The below code should begin to output some adjustable PWM on P0.3 using Timer1, but I can't guarantee that it's complete.

    // Stop Timer 1
    T1CTL = 0;

    // Give peripheral module priority to Timer 1 channel 0,1
    P2DIR = (P2DIR & ~(0x03 << 6)) | (0x02 << 6);

    // Set Timer1 to alternate 1 location
    PERCFG = (PERCFG & ~(1<<6)) | (0<<6);

    // Set GPIO P0.3 to peripheral function
    P0SEL |= (1 << 3);

    // For GPIO mode during reset, set P0.3 output low.
    P0DIR |= (1<<3);
    P0_3 = 0;

    // Set T1C1: IM=0,CMP=4, MODE=compare, no capture
    T1CCTL1 = (0 << 6) | (4 << 3) | (1 << 2);

    // Set modulo period to 40 ticks
    T1CC0L = 40;
    T1CC0H = 0;

    // Set output compare to "1" value
    T1CC1L = 26;
    T1CC1H = 0;

    // Set Timer1 to modulo mode, 1 tick per systick
    T1CTL = 0x02;

    BR,
    Aslak

  • @Joakim 

    I just load the code into CC2540 USB Debugger from TI and problem still same as my PCB. 

    @Aslak

    I dont need a single PWM signal output. In my case I need precise timing to running a code part (or function)

    For example:
    In this project, the function must be called in every 1500us. This is very simple and important requirement for most of projects and I hope CC2540 can handle this simple job when 0.2$, 1Mhz, 256byte Flash 16byte RAM processors can do.
    If you sure about that, mean of this, CC2540 can handle only BLE functions and we need another processor for time critical applications? (software serials, PWM signals, 1Wire and other communication applications)

    I guess I have to chance whole circuit designs and future ideas about BLE technology. Because we can make only some RF Beacons or I2C sensor circuits without time critical architecture. :/