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.

MSP430 PWM Timer transient glitch

Other Parts Discussed in Thread: MSP430G2452

Using an MSP430G2452 on my Launch Pad I programmed a slowly varying PWM Signal to drive the green LED.

When using the SMCLK-Signal I noticed a strange transient pulse close to Zero duty cycle which I cannot explain. The glitch does not appear with the ACLK-Signal or with a Minimum PWM duty cycle of more than approx. 5%. The same thing happens with OUTMOD_3 near 100% duty cycle.

Here is a test program to demonstrate this effect:

 

/* TEST_PWM

* Test Program to reproduce Timer glitch near zero duty cycle

*/

#include <msp430.h>

int Level; // PWM Duty Cycle

int Delta; // Step size

const int TA0CCR1_MAX = 5000; // Max Duty Cycle

const int TA0CCR1_MIN = 0; // Min Duty Cycle

int Flag; // Flag for Timer Interrupt

/*

* main.c

*/

int main(void) {

 

// Initialization of all timer registers

    WDTCTL = WDTPW | WDTHOLD;

    TA0CTL = TASSEL_2 + ID_2 + MC_1;

    TA0CCTL0 = CM_0 + CCIS_0 + OUTMOD_0 + CCIE;

    TA0CCTL1 = CM_0 + CCIS_0 + OUTMOD_7;

    TA0CTL = TASSEL_2 + ID_2 + MC_1;

    TA0CCR0 = 4999; // TImer 0 with 20 ms period interrupt

   // configure green LED at Pin 1.6 as PWM Output

 

    P1OUT = BIT6;

    P1SEL = BIT6;

    P1DIR = BIT6;


// Enable Interrupts

    __bis_SR_register(GIE);

    Level = TA0CCR1_MAX;

    Delta = 15; // Up/Down Step Size

    Flag = 0; // Reset Flag

while (1)

    {

if (Flag == 1) // Wait Loop until Flag

{

Flag = 0; // Clear Flag

 

if (Delta > 0)

{

Level = Level + Delta;

if (Level > TA0CCR1_MAX) // inc Level by Delta up to TA0CCR1_MAX

{

Level = TA0CCR1_MAX;

Delta = -Delta; // reverse direction

}

}

else

{

Level = Level + Delta;

if (Level < TA0CCR1_MIN)

{

Level = TA0CCR1_MIN; // dec Level by Delta down to TA0CCR1_MIN

Delta = -Delta; // reverse direction

}

}

TA0CCR1 = Level; // Update TA0CCR1

}

    }

}

// Timer ISR to increment/decrement PWM duty cycle every 20ms

#pragma vector=TIMER0_A0_VECTOR

__Interrupt void TIMER0_A0_ISR_HOOK(void)

{

TA0CTL &= ~TAIFG; // Clear Timer A Interrupt flag

Flag = 1; // Set Flag for Main()

}

  • Timer_A does not have double-buffered CCR registers, CCR register is effective immediately on write. When you set CCR from N to N-1 while timer counter equals N-1, timer can meet CCR new value only during next cycle - current cycle ends without CCR match.

  • Thank you for your hint.

    I could avoid the glitch occurrence by using PWM Outmode 3 and by stopping the timer before modifiying CCR1. In addition to that I reset Timer A before restarting it in up direction, thus avoiding the N to N-1 Problem.

     

  • Thomas Weber99892 said:
    I could avoid the glitch

    You can avoid glitch by modifying CCR right after timer rollover (which you can detect and wait for). Of course it depends on how much faster MCLK is versus timer rollover frequency, but it's doable for most DC and stepper motor applications at least.

**Attention** This is a public forum