Jump to content
Sign in to follow this  

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;

Share this post

Link to post
Share on other sites

No, it can't be used directly. P1.0 is Timer0_A, clock signal TACLK input only. It cannot be set as a hardware Timer0_A output.


You can use it with a software assisted PWM. You need an Interrupt for your timer, and just have it manually toggle the P1.0 in gpio output mode.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this