A few other comments:
ADC0_CFG1 = 0b00000000;
This means you are running the ADC with a speed of 48 MHz, the specs limit for resolutions less than 16 bits is 18 MHz, so you are running at 3 times the maximum speed! The manual doesn't say if this can lead to actual physical damage of the ADC, or only loss of precision. It's true that you're using the ADHSC bit though, but adding 2 ADCK at 48 MHz (0.04 us!) won't probably be enough (I think min time for a conversion is around 1 us). If it works for you then it's fine, but I mention it so you know that maybe the ADC fails under the stress sooner than it should.
An idea to make it run even faster (I haven't really thought about this in detail):
Start a continuous measurement on both ADCs using pins A2, and A3 (for example) in the setup already.
In the loop:
- store the values value1,value2.
- start a normal measurement on pins A11, A10 and get the value (like you do now).
- start a continuous measurement again on pins A2, A3.
- process data.
This algorithm is faster if the time that it takes to start the continuous measurement is less than the total time of highSpeed8bitAnalogReadMacro(...), which I think is the case. You'd be measuring the new values of A2, A3 while doing you processing!
To start the continuous thingy you set SC3[ADCO] and write to SC1A.
I read a little bit about your project and you said that you wrote some java program to log the values from the Teensy, I'm interested in something like that to test the ADC in a more systematic way. Can you give me a copy and some instructions on how to use it? (I've never used java).
I'm preparing a big update for the library adding support for different conversion and sampling speeds, adding more synchronous methods (single-ended, differential, both single-shot and continuous), and using bitband for atomic access to the registers so everything is interrupt safe. I won't include methods for analog timers, but there will be examples on how to use IntervalTimer.
ADC0_CFG1 = 0b00000000;
This means you are running the ADC with a speed of 48 MHz, the specs limit for resolutions less than 16 bits is 18 MHz, so you are running at 3 times the maximum speed! The manual doesn't say if this can lead to actual physical damage of the ADC, or only loss of precision. It's true that you're using the ADHSC bit though, but adding 2 ADCK at 48 MHz (0.04 us!) won't probably be enough (I think min time for a conversion is around 1 us). If it works for you then it's fine, but I mention it so you know that maybe the ADC fails under the stress sooner than it should.
When the calibration finishes it sets SC3[CAL] AND SC1n[COCO], so you could check either, but it makes more sense to check SC3[CAL] (and SC3[CALF] to make sure the calibration was successful), as you do.Waiting for calibration to finish. The documentation is confused as to what flag to be waiting for (SC3[CAL] on page 663 and SC1n[COCO] on page 687+688)
An idea to make it run even faster (I haven't really thought about this in detail):
Start a continuous measurement on both ADCs using pins A2, and A3 (for example) in the setup already.
In the loop:
- store the values value1,value2.
- start a normal measurement on pins A11, A10 and get the value (like you do now).
- start a continuous measurement again on pins A2, A3.
- process data.
This algorithm is faster if the time that it takes to start the continuous measurement is less than the total time of highSpeed8bitAnalogReadMacro(...), which I think is the case. You'd be measuring the new values of A2, A3 while doing you processing!
To start the continuous thingy you set SC3[ADCO] and write to SC1A.
I read a little bit about your project and you said that you wrote some java program to log the values from the Teensy, I'm interested in something like that to test the ADC in a more systematic way. Can you give me a copy and some instructions on how to use it? (I've never used java).
I'm preparing a big update for the library adding support for different conversion and sampling speeds, adding more synchronous methods (single-ended, differential, both single-shot and continuous), and using bitband for atomic access to the registers so everything is interrupt safe. I won't include methods for analog timers, but there will be examples on how to use IntervalTimer.