This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Trying to set up ADC to read from a potentiometer

Hey guys!

So i have been trying to set up to read values from a potentiometer. I was checking any type of other issues i could be having such as UART but i can output to the console so i believe i must be setting up my adc wrong. I believe my issue is not using this function correctly (ADCIntRegister) but i really am not sure. I posted my code below.

/*
* main.c
*/
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_adc.h"
#include "inc/hw_ints.h"
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "inc/hw_gpio.h"
#include "driverlib/adc.h"
#include "utils/uartstdio.h"
#include "driverlib/uart.h"

int main(void) {
uint32_t result;
uint32_t ISR_ADC_Read;

SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
UARTStdioConfig(0, 115200, 16000000);
// adc stuff
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralReset(SYSCTL_PERIPH_ADC0);
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);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
//ADCIntRegister(ADC0_Base,3, &ISR_ADC_Read);
ADCIntEnable(ADC0_BASE, 3);
IntMasterEnable();
ADCProcessorTrigger(ADC0_BASE, 3);
ADCIntClear(ADC0_BASE, 3);

while (!ADCIntStatus(ADC0_BASE, 3, false))
{
}

ADCSequenceDataGet(ADC0_BASE, 3, &result);

float voltage = result*.000805664;

UARTprintf("The value for the Horizontal value for result is:", result);
UARTprintf("The value for the Horizontal value for voltage is:", voltage);

return 0;
}

  • Hello Nelson

    1. You have not enabled the floating point unit.
    2. A UART print requires the value in the string to be replaced by the value. The normal method is to use %d for integer, %c for character and so on. I don't see any of them in the UARTprintf statement.