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.
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 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,
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.