I am trying to do simple PWM with MSP430. Working with timer I am facing one issue. I have noticed that clock divider doesn't make any sence eather I set ID_3 that suppose divide clock by 8, or I set ID_1 or ID_2. The output frequency that I am seeing with the scope is 130Hz. Is there any mistakes?
#include "msp430g2553.h"
volatile unsigned long i;
volatile unsigned int D1=50;
void main(void)
{
i=0;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
CCTL0 = CCIE; // CCR0 interrupt enabled
TACTL = TASSEL_2 + MC_1 + ID_1; // SMCLK, upmode MC1
CCR0 = 5; // Timer should count up to CCR) and reset
P1OUT &= 0x00; // Shut down everything
P1DIR &= 0x00;
P1DIR |= BIT0; // P1.0 pin output
_BIS_SR(CPUOFF + GIE); // Enter LPM0 w/ interrupt
while(1) //Loop forever, we work with interrupts!
{}
}
// Timer A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
i=i+1;
if (i>=100) {i=0;}
if (i<=D1) {P1OUT = BIT0;}
if (i>D1) {P1OUT &= 0x00;}
}