Advertisement
LshySVK

MSP430 PWM

May 4th, 2023
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | Source Code | 0 0
  1. #include <msp430g2553.h>
  2.  
  3. int main(void) {
  4.     WDTCTL = WDTPW + WDTHOLD; //Disable the Watchdog timer for our convenience.
  5.     P1DIR |= BIT2; //Set pin 1.2 to the output direction.
  6.     P1SEL |= BIT2; //Select pin 1.2 as our PWM output.
  7.     TA0CCR0 = 1000; //Set the period in the Timer A0 Capture/Compare 0 register to 1000 us.
  8.     TA0CCTL1 = OUTMOD_7;
  9.     TA0CCR1 = 500; //The period in microseconds that the power is ON. It's half the time, which translates to a 50% duty cycle.
  10.     TA0CTL = TASSEL_2 + MC_1; //TASSEL_2 selects SMCLK as the clock source, and MC_1 tells it to count up to the value in TA0CCR0.
  11.     __bis_SR_register(LPM0_bits); //Switch to low power mode 0.
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement