hi speed event detection

New guy here, that plus the fact my background is mechanical… I’m looking at detecting a break in a dc signal during some vicious shaking. The break will be 1 microsecond max. Can I just loop the digital read and look for a change? Any rough ideas on what the frequency of the loop would be for a very simple loop, ie, digitalread - if low, jump out of the loop and trigger an LED. Thanks for any input. ~ bob

digitalRead() will probably not be fast enough as it can take several microseconds to execute. You should use the AVR registers directly so you get the tightest loop possible. For example:

pinMode(2, INPUT); // configure pin 2 as an input
while (~PIND & (1 << PD2)) // loop here while pin 2 is low

It might be even better if you were to use interrupts for this application. You can use an external interrupt if you connect your signal to an external interrupt pin, or you could use a pin change interrupt, which is slightly more complicated and will result in an interrupt for both the rising and falling edge but is on every pin.

  • Ben

try this

Thank you for your advice. I will check it all out and post back with what works. Open source really rocks. ~ bob

The break will be 1 microsecond max.

I’m not sure of your application, but you might find you can do what you want without a micro controller. Using something like a d-type flip flop will enable ypu to detect breaks in a circuit.

A counter like the 4017 will enable you to count breaks in the circuit.

You could always connect the output of the d-type to the arduino.