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.

ADC with TivaWare TM4C123GH6PM

Other Parts Discussed in Thread: TM4C123GH6PM

Hey guys,

I'm trying to configure the ADC on TM4C123GH6PM using the TivaWare Library since i'm using the grLib in my project.

Here is the exemple for measuring the temperature (Lab 5).

I'm trying to modify the code to measure a voltage from port PE3.

I will be very gratefull if someone can help me with that !

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/sysctl.h"
#include "driverlib/adc.h"
#define TARGET_IS_BLIZZARD_RB1
#include "driverlib/rom.h"

int main(void)
{
	uint32_t ui32ADC0Value[4];
	volatile uint32_t ui32TempAvg;
	volatile uint32_t ui32TempValueC;
	volatile uint32_t ui32TempValueF;

	ROM_SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);

	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
	ROM_ADCHardwareOversampleConfigure(ADC0_BASE, 64);

	ROM_ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
	ROM_ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS);
	ROM_ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS);
	ROM_ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS);
	ROM_ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);
	ROM_ADCSequenceEnable(ADC0_BASE, 1);

	while(1)
	{
		ROM_ADCIntClear(ADC0_BASE, 1);
		ROM_ADCProcessorTrigger(ADC0_BASE, 1);

	   while(!ROM_ADCIntStatus(ADC0_BASE, 1, false))
	   {
	   }

	   ROM_ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value);
	   ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4;
	   ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096)/10;
	   ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5;
	}
}

  • My friend - some (but possibly not all) difficulties quickly reveal - your code.

    Code you show uses the MCU's internal temperature sensor - which is not very helpful for more "normal/general" ADC use.

    Here's a brief guide which should assist:

    a) if PE3 is indeed an ADC pin you must first enable Port E - and then configure PE3 for it's ADC role'

    b) PE3 will have some definite, "ADC channel number assignment" - your review of the MCU manual's ADC chapter should detail

    c) armed with (b) you must config PE3 to it's ADC role

    d) w/in function, "ADCSequenceStepConfigure() you must "ADC_CTL_TS" with PE3's Analog channel number

    e) suggest that you connect a 10K (or so) pot to 3V3 and ground - wiper then to PE3.   Set this to mid-range - and then run.  

    As your PE3 voltage approaches 3V3 the ADC should come close to 4095 - 1V65 should yield (near) 2048 - and 0V should yield w/in 10 counts of 0.

    Consult examples/peripherals/adc/"single_ended.c" for an excellent code example.

    You're close - that example has served many - good luck.   Remember to enable other ports (beyond Port E) when you expand your efforts to other ADC channels.  Those (new) ADC channels not resident upon Port E.