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()
}