Hi guys
I am now having some problems with a simple PWM signal out of my MSP430F5510. I noticed that in my previous code the PWM seemed to be extending its duty cycle for just one period once in a while. I thought it might have been problem of the whole code interfering with the PWM generation so I reduced the code to just outputting the PWM, and the problem is still there. I have the program loop the PWM duty cycle from 0-100% and I use an LED to visualize it. Watching the LED it goes from non to full brightness, but ocasionally it flickers with full brightness, sometimes when it is at approx. 50%, sometimes when it is at approx. 20%, and so on. I couldn't find a pattern in the flickering. My PWM implementation (Sorry I didn't get the hang of the Code-inserting tool) :
#include <msp430.h> int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT P1DIR |= BIT2 + BIT3; // P1.2, P1.3 P1SEL |= BIT2 + BIT3; // P1.2, P1.3 options select TA0CCR0 = 5275; // PWM Period ~@200Hz TA0CCTL2 = OUTMOD_7; // CCR2 reset/set TA0CTL = TASSEL_2 + MC_1 + TACLR; // SMCLK, up mode, clear TAR TA0CCR2 = 0; // CCR2 initial PWM duty cycle volatile unsigned int i,guf=1; for(;;){ if(TA0CCR2<TA0CCR0 && guf){ // Duty cycle lower than 100% and currently going up? TA0CCR2++; // Increase duty cycle for(i=50;i>0;i--); if(TA0CCR2==TA0CCR0) guf=0; // if duty cycle of 100% reached, clear going-up-flag } if(TA0CCR2>0 && !guf){ // Duty cycle greater than 0 and currently going down? TA0CCR2--; // Decrease duty cycle for(i=50;i>0;i--); if(TA0CCR2==0) guf=1; // If duty cycle of 0% reached, set going-up-flag } } }
Using the oscilloscope to analyse the signal it looks something like this:
Sorry for the horrible MSPaint drawing but I don't have the oscilloscope right now, I hope you get the idea. And like I said, the flicker occurs sometimes when the duty cycle is at 50%, sometimes at 10%, at 0%, sometimes it doesn't even appear. I noticed that the higer the TA0CCR0 value, the more frequent the flickering occurs. From approximately 1500 and below the flickering disappears. The problem is that I need a 200Hz frequency, which is that TA0CCR0 value.
Am I missing something pretty obvious there? I've tried the same code with two different MSP430F5510 chips, and it behaves the same way in both of them, so I'm guessing it is a code issue.
Thanks in advance for your help!
Best Regards