Code:
#if !defined(__IMXRT1062__) // Teensy 4.x
#error "Only runs on T4"
#endif
#include "ADC4_lite.h"
void setup() {
// put your setup code here, to run once:
while (!Serial && millis() < 5000) ;
Serial.begin(115200);
Serial.println("Quick and dirty T4 Analog Read stuff");
}
typedef struct {
uint8_t resolution;
uint8_t averaging;
} analog_configs_t;
const analog_configs_t test_configs[] = {
{8, 2}, {8, 4}, {8, 8}, {8, 16}, {8, 32},
{10, 2}, {10, 4}, {10, 8}, {10, 16}, {10, 32},
{12, 2}, {12, 4}, {12, 8}, {12, 16}, {12, 32}
};
uint8_t test_config_index = 0xff;
void loop() {
test_config_index++;
if (test_config_index == (sizeof(test_configs) / sizeof(test_configs[0]))) {
test_config_index = 0;
}
T4AnalogReadRes(test_configs[test_config_index].resolution, 1);
T4AnalogReadRes(test_configs[test_config_index].resolution, 2);
T4AnalogReadAveraging(test_configs[test_config_index].averaging, 1);
T4AnalogReadAveraging(test_configs[test_config_index].averaging, 2);
//analogReadAveraging(averaging_count);
// put your main code here, to run repeatedly:
uint32_t t1 = micros();
int a0 = analogRead(14);
int a1 = analogRead(15);
uint32_t t2 = micros();
int a0_4 = T4AnalogRead(14, 1);
int a1_4 = T4AnalogRead(15, 2);
uint32_t t3 = micros();
T4AnalogReadStart(14, 1);
T4AnalogReadStart(15, 2);
int a0_4C = T4AnalogReadComplete(1, true);
int a1_4C = T4AnalogReadComplete(2, true);
uint32_t t4 = micros();
uint16_t a0_both, a1_both;
T4AnalogReadBoth(14, a0_both, 15, a1_both);
uint32_t t5 = micros();
Serial.printf("%u:%u(%08x %08x)> %d %d %u : %d %d %u : %d %d %u : %u %u %u\n",
test_configs[test_config_index].resolution, test_configs[test_config_index].averaging,
ADC1_CFG, ADC1_GC,
a0, a1, t2 - t1,
a0_4, a1_4, t3 - t2,
a0_4C, a1_4C, t4 - t3,
a0_both, a1_both, t5 - t4);
delay(500);
}
Example output: