Digital Pin Read Takes About 4.78 Microseconds.
#define MY_PIN 8 // do this once at setup uint8_t myPin_mask = digitalPinToBitMask(MY_PIN); volatile uint8_t *myPin_port = portInputRegister(digitalPinToPort(MY_PIN)); // read the pin uint8_t pinValue = (*myPin_port & myPin_mask) != 0;
Thanks a lot, Peter, that's what I needed to know. One more question though: all those timings are going to double when running at 8 MHz, right?
Indeed, it is. I have a signal that I must sample on a 12 us clock. Of course I use an interrupt: it seems it takes about 3 us to enter the handler and 2 more to leave it. If running at 8 MHz, like I plan, that doubles and doesn't leave much time for the actual job .
A single I/O instruction is 0.125us.