frozencarbonite 4 Posted July 16, 2011 Share Posted July 16, 2011 Hi, I'm pretty new to programing microcontrollers but I am trying to learn. I came across NJC's PWM code (attached below). I wanted to change the timer A output from P1.2 to P1.5. I looked at the datasheet for MSP430G2231 and it says it has Timer0_A, compare: Out0 output (TA0.0) on this pin. The pins that work with this code all say Timer0_A, compare: Out1 output (TA0.1) I tried changing the code below by just changing the instances of BIT2 to BIT6 but it did not work. Can someone explain how to use this code for BIT6 or any of the TA0.0 pins and explain what the significance is between these TA0 bits? //************************************************************************ // MSP430G2231 Demo - Timer_A, PWM TA1, Up Mode, SMCLK // // Description: This program generates one PWM output on P1.2 using // Timer_A configured for up mode. The value in CCR0, 1000-1, defines the // PWM period and the value in CCR1 the PWM duty cycles. Using SMCLK, // the timer frequenciy is about 1.1kHz with a 25% duty cycle on P1.2. // Normal operating mode is LPM0. // MCLK = SMCLK = default DCO (about 1.1MHz). // // MSP430G2231 // ----------------- // /|\ | | // | | | // --|RST P1.2/TA1|--> CCR1 - 75% PWM // | | // | | // // M.Buccini / L. Westlund // Texas Instruments, Inc // October 2005 // Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.40A // // Modified by NJC for MSP430LaunchPad.com - July 2010 // //************************************************************************ #include "msp430G2231.h" void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT P1DIR |= BIT2; // P1.2 to output P1SEL |= BIT2; // P1.2 to TA0.1 CCR0 = 1000-1; // PWM Period CCTL1 = OUTMOD_7; // CCR1 reset/set CCR1 = 250; // CCR1 PWM duty cycle TACTL = TASSEL_2 + MC_1; // SMCLK, up mode _BIS_SR(LPM0_bits); // Enter LPM0 } Quote Link to post Share on other sites
NatureTM 100 Posted July 17, 2011 Share Posted July 17, 2011 If you look at the "application information" section of that datasheet, it shows what pins are connected to the timer A hardware. You're looking for TA0.1 (Timer A0, CCR1) under the "function" column. You'll see your only options are P1.2 and P1.6. I usually try to build my design around the hardware, but if that's not an option, you could use interrupts and software to make it work. It would be a matter of toggling the pin appropriately during the CCR0 and CCR1 ISR's. To use P1.6, change the instances of BIT2 to BIT6 like you did, but use P1.6, not P1.5. If you really want to use P1.5, this might be a good chance to (re)familiarize yourself with interrupts. frozencarbonite 1 Quote Link to post Share on other sites
frozencarbonite 4 Posted July 17, 2011 Author Share Posted July 17, 2011 First sorry I will probably look a bit naive as I am very much new to this. I tried changing the code below by just changing the instances of BIT2 to BIT6 but it did not work. Can someone explain how to use this code for BIT6 or any of the TA0.0 pins and explain what the significance is between these TA0 bits? Woops, that was a typo, I meant to say: "I tried changing the code below by just changing the instances of BIT2 to BIT5 but it did not work. I have no application in mind yet just came across something I did not understand and thought I'd ask. I do see the pins I can use have listed TA0.1 in the function but I didn't quite understand exactly because on P1.5 it shows TA0.0 and that is why I thought there was a way of enabling the timer. Does TA0.0 not have a CCR1 register? Is that the difference? Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.