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.
Please help,
I am working on MSP430G2553 for generating a sine PWM of 10 KHZ inorder to drive a full bridge inverter. When i tried to load, the waveform obtained is not repeating in nature. Can you please suggest me a possible solution for the same.
Looking forward for your reply.
The source code used is provided below.
#include <msp430g2553.h>
#define pwmPeriod 1200 // carrier of 10kHz and reference of 50Hz. PWM period is 1200 ms.
const unsigned int phalfcycle[100] = {600,618,637,656,675,693,712,730,749,767,785,803,820,838,855,872,889,905,921,937,952,967,982,996,1010,1024,1037,1050,1062,1074,1085,1096,1106,1116,1125,1134,1142,1150,1157,1164,1170,1176,1181,1185,1189,1192,1195,1197,1198,1199,1200,1199,1198,1197,1195,1192,1189,1185,1181,1176,1170,1164,1157,1150,1142,1134,1125,1116,1106,1096,1085,1074,1062,1050,1037,1024,1010,996,982,967,952,937,921,905,889,872,855,838,820,803,785,767,749,730,712,693,675,656,637,618};
unsigned int pulsecounterA0 = 0;
unsigned int pulsecounterA1 = 0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
//Calibrate DCO for 1MHz operation
BCSCTL1 = CALBC1_12MHZ;
DCOCTL = CALDCO_12MHZ;
P1OUT &= 0x00; // Setting all pins as low
P2OUT &= 0x00;
P1DIR |= BIT2 + BIT6; // PWM Outputs
P2DIR |= BIT1 + BIT2;
P1SEL |= BIT2;
P2SEL |= BIT1;
TACCR0 = pwmPeriod - 1; //
TA1CCR0 = pwmPeriod - 1;
TACCTL0 = CCIE; // Enable Timer A0 Interrupt for CCR0
TA1CCTL0 = CCIE;
TACCTL1 = OUTMOD_2; // RESET/SET for Timer A0 CCR1
TA1CCTL1 = OUTMOD_6;
TACTL = TASSEL_2 + MC_1 + TACLR; // Timer_A0 control register with SMCLK = 12 MHz, Upmode. Starting the timer
TA1CTL = TASSEL_2 + MC_1 + TACLR;
_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}
// Timer A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A0 (void)
{
//TACCTL1 = OUTMOD_7;
if (pulsecounterA0 < 100)
{
TACCR1 = phalfcycle[pulsecounterA0];
pulsecounterA0 = pulsecounterA0 + 1;
}
else
{
P1SEL ^= (BIT2 + BIT6);
pulsecounterA0 = 0;
}
}
// Timer A1 interrupt service routine
#pragma vector=TIMER1_A0_VECTOR
__interrupt void Timer_A1 (void)
{
if (pulsecounterA1 < 100)
{
TA1CCR1 = phalfcycle[pulsecounterA1];
pulsecounterA1 = pulsecounterA1 + 1;
}
else
{
P2SEL ^= (BIT1 + BIT2);
pulsecounterA1 = 0;
}
}
thanks ilmars for your quick reply
As my intention is to generate sine PWM for each half cycle of sine wave on different output pins, Also toout the complement of this sine Pwm on other pins.
and my system will also work if i obtain a sine PWM for entire full cycle of a sine on single pin itself and its compliment on any other pin
Hi, As I am not going to compile your code to find what's wrong with it, would be nice if you somehow give more information about "waveform obtained is not repeating in nature"
**Attention** This is a public forum