I have a small project (quite big for me anyway) where I need the ADC in my teensy 4.1 to continuously take measurements. Meanwhile, the main loop should be waiting for a pin to go low. The way I have structured everything, there is a timer that periodically throws interrupts which start the ADC conversions, and the ISR called by the ADC when a conversion is complete, moves the result to a buffer.
Meanwhile, the main is using the following function to wait for the pin to go low:
Now, this was not working, and so, after some trial and error, I've reached the conclusion that the interrupts interfere with the digitalRead(), as it starts working properly when I lower the interrupt frequency (ideally there is an interrupt thrown every 3us, and, from what I've gathred, digitalRead() takes a bit longer).
Now, I know there are different ways of approaching this program, but this is the most optimal way I thought of, and am more interessted in learning why this does not work than in changing the way the program works.
It is my understanding that, whenever an interrupt ends, the processor returns to the point where it was when the interrupt was thrown, so it should not affect the correct execution of a function for an interrupt to be thrown midway through the execution. I'd like to know what I'm getting wrong for digitalRead() not to work.
Thanks in advance for any help
Meanwhile, the main is using the following function to wait for the pin to go low:
Code:
void waitForPin(uint8_t triggerPin) {
bool keep = true;
while (keep) {
keep &= digitalRead(triggerPin);
}
}
Now, this was not working, and so, after some trial and error, I've reached the conclusion that the interrupts interfere with the digitalRead(), as it starts working properly when I lower the interrupt frequency (ideally there is an interrupt thrown every 3us, and, from what I've gathred, digitalRead() takes a bit longer).
Now, I know there are different ways of approaching this program, but this is the most optimal way I thought of, and am more interessted in learning why this does not work than in changing the way the program works.
It is my understanding that, whenever an interrupt ends, the processor returns to the point where it was when the interrupt was thrown, so it should not affect the correct execution of a function for an interrupt to be thrown midway through the execution. I'd like to know what I'm getting wrong for digitalRead() not to work.
Thanks in advance for any help
Last edited: