///// ADC0 ////
// reference can be ADC_REF_3V3, ADC_REF_1V2 (not for Teensy LC) or ADC_REF_EXT.
adc->setReference(ADC_REF_1V2, ADC_0); // change all 3.3 to 1.2 if you change the reference to 1V2
adc->setAveraging(1); // set number of averages
adc->setResolution(13); // set bits of resolution
// it can be ADC_VERY_LOW_SPEED, ADC_LOW_SPEED, ADC_MED_SPEED, ADC_HIGH_SPEED_16BITS, ADC_HIGH_SPEED or ADC_VERY_HIGH_SPEED
// see the documentation for more information
adc->setConversionSpeed(ADC_HIGH_SPEED); // change the conversion speed
// it can be ADC_VERY_LOW_SPEED, ADC_LOW_SPEED, ADC_MED_SPEED, ADC_HIGH_SPEED or ADC_VERY_HIGH_SPEED
adc->setSamplingSpeed(ADC_HIGH_SPEED); // change the sampling speed
adc->setConversionSpeed(ADC_VERY_LOW_SPEED)
adc->setConversionSpeed(ADC_CONVERSION_SPEED::VERY_LOW_SPEED)
I also gutted your analogContinuousRead.ino to find the speed of acquisition with a 5KHz 0.2V sine signal on A10, A11 using the version below.
I got the following output, displayed using Excel, which shows a sampling rate of about 45ksps, adequate for my purpose but not as fast as I expected.
View attachment 8909
Will the ADC go faster?
I know in synced mode, you have to select both ADC0 and ADC1 on separate pins. In differential mode, is there a requirement for how/which ADC pins are selected?
I'm looking into these issues, but I have a lot of work. I hope I can do something on the weekend.
Please note that Teensy 3.6 only has one differential pair!
Also I see that you're casting the results to uint, so you won't get negative values, which are possible for a diff measurement.
Also, what happens if you run that while loop inside the loop() function?b
Also, in the loop you're printing every value as you read it. This means that the 45 ksps may very well be because of the constant sending of a value via usb and printing it. Better fill an array and print it at once.
Pedvide and other experts,
Anyone know if the ADC Library and AnalogReadAudio can still play nice together if implemented seperately on ADC_0 & ADC_1?
After updating my libraries and editing some code I found my adc->analogRead(readPin, ADC_1) resulted in mostly Max Values. I'm reading a log-scale light sensor with AnalogReadAudio, which started reading max values expect in very dark circumstances.
This seems to be the same issue, using the similar code: https://forum.pjrc.com/threads/39377-A-problem-using-the-Audio-library-and-ADC-library.
#if ADC_NUM_ADCS==2
, IRQ_ADC(ADC_num? IRQ_ADC1 : IRQ_ADC0) // fix by SB (Teensy 3.6)
#else
, IRQ_ADC(IRQ_ADC0 + ADC_num*1)
#endif
uint8_t pin = ADC::sc1a2channelADC1[ADC1_SC1A&ADC_SC1A_CHANNELS]; // the bits 0-4 of ADC1_SC1A have the channel
///////// ADC1
#if defined(ADC_TEENSY_3_1)
const uint8_t ADC::sc1a2channelADC1[]= { // new version, gives directly the pin number
36, 0, 0, 34, 28, 26, 29, 30, 16, 17, 0, 0, 0, 0, // 0-13. 5a=26, 5b=27, 4b=28, 4a=31
0, 0, 0, 0, 39, 37, 0, 0, // 14-21
0, 0, 0, 0, 38, 41, 0, 42, // 22-29. VREF_OUT, A14, temp. sensor, bandgap, VREFH, VREFL.
43
};
#elif defined(ADC_TEENSY_3_5) || defined(ADC_TEENSY_3_6)
const uint8_t ADC::sc1a2channelADC1[]= { // new version, gives directly the pin number
36, 0, 0, 34, 28, 26, 29, 30, 16, 17, 0, 0, 0, 0, // 0-13. 5a=26, 5b=27, 4b=28, 4a=31
0, 0, 0, 0, 39, 37, 0, 0, // 14-21
0, 0, 0, 0, 38, 41, 0, 42, // 22-29. VREF_OUT, A14, temp. sensor, bandgap, VREFH, VREFL.
43
};
#endif
#elif defined(ADC_TEENSY_3_5) || defined(ADC_TEENSY_3_6)
const uint8_t ADC::sc1a2channelADC1[]= { // new version, gives directly the pin number
0, 69, 0, 0, 35, 36, 37, 38, 0, 0, 49, 50, 0, 0, // 0-13.
31, 32, 0, 39, 71, 65, 0, 0, // 14-21
0, 67, 0, 0, 0, 0, 0, 0, // 22-29.
0
};
#endif
#elif defined(ADC_TEENSY_3_5) || defined(ADC_TEENSY_3_6)
const uint8_t ADC::sc1a2channelADC0[]= { // new version, gives directly the pin number
0, 68, 0, 64, 23, 14, 20, 21, 16, 17, 0, 0, 19, 18, // 0-13
15, 22, 0, 33, 34, 0, 0, 0, // 14-21
0, 66, 0, 0, 70, 0, 0, 0, // 22-29
0 // 31 means disabled, but just in case
};
#endif // defined
What is the Pin Layout for this library? I`m trying the analogRead example and connect A9 and A2 to GND and expect the output to be 0 but I get random values (because it is not the correct pin connected) around 2V and around 3V.
I`m using the unmodified example on a Teensy 3.1 24MHz.
What am I doing wrong?
Thanks
/* Change the resolution of the measurement
* For single-ended measurements: 8, 10, 12 or 16 bits.
* For differential measurements: 9, 11, 13 or 16 bits.
* If you want something in between (11 bits single-ended for example) select the inmediate higher
* and shift the result one to the right.