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.

Problem ADC with tm4c123g

Hello my name is yohan guerraz and I am currently in work-study at Valeo.

My company put me on a project which consists in recovering a battery voltage with a tiva TM4C123G which will have several functions including an ADC.

I would like to know if it is possible to use several AINX with the SSMUX3 in one and the same function or am I obliged to recreate a configuration function for each AINX because for the moment I have the possibility of applying my adc on the AIN9?


Thank you in advance for your answer cordially Guerraz Yohan

  • I am not sure I understand your question. Sequence 3 supports reading a single ADC channel. To configure sequence 3 to convert AIN9 you would use TivaWare calls like this:

        ADCSequenceDisable(ADC0_BASE, ADC_SAMPLE_SEQUENCER3);
        //Configure ADC sample sequencer3
        ADCSequenceConfigure(ADC0_BASE, ADC_SAMPLE_SEQUENCER3, ADC_TRIGGER_PROCESSOR, 0U);
        ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH9 | ADC_CTL_END);
        //Enable sample sequencers
        ADCSequenceEnable(ADC0_BASE, ADC_SAMPLE_SEQUENCER3);
    

  • yes I saw that but I use this code for ADC : 

    In  initSequencer() I call the input (AINx) I want to use and I will want to know if it's possible to use 2 input (AIN9 and AIN8 for example). 

    I don't know if my question is very clear Sweat smile

    /*
     * pg799 - ADC
     * pg649 - GPIO
     *
     * AIN0 - PE3 (6)
     * AIN1 - PE2 (7)
     * AIN2 - PE1 (8)
     * AIN3 - PE0 (9)
     * AIN4 - PD3 (64)
     * AIN5 - PD2 (63)
     * AIN6 - PD1 (62)
     * AIN7 - PD0 (61)
     * AIN8 - PE5 (60)
     * AIN9 - PE4 (59)
     * AIN10 - PB4 (58)
     * AIN11 - PB5 (57)
     *
     * Frequence d'horloge: 16 MHz
     *
     *
     */
    
    
    #define ADC_INPUT 0x040;
    
    
    //---------------------
    //-------FONCTIONS-------
    
    void initADC();
    void initSequencer();
    
    //-------------------------------
    
    unsigned long valorADC = 0;
    float valorADC2 = 0;
    float Num_ADC = 0;
    float quotienADC = 0.0092879256965944;
    
    //--------------------
    //---IMPLEMENTED---
    
    void initADC() {
        SYSCTL_RCGCGPIO_R |= 1 << 4;        // Clock activate in GPIO (pg340)
        SYSCTL_RCGCADC_R |= 0b11;           // activate ADC clock (pg352): bit0 (ADC0), bit1 (ADC1)
    
        GPIO_PORTE_DIR_R &= ~ADC_INPUT;     // PE4 as input
        GPIO_PORTE_AFSEL_R |= ADC_INPUT;    // AFSEL standard for ADC inputs pins, enable alternate function on PE4 (pg1344)
        GPIO_PORTE_DEN_R &= ~ADC_INPUT;     //AINx - GPIO_DEN_R; // configure AINx to receive analog signal, clearing GPIO's DEN (digital enable)(pg682)
        GPIO_PORTE_AMSEL_R |= ADC_INPUT;    // disable the ANALOG ISOLATION of the input pins (pg687)
        //ADCSSPRI; // set the data acquisition priority 0 (high) to 3 (low) (p823)
    }
    
    void initSequencer() {
        ADC0_ACTSS_R &= ~0b1000; // Disable the sequencer for configuration (p821)
        ADC0_PP_R |= ADC_PP_MSR_125K; // set up for 125k samples (p889)
        ADC0_SSPRI_R = 0x123;           // Sequencer 3 is highest priority
        ADC0_EMUX_R |= ADC_EMUX_EM3_PROCESSOR;          //Configure the trigger for the sample sequencer (p833): software trigger
        //ADCTSSEL_R; // ADC Trigger Source Select - select PWM when used (p839)
        ADC0_SSMUX3_R &= ~0x000F;       // configure the corresponding entry of each sample of the sample sequence (p851): clear SS3 field
        ADC0_SSMUX3_R += 9;             //  AIN9 (PE4)
        ADC0_SSCTL3_R = 0x0006;         // set the control bits, set the final END bit. (p853): [no TS0 D0, yes IE0 END0
        //ADCIM_R; // if using interrupts, set the MASK bit (p825)
        ADC0_ACTSS_R |=  0b1000; // Enable the sequencer (p821)
    }
    
    
    unsigned long adcInSeq3 () {
        unsigned long result;
        ADC0_PSSI_R = 0x0008;                   // 1) initiate
        while ((ADC0_RIS_R & 0x08) == 0) {};    // 2) wait for conversion done
        result = ADC0_SSFIFO3_R & 0xFFF;        // 3) read result
        ADC0_ISC_R = 0x008;                     // 4) acknowledge completion
    
        return result;
    }
    
    int main(void) {
        SYSCTL_RCGCGPIO_R |= 1 << 5;
    
        GPIO_PORTF_DIR_R  |= 0b1110;
        GPIO_PORTF_DEN_R  |= 0b1110;
    
        initADC();
        initSequencer();
    
        while (1) {
            valorADC = adcInSeq3();
            Num_ADC = (float)(valorADC);
            valorADC2 = Num_ADC * quotienADC;
    
            System_printf("Valeur analog en entree : %i  \n",valorADC);
            System_flush();
            System_printf("Valeur Convertie : %f V \n",valorADC2);
            System_flush();
            SysCtlDelay(200000);
    
    
            if (valorADC >= 1000) {
                GPIO_PORTF_DATA_R = 0b1110;
            } else if (valorADC < 1000 && valorADC > 0) {
                GPIO_PORTF_DATA_R = 0b1100;
            } else if (valorADC == 0) {
                GPIO_PORTF_DATA_R = 0;
            } else {
                GPIO_PORTF_DATA_R = 0b10;
            }
        }
    
        return 0;
    }
  • In short, no. You may only write a single channel number.

    Please see item 4 of the  TM4C Forum General Guidelines. We typically will not support questions about code using that exclusively use direct register modification.

  • Thank for your reply.

    But I have a other question if i use ADCSSMUX0 i can use 2 input (AINx) or it's like with the ADCSSMUX3  ? 

    I ask because this is my first experience with a TIVA and I do not understand everything that is said in the datasheet. Sweat smile

  • As described in the datasheet, sequence 0 can have up to 8 channels (different, or some repeating), sequences 1 and 2 have up to four. Sequence 3 can have only a single channel.