Jump to content

Simple PWM using timer

Recommended Posts



Can I output a PWM signal to P1.0 pin (G2231 chip) using timer A in up mode and setting CCR0 / CCR1 accordingly?


In short, I was going to use the example code provided by TI (see slac163 and slaa428, example I'm using is the "C" code msp430x21x2_ta_1.c), where pin P1.2 is used for the PWM output.


Well, I tried to modify the code to output the signal to P1.0 but can't get it to work. My conclusion is that P1.0 cannot be selected for such function, but I cannot find anythere in the user guide or datasheets a confirmation. In fact, by reading the datasheet (page 6) I had understood it can do that... (link).


What am I doing wrong? Can the timer output be in pin P1.0?


Here is the code I'm using - below it is set to output to pin P1.2, but there's commented code for pin P1.0 that I tried using.

#include <msp430.h>
#include <stdlib.h>

int main( void )
  //---------------- //
  // Hardware config //
  //---------------- //
  WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
  // DCO configuration
  DCOCTL = CALDCO_1MHZ; //Set DCO to 1 MHz
  BCSCTL1 = CALBC1_1MHZ; // Calibrate internal clock for 1 MHz
  // Port 1 configuration
  P1DIR = 0x04;
  P1SEL |= BIT2;
//  P1DIR = 0x01;
//  P1SEL |= BIT0;
  // Timer A configuration
  TACTL =  TASSEL_2 + // Set clock to internal DCO
           ID_0 +     // No frequency divider
           MC_0;      // Stopped to begin with
  CCR0 = 1000-1;  // PWM Period (1 us)
  CCTL1 = OUTMOD_7; // CCR1 reset/set
  CCR1 = 500; // CCR1 PWM duty cycle
  //----------- //  
  // Main logic //
  //----------- //
  TACTL  |= MC_1;
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...