How can I make the code statement to toggle change an output, only if an input goes HIGH to LOW for a duration window of time of .2secs to .5secs?
I don’t think that I can do it with pulseIn.
I neglected to add that I’m detecting a change of state from .6VDC to 1.2VDC using an analog input.
That makes a bit of a difference. :mrgreen:Eos:
I neglected to add that I’m detecting a change of state from .6VDC to 1.2VDC using an analog input.
There are several ways to go about this;
-
code a loop that repetitively sample the analog input and counts the number of loops that the signal is above (or below, depending on the sense of the pulse) a threshold voltage btw the 2 levels. Using the micros() function measure (ahead of time) how long the loop takes to execute. Then compute loop count * time/loop to get your pulsewidth.
-
grab a timer (the MCU has 3) and use it to cause an interrupt every T usecs, (T > 200 usecs). In the interrupt service routine do pretty much the same as the above. This way you don’t have to measure the loop timing, you’ll know it by virtue of how you setup the timer interrupt.
-
setup the analog comparator input(s) to cause an interrupt on the first edge (rising or falling) and then again on the second edge (falling or rising). In the ISR store the time(s) via the micros() or millis() function. The PW is then storedTime2 - storedTime1. I would go this route myself and I would further guess that if you search enough you’ll find code that can be used for your purpose.
http://forum.arduino.cc/index.php/topic,149840.0.html