Hi,
I have built a timer triggered ADC program to read 4 different channel using sequencer 1. I am checking values in watch window in debug mode. While the ADC is measuring values properly, channels are getting swapped. Here is the code:
#include <stdint.h> #include <stdbool.h> #include <math.h> #include "inc/tm4c123gh6pm.h" #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "driverlib/sysctl.h" #include "driverlib/interrupt.h" #include "driverlib/gpio.h" #include "driverlib/timer.h" #include "driverlib/adc.h" #include "driverlib/fpu.h" #include "driverlib/pin_map.h" uint32_t ui32ADC0Value[4]; volatile uint32_t a,b,c,d; int main(void) { //Set processor @ 80 MHz. SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); //=============================================================================================== //Give clock to the peripherals: //GPIO for testing: LED: R B G SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //GPIO for capture interrupt SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); //ADC pins SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); //Timer for 40 kHz calc and adc trigger SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); //ADC 0 SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlDelay(10); //=============================================================================================== //Peripheral configuration //Config GPIO: LED R B G GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); //Config Timer0: 40 kHz TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); //32 bit mode TimerLoadSet(TIMER0_BASE, TIMER_A, 2000-1); //load period IntEnable(INT_TIMER0A); //interrupt enable TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); //interrupt condition: timeout TimerControlTrigger(TIMER0_BASE, TIMER_A, true); //ADC trigger //Configure ADC0 ADCSequenceDisable(ADC0_BASE, 1); GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0); GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1); GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2); GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3); GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_3); ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_TIMER, 0); //sequencer 1, proccessor trig, priority zero highest ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH4); ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH3); ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH2); ADCSequenceStepConfigure(ADC0_BASE, 1, 3, ADC_CTL_CH1|ADC_CTL_IE|ADC_CTL_END); //final step: give int, stop IntEnable(INT_ADC0SS1); ADCIntClear(ADC0_BASE, 1); ADCIntEnable(ADC0_BASE, 1); //=============================================================================================== //Enable the peripherals one by one //Int master enable IntMasterEnable(); //Timer0: Calc & ADC trigger TimerEnable(TIMER0_BASE, TIMER_A); //ADC ADCSequenceEnable(ADC0_BASE, 1); //=============================================================================================== while(1) { } } //=============================================================================================== void Timer0IntHandler(void) { TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); if(GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_4)) GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0); else GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 2); } //================================================================================================ void ADC0SS1IntHandler(void) { ADCIntClear(ADC0_BASE, 1); ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value); a = ui32ADC0Value[0]; b = ui32ADC0Value[1]; c = ui32ADC0Value[2]; d = ui32ADC0Value[3]; } //==================================================================================================
e.g. the graph of first value ui32ADC0Value[0] is shown
There are sudden random spikes, which correspond to readings of other channels.
If all 4 steps in the sequencer are configured to read the same channel then the issue does not arise. So hardware seems fine.
Has anyone encountered similar issue?
Thank you.
-Saurabh