Thursday 16 July 2020

Pulse Width Modulation using MSP430 Timer (Launchpad)

Video based Tutorial for PWM generation using MSP430 is covered on my YouTube channel:

Please Subscribe to the Channel!

Code used for generation of PWM:

#include <msp430g2553.h>

void main(void)
{
 WDTCTL = WDTPW + WDTHOLD;  // Stop WDT
 P1DIR |= BIT6;             // P1.6 set for output
 P1SEL |= BIT6;             // select TA0.1 output signal
 CCR0 = 1000-1;             // PWM Time Period/ frequency (1 KHz)
 CCTL1 = OUTMOD_7;          // reset/set mode 7 for output signal
 CCR1 = 750-1;                // PWM Duty cycle is 75%
 TACTL = TASSEL_2 + MC_1;   // SMCLK and Up Mode
 _BIS_SR(LPM0_bits);        // Enter LPM0
}


You can change the value in CCR1 and get different Ton/ Duty cycles. This will cause the LED to appear brighter or dimmer (higher the value or closer it is to CCR0 value, the LED will appear brighter).
Time period or frequency of the PWM signal can be changed by selecting different clock frequency or by dividing the clock frequency and by changing the CCR0 value.

3 comments:

  1. Thanks! I watched the corresponding YouTube video and you have helped me understand how PWM is achieved!

    ReplyDelete