Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <msp430x20x3.h>
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= BIT6; // Set P1.6 to output direction
P1SEL |= BIT6; // P1.6 to TA0.1
CCR0 = 1000-1; // PWM Period
CCTL1 = OUTMOD_7; // CCR1 reset/set
CCR1 = 0; // CCR1 PWM duty cycle
TACTL = TASSEL_2 + MC_1; // SMCLK, up mode
P1IE |= BIT3; // P1.3 interrupt enabled
P1IES |= BIT3; // P1.3 Hi/lo edge
P1IFG &= ~BIT3; // P1.3 IFG cleared
_BIS_SR(LPM0_bits + LPM4_bits + GIE); // Enter LPM4 w/interrupt
}
// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
P1IFG &= ~BIT3; // P1.3 IFG cleared
CCR1 = (CCR1 + 250) % 1000; // Add 25% to PWM
}
@kenemon

This comment has been minimized.

Copy link

@kenemon kenemon commented Feb 26, 2011

Thanks Adam. This has really helped me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment