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.
hello i am generating two pwm one with frequency 2khz...... 2nd with frequency 10khz
when i am observing both pins on oscilloscope the 1st one pwm is accurate but 2nd one is not correct
this mean i am experiencing problem with higher frequency when i change the 10khz to 5khz then it become accurate but i want 10khz
i dont know what is the problem kindly help me below is my code
#include <msp430.h>
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
// Setup Port Pins
P4DIR |= 0xFF; // P4.0 - P4.7 output
P4SEL |= 0xFF; // P4.0 - P4.6 Port Map functions
P1DIR |= 0x01; // P1.0 - Outputs
//Set up Timer B in continuous mode for multiple time base PWMs
TBCCTL1 = CCIS_0 + OUTMOD_4 + CCIE; // CCR1 toggle, interrupt enabled
TBCCTL2 = CCIS_0 + OUTMOD_4 + CCIE; // CCR2 toggle, interrupt enabled
TBCTL = TBSSEL_2 + MC_2 + TBCLR + TBIE; // SMCLK, contmode, clear TAR,
// interrupt enabled
__bis_SR_register(LPM0_bits + GIE); // Enter LPM3, interrupts enabled
__no_operation(); // For debugger
}
/*Multiple timebase PWMs
*Period is determined by the sum of the two TBCCRx offset values
*Duty cycle is determined by the ration of the high/low TBCCRx value
*to the total period.
*/
// Timer B0 interrupt service routine
// Timer_B1 Interrupt Vector (TBIV) handler
#pragma vector=TIMERB1_VECTOR
__interrupt void TIMERB1_ISR(void)
{
switch(TBIV)
{
case 0: break;
case 2: if(TBCCTL1 & CCI)
{
TB0CCR1 += 250; // 2khz 50% high
}
else
{
TB0CCR1 += 250; // 2khz 50%low
}
break;
case 4: if(TBCCTL2 & CCI)
{
TB0CCR2 += 50; // 10khz 50% high .......here i have problem ????
}
else
{
TB0CCR2 += 50; // 10khz 50% low
}
break;
default: break;
}
}
Part Number: MSP430F2481
hello i am generating two pwm one with frequency 2khz...... 2nd with frequency 10khz
when i am observing both pins on oscilloscope the 1st one pwm is accurate but 2nd one is not correct
this mean i am experiencing problem with higher frequency when i change the 10khz to 5khz then it become accurate but i want 10khz
i dont know what is the problem kindly help me below is my code
#include <msp430.h>
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
// Setup Port Pins
P4DIR |= 0xFF; // P4.0 - P4.7 output
P4SEL |= 0xFF; // P4.0 - P4.6 Port Map functions
P1DIR |= 0x01; // P1.0 - Outputs
//Set up Timer B in continuous mode for multiple time base PWMs
TBCCTL1 = CCIS_0 + OUTMOD_4 + CCIE; // CCR1 toggle, interrupt enabled
TBCCTL2 = CCIS_0 + OUTMOD_4 + CCIE; // CCR2 toggle, interrupt enabled
TBCTL = TBSSEL_2 + MC_2 + TBCLR + TBIE; // SMCLK, contmode, clear TAR,
// interrupt enabled
__bis_SR_register(LPM0_bits + GIE); // Enter LPM3, interrupts enabled
__no_operation(); // For debugger
}
/*Multiple timebase PWMs
*Period is determined by the sum of the two TBCCRx offset values
*Duty cycle is determined by the ration of the high/low TBCCRx value
*to the total period.
*/
// Timer B0 interrupt service routine
// Timer_B1 Interrupt Vector (TBIV) handler
#pragma vector=TIMERB1_VECTOR
__interrupt void TIMERB1_ISR(void)
{
switch(TBIV)
{
case 0: break;
case 2: if(TBCCTL1 & CCI)
{
TB0CCR1 += 250; // 2khz 50% high
}
else
{
TB0CCR1 += 250; // 2khz 50%low
}
break;
case 4: if(TBCCTL2 & CCI)
{
TB0CCR2 += 50; // 10khz 50% high .......here i have problem ????
}
else
{
TB0CCR2 += 50; // 10khz 50% low
}
break;
default: break;
}
}
Part Number: MSP430F2418
hello i am generating two pwm one with frequency 2khz...... 2nd with frequency 10khz
when i am observing both pins on oscilloscope the 1st one pwm is accurate but 2nd one is not correct
this mean i am experiencing problem with higher frequency when i change the 10khz to 5khz then it become accurate but i want 10khz
i dont know what is the problem kindly help me below is my code
#include <msp430.h>
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
// Setup Port Pins
P4DIR |= 0xFF; // P4.0 - P4.7 output
P4SEL |= 0xFF; // P4.0 - P4.6 Port Map functions
P1DIR |= 0x01; // P1.0 - Outputs
//Set up Timer B in continuous mode for multiple time base PWMs
TBCCTL1 = CCIS_0 + OUTMOD_4 + CCIE; // CCR1 toggle, interrupt enabled
TBCCTL2 = CCIS_0 + OUTMOD_4 + CCIE; // CCR2 toggle, interrupt enabled
TBCTL = TBSSEL_2 + MC_2 + TBCLR + TBIE; // SMCLK, contmode, clear TAR,
// interrupt enabled
__bis_SR_register(LPM0_bits + GIE); // Enter LPM3, interrupts enabled
__no_operation(); // For debugger
}
/*Multiple timebase PWMs
*Period is determined by the sum of the two TBCCRx offset values
*Duty cycle is determined by the ration of the high/low TBCCRx value
*to the total period.
*/
// Timer B0 interrupt service routine
// Timer_B1 Interrupt Vector (TBIV) handler
#pragma vector=TIMERB1_VECTOR
__interrupt void TIMERB1_ISR(void)
{
switch(TBIV)
{
case 0: break;
case 2: if(TBCCTL1 & CCI)
{
TB0CCR1 += 250; // 2khz 50% high
}
else
{
TB0CCR1 += 250; // 2khz 50%low
}
break;
case 4: if(TBCCTL2 & CCI)
{
TB0CCR2 += 50; // 10khz 50% high .......here i have problem ????
}
else
{
TB0CCR2 += 50; // 10khz 50% low
}
break;
default: break;
}
}
My first guess is that 50 CPU clocks isn't (always) enough to run your ISR. I usually estimate about 20 clocks just to get into/out of the ISR, and the other 30 clocks disappear quickly. Using OUTMOD=4, the effect of missing the deadline is an inversion of the signal.
Also the two CCR interrupts happen at the same time, and the CCR1 (longer deadline) is always presented first. This creates even more latency for CCR2 and increases the probability of missing the deadline every 5 cycles.
I suspect you can improve things by running at 8MHz (CAL[DCO/BC1]_8MHZ) and running the timer with ID_3 to slow it back down to 1MHz.
Also, it looks as though you take the same action whether you're in the high or the low phase. If you'll always be using 50% duty, these can be combined (maybe save 10-15 clocks).
[Edit: Clarified wording slightly.]
Hello Adnan,
I think Bruce is correct in your issues with your ISR taking to long. I would definitely speed the clock up to 8MHz as a first step.
Are you trying to just generate a square wave with a duty cycle? If so, this can be done automatically by the timer using it's output modes. Here is a software example generating a 25% and 75% duty cycle. http://dev.ti.com/tirex/explore/node?node=AJhhl6hXCpZyIErKG51zqA__IOGqZri__LATEST
Sounds like you would just want 2 different periods. This might be able to be done with a single timer but it can also be done with the 2 separate Timers on the device.
Thanks,
JD
**Attention** This is a public forum