Part Number: TM4C129ENCPDT
Hi all. I'm having a some ADC problems with this board, and I haven't found a solution. I've done similar ADC tasks on some previous boards and not had this problem. Same processor as well. At this point, I've stripped it down to the most basic ADC code, and still see the issue.
I'm reading values from a 2 axis analog joystick. I get 0-3V from it on each axis. I've stripped the code down to just read one axis right now, since I can't figure out what is going on.
#define SEQ_NUM 3
uint32_t pui32ADC0Value[4];
uint32_t pui32ADC1Value[4];
void joystick_init(void) {
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_2);
ADCReferenceSet(ADC0_BASE, ADC_REF_EXT_3V);
ADCSequenceDisable(ADC0_BASE, SEQ_NUM);
ADCSequenceConfigure(ADC0_BASE, SEQ_NUM, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, SEQ_NUM, 0, ADC_CTL_CH13 | ADC_CTL_IE | ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, SEQ_NUM);
ADCIntClear(ADC0_BASE, SEQ_NUM);
}
void joystick_thread(void) {
while (1) {
ADCProcessorTrigger(ADC0_BASE, SEQ_NUM);
while (!ADCIntStatus(ADC0_BASE, SEQ_NUM, false)) {
}
ADCIntClear(ADC0_BASE, SEQ_NUM);
ADCSequenceDataGet(ADC0_BASE, SEQ_NUM, pui32ADC0Value);
inputvalue = (pui32ADC0Value[0] & 0xFFF);
sprintf(string, "raw = %d", inputvalue);
send_string_msg(STRING_COMMAND, 0, string);
SysCtlDelay(ui32SysClock / 120);
}
}
The send_string_msg() sends the value to a LED display.
It all seems really basic, but most of the time, I get the values expected from the ADC, but maybe 10% of the time, I get a value, 0, 3, 7, 15, 31, 63, 127, 255, you get the idea. This causes havoc with the controls system.
It doesn't seem to matter what delay I put in the loop. I've tried doing sequences, using sequence number 0 or 1 for example, and reading 4 values. I've tried using the oversampling, but then I just get a value below the expected since more low values are averaged. I've tried adding the ADC_CTL_SHOLD_16 values in the sequence step. If I do a sequence of 4 steps for example, any one of the 4 samples at any time might be correct, or might be low, so say, one or two are low, the other two are expected.
Maybe the solution is right in front of me and I'm not seeing it, having looked at this for a while. Any help is appreciated.
