Molorius/ATSAMD21-ADC

Multiple ADC differential measurement

Opened this issue · 2 comments

I have ran into a problem which I have tried to find the cause for, but not being able to.

I am trying to establish 3 ADC differential channels (tot. 6 pins) for measuring 3 different analog signals. However this is not working if I have all the three analog signals connected to the 3 ADC differential channels.

If I disconnect all the analog signals. Connect only one at a time and measure it, and disconnect the signal after measurement, then all the three ADC differential channels will work. See detailed explanation below,
AS# = Analog signal
ADCD# = ADC differential (each channel has 2 pins)

// Results of all three ADC are wrong
AS1 - connected - ADCD1
AS2 - connected - ADCD2
AS3 - connected - ADCD3

// Works
Step 1
AS1 - connected - ADCD1
AS2 - disconnected - ADCD2
AS3 - disconnected - ADCD3

Step 2
AS1 - disconnected - ADCD1
AS2 - connected - ADCD2
AS3 - disconnected - ADCD3

Step 3
AS1 - disconnected - ADCD1
AS2 - disconnected - ADCD2
AS3 - connected - ADCD3

My code:
/*
Name: AdcDifferential.ino
Created: 11/16/2020 9:26:38 AM
Author: SherjeelTon
*/

#include "ATSAMD21_ADC.h";

#define Negative1 A0
#define Positive1 A3

#define Negative2 A4
#define Positive2 A6

#define Negative3 A5
#define Positive3 A7

int16_t signedResult;
float result;
float voltRef = 2.048;
float elevenBitResolution = 2047;
float fifteenBitResolution = 32767;

// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(9600);
analogReference2(ADC_REF_VREFA);
analogReadExtended(16);
analogPrescaler(ADC_PRESCALER_DIV512);
analogGain(ADC_GAIN_1);
analogCalibrate();
}

// the loop function runs over and over again until power down or reset
void loop() {
signedResult = analogDifferential(Positive1, Negative1);
result = signedResult * voltRef / fifteenBitResolution;
Serial.print("Channel 1: ");
Serial.println(result, 6);
delay(1000);

signedResult = analogDifferential(Positive2, Negative2);
result = signedResult * voltRef / fifteenBitResolution;
Serial.print("Channel 2: ");
Serial.println(result, 6);
delay(1000);

signedResult = analogDifferential(Positive3, Negative3);
result = signedResult * voltRef / fifteenBitResolution;
Serial.print("Channel 3: ");
Serial.println(result, 6);
delay(1000);

}

I realize this is is over a year old, were you able to figure out the problem? Do you still need help with this?

No, I never figured out how to solve this problem. I tried to find out if it was a problem within the library or the hardware itself but i didn't get so far.