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))
{
...
}
}