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

Thread: Teensy 3.2 DAC accuracy? Alternatives?

  1. #1

    Teensy 3.2 DAC accuracy? Alternatives?

    I finally started using the Teensy 3.2's built in DAC. Great feature, I love how easy it is to use...

    My first application involves sampling a DC voltage on an ADC pin and then outputting the same voltage on the DAC. It's pretty straight forward (just passing the same value) and my results are "good", but I'm wondering what would be involved in making them better.

    I graphed the ADC input and DAC output (in .2V steps) to see how accurate they stay. Interestingly, the difference is only 1-2mV for the first 11bits (0 - 1.65V) and then it jumps up to 6-7mV for the rest (1.65V - 3.3V).

    I'll admit to being pretty overwhelmed by the datasheets for the teensy microcontrollers, but what spec determine the accuracy I could expect from a DAC in this application?

    Also while I'm here, can anyone recommend any DAC's that might be better in this regard? Teensy library compatibility is a must (non-programmer here), and 12-bits is totally fine for my application.

    Thanks everyone!

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,770
    Perhaps the small error is not from the DAC, but in the ADC? How would you know which is giving the extra few mV error?

    My guess is you may have pinMode INPUT in your code, rather than leaving the pin alone or using INPUT_DISABLE to turn off the digital input circuitry. If the pin is configured for digital input mode (guesswork on my part, since you didn't show the code) the leakage current inside the chip could be causing the small analog error.

  3. #3
    Quote Originally Posted by PaulStoffregen View Post
    Perhaps the small error is not from the DAC, but in the ADC? How would you know which is giving the extra few mV error?

    My guess is you may have pinMode INPUT in your code, rather than leaving the pin alone or using INPUT_DISABLE to turn off the digital input circuitry. If the pin is configured for digital input mode (guesswork on my part, since you didn't show the code) the leakage current inside the chip could be causing the small analog error.
    Thanks Paul, I guess it's true that from the way I tested I have no way of knowing if the error an inaccuracy in the DAC output or in the ADC reading. No pin is set to INPUT and the DAC output is the one that measures higher by 2-6mV. The code is quite big, but hopefully here is all the relevant stuff.

    Code:
    ResponsiveAnalogRead sample(A9, false);
    
    void setup() {
    
        analogWriteResolution(12);
        pinMode(A14, OUTPUT);
        analogReadAveraging(16); 
        analogReadRes(16);     
        sample.setAnalogResolution(65536);
    }
    
    void loop()
    
        sample.update();
    
       if (complicated stuff ) {
          analogWrite(A14, sample.getValue() / 16);
      }
    {

    And here's a CSV showing the measured voltage at the ADC and DAC pins:

    Code:
    SAMPLE CV ADC,FREEZE CV DAC,DELTA
    0.2,0.199,-0.001
    0.299,0.299,0
    0.4,0.399,-0.001
    0.499,0.499,0
    0.599,0.599,0
    0.699,0.699,0
    0.799,0.799,0
    0.899,0.9,0.001
    0.999,1,0.001
    1.099,1.101,0.002
    1.2,1.2,0
    1.299,1.301,0.002
    1.399,1.401,0.002
    1.499,1.5,0.001
    1.599,1.601,0.002
    1.702,1.708,0.006
    1.802,1.807,0.005
    1.903,1.907,0.004
    2.002,2.007,0.005
    It's interesting that the DELTA stays very small (1-2mV) and then suddenly jumps to 6mV at the transition from 011111111111 to 100000000000 at the DAC.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,770
    Maybe there's something wrong inside the "complicated stuff" part?

    Can you recreate this problem using only a very small & simple program?

  5. #5
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    650
    What does a good multimeter say is correct?

    Consider over sampling and a trimmed mean for the ADC value.

    If all else fails, consider calibrating it out. If necessary, with a 4096 entry lookup table.

  6. #6
    Senior Member
    Join Date
    Jul 2020
    Posts
    406
    Quote Originally Posted by gatheround View Post

    It's interesting that the DELTA stays very small (1-2mV) and then suddenly jumps to 6mV at the transition from 011111111111 to 100000000000 at the DAC.
    Yes, that's a very common problem with a DAC or ADC - all the bits change at once, maximal error point.
    The key specifications are INL and DNL (integral non linearity and differential non-linearity). Its worth checking to see
    if the device is listed as "no missing codes", meaning the inaccuracies consist of gaps, not overlaps.

    I suspect the desire to have "no missing codes" in the datasheet leads to designs being less linear than they
    could be.

    But you can finesse the issue by going to a topology which is inherently linear/monotonic such as sigma-delta.

  7. #7
    Quote Originally Posted by jonr View Post
    What does a good multimeter say is correct?

    Consider over sampling and a trimmed mean for the ADC value.

    If all else fails, consider calibrating it out. If necessary, with a 4096 entry lookup table.
    Hi Jon, the ADC value is already averaged across 16 readings and is surprisingly solid (2-4 counts of noise at 16 bits!). I considered the look up table solution, but I want to make approx 20 of these and I noticed the DELTA error changes unit to unit (I only tested with an older Teensy 3.1 I had on hand, the error was similar but different and also had the same "jump" between 011111111111 and 100000000000. So maybe I could just account for that transition in software.. but would also be interested in trying an external DAC that might just be more accurate straight out of the box.

  8. #8
    Quote Originally Posted by MarkT View Post
    Yes, that's a very common problem with a DAC or ADC - all the bits change at once, maximal error point.
    The key specifications are INL and DNL (integral non linearity and differential non-linearity). Its worth checking to see
    if the device is listed as "no missing codes", meaning the inaccuracies consist of gaps, not overlaps.

    I suspect the desire to have "no missing codes" in the datasheet leads to designs being less linear than they
    could be.

    But you can finesse the issue by going to a topology which is inherently linear/monotonic such as sigma-delta.
    Hi Mark, thanks for the reply. Using a DAC is new to me, so I didn't know that the maximum error would be at that point.. that's interesting. Is "Sigma-Delta" a style/type of DAC that I should be looking for?

  9. #9
    Quote Originally Posted by PaulStoffregen View Post
    Maybe there's something wrong inside the "complicated stuff" part?

    Can you recreate this problem using only a very small & simple program?
    Thanks for the suggestion Paul, the "complicated stuff" actually isn't complicated at all - just a comparison ( pressure.getValue() >= freezethresh ) between another ADC reading and a CONST. I will simplify my code as you suggested to just this ADC to DAC function and see if it changes anything and I will also record the ADC readings which might help to see if the inaccuracy is in the ADC or the DAC.

  10. #10
    Senior Member
    Join Date
    Jul 2020
    Posts
    406
    Quote Originally Posted by gatheround View Post
    Hi Mark, thanks for the reply. Using a DAC is new to me, so I didn't know that the maximum error would be at that point.. that's interesting. Is "Sigma-Delta" a style/type of DAC that I should be looking for?
    It depends, each architecture of ADC and DAC have strengths and weaknesses.

  11. #11
    Quote Originally Posted by MarkT View Post
    It depends, each architecture of ADC and DAC have strengths and weaknesses.
    In this case, accurate DC voltages that change between 1-100 seconds.

Posting Permissions

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