I am developing a simple application which uses the high speed XOSC clock, 16 bit timer 1 and 1 IO pin.
I enable the XOSC clock like in the example code and next start up timer 1 to trigger an interrupt each 1 ms. In the interrupt I just toggle a IO pin.
At a certain time (e.g. 20 minutes) I notice that the IO pin is toggled each 2 ms. If I output the registers of timer 1 and clock, they still have the values from startup.
Because it is such a basic thing I am doing, I am doubting my compile/linking settings of my framework.
Does somebody have an idea where to look?
#include <hal_types.h> #include <hal_defs.h> #include <hal_cc8051.h> #include <ioCCxx10_bitdef.h> #include <ioCC2510.h> #pragma vector = T1_VECTOR __interrupt void timer1_ISR(void) { T1CTL = (~T1CTL_OVFIF & 0xF0) | (T1CTL & 0x0F); // Clear Timer 1 overflow interrupt flag but keep all other registers P1_3 ^= 1; } void main( void ) { EA = 0; // disable all interrupts // Set system clock source to 26 Mhz XSOSC to support maximum transfer speed, ref. [clk]=>[clk_xosc.c] SLEEP &= ~SLEEP_OSC_PD; // Power up XOSC and HS RCOSC oscillators while( !(SLEEP & SLEEP_XOSC_S) ); // Wait until XOSC is powered on and stable CLKCON = (CLKCON & ~(CLKCON_CLKSPD | CLKCON_OSC)) | CLKSPD_DIV_1; // Select 26 Mhz XOSC while (CLKCON & CLKCON_OSC); // Wait until XOSC is stable SLEEP |= SLEEP_OSC_PD; // HS RCOSC powered down // P1_3 as output P1SEL &= ~(BIT3); P1DIR |= (BIT3); P1INP &= ~(BIT3); // 1ms interrupt on timer1 T1CTL &= ~T1CTL_CH0IF; // Clear Timer 1 Channel 0 interrupt flag T1CCTL0 &= ~T1CCTL0_IM; // Disable Timer 1 Channel 0 interrupt mask T1CCTL1 &= ~T1CCTL1_IM; // Disable Timer 1 Channel 1 interrupt mask T1CCTL2 &= ~T1CCTL2_IM; // Disbale Timer 1 Channel 2 interrupt mask OVFIM = 1; // Enable Timer 1 overflow interrupt mask T1CC0L = 0xc7; // Set Timer 1 Channel 0 compare value low byte T1CC0H = 0x32; // Set Timer 1 Channel 0 compare value high byte T1CTL = (T1CTL & ~(T1CTL_MODE | T1CTL_DIV)) | T1CTL_MODE_MODULO | T1CTL_DIV_1; // First suspend Timer 1 operation and clear prescale divider, next set to modulo operation and divide tick frequency by 1 T1IE = 1; EA = 1; // enable all interrupts while(1) { ; } }