I have spent hours upon days trying to figure out how to configure the ADC to work. I am pretty sure it's a clocking problem because I am doing everything exactly how the tiva examples show as well as many online examples. I am short on time and could use some help. This is for my dad's business.
I am using the TM4CXNCZAD.
Relevant code is as follows:
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "inc/hw_ints.h"
#include "inc/hw_pwm.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/systick.h"
#include "driverlib/pwm.h"
#include "driverlib/adc.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
uint32_t ADC_Data[1];
void ConfigADC()
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);//The ADC0 peripheral must be enabled for use.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
//ADCHardwareOversampleConfigure(ADC0_BASE, 64);
//ADCReferenceSet(ADC0_BASE, ADC_REF_INT);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0);//Select the analog ADC function
// Enable the first sample sequencer to capture the value of channel 0 when
// the processor trigger occurs.
ADCSequenceDisable(ADC0_BASE, 3);
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
//ADCIntRegister(ADC0_BASE, 3, ADC0Handler);
ADCSequenceEnable(ADC0_BASE, 3);
ADCIntClear(ADC0_BASE, 3);//to make sure the interrupt flag is cleared before we sample.
while(1)
{
ADCProcessorTrigger(ADC0_BASE, 3);//Trigger the ADC conversion.
while(!ADCIntStatus(ADC0_BASE, 3, false)){}//Wait until the sample sequence has completed.
ADCIntClear(ADC0_BASE, 3);//Clear the ADC interrupt flag.
ADCSequenceDataGet(ADC0_BASE, 3, ADC_Data);//Read the value from the ADC (stored in ADC_Data).
SystickDelay5ms();
}
}
int main(void)
{
//SysCtlClockSet(SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
//SysCtlClockSet(SYSCTL_OSC_MAIN);
//SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);//taken from and for the ADC example
//SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);//taken from and for the UART example
ConfigSystickTimer();
ConfigGPIOExample();
ConfigPWMs();
ConfigUART();
ConfigADC();
IntMasterEnable();//Enable the processor interrupt(possibly needed for all interupts to work)
while(1){}
}
