Improve ADC Readings Teensy 4

Status
Not open for further replies.

CanD3mir

New member
Hello Guys,

Today I connected the Teensy 4 ADC to a signal generator and started measuring.
I included the simple ADC Reading Script and the Serial Output of the values. As you can see the ADC Readings are "quite" noisy. I know that the teensy 4 is not a high-end professional adc device, but is there a way to improve the adc accuracy?

I used averaging, but that did not really help.

The first thing that came to my mind was to use an external reference voltage that performs better than the inbuilt voltage regulator.

What do you guys think?


Code:
// variables
int adcs = 0;                   // raw value from analog in
float voltage=0.0;                 //Voltage
// constants
const int adcPin = A2;           // analog in pin identifier

/* setup, run once */
void setup(){
    Serial.begin(9600);
    // configure Teensy pins
    analogReadResolution(12);   // (0-4095)
    analogReadAveraging(12);
 }

/* loop, run continuously */
 void loop() {

 
    adcs = analogRead(adcPin);
    voltage= (adcs * 3.295)/4095;
    Serial.print("ADC Value: ");Serial.print(adcs);Serial.print(" Voltage: ");Serial.println(voltage,3);
  
    delay(250);
}
HTML:
ADC Value: 2500 Voltage: 2.012
ADC Value: 2505 Voltage: 2.016
ADC Value: 2497 Voltage: 2.009
ADC Value: 2502 Voltage: 2.013
ADC Value: 2497 Voltage: 2.009
ADC Value: 2494 Voltage: 2.007
ADC Value: 2488 Voltage: 2.002
ADC Value: 2502 Voltage: 2.013
ADC Value: 2497 Voltage: 2.009
ADC Value: 2498 Voltage: 2.010
ADC Value: 2502 Voltage: 2.013
ADC Value: 2495 Voltage: 2.008
ADC Value: 2497 Voltage: 2.009
ADC Value: 2501 Voltage: 2.012
ADC Value: 2500 Voltage: 2.012
ADC Value: 2503 Voltage: 2.014
ADC Value: 2498 Voltage: 2.010
ADC Value: 2495 Voltage: 2.008
ADC Value: 2502 Voltage: 2.013
ADC Value: 2495 Voltage: 2.008
ADC Value: 2503 Voltage: 2.014
ADC Value: 2507 Voltage: 2.017
ADC Value: 2502 Voltage: 2.013
ADC Value: 2503 Voltage: 2.014
ADC Value: 2494 Voltage: 2.007
ADC Value: 2502 Voltage: 2.013
ADC Value: 2502 Voltage: 2.013
ADC Value: 2504 Voltage: 2.015
ADC Value: 2496 Voltage: 2.008
ADC Value: 2496 Voltage: 2.008
 
The Teensy 4.0 doesn't have any capability to use anything except V3.3 as the analog reference. If you need better results, you'll need an external ADC.

Various earlier posts say that the T4.0 ADC really only has 10 effective bits--or one part in 1024. For a max 4096 counts, that's about 4 LSBs. You could improve things a bit with more oversampling and filtering, but intermittent loads on the 3.3V (such as writing to SD cards) are going to tweak the 3.3Volt reference and add noise.
 
I've been able to eek out 11 bits resolution on the Teensy 4 using a bit of averaging magic. First, I was hardware sampling a piezo sensor conditioning circuit (which produced full, non-rectified +/- 1.65V signals, using the 3.3V output of the Teensy as the reference) at 14.4kHz, using 4x hardware averaging in the Teensy. Then, on those samples as received from the hardware, I did a 3:1 decimation in software to 4.8 kHz, using a three-sample average. That is, take three of the samples from the averaged hardware samples, compute their average, and using the resulting sample in a 4.8 kHz polled loop. My tests show I can achieve around 1.5 - 2 mV peak noise in quiescent state (that is, no hits on the piezo.) As a rough calculation, 3.3V / 2^11 is 1.6 mV, so my results are in the ballpark of 11 bits resolution. Note that the NXP docs for the microcontroller in the Teensy 4 state 11 effective bits.

The trick, I've found, is to use three-way averaging. Why three? Well, if you use too small a window (such as 1 or 2 samples) you won't get much noise reduction. If you use a bigger window, (like say, 10 samples) you run the risk of missing real peaks in the data. It turns out that using three samples seems to be optimum. It does decent noise reduction, getting rid of most of the noisy spikes, without rounding off real data peaks too much.

To recap, in my case, the three-way averaging came *after* doing 4-way averaging in the Teensy ADC hardware. The hardware averaging is done in "bursts" so you can think of it as producing a sample at the nominal sampling rate, (in my case, 14.4 kHz). Then the 3:1 decimation produces a "virtual" sampling rate, in my case, 4.8 kHz.

Anyway, that's what has worked for me.

In my project, I deemed 11 bits wasn't good enough, so I've stuck with using a Teensy 3.5 or 3.6 and getting real 12 bit resolution.
 
Status
Not open for further replies.
Back
Top