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.

A small problem with ADC

Hey I have a small question.

I'm trying to read analog inputs from the pins PE1-4

I can read the data from pins PE2 and PE3 but can't read the data from PE4 (didnt try yet reading from PE1)

Its probably a small thing I did wrong in the initialization, can someone please take a quick look?

Thanks.

This is how I try to read the data:

ADCIntClear(ADC0_BASE, 0);
ADCSequenceDataGet(ADC0_BASE, 0, adc_data);

data_PE4 = adc_data[3];

And this is how I initialize the ADC:

// Configure the ADC sample sequence.
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
while(!(SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0)));

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1| GPIO_PIN_2| GPIO_PIN_3| GPIO_PIN_4);

GPIOPadConfigSet(GPIO_PORTE_BASE,GPIO_PIN_1,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_ANALOG);
GPIOPadConfigSet(GPIO_PORTE_BASE,GPIO_PIN_2,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_ANALOG);
GPIOPadConfigSet(GPIO_PORTE_BASE,GPIO_PIN_3,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_ANALOG);
GPIOPadConfigSet(GPIO_PORTE_BASE,GPIO_PIN_4,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_ANALOG);

ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_TIMER, 0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH1);
ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH2);
ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH9 | ADC_CTL_END | ADC_CTL_IE);
ADCSequenceEnable(ADC0_BASE, 0);

// Enable 8x hardware averaging
ADCHardwareOversampleConfigure(ADC0_BASE, 8);

IntEnable(INT_ADC0SS0);
ADCIntEnable(ADC0_BASE, 0);

  • There are multiple TM4C MCUs - you don't list yours - and there is variation w/in the pin configuration among these many MCUs.
    Notably your code makes quite a jump for that 4th item w/in your sequence. Is ADC_CTL_CH9 (really) proper for your pin PE4?

    There are (some) active on this forum who favor, "KISS" - and would prefer your "Avoiding use of hardware averaging" until the "basic ADC operation" has been tested & confirmed.     (i.e. what happens to your ADC results if you make "fewer" than the number of measurement loops "demanded" by hardware averaging?)     Limiting your field of battle to, "One battlefield at a time" will "Speed, Ease & Enhance" your development tasks...

  • I'm sorry,

    I'm using the TM4C123 with the 64 pins.

    I saw that PE4 is AIN9

  • OK - then you've got that right. (Good that)
    Re-read my post as I was editing and our posts have crossed... (I'd like you to "kill" hw averaging for now)

    You claim that you, "Can't read PE4" - and that cannot be true!      Surely you can "read" it - you (likely) disagree w/the result of the read.      What is that result and what input voltage have you applied?

  • Okay, great thanks. I'll try that.

    Yes the result doesn't look like what the sensor should show.

    I'll be back in office only on Sunday, if disabling the averaging doesn't help I'll take a look at the sensor with the oscilloscope.

  • It is most common for the input signal to be introduced upon the "wrong pin" or for the signal to be improper (outside the range of "0V - 3V3."
    If that's not the case simply swap the signal input to PE3 (which you note as "good") w/the PE4 input - and then repeat the code run. Should PE4 (still) be in error - check carefully for other (unwanted) connections to that pin - or (other) spots in your code which switch that pin away from its "analog intent."

    [edit] - You've just edited your post (12:19) and describe "Sensor Input."      That is FAR from KISS - and will eat much of your time & effort.     (and that of your (less important) helpers...)

    Instead - feed (ideally) low impedance KNOWN Voltages into each of those ADC pins - do NOT "Start w/a sensor - which may provide questionable data - you are presenting TOO MANY UNKNOWNS!    Let's confirm that your ADC is working well FIRST - only then should the Sensor be introduced.     (low impedance is easily obtained via a "Quad Op Amp" (lowly 324 or similar) operated as a voltage follower - w/its output driving the ADC input thru ~100 ohm series R and 0.01µF cap tied to the junction of the R and ADC input.    (caps other end to GND))

    Stay true to "KISS" (one battle/unknown) at a time...

  • Thanks but I can't do these things, I'm working on a costum made board, not the evaluation board.  

    I started the development on the evaluation board but I didn't have that sensor on that setup.

    I'll take another look at the code, there is a chance there is some other definition to PE4 I missed .

    I posted here because I wasn't sure about the initialization . If it's okay, I probably just missed something in the code.

  • If your sensor, "Works perfectly from the beginning" AND w/a custom made board AND w/software which has not EARLIER been tested on the LPad - I will buy your lunch at a fine Chicago hotel. (of course under agreed conditions)

    Such is unlikely - kicking KISS to the curb will NOT yield optimal or quick (desired) results. Easiest test of PE4 is as (earlier) suggested - temporarily switch the signal into PE2 or PE3 into PE4 - then Run & Observe...
  • Ok , but please no disgusting deep dish pizza.

    I agree with you, but I still need to convince the hardware guys. I had to put my foot down for starting the development with the LPad.
  • As a NYC boy who migrated to Los Angeles - then Chicago - deep dish does NOT arrive my plate. (one properly folds the "thin" pizza slice in half) That said - the "all at once" method you outline - has (almost) NO/ZERO chance!

    Anyone - even hardware guys - who expect "multiple, untested assemblies" to "work perfectly together" - have not been w/in the "real tech world" for long! My suggestion - as always - is very small, tightly focused, and well monitored - SINGLE STEPS.     (i.e. "KISS")

  • An update , everything worked fine. 

    I just thought the sensor is more sensitive than it really is.

  • Nadav Bahana said:
    An update , everything worked fine. 

    Might this mean that you've, "Changed nothing" - and that your original "4C123" MCU code may be "used by other forum members" - with confidence?

    Once again - the "too early" introduction of your "sensor" (rather than a proper, known, voltage) [which was a clear violation of KISS] caused & complicated your issue.

  • Then my friend - a (proper) slice (perhaps two) of NYC style (thin & folded) Pizza awaits you - upon your next visit to Chicago...
    Bon chance, mon ami.