Forum Rule: Always post complete source code & details to reproduce any issue!
Page 21 of 21 FirstFirst ... 11 19 20 21
Results 501 to 517 of 517

Thread: ADC library, with support for Teensy 4, 3.x, and LC

  1. #501
    Hi,

    I am aware that for the Teensy 4.0, all analog pins up to A9 can be read by both ADCs. Does anybody know which ADCs can access analog pins A10-A17 on the 4.1?

  2. #502
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,077
    From the core library, looks like A12,A13,A14,A15 are the pins requiring ADC2.

    Code:
    const uint8_t pin_to_channel[] = { // pg 482
            7,      // 0/A0  AD_B1_02
            8,      // 1/A1  AD_B1_03
            12,     // 2/A2  AD_B1_07
            11,     // 3/A3  AD_B1_06
            6,      // 4/A4  AD_B1_01
            5,      // 5/A5  AD_B1_00
            15,     // 6/A6  AD_B1_10
            0,      // 7/A7  AD_B1_11
            13,     // 8/A8  AD_B1_08
            14,     // 9/A9  AD_B1_09
            1,      // 24/A10 AD_B0_12 
            2,      // 25/A11 AD_B0_13
            128+3,  // 26/A12 AD_B1_14 - only on ADC2, 3
            128+4,  // 27/A13 AD_B1_15 - only on ADC2, 4
            7,      // 14/A0  AD_B1_02
            8,      // 15/A1  AD_B1_03
            12,     // 16/A2  AD_B1_07
            11,     // 17/A3  AD_B1_06
            6,      // 18/A4  AD_B1_01
            5,      // 19/A5  AD_B1_00
            15,     // 20/A6  AD_B1_10
            0,      // 21/A7  AD_B1_11
            13,     // 22/A8  AD_B1_08
            14,     // 23/A9  AD_B1_09
            1,      // 24/A10 AD_B0_12
            2,      // 25/A11 AD_B0_13
            128+3,  // 26/A12 AD_B1_14 - only on ADC2, 3
            128+4,  // 27/A13 AD_B1_15 - only on ADC2, 4
    #ifdef ARDUINO_TEENSY41
            255,    // 28
            255,    // 29
            255,    // 30
            255,    // 31
            255,    // 32
            255,    // 33
            255,    // 34
            255,    // 35
            255,    // 36
            255,    // 37
            128+1,  // 38/A14 AD_B1_12 - only on ADC2, 1
            128+2,  // 39/A15 AD_B1_13 - only on ADC2, 2
            9,      // 40/A16 AD_B1_04
            10,     // 41/A17 AD_B1_05
    #endif
    };
    I have some other written notes (not tested code) that A10,A11 are only accessible with ADC1.

  3. #503
    I'm glad i found this! using teensy 4.1 with single reads of several pins assuming 4.1 had "all ADC pins work with all ADCs"
    It was stopping reading when ADC1 read 24/A10 and 25/A11, swapped them to ADC0 and now it is good.

  4. #504
    Junior Member
    Join Date
    Apr 2021
    Posts
    4
    I'm having a problem with "setReference"

    --------

    #include <ADC.h> //ADC support
    ...
    setReference(EXTERNAL); //use external 2.5V ref

    -------

    gives the following compile error:
    'setReference' was not declared in this scope

    with Teensy LC / Arduino IDE v1.8.13/ Teensyduino v1.53

    setReference(REF_EXT); //gives the same error...

    Am I missing something really basic or has a bug crept in? Same results with Teenysduino v1.51 also.

  5. #505
    Senior Member
    Join Date
    Apr 2020
    Location
    DFW area in Texas
    Posts
    297
    Might try the following:

    Code:
       analogReference(EXTERNAL);
    Mark J Culross
    KD5RXT

  6. #506
    Junior Member
    Join Date
    Apr 2021
    Posts
    4
    Quote Originally Posted by kd5rxt-mark View Post
    Might try the following:

    Code:
       analogReference(EXTERNAL);
    Mark J Culross
    KD5RXT
    Mark, thanks that did the trick. How do we fix the documentation?

  7. #507
    Senior Member
    Join Date
    Apr 2020
    Location
    DFW area in Texas
    Posts
    297
    Quote Originally Posted by RJF View Post
    Mark, thanks that did the trick. How do we fix the documentation?
    Glad to be able to help !!

    Sorry, I don't know the answer for your follow-up question. If the error appears on a PJRC website, there's <this thread> where you can report it. If it's some other documentation, Paul will probably need a more specific description of where you found the discrepant info.

    Mark J Culross
    KD5RXT
    Last edited by kd5rxt-mark; 06-18-2021 at 03:02 AM. Reason: fixed typo(s)

  8. #508
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    15,088
    @pedvide provides the ADC library as a personal external library included with teensyduino: github.com/pedvide/ADC/

    And issues could be made against that github for attention resolution in some fashion.

    Was "REF_3V3" tried per the docs? The REF_EXT may have a different meaning in ADC context ... i.e. an External pin

  9. #509
    Senior Member+
    Join Date
    Jul 2013
    Posts
    294
    Hey, you are using a ADC library method without calling it with `ADC->setReference(ref)`.
    The solution given to use `analogReference` is using a Teensy core library ADC functions, so not using the ADC library.
    See the examples for more information.

  10. #510
    Senior Member
    Join Date
    Jan 2020
    Posts
    216
    I'm using a teensy 4.0. Is there a reason why I'm getting twice the noise if I choose to read certain combinations of analog inputs simultaneously? I'm not quite sure what's going on, I'm reading all sensors, two at a time like this:

    Code:
    void setup() {
    
    ///// ADC0 ////
      adc->adc0->setAveraging(4);                                             // set number of averages
      adc->adc0->setResolution(12);                                           // set bits of resolution
      adc->adc0->setConversionSpeed(ADC_CONVERSION_SPEED::HIGH_SPEED );       // change the conversion speed
      adc->adc0->setSamplingSpeed(ADC_SAMPLING_SPEED::HIGH_SPEED );           // change the sampling speed
      ////// ADC1 /////
      adc->adc1->setAveraging(4);                                             // set number of averages
      adc->adc1->setResolution(12);                                           // set bits of resolution
      adc->adc1->setConversionSpeed(ADC_CONVERSION_SPEED::HIGH_SPEED);       // change the conversion speed
      adc->adc1->setSamplingSpeed(ADC_SAMPLING_SPEED::HIGH_SPEED );           // change the sampling speed
    
    }
    
    void loop() {
    
    
    
    
    adc->startSynchronizedSingleRead(A0, A1);
    
    //Here I do some calculations and filtering on the previous two readings
    
      while (adc->adc0->isConverting() || adc->adc1->isConverting());
      g_sensorValue[0] = (adc->adc0->readSingle());
      g_sensorValue[1] = (adc->adc1->readSingle());
      adc->startSynchronizedSingleRead(A2, A3);
      
    //Here I do some calculations and filtering on the previous two readings
    
      
      while (adc->adc0->isConverting() || adc->adc1->isConverting());
      g_sensorValue[2] = (adc->adc0->readSingle());
      g_sensorValue[3] = (adc->adc1->readSingle());
      adc->startSynchronizedSingleRead(A4, A5);
    
      //Here I do some calculations and filtering on the previous two readings
    
     //and so on in the main loop
    It seems I get inconsistent results. When ever I recompile and get more noise I recompile using a different combination of two sensors and usually it cleans up. I haven't noted which combinations work and which don't or if it's completely random.

    Is there a best combination of analog inputs?

    It's not an anomaly, we are talking literally twice the noise. And the noise is 1/f noise.

    Here is a picture showing a filtered analog read of an analog input while at the same time another input is being read but not shown here. The only difference between the left and right on the picture is I changed the other analog read input. So if I for example read A0 and A1 I may get noisy readings on A0 and if I change to A0 and A2 I may get low noise on A0.

    Click image for larger version. 

Name:	noise.jpg 
Views:	44 
Size:	84.6 KB 
ID:	25311
    Last edited by frankzappa; 07-21-2021 at 12:52 PM.

  11. #511
    Senior Member
    Join Date
    Apr 2018
    Location
    Eastern Time, USA
    Posts
    163
    @frankzappa

    As I recall, on the Teensy 3.2 those channel combinations use the same ADC in one case, and different ADC's in the other.

    I notice you have the ADC's set for different speeds. The faster setting on ADC0 might produce more noise whenever you are using that ADC. And it seems plausible that when you use them together for a simultaneous read, you could see different behavior.

    On noise in general, you will see a lot of noise and a lot of cross talk, if you work with hookup wire and hobby board, and through hole boards will usually give you a lot of noise also.

    See this for a link to a note from NXP on noise management,

    https://forum.pjrc.com/threads/54977...y-close-to-it)


    And here is a picture of an SMT board that I built for low noise. You can see some of what is involved.

    Name:  IMG_7161.small.JPG
Views: 144
Size:  7.9 KB
    Last edited by DrM; 07-21-2021 at 12:22 PM.

  12. #512
    Senior Member
    Join Date
    Jan 2020
    Posts
    216
    Quote Originally Posted by DrM View Post
    @frankzappa

    As I recall, on the Teensy 3.2 those channel combinations use the same ADC in one case, and different ADC's in the other.

    I notice you have the ADC's set for different speeds. The faster setting on ADC0 might produce more noise whenever you are using that ADC. And it seems plausible that when you use them together for a simultaneous read, you could see different behavior.

    On noise in general, you will see a lot of noise and a lot of cross talk, if you work with hookup wire and hobby board, and through hole boards will usually give you a lot of noise also.

    See this for a link to a note from NXP on noise management,

    https://forum.pjrc.com/threads/54977...y-close-to-it)


    And here is a picture of an SMT board that I built for low noise. You can see some of what is involved.

    Name:  IMG_7161.small.JPG
Views: 144
Size:  7.9 KB
    No the different speeds is a typo. I'm usig the same speeds.

    It's an SMT board which I designed to the best of my ability. I'm not dissatisfied with the noise I just want it to be consistent.

    What would it be on the board that would give inconsistent results? I'm not sure that it's the switching of analog inputs or if it's just inconsistent?

    Note that this is a very filtered signal and what you see is 1/f noise zoomed in.

    Here is a more common signal:Click image for larger version. 

Name:	signal.jpg 
Views:	34 
Size:	62.2 KB 
ID:	25315

  13. #513
    Senior Member
    Join Date
    Apr 2018
    Location
    Eastern Time, USA
    Posts
    163
    @frankzappa

    Well that is interesting indeed. So the ADC's are configured identically (averaging, speed, amplifier, etc)?

    The engineers at NXP are pretty knowledgeable, it would be a big surprise if the two ADC's had significantly different noise.

    Nonetheless, my next step would be to compare the noise from the same channel using each of the two ADC's. I recall that the library has calls to read an input with a specific ADC, and that there are a few specific channels that can be read by either ADC.


    P/S What do you mean by filtered signal? In circuitry or software? Can we see the unfiltered signals?

  14. #514
    Senior Member
    Join Date
    Jan 2020
    Posts
    216
    Quote Originally Posted by DrM View Post
    @frankzappa

    Well that is interesting indeed. So the ADC's are configured identically (averaging, speed, amplifier, etc)?

    The engineers at NXP are pretty knowledgeable, it would be a big surprise if the two ADC's had significantly different noise.

    Nonetheless, my next step would be to compare the noise from the same channel using each of the two ADC's. I recall that the library has calls to read an input with a specific ADC, and that there are a few specific channels that can be read by either ADC.


    P/S What do you mean by filtered signal? In circuitry or software? Can we see the unfiltered signals?
    Yes same configuration on both channels. The signal I showed is low pass filtered in software. It is a 1.25V DC signal from a voltage reference although you are seeing it as 0. I didn't take a snaphot of the unfiltered signal but it's visible there as well. The noise is the same peak to peak but it switches to the neighboring values much more often.

    You are misunderstanding, the ADC's don't have different noise. They behave differently depending on which two analog inputs are selected. Sometimes if I read 10 sensors, 7 of them can look very clean and the other three are misbehaving. If I switch the order of the ADC acquisitons and switch them around I can maybe get 9 of them to look clean.

    This is the same on breadboards, SMD PCB's, through hole PCB's. I've only tried it on teensy 4.

    It would seem the order of the ADC readings and/or which two are sampled together seems to affect the quality. However I'm not sure it's consistent, I need to write down which analog pairs work well together and test if that's always the case.
    Last edited by frankzappa; 07-21-2021 at 02:43 PM.

  15. #515
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,246
    This will be capacitive coupling issues I think - ADC input sample/hold caps on modern silicon are only a few pF.
    If you want noise-free ADC operation you may have to stop the processor to eliminate wide-band signals banging
    around the chip all the time. The more complex the chip (code excuting, DMA running, IRQs running, peripherals
    active), the more noise is around on the die. If the pins used were only connected to the ADC multiplexer and
    nothing else it might be possible to route them away from crosstalk, but if not its pretty much impossible I suspect.

    Basically an ADC on a microcontroller/microprocessor chip is always quite a compromize. A dedicated ADC chip with
    separate analog and digital supplies and grounds is able to perform way better. But there is a strong business case
    for an on-chip ADC even if its poor, as often this enables a smaller BoM when any old ADC will do...

  16. #516
    Senior Member
    Join Date
    Jan 2020
    Posts
    216
    Quote Originally Posted by MarkT View Post
    This will be capacitive coupling issues I think - ADC input sample/hold caps on modern silicon are only a few pF.
    If you want noise-free ADC operation you may have to stop the processor to eliminate wide-band signals banging
    around the chip all the time. The more complex the chip (code excuting, DMA running, IRQs running, peripherals
    active), the more noise is around on the die. If the pins used were only connected to the ADC multiplexer and
    nothing else it might be possible to route them away from crosstalk, but if not its pretty much impossible I suspect.

    Basically an ADC on a microcontroller/microprocessor chip is always quite a compromize. A dedicated ADC chip with
    separate analog and digital supplies and grounds is able to perform way better. But there is a strong business case
    for an on-chip ADC even if its poor, as often this enables a smaller BoM when any old ADC will do...
    Yeah I figured it would be something like that. It seems to not be consistent. It doesn't matter which two analog inputs I read simultaneously. If I get noisy signals I just have to recompile a few times until I get a compilation when the planets have aligned and the ones and zeros inside the teensy are in order (or something).

  17. #517
    Senior Member
    Join Date
    Jan 2020
    Posts
    216
    I noticed something else. I connected a sensor that I deliberately used a much longer cable so it picks up 60 Hz mains hum, you can see the 60Hz oscillation clearly. When it's misbehaving the 60Hz hum is exactly twice the amplitude. What the hell is going on?

    How can it pick up twice the amount of 60Hz from the long cable?

    As far as I understand an unshileded cable will pick up mains hum from the power in the walls by capacitive coupling. How come it's sometimes twice as susceptible? It's like a switch inside that randomly turns on to mess with you.

Posting Permissions

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