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.

Basic ADC configuration on TM4C123G

Other Parts Discussed in Thread: EK-TM4C123GXL

I'm working on first ARM core, specifically the EK-TM4C123GXL board, which uses the the TM4C123GH6PMI controller. I'm trying to set up a simple program to poll the ADC and turn on some GPIO pins based on the value. I have not implemented the GPIO stuff yet as I'm trying to get the ADC working before going any further.

#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_memmap.h"
#include "driverlib/adc.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
//#include "driverlib/rom.h"

/***************************************************************************/

#define ONE_LED 0x01
#define TWO_LED 0x03
#define THREE_LED 0x07
#define FOUR_LED 0x0F

/***************************************************************************/

int main(void)
{
uint32_t pui32ADC0Value[1];

//Configure clock
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);

//Enable Port E
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

//Enable ADC0 using Port E/Pin 2, then enable the sequence
//and finally clear the interrupt flag
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2);
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);

while(1)
{
//Trigger the read, wait for it to finish, clear the
//interrupt flag and finally read the data
ADCProcessorTrigger(ADC0_BASE, 3);
while(!ADCIntStatus(ADC0_BASE, 3, false)) {}
ADCIntClear(ADC0_BASE, 3);
ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value);

// this is here simply for debugging purposes
pui32ADC0Value[0]++;
/* Add code to process later...
if (pui32ADC0Value[0] < 1000)
{
}
else if (pui32ADC0Value[0] >= 1000 && pui32ADC0Value[0] < 2000)
{
}
else if (pui32ADC0Value[0] >= 2000 && pui32ADC0Value[0] < 3000)
{
}
else
{
}
*/
SysCtlDelay(SysCtlClockGet() / 12);
}
}

 

My code is always stuck in the while(!ADCIntStatus(ADC0_BASE, 3, false)) {} loop and won't go from there. This is my first project on this processor so maybe I have a configuration issue in CCS? Also, I've seen some projects that use the ROM_ (function_name) Macro to accomplish tasks. What is the difference between that and simply calling the function itself (e.g. SysCtlPeripheralEnable vs ROM_SysCtlPeripheralEnable)? When I try and do this by including the ROM header file the code is "greyed out", as to indicate that it won't be compiled because none of the requested parameters are defined. I can post more info if needed, thanks for the help!

  • Hi,

    Austin Riffle said:
    ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE |
    ADC_CTL_END);

    PE2 is CH1 so change ADC_CTL_CH0 to ADC_CTL_CH1Also you did not enable ADC Interrupt using ADCIntEnable().

    There are lots of ADC codes in the forum that you can learn from, so do a search in the forum. 

    - kel

  • Hi,

    I was saw this "yesterday", or better, 5h ago but i was more sleeping than awake, so anything you would put in front of me would be alright... note to self, never come here at 4am.

    Here is a example:

    http://forum.stellarisiti.com/topic/2045-adc-peripheral-has-alot-of-fuctions/

  • Hi Kel

    Thanks for your answer. Out of curiosity, where did you find the information regarding which pin is used for each channel? I looked through the datasheet (Datasheet-TM4C123GH6PM.pdf - chapter 14) and could not find anything regarding that configuration. Also, I added those changes to my code and it seems to have fixed the problem. However, I think that I may have pushed too much current through PE2, as now whenever I call
        GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2);
    the FaultISR() function is called. Is there anyway to verify this in software? Thanks

    Austin

  • Hi Austin, after you enable a peripheral you need to wait at least 3 system clocks before accessing the registers. So adding a SysCtlDelay(3) (it adds 9 cycles) should do. You can also re-arrange the function calls.

     I looked through the datasheet (Datasheet-TM4C123GH6PM.pdf - chapter 14)

    i think you meant 13 right?

    Table 13-1 should give you that information. You can use any of the ADCs for any channel. But each channel has a specific pin.

    You can see in Figure 13-1. that the inputs are connected to both ADCs

  • Hi Austin,

        I just did a search for PE2, and at chapter 13 you can find a ADC Signals Table. PE2 is AIN1 or CH1.

    - kel