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: TM4C123GH6PM

Part Number: TM4C123GH6PM

I am using ADC0 sequencer 1 with 3 different inputs.the values in the register changing continuously.how can i get three analogue inputs after conversion ho can i read them from register.

  • There's so much missing here

    What do you mean by changing continuously? Noise is to be expected.
    What are you using as signals?
    What are you using to setup and read the A/Ds?

    Robert
  • i am sending 0,1 3.3 at three different inputs.I followed all the steps as in example.but i am not sure where my converted vales in register
  • One senses that (more) cb1s (may) be welcomed... I cede this (well detailed) one to you...
  • #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "inc/hw_gpio.h"
    #include "driverlib/debug.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/sysctl.c"
    #include "driverlib/adc.h"
    #include "driverlib/gpio.h"
    #include "driverlib/gpio.c"
    #include "driverlib/interrupt.h"
    #include "driverlib/timer.h"
    //#include "inc/tm4c123gh6pm.h"

    uint32_t Value[4];
    uint8_t data=14;
    uint32_t a,b,c;

    main(void)


    {

    //SysCtlClockSet(SYSCTL_SYSDIV_1| SYSCTL_USE_OSC| SYSCTL_OSC_MAIN| SYSCTL_XTAL_16MHZ);
    SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN| SYSCTL_XTAL_16MHZ);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    //ADCReferenceSet(ADC0_BASE, ADC_REF_INT);

    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5);
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4);
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3);

    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0))
    {

    }
    //ADCIntEnable(ADC0_BASE, 3);
    ADCSequenceDisable(ADC0_BASE, 1);
    ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);


    ADCSequenceStepConfigure(ADC0_BASE,1, 0, ADC_CTL_CH2);
    ADCSequenceStepConfigure(ADC0_BASE,1, 1, ADC_CTL_CH9);
    ADCSequenceStepConfigure(ADC0_BASE,1, 2 , ADC_CTL_CH8 | ADC_CTL_IE | ADC_CTL_END);



    IntEnable(INT_ADC0SS1);
    ADCIntEnable(ADC0_BASE, 1);
    ADCSequenceEnable(ADC0_BASE, 1);

    IntMasterEnable();

    while (1)
    {

    ADCProcessorTrigger(ADC0_BASE, 1);


    }
    }

    void ADC0IntHandler(void)
    {
    //int i;

    while (!ADCIntStatus(ADC0_BASE, 1, false))
    {
    }
    ADCIntClear(ADC0_BASE, 1);
    ADCSequenceDataGet(ADC0_BASE, 1, Value);

    /*
    for(i=0;i<3;i++){
    adc[i]=Value[i];
    }
    */
    a=Value[0];
    b=Value[1];
    c=Value[2];

    if(Value[0] & 0x00000800)
    {
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1,data);
    }

    else GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1,0);



    }


    this is my code. i am not sure i am getting correct values after conversion.I am sending 1at CH2 ,0 at Ch9, 3.3 at Ch8.i dont know the location of the each channel value after conversion.could anyone help me wit this
  • Your post is far clearer (now) w/the inclusion of your code - poster Robert and I appreciate its inclusion.

    You write of "sending" (voltages?) to your 3 Analog Channels. "Applying or inputting" voltages to the MCU's ADC is the "more usual" means of describing such voltage introduction. (sending most always applies to data transfer)

    Your code looks similar to "Single_ended.c" found in "Examples/Peripherals" - IIRC that code may not use "interrupts" - which greatly speeds & simplifies your task.

    You report "not being sure of your ADC values" - yet you don't describe those values - and they may prove useful to your diagnostic crüe...

  • I don't understand what are you trying to explain.how can I confirm my adc is working.

  • Kindly provide these details:

    • how you create those differing voltages - and connect them to the MCU?
    • what are the "range of readings" which you describe as being in error/improper?
    • can you "switch" away from the "internal ADC reference?" (as this simplifies your code)

    Your choice of introducing both 0V and 3V3 proves of little value.    (those 2 levels are at the ADC's extremes - which may reduce your accuracy by one-half)

    Should your ADC voltages still "disturb" - outlined below is a "quick/dirty" means to generate various voltages - with the minimum of parts.

    The input voltages you may (more properly/effectively) provide can be (easily) created via 8, 1K resistors - configured as simple (3 resistors in series) voltage dividers.    (such 3 resistor chain ties to 3V3 and Gnd - you tap at the first resistor (one of its ends @ Gnd - thus 3V3/3 results and is fed to the ADC);  second set of 3 Rs taps at the 2nd & 3rd "R junction" (yields (3V3 * 2)/3; and just 2 resistors (again w/3V3 impressed - feed the 3rd ADC channel.   (yielding 3V3/2)    If a simple op-amp is available - those resistors may tie into the amp's (+) terminal - w/the amp configured as "voltage follower."

    Again you are NOT "sending" such voltages - your are "introducing" them to the MCU's ADC.

  • cb1_mobile said:
    can you "switch" away from the "internal ADC reference?" (as this simplifies your code)

    Good catch. I haven't used a variant with the internal reference. I took a quick look at it and my advice would be to stay away from it unless you really know what you're doing.

    Robert

  • i am creating these voltages from AC opal RT model.

  • Good Catch! Good Catch! Such can (hardly) compete w/a "LIKE" or two - (especially proper for one "eagle eyed") -is that not true?

    Poster's "one sentence responses" - which cover (barely) "One of N questions" are "Krazy Making."
  • i am not using internal reference.could you please explain in simple words.what input i should apply at adc analogue inputs to check if it is working or not.

  • Had I not done - just that - several posts earlier - today? (i.e. via description of 3 resistors - series connected - powered by 3V3 and Gnd?
    I don't know how to write "simpler."

    Earlier your posted code contained, "ADCReferenceSet(ADC0_BASE, ADC_REF_INT);"   did it not?

    If you "list" what is NOT understood - another description may be applied - is there not another person (nearby) who may read & better explain?

  • rabbia qamar said:
    i am creating these voltages from AC opal RT model.

    Umm....

    Ummm.....

    Well, I suppose if you are going to violate KISS there might be something said for going whole hog (probably not polite but something). Good heavens.

    There's so many ways this could go badly.

    Two suggestions

    1. Follow cb1's suggestions on voltage sources for testing
    2. Sit down, go through the questions cb1 and I asked. Answer all of them. So far I think you've actually answered only one with a partial attempt at another.
      1. help us help you

    Robert

  • I am connecting ADC correctly and i am getting correct results one i am using one channel.but when i am using more than one channels i am getting the correct results but different locations of array.and location of results keep changing.
    could you please tell me how can i fix that
  • rabbia qamar said:
    ...am connecting ADC correctly and i am getting correct results ... (on) ... one channel...(only!)...

    Would it not make sense then to, "Alter your voltage source connection from that (succeeding) channel to the (failing) channels - but (only) one (new) connection at a time.   Repeat the test, note & report your results.    This IS "KISS" - your job is to confirm that you are (potentially) injecting that same (succeeding) voltage into the failing channels - which enables you to better detect "misconnections."    (which seems most likely - at this early stage in your diagnostics.)

    This description - only one channel (apparently) working and "locations" changing - were not supplied earlier...