What is the status of Teensy 4.0 ADC support, using Teensyuino1.53 (or other version if better)
I find the information very scattered, what is supported and not for Teensy 4.0 and how to use it correctly
There is formal documentation for ADC.h but find it easier to find the information reading the actual files, but even with that it is difficult as they speak of many Teensy versions.
The DMA examples I do not get running, and find them difficult too, they are trying to do too many things with too many Teensy versions.
I thought it would be possible to set up continious reading so that it is reading many channels, but seems not It seems it can read only one pin per ADC.
I understood that Teensy 4.0 has only one ADC, but seems to have two, I got this working and providing correct values.
But would need to read 4 inputs at relatively fast rate.
Reading them all with analogRead(pin);works, but the documentation says
"It waits until the value is read and then returns the result. " so not nice when trying to read all channels 10 kHz, and need to do many other things also.
Is it possible to mix analogReadContinuous(); and analogRead(pin);? I will try.
What I really would like to have is all 4 channels read with DMA at least 100 samples, 150 times per second, possible? how?
The 100 or more samples should distribute about evenly during the 6,6 ms sampling time, but it is ok if there is some missed samples between the 150 samplings per second as these readings would be used for weighted averaging and speed calculation, 150 times per second, it does not need to be sliding.
While testing DMA so far I got strange hysteresis on pin 15 readings, potentiometer moves couple of degrees before changing the value. The pins are set as suggested by some who had the same problem
pinMode(15, INPUT_DISABLE); //Potentiometer 2 (focus)
But this does not help
Gives the same for all pins
10000000000111000
10000000000111000
10000000000111000
10000000000111000
I find that a bit strange as this indicates the hysteresis is active and output driver is set to strong strength, but changing these does not help to the problem. It is high quality potentiometer, but problem could be also that it is broken, but do not think so.
about the
adc->adc1->recalibrate();
I added that because without that the range was 0 to 1021, now it is correctly 0 to 1023 (I do filtering with 12 bits and divide result by 4)
I find the information very scattered, what is supported and not for Teensy 4.0 and how to use it correctly
There is formal documentation for ADC.h but find it easier to find the information reading the actual files, but even with that it is difficult as they speak of many Teensy versions.
The DMA examples I do not get running, and find them difficult too, they are trying to do too many things with too many Teensy versions.
I thought it would be possible to set up continious reading so that it is reading many channels, but seems not It seems it can read only one pin per ADC.
I understood that Teensy 4.0 has only one ADC, but seems to have two, I got this working and providing correct values.
Code:
#include <ADC.h>
ADC *adc = new ADC();
void setup() {
adc->adc0->setAveraging( 32 );
adc->adc0->setResolution( 12 );
adc->adc0->setConversionSpeed( ADC_CONVERSION_SPEED::VERY_LOW_SPEED );
adc->adc0->setSamplingSpeed( ADC_SAMPLING_SPEED::VERY_LOW_SPEED );
delay(100);
adc->adc0->recalibrate();
delay(100);
adc->adc1->setAveraging( 32 );
adc->adc1->setResolution( 12 );
adc->adc1->setConversionSpeed( ADC_CONVERSION_SPEED::VERY_LOW_SPEED );
adc->adc1->setSamplingSpeed( ADC_SAMPLING_SPEED::VERY_LOW_SPEED );
delay(100);
adc->adc1->recalibrate();
delay(100);
pinMode(14, INPUT_DISABLE); //Potentiometer 1 (iris)
pinMode(15, INPUT_DISABLE); //Potentiometer 2 (focus)
pinMode(16, INPUT_DISABLE); //Joystick X
pinMode(17, INPUT_DISABLE); //Joystick Y
adc->adc0->startContinuous(14);
adc->adc1->startContinuous(15);
delay(1000);
uint16_t value14 = (uint16_t)adc->adc0->analogReadContinuous()/4;
Serial.println(value14);
uint16_t value15 = (uint16_t)adc->adc1->analogReadContinuous()/4;
Serial.println(value15);
}
But would need to read 4 inputs at relatively fast rate.
Reading them all with analogRead(pin);works, but the documentation says
"It waits until the value is read and then returns the result. " so not nice when trying to read all channels 10 kHz, and need to do many other things also.
Is it possible to mix analogReadContinuous(); and analogRead(pin);? I will try.
What I really would like to have is all 4 channels read with DMA at least 100 samples, 150 times per second, possible? how?
The 100 or more samples should distribute about evenly during the 6,6 ms sampling time, but it is ok if there is some missed samples between the 150 samplings per second as these readings would be used for weighted averaging and speed calculation, 150 times per second, it does not need to be sliding.
While testing DMA so far I got strange hysteresis on pin 15 readings, potentiometer moves couple of degrees before changing the value. The pins are set as suggested by some who had the same problem
pinMode(15, INPUT_DISABLE); //Potentiometer 2 (focus)
But this does not help
Code:
Serial.println(IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_02, BIN);//pin14
Serial.println(IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_03, BIN);//pin15
Serial.println(IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_07, BIN);//pin16
Serial.println(IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_06, BIN);//pin17
Gives the same for all pins
10000000000111000
10000000000111000
10000000000111000
10000000000111000
I find that a bit strange as this indicates the hysteresis is active and output driver is set to strong strength, but changing these does not help to the problem. It is high quality potentiometer, but problem could be also that it is broken, but do not think so.
about the
adc->adc1->recalibrate();
I added that because without that the range was 0 to 1021, now it is correctly 0 to 1023 (I do filtering with 12 bits and divide result by 4)
Last edited: