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.

ADC0 SEQ1 FIFO1 sample acquire problem

Hello ALL,

I am trying to use TM4C123G , ADC0, Sequencer 1, to acquire readings from two sensors connected as foolow:

Sensor 1 --- AIN0 (PE3)

Sensor 2 --- AIN1(PE2)

the code that acquire samples is: 

unsigned long ADC0_InSeq1(void)

{  

unsigned long result, result2;

ADC0_PSSI_R = 0x00000002;      / /   initiate SS1
while((ADC0_RIS_R&0x02)==0){}; // wait for conversion done
result = ADC0_SSFIFO1_R&0xFFF; //   read result
result2 = ADC0_SSFIFO1_R&0xFFF;

ADC0_ISC_R = 0x0002; //  acknowledge completion
return result2;

 }

but if any one sensor on input pin is disconnected the value of other connected sensor is returned at "result2" by function above.

How can i properly and seperately acquire individual sensor values?

I think it has to do with  ADC0_sequencer1_ FIFO1 processing?

  • Hello Trev

    First of all: the DRM method is not recommended as it is easy to make mistakes.

    Secondly, if you put a break point in the function, what does single stepping show the value of result and result2,. A simple experiment would be to connect the disconnected sensor pin to a known voltage level and then check.

    Regards
    Amit
  • Bravo for discouraging DRM use. This must be done w/consistency & firmness.

    Perhaps it's clearer if we state that after disconnecting the sensors from PE2 & PE3 - a low impedance voltage (within the range 0V - 3V3) should be applied to PE2 and PE3. (this is more certain than "connecting to disconnected sensor pin" (which seems more like a sensor, not MCU connection.)

    Only after the correct results are obtained should the, "challenge of the sensors" be introduced.
  • Hi Trev,

    Can you please post your ADC configuration? There is one sample code for ADC. The sample code is located in
    C:\ti\TivaWare_C_Series-2.1.2.111\examples\peripherals\adc

    Regards,
    QJ
  • So much for "consistency" in discouraging the extra time + work - and likelihood of error - always introduced by DRM...
  • MY ADC configuration:
    void ADC0_InitSWTriggerSeq3_Ch1(void)

    { volatile unsigned long delay;
    SYSCTL_RCGC2_R |= 0x00000010; // 1) activate clock for Port E
    delay = SYSCTL_RCGC2_R; // allow time for clock to stabilize
    GPIO_PORTE_DIR_R &= ~0x0C; // 2) make PE2 and PE3 input
    GPIO_PORTE_AFSEL_R |= 0x0C; // 3) enable alternate function on PE2 ,3
    GPIO_PORTE_DEN_R &= ~0x0C; // 4) disable digital I/O on PE2,3
    GPIO_PORTE_AMSEL_R |= 0x0C; // 5) enable analog function on PE2,3
    SYSCTL_RCGC0_R |= 0x00010000; // 6) activate ADC0 .
    delay = SYSCTL_RCGC2_R;
    SYSCTL_RCGC0_R &= ~0x00000300; // 7) configure for 125K

    ADC0_SSPRI_R = 0x1203; // 8) seq 1 is highest priority
    ADC0_ACTSS_R &= ~0x0002; // 9) disable sample sequencer 1


    ADC0_EMUX_R &= ~0x00F0; // 10) // seq 1 is used ... software trigger


    ADC0_SSMUX1_R = (ADC0_SSMUX1_R&0xFFFFFF00)|(0x00000010); // 11) channel AIN0 (PE3) is first sensor and Ain1 (PE2) is second

    ADC0_SSCTL1_R = 0x0060; // 12) samp0 = no TS0 D0 END0, yes IE0 , samp 1= no TS1 D1, yes IE1 END1
    ADC0_ACTSS_R |= 0x0002; // 13) enable sample sequencer 1

    }
    I have also applied the voltages at input instead of sensor. But the thing is if any one voltage at the input lets say..
    PE2 is removed , then output result is mixed with PE3 input i.e., the result which should have PE2 value has PE3 value... Also I cant see 4-element FIFO of SEQ1 in the Keil window of peripherals. It only shows one reading.

    Please also tell me how can I start using drivers instead of DRM.. Any quick tutorial links ??
  • trev zic said:
    how can I start using drivers instead of DRM

    Poster's wish - cb1's command.

    TivaWare\examples\peripherals\adc\single_ended.c employs (only) the API and has been used successfully by hundreds - for years here.

    Beyond that code example - use of a capacitor (0.01 - 0.1µF) placed close to the MCU's ADC pin proves greatly helpful - as does "matching" the ADC's input impedance to your "test voltage source."   Such likely explains the inconsistency of ADC readings which you report.

    As to, "inability to see 4 element FIFO" - that's pretty much standard as the IDE's window view of the FIFO disables your view.   One work-around is to display your ADC conversion results w/in "Live Watch" (that's IAR's naming convention - Keil should be similar).

    DRM - even though (encouraged thru (some) vendor silence) most always results in, "crash/burn" due to its great complexity and extensive time/effort demands.   DRM has NOT "passed the test of user use & time" - which is enjoyed by the API - thus DRM proves ALWAYS an (unwelcome) ADVENTURE!   

    One fine day vendor reps may become consistent and "guide posters" away from the rocks of unnecessary complexity...

  • trev zic said:
    But the thing is if any one voltage at the input lets say..
    PE2 is removed , then output result is mixed with PE3

    That is to be expected. You must always have a low impedance connection on any A/D input. A charge storage capacitor next to the input pin is highly recommended (even essential)

    There are references to the documentation TI's seminars on A/Ds available if you search for the tag Bookshelf. Recommended reading.

    Robert

  • Robert Thanks ... I think if I do not leave the input pin floating, the problem is solved and I dont get unexpected results. It has to do with the input floating condition.
  • Hello Trev,

    Did you try the suggestion presented earlier

    "Secondly, if you put a break point in the function, what does single stepping show the value of result and result2,. A simple experiment would be to connect the disconnected sensor pin to a known voltage level and then check."

    Regards
    Amit
  • Amit,

    The values are inconsistent thoug using the break point method... And some times the values go out of scope ... Any idea how to resolve this out of scope thingy,
    My priority is optimization level 0.
    THanks for concern and help
  • "There are references to the documentation TI's seminars on A/Ds available if you search for the tag Bookshelf. "

    Where/ how can i find this ... Link?
    Sorry I am new to this tag thing and I cant place how it works...
  • Voici:

  • Don't float the A/D inputs. Seriously, never float the A/D inputs. You cannot have any expectation of the value if they are floating.

    Robert
  • cb1- said:
    a low impedance voltage (within the range 0V - 3V3) should be applied to PE2 and PE3.

    Such was (earlier - and FIRST) suggested (yesterday) and (equally) deserves, "Splash of green."