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.

CC2530 Timer3 at 2MHz

Hello,

I am trying to drive timer 3 at 2 MHz, with a pulse of one timer tick (31.25 ns). My clock speed and timer ticks is at 32 MHz, so I use the timer 3 in modulo mode with T3CC0 = 0x10 for 500 ns period. I also set it at compare mode at  T3CC1 = 0x01 for 31.25 ns pulse period. Using this settings and looking at the timer 3 output, I can only get a frequency of 470 KHz, and a pulse of 130 ns. Is timer 3 using a different clock source? Below is my code for your reference. Thanks for your help.

 

// *************** change clock speed
CLKCONCMD &= ~0x80; // select 32KHz XOSC source
while((CLKCONSTA & 0x80) == 0x80); // wait until stable
CLKCONCMD &= ~0x40; // select 32MHz XOSC source
while((CLKCONSTA & 0x40) == 0x40); // wait until stable
CLKCONCMD &= ~0x38; // select 32MHz timer ticks
CLKCONCMD &= ~0x07; // select 32MHz clock speed

// timer 3 initialization
PERCFG &= ~0x20; // set Timer3 alt1 location
P1SEL |= 0x18; // peripheral mode
T3CNT = 0; //T3 initial value
T3CTL = 0x02;//modulo mode
T3CC0 = 0x10; //overflow value
T3CCTL1 = 0x1C; //compare mode, set output on compare, clear on 0
T3CC1 = 0x01; // compare value
T3CTL |= 0x40; //clear timer3
T3CTL |= 0x10; //start timer3

while(1);

  • Hi,

    There are two problems with your code that gives you the frequency of 470 kHz.

    1:

    JC de Dios said:
    T3CTL |= 0x40; //clear timer3

    This statement causes the timer to run with a prescaler that divides the clock by 4. The correct statement for clearing the timer would be

    T3CTL |= 0x04;

    2:

    JC de Dios said:
    T3CC0 = 0x10; //overflow value

    Note that Timer 3 will count from 0 to T3CC0 inclusively. So this will give you a period of 17 ticks, not 16 as you wanted. Change it to

    T3CC0 = 0x0F;

    With these two changes, I believe you will get the correct period.