I am trying to sample to sample a 50 Hz sine signal using a timer trigger. The timer has a period of 1000 Hz. The problem is that my output looks nothing like the signal coming in.
Below is my code and corresponding graph---
uint32_t Voltage; uint32_t pui32ADC0Value[1]; void InitConsole(void) { SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioConfig(0, 115200, 16000000); } int main(void) { uint32_t ui32Period; //Set Timer0 SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); ui32Period = (SysCtlClockGet()/1000)/2 ; TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period-1); IntEnable(INT_TIMER0A); TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); IntMasterEnable(); TimerEnable(TIMER0_BASE, TIMER_A); InitConsole(); SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3); ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE |ADC_CTL_END); ADCSequenceEnable(ADC0_BASE, 3); ADCIntClear(ADC0_BASE, 3); ADCIntEnable(ADC0_BASE, 3); while(1){ } } void timer_ADC(void) { ADCProcessorTrigger(ADC0_BASE, 3); while(!ADCIntStatus(ADC0_BASE, 3, false)) ; ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value ); Voltage = (pui32ADC0Value[0]*3.3/4096); } void Timer0IntHandler(void) { TimerIntClear(TIMER0_BASE,TIMER_TIMA_TIMEOUT); timer_ADC(); UARTprintf("%4d\r", pui32ADC0Value[0]); }