teensy 4.1 analogRead inconsistenct

lokki

Well-known member
hi there,

I migrated a project from a teensy 3.6 to a teensy 4.1 and I noticed a very strange problem:

I have set analogRead resolution to 12 bit, and whenever I read an analog pin that should have a gradual increase or decrease there is a sudden jump in the readings at about half the max voltage (3.3v)

so if I sweep a pot connected to ground and 3.3v I get a jump of approximately 200 units at half the pots gangway. the transition is aprupt, so it jumps from 1900 to 2150 or so.

is there a known problem with reading analog inputs on teensy 4.1? or some setting I can adjust?

I will try to do a simple sketch and schematic that exhibits the problem...
 
as a small addendum. I also tried setting the analog resolution to 11 bit in setup()
Code:
 analogReadResolution(11);
, but this is ignored, it still uses 12 bits.
 
There was a recent note regarding adding a capacitor - quick search found this older note: capacitors-best-option-for-removing-analog-sensor-noise

Not sure the recent post had more or better info - but it was in past weeks...

It also refers to T_3.6 that had a separate AGND pin which the T_4.1 does not have. The higher speed at 600 MHz and design does compromise the analog performance for the faster digital. But such swings are possible long wires picking up noise - there are notes in that post about wire routing as well.

Looks like the resolution can be only 8, 10 or 12: ...\arduino-1.8.19\hardware\teensy\avr\cores\teensy4\analog.c
Code:
void analogReadRes(unsigned int bits)
{
  uint32_t tmp32, mode;

   if (bits == 8) {
    // 8 bit conversion (17 clocks) plus 8 clocks for input settling
    mode = ADC_CFG_MODE(0) | ADC_CFG_ADSTS(3);
  } else if (bits == 10) {
    // 10 bit conversion (17 clocks) plus 20 clocks for input settling
    mode = ADC_CFG_MODE(1) | ADC_CFG_ADSTS(2) | ADC_CFG_ADLSMP;
  } else {
    // 12 bit conversion (25 clocks) plus 24 clocks for input settling
    mode = ADC_CFG_MODE(2) | ADC_CFG_ADSTS(3) | ADC_CFG_ADLSMP;
  }
 
thanks for your answer. hmm, might have to switch back to teensy 3.6 then. this sudden jump does not at all seem to be noise, it does not jump fourth and back between values, it just jumps at half the supply voltage and continues from there smoothly if i turn the pot further.
 
Hi lokki, were you able to fix the problem adding pinMode(xx, INPUT_DISABLE) to setup()?
I was not aware of this issue and will probably need to fix all my T4.1 projects if that's the case.
 
yes, I just did this and it works flawlessly now. I will open another thread and describe what other changes I had to do to the code when migrating from teensy 3.6 to 4.1
 
yes, I just did this and it works flawlessly now. I will open another thread and describe what other changes I had to do to the code when migrating from teensy 3.6 to 4.1

That's great! Thanks for sharing the results. That's exactly my case, a code port from a Teensy 3.5 to 4.1 and this ADC pinMode config change was going completely unnoticed. Glad I read this post out of curiosity while scrolling through the forum.
 
Back
Top