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.

Timer 1 problem cc2530

Other Parts Discussed in Thread: CC2530

Hello guys,

My timer1 is not working properly and it's driving me crazy. The problems is when I set an interrupt on a channel of the Timer1 (I want on compare) it goes to the interrupt even the timer value is not as expected. Here is my code and attached is a print screen of the registers. I expected the T1CNT == T1CC0 but, as you can see, it's not. (Ofcourse EA = 1)

Many thanks and hope for a solution,

Mircea

// init timer

// Set prescaler to 128 halt timer, free running mode
T1CTL = 0x0C;

// Initial start value
T1CNTH = 0x00;
T1CNTL = 0x00;

// Disable the overflow interrupt - this will never be used
T1OVFIM = 0;

// clear all interrupt flags
T1STAT = 0;

// Set period
T1CC0L = LO_UINT16(timeout_ticks);
T1CC0H = HI_UINT16(timeout_ticks);
// set IM: interrupt mask
set_flag(T1CCTL0,BIT6 + BIT2);

T1CTL = 0x0D;

T1IE = 1;

// interrupt

#pragma vector = T1_VECTOR

#pragma vector = T1_VECTOR
__interrupt void Timer1_ISR(void)
{
// channel 0
if (is_flag_set(T1STAT,BIT0))
{

...

}

}

  • Hello Mircea,

    What values to you get?

    Are you reading the register while in debug mode? When you are in debug mode you halt the CPU, but the timers keep running which might result in an unexpected behavior.

    Do you clear the interrupt flag in the timer1 ISR?

    BTW:

    Don't you want to set the T1CTL to 0x0E to get "Modulo, repeatedly count from 0x0000 to T1CC0"? Currently you are running in free running mode meaning your counter will wrap around before you reach your compare value, if I am not mistaken.

  • Hello Eirik,

    What I'm trying to achieve is this: Have a timer, start it and when I get to the specific value (let's say 1 000), reset the timer and write something else on another channel (let's say 2 000) and disable previous channel. After that I stop the timer and when I need it again I reset it's value. That's why I would like Timer 1. Also I need big values (like max 1 minute) so I need the 16 bit timer. I run the code in Debug mode and I put a breakpoint in the timer interrupt routine. I sense it enters very fast in interrupt, like it doesn't care  the value it's written into register. Also I compare with Sleep_Timer - which is running great and it enters in timer 1 before Sleep Timer although the sleep timer is set to a much bigger value (transformed from MS to ticks) 

    Below you have the interrupt routine.

    #pragma vector = T1_VECTOR
    __interrupt void Timer1_ISR(void)
    {
    // channel 0 - TIMEOUT
    if (is_flag_set(T1STAT,BIT0))
    {
    clear_flag(T1STAT,BIT0);

    ... }

    Much appreciate your help,

    Mircea

  • Hello Mircea,

    I would advice you to make a simpler version of your program first where you just do a simple compare on timer 1 channel0, then toggle an GPIO and measure on that GPIO with a digital logic analyzer or oscilloscope. That way you have a more reliable real time debug setup. Off course you can still use debug mode to look in registers, but this setup is recommended to make development easier.

  • Hello Eirik,

    I will do that, but in the meantime could you please provide me an example of typical application that would use something close to what I need? Perhaps some pins influence my timer? I use almost all my pins to something.

    Really appreciate the help,

    Mircea

  • Hello,

    I am not sure if we have something close, but you could have a look at the CC2541/43/44/45 Peripherals Software Examples and look at the timer1 examples. They are quite simple, but the functionality should be almost the same for timer1 as in CC2530.

  • Hello Eirik,

    I'll try with examples and let you know when I come back from vacation. Thanks for everything.

    Mircea

  • Hello,

    I changed the architecture of the timer (I'm not resetting its value but I add the timeout value to current value and write it to channel X) and now it is working. Thank you very much for all the support.

    Mircea

    PS: examples didn't really help