Teensy 4.1 Reading both ADCs with IntervalTimer

Status
Not open for further replies.

MrZ80Dude

Member
Hello Teensy community,

I'm currently trying to measure two analog values synchronously with the ADCs of the Teensy 4.1. For a general orientation I used the example code from pedvide and KurtE https://github.com/pedvide/ADC/blob/master/examples/analogReadIntervalTimer/analogReadIntervalTimer.ino
I'm very thankful, that this example exists :)

My loop() function is similar to the one in the example but I have some questions I couldn't really find an answer to. Can someone please help me a bit?

1. How to properly set the readPeriod for delayMicroseconds(readPeriod); in the void loop()? I know from the oscilloscope picture that the board kind of overruns itself if the line isn't there, but why does it do that?

2. Why does the microcontroller crash after some seconds and restarts if I measure with a single ADC in an ISR and put out the measured voltage values constantly with Serial.println(); in the void loop()?

3.
Code:
if(adc->adc0->adcWasInUse) {
        // restore ADC config, and restart conversion
        adc->adc0->loadConfig(&adc->adc0->adc_config);
        // avoid a conversion started by this isr to repeat itself
        adc->adc0->adcWasInUse = false;
    }
Why do I need those lines? I know partially what they do:
-checking if the adc was in use
-loading a kind of an initial configuration which was changed during the measurement?
-resetting adc0 WasInUse flag

If I leave these lines in my code, the board only measures one time and never calls the ISR for reading the value again.

4. Where can I find details about the asm() function in
Code:
#if defined(__IMXRT1062__)  // Teensy 4.0
        asm("DSB");
    #endif
?
I'd like to figure out what it does and why it is there.

5. If I put an analogSynchronizedRead(pin1, pin2); function into the ISR to start the measurement, is it correct to get the measured values also with readSingle(); in a second ISR like in the example? Or do I need something else?

Thank you in advance :)
 
Status
Not open for further replies.
Back
Top