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.

Analog signal sampling of a chosen pin

Hey TI og others. 

I have been doing the tutorial Lab 5 where he samples a temperature signal on the stellaris LM4F120XL. Now I want to sample an external analog signal  through to a chosen pin, but I am pretty confused of how to configure it and which pins the analog signal input to, can anybody help me?

My guess was: 

Void  Unit_ADC_analog_input (void) {

          SysCtlPeripheralEnable (SYSCTL_PERIPH_ADC0); 

          SysCtlADCSpeedSet(SYSCTL_ADCSPEED_250KSPS);

           ADCSequenceDisable(ADC0_BASE, 1);

           ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);

           SysCtlPeripheralEnable (SYSCTL_PERIPH_GPIOE);

           GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);    // Cant I use that pin to sample analog signal???

          ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH0);  // I don't which channals to use here,                 just used CHO, should I use a different one ???

          ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH0);

          ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH0);

          ADCSequenceStepConfigure(ADC0_BASE, 1, 3, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);

          ADCSequenceEnable(ADC0_BASE, 1);

}

void main (void) {

     unsigned long Analog_sample[4] ;

       ADCIntClear(ADC0_BASE, 1);

        ADCProcessorTrigger(ADC0_BASE, 1);

       while(!ADCIntStatus(ADC0_BASE, 1, false))

       {

       }

       ADCSequenceDataGet(ADC0_BASE, 1, Analog_sample);

}

  • Hi Nilas,

        Compare your code to the adc example code at the examples folder.

    -kel

  • Thanks kel, but which examples folder  and where can I find it? 

  • It is at "TivaWare_C_Series-1.0\examples\peripherals\adc"

  • Nilas St���hrmann said:
    pretty confused of how to configure...ADC... and which pins the analog signal input to

    Friend Kel provided SW advice - suspect bit of, "real-world" board advice targets your, "which pin" issue.  Board designers likely routed many - but not all - of your MCU's ADC pins to edge connector(s).  It is unpleasant (possibly destructive) to "tack-solder" to an MCU pin - so your attention must start w/your board schematic or examination of the board's screened markings.  Best to choose one/several of the MCU pins which serve as ADC - AND which route to an edge connector.  (MCU manual will detail which pins may be employed as ADC - after proper set-up/config.)

    Prior to introducing an external signal - insure that it is stable and w/in the acceptable voltage limits of your ADC.  MCU manual (rear) details acceptable ADC input voltage levels.  Suggest that you start w/voltage near the center of ADC's input range - when properly introduced, routed & converted - 1/2 of Max-ADC count should reveal.

    Simple 10K pot - ends tied to 3V3 & Gnd - wiper to edge connector - enables eased adjustment.  You may construct a simple - 2 resistor divider - to further reduce the wiper voltage - and then provide 2 different (yet tracking) voltages to 2 ADC Channels.  (avoid modulated or time varying voltages at the beginning - KISS most always is best/shortest path...)

    Note that rebrandWare has been suggested - yet iirc - your MCU is Stellaris class...

  • Thanks for the tips but It did not really help me because I still don’t know how configure the edge connectors. 

    I have been looking for a datasheet for the LM4120XL stellaris but I can’t find it anywhere. It’s very frustrating and I am actually considering buying a different microcontroller. 

    I looked in the LM4120XL user guide and driver library user guide and found out that PORT E, pin: E3 have a GPIOAMSEL as “AIN0”, not sure if that means analog to digital input?.

    But figured I could do the code below as start:

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3); 

    But It does not recognize “GPIO_PIN_3”, so how do I connect to PE3???

    Please help its all getting a little hopeless.

    Thanks.

    The complete code is below

    1. #ifdef DEBUG
    2. void
    3. __error__(char *pcFilename, unsigned long ulLine)
    4. {
    5. }
    6. #endif
    7.  
    8. int main(void)
    9. {
    10.     unsigned long ulADC0Value[4];
    11.    SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
    12.    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    13.    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_7);
    14.  
    15.     SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    16.     SysCtlADCSpeedSet(SYSCTL_ADCSPEED_250KSPS);
    17.     ADCSequenceDisable(ADC0_BASE, 1);
    18.  
    19.     ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
    20.     ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH0);
    21.     ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH0);
    22.     ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH0);
    23.     ADCSequenceStepConfigure(ADC0_BASE, 1, 3, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
    24.                ADCSequenceEnable(ADC0_BASE, 1);
    25.  
    26.                while(1)
    27.                {
    28.                              ADCIntClear(ADC0_BASE, 1);
    29.                              ADCProcessorTrigger(ADC0_BASE, 1);
    30.  
    31.                              while(!ADCIntStatus(ADC0_BASE, 1, false))
    32.                              {
    33.                              }
    34.  
    35.                              ADCSequenceDataGet(ADC0_BASE, 1, ulADC0Value);
    36.                             
    37.  }
  • Nilas St���hrmann said:
    I still don’t know how configure the edge connectors. 

    One doesn't really, "configure" edge connectors.  They are what they are - vendor-designer supplied - but you must gain that, "signal routing" awareness - and use it - prior to applying your external analog signal - as you seek. 

    You never explicitly identify your board - I am guessing yours is the early launchpad - replaced by vendor's rebranded components.  I would bet that google would find that board - and your review of a schematic would reveal which of the MCU-ADC pins (if any) are routed to the edge connectors.

    Update1:  Spent < 10 minutes on the net - found/learned that PE3 = ADC_CTL_CH0 and appears upon J3-9. PE2, PE1 reside adjacent pins - that header/edge connector.  Your investigative efforts may require some "tweaking."  (assumes your board is launchpad...)

    Our group has a similar, "LX4F" MCU (64 pin device) and this "PinTypeADC" function works fine for us: (note that our IDE and/or set-up has no problem w/parameter GPIO_PIN_3 - which you list.)

     ROM_GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 |
                                                                             GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5);

    Update2: 19:29 08 Sept - Note that PE3 is indeed AIN0 - aka (also known as) "ADC_CTL_CH0" - and you've nailed that nicely!  However -  your most recent code now lists (inexplicably):

     GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_7);  and this is not PE3 - nor CH0!  (which are the sole recipients of your follow-on "Sequence Step" targets)  Suspect replacing "7" w/proper GPIO_PIN_3 will improve results.  ARM MCUs are highly complex - deserve & demand great attention to detail...

    Should this not immediately "cure" - may well be an issue with your IDE - so often brought about when new users strive to, "create their own project" rather than choosing a known-good, factory supplied project - simply modified to their purpose.  Suggest that you search for such "existing project" (close to what you seek) and review their ADC code and configurations. 

    Our group works with many ARM MCUs - multiple vendors - thus have little interest/use for vendor's greatly restricted IDE offering and am unable to advise (IDE issues) beyond this/earlier postings...