Other Parts Discussed in Thread: MSP430F5529
Hello Everyone,
I am currently having issues with updating the timer capture/compare register for timer A1 on an MSP430F5529 Launchpad. I need to constantly update the value of this register to adjust the output frequency of a digital signal in accordance with an analog input. My algorithm works for updating the frequency according to the input signal, and when I use a constant value for the capture/compare register it works fine. However, my issue arises when I repeatedly refresh the capture/compare register. Every now and then (not periodic) there are 'missing' pulses, or extra-long pulses on the oscilloscope. I have attempted stopping the timer by using TA1CTL = MC_0, then writing the new value for the frequency to the capture/compare register, and then restarting the timer with TA1CTL = MC_1 but when I do this I don't get any output whatsoever.
I have heard of a way of using timer B to synchronize how it updates the frequency, but I am unsure of how to do this. Could anyone lend me an example of this? Or suggest any other remedies to this rather irksome problem? I'm so close to solving this! Here is the snippet of my code that deals with setting up timer A, updating it's register value, and then the interrupt it uses to toggle the digital output:
//***************** BEGIN TIMER INTERRUPT SETUP *****************\\
TA1CCTL0 = CCIE; //enable timerA1 interrupts
TA1CCR0 = 10; //set value for timerA1 to count up to
TA1CTL = TASSEL_1 + MC_1 + TACLR + ID_0; //use SMCLK for timerA1, up mode, clear TA, /2
__bis_SR_register(GIE); //enable maskable interrupts
//***************** END INTERRUPT TIMER SETUP *******************************\\
Math_Sub_Routine(){
//A bunch of math also goes on in this subroutine, but not related to the timer, relates to finding the Timer_Register_Value, works fine.
Timer_Register_Value = Timer_Calib / Foot_Pulse_Freq;
//TA1CTL = MC_0; //this was my attempt at stopping the timer
TA1CCR0 = Timer_Register_Value;
//TA1CTL = MC_1; //and restarting after the value had been written.
}
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//Timer1 Interrupt used to output digital signal
#pragma vector=TIMER1_A0_VECTOR
__interrupt void TIMER1_A0_ISR(void)
{
if(Foot_Pulse_Output_Enable == 1){
P2OUT ^= BIT0; //toggles GPIO P2.2
}
}
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Thanks to everyone who replies in advance, you have all been helpful in the past.
Thanks!
Thomas