PWM Help

Hi,

I have the MSP430 F2013 (eZ430-F2013) Demo/evaluation kit.

I am trying to make a project that runs the LED through a timer PWM output so i can change the speed at which it is turned ON/OFF and the brightness.

The following code works and basically makes the LED turn ON/OFF using a software delay: -

#include "msp430.h"

volatile unsigned int i;            // volatile to prevent optimization

int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
  P1DIR |= 0x01;                        // Set P1.0 to output direction

  for (;;)
  {


    P1OUT ^= 0x01;                      // Toggle P1.0 using exclusive-OR

    while( i != 10000)
    {
    
      i++;
    
    }
    
    i=0;

  }
}

Quick question what is this include file?

#include “msp430.h”

and as i am using a F2013 do i need a different include file?

Back to my problem i have tried using the following code to switch the LED ON?OFF but it does not work, all that happens is that the LED stays on all the time CAN ANYBODY HELP?

#include  <msp430x20x3.h>

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  P1DIR |= 0x01;                            // P1.2 and P1.3 output
  P1SEL |= 0x01;                            // P1.2 and P1.3 TA1/2 otions
  CCR0 = 128;                               // PWM Period/2
  CCTL1 = OUTMOD_6;                         // CCR1 toggle/set
  CCR1 = 32;                                // CCR1 PWM duty cycle
  TACTL = TASSEL_1 + MC_3;                  // ACLK, up-down mode

  _BIS_SR(LPM3_bits);                       // Enter LPM3
}

Thanks,

Xplosiv

PWM from TA1 can only use P1.2 or P2.6.

Your code is using P1.0 which TA1 cannot use.

Also you selected ACLK for Timer. Do you have a crystal connected?

what I’ve seen done is to set P1.0 as input but do nothing in the code with this, then install a jumper wire from P1.2 to P1.0 so that the PWM of P1.2 drives the LED tied to P1.0. Notice there are 14 holes so look at schematic for what pins are P1.0 and P1.2.

If you’ve got a soldering iron around, you could add solder to a wire to give a good fit in the existing holes so you don’t need to solder anything into the holes.