I have been hunting around for sample rates and the analog rate I can find, but I am struggling to find the digital sample rate. I`m looking to sample 2 digital inputs at around 5000 pulses per second, and sample them at the same time (no delays)
Would this be possible ?
If something similar has been asked before then apologies.
void loop(){
current_time = micros(); // capture the current time; time elements are all unsigned long data type
if ( (current_time - previous_time)>=sample_time){ // time for next sample?
previous_time = previous_time + sample_time; // set up for next tim
// direct port manipulation read, and mask off for the intended bit. S/W guys probably have a fancier way to do this
dataBit0 = PORTx & B00000001; // where x is the port you are reading, mask for the desired bit
dataBit1 = (PORTx & B00000010)>1; // result is 0,1 for the 2 bytes dataBit0 & dataBit1
}
// do other stuff while waiting for next sample_time to come up
}
I've done it with just digitalRead at 100us interval. If you need say 10us or less, maybe read directly from the port. If even less time is required, use some assembly. I don't even know how to write assembly for this chip since I didn't find need to do 4us timing. I kind of said bye-bye to 80386 assembly in late 1990s, although it's cool to know it.