Hi,
I am preparing for an exam and am having a hard time wrapping my head around timers. I have (simple) working code that alternatively blinks the red and green LED approx. every second using a timer. I am using TASSEL_1 which is the ACLK clock. This clock runs at 32 kHz. I set the timer to be an UP timer and am counting to 200 (well, the interrupt is occurring every 201 counts :o) and this is what confuses me -> the interrupt is happening about every second but the way I got there was with playing with the TACCR0 value until it seemed ok to me. So how do I calculate the correct value for TACCR0 and not just guess it?
I do realize that this has been explained about 1000 times online but I just cannot seem to understand any of the examples (http://www.msp430launchpad.com/2010/07/timers-and-clocks-and-pwm-oh-my.html, for example, explains it quite well but not for the ACLK). Any help would be greatly appreciated.
Thanking you in advance
Ursus
------------------------------ here is the code
#include <msp430G2553.h> // just some defines #define BOOLEAN int #define FALSE 0 #define TRUE !FALSE // my two LEDs are on BIT0 and BIT6 #define RED_LED BIT0 #define GREEN_LED BIT6 // set when the RED LED is on BOOLEAN led_red = FALSE; /* * main.c */ int main (void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer // setup the timer TACCTL0 = // Capture/Compare Control Register CCIE; // interrupt enable TACTL = // Timer_A Control Register TASSEL_1 + // = ACLK is a 32kHz crystal clock MC_1; // Use the UP mode timer (set up count in TACCRO TACCR0 = 200; // Timer_A will count UP to here // setup LEDs P1DIR |= RED_LED + GREEN_LED; // set P1DIR out for RED and GREEN P1OUT &= ~RED_LED; // turn off red P1OUT &= ~GREEN_LED; // turn off green // start interrupts _enable_interrupts (); while (1==1) { // do nothing } } #pragma vector=TIMER0_A0_VECTOR __interrupt void timer (void) { if (led_red == TRUE) { led_red = FALSE; P1OUT &= ~RED_LED; // RED OFF P1OUT |= GREEN_LED; // GREEN ON } else { led_red = TRUE; P1OUT |= RED_LED; // RED ON P1OUT &= ~GREEN_LED; // GREEN OFF } }