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.
#include <msp430f2011.h>
#define _XTAL_FREQ 20000000
unsigned int width=0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; //turn off the watch dog timer
DCOCTL = CALDCO_16MHZ; //set internal clock speed to 16 MHz
BCSCTL1 = CALBC1_16MHZ; //set internal clock speed to 16 MHz
P1DIR = BIT6;
P1SEL = BIT6; //TA1
TACCR0 = 40000; //2000000/40000 = 50hz = 20ms
TACCTL1 = OUTMOD_3; //set/reset
TACCR1 = width; //1.5ms pulse
TACTL = TASSEL_2 + MC_1 + ID_3; //up mode, SMCLK/8
while(1)
{
if(width<40000)
{
width = width+1;
}
else
{
width = 0;
}
TACCR1 = width;
__delay_cycles(100);
}
}
I need help with this PWM code,it produces a straight line in proteus simulation, maybe there is a problem with the while loop.
I used an external crystal oscillator of 20MHz at P2.7 and P2.6 and even after removing it i'm still not getting a PWM
How do i declare this
P1DIR = BIT6;
P1SEL = BIT6; //TA1
in this form
P1DIR |=0x**;
P1SEL |=0x**; //TA1
I managed to fix it,here is the complete CODE
//Generating 50Hz 0-100% Duty Cycle PWM Waveform using Timer_A
#include "msp430x20x1.h"
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; //turn off the watch dog timer
DCOCTL = CALDCO_16MHZ; //set internal clock speed to 16 MHz
BCSCTL1 = CALBC1_16MHZ; //set internal clock speed to 16 MHz
P1DIR |= 0x0C;
P1SEL |= 0x0C; //TA1
TACCR0 = 40000; //2000000/40000 = 50hz = 20ms
TACCTL1 = OUTMOD_3; //set/reset
TACCR1 = 37000; //1.5ms pulse
TACTL = TASSEL_2 + MC_1 + ID_3; //up mode, SMCLK/8
while (1){
}
}
Hi Timothy,
I tried your original code on an msp430g2452 installed in a launchpad and it worked fine. The green LED connected to P1.6 dimmed from 100% brightness to 0%, then jumped back to 100%. Each PWM cycle took about 0.25s. I'm not sure why it didn't work in your case.
The code in your last post doesn't appear to do a PWM sweep, it just outputs a fixed duty cycle. Did the forum software lose the contents of the while loop?
Rob
**Attention** This is a public forum