Geeks With Blogs
Code Without Fear Ruminations by Don Huff

I have recently been turned on to the world of microcontrollers while doing some hobby development.  Here is the first “real” program I have written with the Texas Instruments MSP430 LaunchPad development tool.  Check it out…$4.30 to get a development board with 2 devices and a USB connection to your Windows PC for programming and debugging.  It’s a lot of fun…especially if you enjoy bit-twiddling!

The MSP430 processors specialize in low power operations. They accomplish this by enabling peripherals to run that require minimal resources. These peripherals have the ability to “wake up” the CPU (in less than 1 micro-second) to service requests through interrupts. The software handles the interrupt and go back to sleep as quickly as possible.

My goal is to create an electrical signal with known period and cycle time (% of the period where the signal is “on”). This is essentially pulse-width modulation, the magic behind many kinds of variable speed electric motors as well as dimming light switches.

As I was reading through the processor data sheet to try to figure out how to generate this signal, I discovered the Timer_A peripheral on these processors can output a signal without code intervention.  Very cool.  This means no software interrupt service routines…the program configures the clocks and enters the low power mode where the CPU and all the clocks are off except a single timer running on the internal low frequency oscillator.

Here is the code:

#include <msp430g2553.h>

int main(void)
{
    WDTCTL = WDTPW + WDTHOLD;    // Stop watchdog timer

    BCSCTL1 &= ~XTS;        // LFXTCLK 0:Low Freq.
    BCSCTL3 |= LFXT1S_2;    // Mode 2 for LFXT1 : VLO

    TA0CTL = TASSEL_1    // Timer A clock source select: 1 - ACLK
            + MC_1;        // Timer A mode control: 1 - Up to CCR0

    // VLO is running at 12 kHz
    TA0CCR0 = 12000;    // the number of counts in the entire period
    TA0CCR1 = 6000;        // the number of counts the output signal is set

    TA0CCTL1 |= OUTMOD_7;    // PWM output mode: 7 - PWM reset/set

    // select P1.6 function as TA0.1
    P1SEL |= BIT6;
    P1SEL2 &= BIT6;

    P1DIR |= BIT6;    // P1.6 to output

    while(1)
    {
        LPM3;    // Enter Low Power Mode 3 - CPU Off, MCLK Off, SMCLK Off, DCO Off, ACLK On
    }
}

Code without fear!

--Don

Posted on Sunday, January 15, 2012 1:19 AM | Back to top


Comments on this post: MSP430 Pulse-Width Modulation in Low Power Mode 3

# re: MSP430 Pulse-Width Modulation in Low Power Mode 3
Requesting Gravatar...
Looking forward to reading more about your discoveries!
Left by Jeff Julian on Jan 19, 2012 7:28 AM

# re: MSP430 Pulse-Width Modulation in Low Power Mode 3
Requesting Gravatar...
sir
i tried to execute this code by using msp340FG4618 its showing some error so plz how to change from this series(MSP430g2553)to msp340FG4618......plz reply fast sir.....
Left by jaisingh yadav on Apr 05, 2014 9:33 AM

# re: MSP430 Pulse-Width Modulation in Low Power Mode 3
Requesting Gravatar...
@jaisingh...I am not familiar with your device. I recommend starting with the data sheet for this processor. Applying your initiative and curiosity to make discoveries like these are some of the most rewarding experiences I have.

When you find a solution, please consider sharing it by posting an article and adding a comment/link.

Best,

Don
Left by Don on Apr 06, 2014 12:16 PM

# re: MSP430 Pulse-Width Modulation in Low Power Mode 3
Requesting Gravatar...
I'm read these things. How to code, to generate 3 PWM to trigger IGBT for 3 phase inverter using the same msp4302553.
Left by shinu on Dec 18, 2014 4:37 AM

Your comment:
 (will show your gravatar)


Copyright © codeWithoutFear | Powered by: GeeksWithBlogs.net