//
// 2-channel hardware PWM example for MSP430G2452
// Written by Ted Burke - last updated 2-11-2015
//
#include <msp430.h>
int main( void )
{
// Watchdog timer
WDTCTL = WDTPW + WDTHOLD; // Disable watchdog timer
// Configure P1.2 (TA0.1) and P1.4 (TA0.2) for PWM output
// To configure P1.2 as TA0.1: P1DIR.2=1, P1SEL.2=1, P1SEL2.2=0
// To configure P1.4 as TA0.2: P1DIR.4=1, P1SEL.4=1, P1SEL2.4=1
P1DIR = 0b00010100;
P1SEL = 0b00010100;
P1SEL2 = 0b00010000;
// Configure Timer A
TACTL = TASSEL_2 + ID_0 + MC_1; // Up mode, input divider=1, SMCLK clock
TACCTL0 = OUTMOD_7; // TA0.0 in Reset/Set output mode
TACCTL1 = OUTMOD_7; // TA0.1 in Reset/Set output mode
TACCTL2 = OUTMOD_7; // TA0.2 in Reset/Set output mode
TACCR0 = 20000; // Start timer with 20ms period
while(1)
{
// P1.2 dim and P1.4 bright for 1 second
TACCR1 = 2000;
TACCR2 = 8000;
__delay_cycles(1000000);
// P1.2 bright and P1.4 dim for 1 second
TACCR1 = 8000;
TACCR2 = 2000;
__delay_cycles(1000000);
}
return 0;
}
↧
Simple 2-channel hardware PWM example for the MSP430G2452 microcontroller
↧