When the device is initially powered up the first pulse is always considerably longer than the desired set point. Once the device is running and inputs direct it back to the start of the main code the pulse width is always correct. I'm only seeing the issue on startup of the very first pulse.
//Setup Timer for PWM
TACCR0 = 360 - 1; // Pulse Frequency
TACCR1 = 0; // Pulse Width - 0 is OFF ?
TACCTL1 = OUTMOD_2; // TA0CCR2 toggle mode
TACCTL2 = OUTMOD_6; // TA0CCR2 toggle mode
TA0CTL = TASSEL_2 + MC_0; // SMCLK, up/down mode
TACCR2 = (TACCR0 - TACCR1); // Set Hi/Lo Pulse Equal
//function called to start PWM output
volatile int Test_Volt(volatile int m)
{
volatile int i = 0;
TACCR1 = 25; // Set width value
TA0CTL = TASSEL_2 + MC_3; // Start
TACCR2 = (TACCR0 - TACCR1);
for (i=0;i<10;) // Code to loop
{
while ((TACTL & CCIFG) == 1)
{i++;
break;
}
}
TACCR1 = 0;
TACCR2 = (TACCR0 - TACCR1);
TA0CTL = TASSEL_2 + MC_0; // Stop pulses for test
TA0CTL = TASSEL_2 + MC_3;
for (i=0;i<60;) // Code to loop
{
while ((TACTL & CCIFG) == 1)
{i++;
break;
}
}
ADC10CTL1 |= INCH_1; //Select Analog Input
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE);
if (ADC10MEM < 512)
{
P1OUT &= ~BIT0; // Turn off 1 LED
P1OUT |=BIT1; // Turn on 2 LED
ADC10CTL0 &= ~ENC; // Stop ADC
ADC10CTL1 &= ~ INCH_15; // Clear ADC Pin Select
m = 1;
return m;
}
else{
P1OUT |= BIT0; // Turn on 1 LED
ADC10CTL0 &= ~ENC; // Stop ADC
ADC10CTL1 &= ~ INCH_15;} // Clear ADC Pin Select
m = 0;
return m;
}
