Hi,
I am very new to using microcontroller. I have been assigned to read an ADC Value using a timer interrupt, then UART-ing the results. The problem I am encountering is when a UART statement is present in the timer interrupt, the result is a delayed timer interrupt. For example, I am sampling a 50Hz sine wave in 12800Hz to produce 256 sample points in one period. I am able to produce the result correctly without UART, but once UART (even a simple \n\f printf) is added, the sample points span across 3 periods. I suspect this is due to delay in sampling.
I hope i make myself clear. Is there any workaround for this? Perhaps i shouldn't place UART in a timer interrupt of 12800Hz.
void Timer0IntHandler(void)
{
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
ADCIntClear(ADC0_BASE, 0);
ADCProcessorTrigger(ADC0_BASE, 1);
while(!ADCIntStatus(ADC0_BASE, 1, false))
{}
ADCSequenceDataGet(ADC0_BASE, 1, data);
dataavg=(data[0]+data[1]+data[2]+data[3])/4;
if (j==256)
{
return;
}
else
{
if (dataavg>2048)
{
ACVoltage[j]= (dataavg-2048)*3.4/2048.00;
// UARTprintf("%d\n\r", dataavg);
j++;
}
else
{
ACVoltage[j]= -((2048-dataavg)*3.4/2048.00);
// UARTprintf("%d\n\r", dataavg);
j++;
}
}
}
* The UARTprintf produces delay.