Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

PWM giving jittery signal

$
0
0

I am using the M430G2553 chip and trying to do a PWM program to control a servo.  I have the script running and it works good except I can see on my scope that every few seconds I get a signal that is at full voltage for the duration of the idle time.  It only happens very suddenly and at random and only for 1 signal duration.  This is causing my servo to jitter.  I have isolated it to the program because when the pot is fully turned to the 10k resistance (the ADC10MEM reads 0x03FF) there is no jitter at all.  When I move anything lower than this the jitteryness happens.  I think it has something to do with the ACD10MEM having problems because when I remove this and hard code a value in it's place, everything works fine.  If I put a 1k resistor in place of the pot it still jitters so it does not have anything to do with a bad pot.  Do you know why this is happening?  Code is below:

 

#include "msp430g2553.h" // make sure you change the header to suit your particular device.

/*  

* Vcc To POT  

* P1.1 From POT  

* P1.2 To Servo  

*/

#define MCU_CLOCK   1000000

#define PWM_FREQUENCY  46  // In Hertz, ideally 50Hz.

unsigned int PWM_Period  = (MCU_CLOCK / PWM_FREQUENCY); // PWM Period

void main(void) {  

WDTCTL = WDTPW + WDTHOLD; // Stop WDT

P1DIR |= 0x0C; // P1.2 and P1.3 output  

P1SEL |= 0x0C; // P1.2 and P1.3 TA1/2 options

TACCTL1 = OUTMOD_7;            // TACCR1 reset/set  

TACTL = TASSEL_2 + MC_1;     // SMCLK, upmode - SETUPS TIMER  

TACCR0 = PWM_Period-1;        // PWM Period - NUMBER TO COUNT TO

 //ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE; // ADC10ON, interrupt enabled  

ADC10CTL0 = SREF0 + ADC10SHT_2 + ADC10ON + REFON + REF2_5V + ADC10SR;

ADC10CTL1 = INCH_1; // input A1  ADC10AE0 |= 0x02; // PA.1 ADC option select

 for (;;){

  ADC10CTL0 |= ENC + ADC10SC;

  while (ADC10CTL1 & ADC10BUSY);

  TACCR1 = ADC10MEM;

 }

}


Viewing all articles
Browse latest Browse all 262198

Trending Articles