Go Down

Topic: Digital input - state change speed (Read 63 times) previous topic - next topic

cromato

Hallo everyone!
I am new wuth arduino and i have some questions about it, so i hope somebody can help.
I have to make a series of very fast sensors, where the state can change from 0 to 1 and back to 0
within 5 miliseconds.
1. Can Arduino see this fast changes on an digital input?
2. If yes, what about of the sum of 16 digital inputs that can change the states so fast?
   Example: The 16 digital inputs have this state:  0000000011111111
   than the states change to:                              0000111111111111
   and after about 5 miliseconds back to:             0000000011111111
If this change happens within 5 miliseconds than set an output,
else if this change takes more than 5 miliseconds do nothing.


dlloyd

For a 16MHz Arduino, you'll have 80,000 cycles to do this. A port (8 inputs) can be read in 1 cycle.

CrossRoads

Something like this, read the 3 ports, move into position in an int, then do it again until it changes

Code: [Select]

byte dPins = PIND; // D7-D0 use bits 7-2, keep 1-0 free for serial
unsigned int bPins = PINB; // D13-D8 use bits 5-0
insigned int cPins = PINC; // D19-D14 use  bits 5-0
// move into position
unsigned int sixteenPins = cPins << 10 | (bPins <<6) | (dPins >>2);

while (sixteenPins == newSixteen){ // keep reading until different
byte dPins = PIND; // D7-D0 use bits 7-2, keep 1-0 free for serial
unsigned int bPins = PINB; // D13-D8 use bits 5-0
unsigned int cPins = PINC; // D19-D14 use  bits 5-0

unsigned int newSixteen = cPins << 10 | (bPins <<6) | (dPins >>2);
//  jump out when it changes
}
Serial.print ("Got a change ");
Serial.print (sixteenPins, HEX);
Serial.print (" new ");
Serial.println (newSixteen, HEX);
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy