Coder Social home page Coder Social logo

Comments (4)

pedvide avatar pedvide commented on August 17, 2024

I'll have a look at it on the weekend. Can you post an example of that problem? Also what versions of the ADC library, Teensyduino and Arduino are you using?

from adc.

kgeorge1student avatar kgeorge1student commented on August 17, 2024

Arduino-1.6.11
Teensyduino version=1.6.7

From ADC_Module.cpp (I suspect the issue is with ADC_MAX_PIN check in checkDifferentialPins as differential pin numbers do exceed the limit its trying to enforce despite the fact they are valid pins on the Teensy 3.6:

//////////////// INFORMATION ABOUT VALID PINS //////////////////

// check whether the pin is a valid analog pin
bool ADC_Module::checkPin(uint8_t pin) {

if(pin>ADC_MAX_PIN) {
    return false;   // all others are invalid
}

// translate pin number to SC1A number, that also contains MUX a or b info.
const uint8_t sc1a_pin = channel2sc1a[pin];

// check for valid pin
if( (sc1a_pin&ADC_SC1A_CHANNELS) == ADC_SC1A_PIN_INVALID ) {
    return false;   // all others are invalid
}

return true;

}

// check whether the pins are a valid analog differential pins (including PGA if enabled)
bool ADC_Module::checkDifferentialPins(uint8_t pinP, uint8_t pinN) {
if(pinP>ADC_MAX_PIN) {
// return false; // all others are invalid
}

// translate pinP number to SC1A number, to make sure it's differential
uint8_t sc1a_pin = channel2sc1a[pinP];

if( !(sc1a_pin&ADC_SC1A_PIN_DIFF) ) {

// return false; // all others are invalid
}

// get SC1A number, also whether it can do PGA
sc1a_pin = getDifferentialPair(pinP);

// the pair can't be measured with this ADC
if( (sc1a_pin&ADC_SC1A_CHANNELS) == ADC_SC1A_PIN_INVALID ) {

// fail_flag |= ADC_ERROR_WRONG_PIN;
// return false; // all others are invalid
}

#if ADC_USE_PGA
// check if PGA is enabled, and whether the pin has access to it in this ADC module
if( isPGAEnabled() && !(sc1a_pin&ADC_SC1A_PIN_PGA) ) {

// return false;
}
#endif // ADC_USE_PGA

return true;

}

/##################################################
The Program:
##################################################
/
/* Example for analogReadDifferential

  • You can change the number of averages, bits of resolution and also the comparison value or range.
    */

#include <ADC.h>

ADC *adc = new ADC(); // adc object

void setup() {

pinMode(LED_BUILTIN, OUTPUT);
pinMode(A10, INPUT); //Diff Channel 0 Positive
pinMode(A11, INPUT); //Diff Channel 0 Negative

Serial.begin(115200);
while(!Serial);

///// ADC0 ////
// reference can be ADC_REF_3V3, ADC_REF_1V2 (not for Teensy LC) or ADC_REF_EXT.
//adc->setReference(ADC_REF_1V2, ADC_0); // change all 3.3 to 1.2 if you change the reference to 1V2

adc->setAveraging(32, ADC_1); // set number of averages
adc->setResolution(16, ADC_1); // set bits of resolution
adc->setConversionSpeed(ADC_VERY_LOW_SPEED, ADC_1); // change the conversion speed
adc->setSamplingSpeed(ADC_VERY_LOW_SPEED, ADC_1); // change the sampling speed

// always call the compare functions after changing the resolution!
//adc->enableCompare(1.0/3.3*adc->getMaxValue(ADC_1), 0, ADC_1); // measurement will be ready if value < 1.0V
//adc->enableCompareRange(-1.0*adc->getMaxValue(ADC_1)/3.3, 2.0*adc->getMaxValue(ADC_1)/3.3, 0, 1, ADC_1); // ready if value lies out of [-1.0,2.0] V

Serial.println("End setup");
delay(500);

}

int value2 = ADC_ERROR_VALUE;

void loop() {
value2 = adc->analogReadDifferential(A10,A11, ADC_1);
/* fail_flag contains all possible errors,
They are defined in ADC_Module.h as

      ADC_ERROR_OTHER
      ADC_ERROR_CALIB
      ADC_ERROR_WRONG_PIN
      ADC_ERROR_ANALOG_READ
      ADC_ERROR_COMPARISON
      ADC_ERROR_ANALOG_DIFF_READ
      ADC_ERROR_CONT
      ADC_ERROR_CONT_DIFF
      ADC_ERROR_WRONG_ADC
      ADC_ERROR_SYNCH

      You can compare the value of the flag with those masks to know what's the error.
  */
  if(adc->adc1->fail_flag) {
      Serial.print("ADC1 error flags: 0x");
      Serial.println(adc->adc1->fail_flag, HEX);
      if(adc->adc1->fail_flag == ADC_ERROR_COMPARISON) {
          adc->adc1->fail_flag &= ~ADC_ERROR_COMPARISON; // clear that error
          Serial.println("Comparison error in ADC1");
      }
  } else {
      Serial.print("Success: ");
      Serial.print(" Value ADC1: ");
      Serial.println(value2*3.3/adc->getPGA(ADC_1)/adc->getMaxValue(ADC_1), 4);
  }
  adc->adc1->fail_flag = 0;
delay(6000);

}

from adc.

pedvide avatar pedvide commented on August 17, 2024

I just pushed an update in the dev branch. I think tt fixes these problems, however my Teensy 3.6 board is an early prototype and doesn't have access to the A10, A11 pins (and hence no differential).
Can you check that they work? Use the sketch readAllPins.ino in the examples.
Connect A10 and A11 to GND and 3.3V and make sure that their values are correct, including the differential. Teensy 3.6 only has that one diff pair.

from adc.

pedvide avatar pedvide commented on August 17, 2024

Fixed with the last commit.

from adc.

Related Issues (20)

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.