Hi all,
I want to ask how much clock cycle ask DigitalREAD(); and how much is possible to lower them.
Thank you.
Hi all,
I want to ask how much clock cycle ask DigitalREAD(); and how much is possible to lower them.
Thank you.
Also, i want to ask if you can perform a direct digital read of a pin, if it's possible with wiring framework and how much cycle are used for a direct digital read.
what do you mean by "direct digital read"? You can always access the register directly instead of using digitalRead() if you want to...
As an experiment you can measure the time something takes by printing microseconds prior to and immediately after an operation.
Serial.print is your friend.
Google: direct port manipulation Arduino.
digitalRead generally takes on the order of 4uS while the macro/function/whatever it is check that the port is setup for a read and all that stuff.
Reading a port itself is really quick:
inputPort = PORTD;
for example. I think just 1 or 2 clock cycles.
Or
if ((PORTD & 0b00000100) == 0){
// test if bit low, do something
}
else {
// bit was high, do something else
}
I often use that with SPI.transfer() as a time saving:
PORTB = PORTB & 0b11111011; // clear bit D10, leave rest alone, slave select
SPI.transfer(dataArray[x]); // send out the data, from an array location
PORTB = PORTB | 0b00000100; // set bit D10, leave rest alone
You initial post requests reading a port/pin so you could use something like PIND that will read ALL the pins connected to port D and then you perform an AND instruction to isolate the bit for the pin your interested in. This will take very few instruction cycles to perform.