This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

setting two outputs in MSP430??

Other Parts Discussed in Thread: MSP430G2452

Hi

I am struggling with modifying code for my project. (almost no experience with C language)

Basically what I am trying to do is to get two switching signals from two separate outputs of MSP430 G2231 (LaunchPad) using PWM.

With the script in the following, I am able to detect the switching signal (with 80% duty ratio) in oscilloscope from Pin 1.6.

How should I modify the code in order to get another inverted switching signal of Pin1.6 from Pin 1.7 (20% duty ratio in this case)?

Can somebody help me with this?

Thanks.

----------------------------------------------------------------------------------------------------------------------------------------

#include <msp430g2231.h>
#include <stdbool.h>

bool inc; // declare a boolean to determine whether to increment CCR1 or decrement it

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD; // Stop WDT
  P1DIR |= BIT6; // P1.6 output
  P1SEL |= BIT6; // P1.6 TA1/2 options
  CCR0 = 1000-1; // PWM Period
  CCTL1 = OUTMOD_7; // CCR1 reset/set
  CCR1 = 800; // CCR1 PWM duty cycle
  TACTL = TASSEL_2 + MC_1 + TAIE; // SMCLK, up mode, Timer_A interrupt enabled, Timer_A interrupt pending

  _BIS_SR(CPUOFF + GIE); // Enter LPM0 with interrupts
 }

------------------------------------------------------------------------------------------------------------------------------------

  • Your existing code is setting up the Timer to generate the output periodically and automatically. The CPU is never use again. This works. But the Timer in G2xx1 is not capable of doing this for more output. Thus you have two options:

    1) Use a different MSP430 chip with a Timer that has 3 or more capture/compare channels

    2) Keep using the same G2xx1 chip, but use the CPU to help the Timer periodically. To do so, you need to set up the Timer in continuous mode and generate interrupts. In the interrupt service routine, you set up the next interrupt and what to output. This way, you can generate two outpust with the same period but independent duty cycle or polarity.

     

  • Jaewoo Kim said:
    How should I modify the code in order to get another inverted switching signal of Pin1.6 from Pin 1.7 (20% duty ratio in this case)?

    Hey Jaewoo,

    Unfortunately you can't with this chip. To have inverted PWM you need to have a timer with 3 capture and compare registers. This chip only has 2.

    I assume you are using the Launchpad?

    If so you can order a free sample from TI of the msp430g2452, this will fit into the launchpad and you can make an inverter PWM from pins 1.2 and 1.4 by making one CCR OUTMOD_6 and the other OUTMOD_2

    This allows you to set deadtime between your PWM signals if you want to aswell

     

**Attention** This is a public forum