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.

TM4C123GH6PM: How do I use ADC4-ADC7 ?

Part Number: TM4C123GH6PM

Hello, I tried to use ADC4, but it gives me error "SYSCTL_PERIPH_ADC4 is Undefinded" & "ADC4 is Undefinded". Thank you for you help!

Below is my code:

#include "include.h"

void ADC4_ISR(void);
void Config_ADC(void);


unsigned int ADC4_Data[3];
float ADC4_Voltage;
//float ADC0_Temperature;

void Config_ADC(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC4);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_3);

ADCSequenceConfigure(ADC4_BASE, 1 ,ADC_TRIGGER_PROCESSOR,0);

ADCSequenceStepConfigure(ADC4_BASE, 1, 0, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC4_BASE, 1, 1 ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC4_BASE, 1, 2, ADC_CTL_CH0
| ADC_CTL_END|ADC_CTL_IE);

ADCSequenceEnable(ADC4_BASE,1);
ADCIntRegister(ADC4_BASE, 1, &ADC4_ISR);
ADCIntEnable(ADC4_BASE,1);
}


void main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); //for 80 MHz
SysCtlDelay(80000000);
Config_ADC();
IntMasterEnable();

while(1)
{
ADCProcessorTrigger(ADC4_BASE,1);
SysCtlDelay(800);
}
}

void ADC4_ISR(void)
{
ADCIntClear(ADC4_BASE,1);
ADCSequenceDataGet(ADC4_BASE, 1, (unsigned int *)&ADC4_Data);
ADC4_Voltage = 0 +((float)(ADC4_Data[0] + ADC4_Data[1] + ADC4_Data[2])/3)*3.25/4096;
}

  • Your creation of  'ADC4-ADC7' and  ADC4_BASE' - while 'original' - indeed are  undefined/illegal!      (and thus - unknown to the compiler & other programming resources.)    

    There exist  two 'ADC Modules' - noted as 'ADC0_BASE' and 'ADC1_BASE'.     Both are 'known' - thus recognized & appropriate - for your (and others') use.    These (must) be used - in place of your 'invention.'

    ADC4-ADC7  also illegal - should be replaced with: 'ADC_CTL_CH4 - ADC_CTL_CH7' - which ARE recognized & legal.

    Your read/review of this vendor's,  'Peripheral Library User Guide' (SW-TM4C-DRL-UG-2) reveals:

    4.2.2.27 ADCSequenceConfigure
    Configures the trigger source and priority of a sample sequence.
    Prototype:
    void
    ADCSequenceConfigure(uint32_t ui32Base,
    uint32_t ui32SequenceNum,
    uint32_t ui32Trigger,
    uint32_t ui32Priority)

    Parameters:
    ui32Base is the base address of the ADC module.         ***  ADC4_BASE (creation) is ILLEGAL!     'ADC0_BASE or ADC1_BASE' (only) are proper.
    ui32SequenceNum is the sample sequence number.
    ui32Trigger is the trigger source that initiates the sample sequence; must be one of the
    ADC_TRIGGER_ values.
    ui32Priority is the relative priority of the sample sequence with respect to the other sample
    sequences.

    To determine the appropriate pin/function labels - consult the specific peripheral module's '.h file' - as well as  (very large) file 'pin_map.h.'

    Numerous code examples - even some aimed at the ADC - exist & will 'well-guide' you.     ('Blind' pin/function 'name creation' ...  Not so much!)

  • Thank for the reply.
    How would I use ADC0 at PIN PD3 in the Launchpad?
  • phuoc nguyen said:
    How would I use ADC0 at PIN PD3 in the Launchpad?

    You would NOT!     Appears that you (still) are 'bit challenged' by the MCU's presentation of the ADC.

    Let's start w/the MCU Manual:

    You should note that AIN0 resides - NOT at  'PD3'  - but instead at 'PE3."     From where are you drawing such erroneous data?    (some other chip perhaps - it helps if  you explain...)

    My original post - in answer to your questions re: 'ADC4-ADC7' - was believed to provide you w/sufficient guidance - to enable you to configure your MCU to (any) of the ADC pins which your LPad exposes.   (i.e. brings out to the board's headers)

    You are silent as regards the, 'Proper Base Address' (0 or 1- never 4.)     The MCU's manual 'AIN0' nomenclature is properly noted as, 'ADC_CTL_CH0'.     (that should have been clear to you.)

  • How would I set the ADCSSMUXn to use AIN4 at PD3 in the launchpad?
  • One (well answered) question appears to lead (inevitably) to two more.     (that's not especially satisfying - is it?)

    Your original question has LONG been effectively answered - awaits its deserved, "Tick of, This Resolved my Issue."

    And ... you've not answered - from WHERE are you drawing your erroneous data?     That must be  identified & corrected - don't you agree?

    It is 02:50 (local, CST time (Chicago) - I am 'done' for now... (several green ticks (to my posts - not yours) have been earned - have they not?

  • Thank you - appreciated.     It is (still) believed useful - for you to advise - as to the 'source' of your  often, 'erroneous data.'

    I've listed multiple (known valid/good) 'PROPER SOURCES' for you - you should BANISH that (earlier) - error-generating alternative.     It does NOT ... well serve you - that's been proven.

    Why don't you - after a (fair) read/review of the MCU Manual - the Peripheral Library User Guide (especially) - and several T-Ware (adc examples)  (found: T-Ware\examples\peripherals\adc) attempt to, 'Set the ADCSSMUXn to use AIN4 at PD3 in the launchpad?     Our office is closed (in honor of tomorrow's  U.S. 'Independence Day') and I should be able to (further) guide - as/if required.

    It's long proven - that  your effort - hugely trumps 'spoon-feeding' of answers - by others.    (even & especially 'vendor others')
    Your  'growth'  -  in both knowledge & confidence  - flow from your efforts & building mastery - not from the 'rubber stamp'  (copy/paste) provided by  'rushed & driven' others!'      Allez!