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.

TM4C1294NCPDT: TM4C1294NCPDT

Part Number: TM4C1294NCPDT

Hi All,
I checked several resources and looked on the forum but could not find any substantial solution for my problem. I have 2 sensors and these are on PE2 and PE1. I am trying to read from both of them at the same time with ADC. But I get the same value for both of them. Not sure what I am doing wrong below.
Thanks in advance.

SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1);

ADCSequenceConfigure(ADC1_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceConfigure(ADC1_BASE, 1, ADC_TRIGGER_PROCESSOR, 1);

ADCSequenceStepConfigure(ADC1_BASE, 0, 0, ADC_CTL_CH2); //PE2->AIN1
ADCSequenceStepConfigure(ADC1_BASE, 0, 1, ADC_CTL_CH2);
ADCSequenceStepConfigure(ADC1_BASE, 0, 2, ADC_CTL_CH2);
ADCSequenceStepConfigure(ADC1_BASE, 0, 3,
ADC_CTL_CH2 | ADC_CTL_IE | ADC_CTL_END);

ADCSequenceStepConfigure(ADC1_BASE, 1, 0, ADC_CTL_CH1); //PE1->AIN2
ADCSequenceStepConfigure(ADC1_BASE, 1, 1, ADC_CTL_CH1);
ADCSequenceStepConfigure(ADC1_BASE, 1, 2, ADC_CTL_CH1);
ADCSequenceStepConfigure(ADC1_BASE, 1, 3,
ADC_CTL_CH1 | ADC_CTL_IE | ADC_CTL_END);

ADCSequenceEnable(ADC1_BASE, 0);
ADCSequenceEnable(ADC1_BASE, 1);
ADCIntClear(ADC1_BASE, 0);
ADCIntClear(ADC1_BASE, 1);

ADCProcessorTrigger(ADC1_BASE, 0);
while (!ADCIntStatus(ADC1_BASE, 0, false))
{
}
ADCIntClear(ADC1_BASE, 0);

ADCSequenceDataGet(ADC1_BASE, 0, &reading1);

ADCProcessorTrigger(ADC1_BASE, 1);
while (!ADCIntStatus(ADC1_BASE, 1, false))
{
}
ADCIntClear(ADC1_BASE, 1);
ADCSequenceDataGet(ADC1_BASE, 1, &reading2);

  • Hi,
    I see some issues.

    1. You should change below

    from:
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2);
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1);

    to:
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2|GPIO_PIN_1);


    2. Why are you doing the below? Do you really want to sample AIN2 (ADC_CTL_CH2) 4 times as you map AIN2 to four steps (0,1,2,3). If this is really want you want then it is fine. Otherwise you should change to below. Please also note that your comment is wrong. ADC_CTL_CH2 is AIN2 which is PE1. Make sure which AIN you want to assign to which step and which sequencer.

    From:
    ADCSequenceStepConfigure(ADC1_BASE, 0, 0, ADC_CTL_CH2); //PE2->AIN1
    ADCSequenceStepConfigure(ADC1_BASE, 0, 1, ADC_CTL_CH2);
    ADCSequenceStepConfigure(ADC1_BASE, 0, 2, ADC_CTL_CH2);
    ADCSequenceStepConfigure(ADC1_BASE, 0, 3,
    ADC_CTL_CH2 | ADC_CTL_IE | ADC_CTL_END);

    To:
    ADCSequenceStepConfigure(ADC1_BASE, 0, 0, ADC_CTL_CH2 | ADC_CTL_IE | ADC_CTL_END);

    3. The ADC can only sample AIN1 and AIN2 sequentially even if you assign these two inputs to two different sequencers. If you really wanted to have AIN1 and AIN2 sampled at exact same time using a common trigger then you need to assign these two inputs to two different ADC modules, like one to ADC0_BASE and another to ADC1_base.
  • Hi Charles,

    Thank you for your response. I do not need to sample 4 times. So, I can go with the SS3. What I want to do is. I have two sensors which are hooked up AIN1 and AIN2. The sensors should give separate readings. They are not related to the each others' readings. I want to be able to read their values with  the same trigger. So, Can I do this? Read the AIN1 and clear the interrupt and then again trigger the interrupt and read from AIN2? is this going to mess up the readings(FIFO)? Please see the code below. If this will not work out. Can you paste a sample code for your #3 suggestion?

    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2 | GPIO_PIN_1);
    
        ADCSequenceConfigure(ADC1_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
        ADCSequenceConfigure(ADC1_BASE, 1, ADC_TRIGGER_PROCESSOR, 1);
    							 
    	ADCSequenceStepConfigure(ADC1_BASE, 0, 0,
                                 ADC_CTL_CH1 | ADC_CTL_IE | ADC_CTL_END); //PE2->AIN1
    							 
    	ADCSequenceStepConfigure(ADC1_BASE, 1, 0,
                                 ADC_CTL_CH2 | ADC_CTL_IE | ADC_CTL_END); //PE1->AIN2
    							 
        ADCSequenceEnable(ADC1_BASE, 0);
        ADCSequenceEnable(ADC1_BASE, 1);
        ADCIntClear(ADC1_BASE, 0);
        ADCIntClear(ADC1_BASE, 1);
    	
    	
    	 ADCProcessorTrigger(ADC1_BASE, 0);//Trigger for AIN1 reading
        while (!ADCIntStatus(ADC1_BASE, 0, false))
        {
        }
        ADCIntClear(ADC1_BASE, 0);//Clear the flag
    
        ADCSequenceDataGet(ADC1_BASE, 0, &reading1);//read AIN1
    
        ADCProcessorTrigger(ADC1_BASE, 1);//Re trigger for AIN2 reading
        while (!ADCIntStatus(ADC1_BASE, 1, false))
        {
        }
        ADCIntClear(ADC1_BASE, 1);//Clear the flag
        ADCSequenceDataGet(ADC1_BASE, 1, &reading2);
    

  • Hi,
    I don't see an issue with your method. You should be able read both sensor inputs.
  • Hi,
    So, with the code above I can read two different sensor values from (AIN1 and AIN2) pins? This way the readings will not be mixed since I am using ADC1_BASE for both of them? and sample sequence 0 and 1 for AIN1 and AIN2?

    Thanks.

  • Hi Veruma,
    That is correct. You can even put AIN1/AIN2 in the same sequencer if you want. They become two different steps in the same sequencer. Their readings will not interfere with each other. Just look at the sequencer 0 which supports 8 steps. Why 8 steps? This is to allow sequencer 0 to potentially sample 8 different inputs. After 8 are samples, each converted value can be read out from FIFO. Same thing with only two inputs. Please refer to the datasheet for details.
  • Thank you so much for the clarification, Charles.