GithubHelp home page GithubHelp logo

atsamd21-adc's Issues

analogDifferential 11 bits only?

I'm not quite clear if this is a bug or if I'm missing something here, any help to get to the bottom of this would be great.

Is there any way to obtain a true 12bit differential result using analogDifferential()?

For instance if we do a single ended analogRead of a 3V input the 12bit ADC result is the expected ~3720 (of a max 4095).
Simply switching ADC->CTRLB.reg to CTRL DIFFMODE and setting the MUXPOS/MUXNEGs, then applying 3V of difference between these differential inputs, produce half of the expected value. The reference is unchanged in both cases and is the default analogReference(AR_DEFAULT) which should be 3.3V. If I change the reference to not do a DIV2 then the result saturates to 2047 (11bit).

In this Arduino forum post you seem to suggest the true 12bit value in differential reads is still available but I could not find a way to obtain it. Or maybe differential mode shifts the reference to half of whatever it is set to, and then yields a signed 12bit (11bits + 1 sign bit) result from that? That would seem quite wrong.

Multiple ADC differential measurement

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);

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.