Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: Teensy 4.0 adc0/adc1 swapped... possible bug?????

  1. #1
    Junior Member
    Join Date
    May 2019
    Posts
    12

    Teensy 4.0 adc0/adc1 swapped... possible bug?????

    Hi All,

    I am trying to to perform single reads on 3 different IOs on Teensy 4.0.
    I got it working but only swapping the ADC peripherals, let me explain further more.

    So, I am trying to use adc0 to read A0 and adc1 to read both A1 and A2.

    The application only works when do this:
    setup adcX->adc0
    setup adcY->adc1
    read adcValueX with adc1*
    read adcValueY with adc0*
    *notice how I swapped the adc peripheral reference to the setup.


    Here is the code:
    #include <ADC.h>
    #include <ADC_util.h>

    unsigned char adcValueX,
    adcValueY[2];

    ADC *adcX = new ADC();
    ADC *adcY = new ADC ();


    void setup() {
    adcX->adc0->setReference(ADC_REFERENCE::REF_3V3);
    adcX->adc0->setAveraging(16);
    adcX->adc0->setResolution(8);
    adcX->adc0->setConversionSpeed(ADC_CONVERSION_SPEED::MED_SPEE D);
    adcX->adc0->setSamplingSpeed(ADC_SAMPLING_SPEED::MED_SPEED) ;

    adcY->adc1->setReference(ADC_REFERENCE::REF_3V3);
    adcY->adc1->setAveraging(16);
    adcY->adc1->setResolution(8);
    adcY->adc1->setConversionSpeed(ADC_CONVERSION_SPEED::MED_SPEE D);
    adcY->adc1->setSamplingSpeed(ADC_SAMPLING_SPEED::MED_SPEED) ;
    }

    void loop() {
    adcValueX = adcX->adc1->analogRead(A0);
    adcValueY[0] = adcY->adc0->analogRead(A1);
    adcValueY[1] = adcY->adc0->analogRead(A2);

    Serial.print(adcValueX, DEC);
    Serial.print(" ");
    Serial.print(adcValueY[0], DEC);
    Serial.print(" ");
    Serial.println(adcValueY[1], DEC);
    delay(500);
    }

    Maybe I am defining something wrong and any help or feedback will be highly appreciated.
    I am concern this may be a bug and in a future Teensyduino release I will break my application.

    Thanks to all,
    Normal.User.

  2. #2
    Senior Member+
    Join Date
    Jul 2013
    Posts
    292
    Code:
    ADC *adcX = new ADC();
    ADC *adcY = new ADC ();
    This is wrong, you should only create one ADC object. Please see the examples.
    The ADC object controls both adc modules ADC0 and ADC1.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •