I have an Arduino nano. The Arduino should wait for a square pulse in its input. When the pulse comes, and after it falls, Arduino should count for 5 seconds and then light ON a LED. Should I use an interrupt? How do I implement this?
No problem. Set LED_turn_on_time = millis() + 5000 when pulse falls.
Check, in the loop, for if( millis() >= LED_turn_on_time) digital output = active.
The Arduino should wait for a square pulse in its input.
What does "square pulse" mean to you? How does that differ from a rectangular pulse?
Should I use an interrupt?
Depends. How long does the pulse last? What should happen if, while the Arduino is twiddling it's thumbs waiting for the 5 seconds to pass, this mysterious pulse arrives again?
Railroader:
No problem. Set LED_turn_on_time = millis() + 5000 when pulse falls.
Check, in the loop, for if( millis() >= LED_turn_on_time) digital output = active.
Wrong. ADDing time is NOT a good idea. Subtraction always works. Addition does not.
-
How can identify the falling edge of the pulse (from where I want to wait 5 seconds), and how do I identify a square (rectangular) pulse in general?
-
How do I prevent that in the waiting time of 5 secs (after the 1st pulse) if a second square (rectangular) pulse comes, does not affect the Arduino?
Thank you...
alex5678:
How can identify the falling edge of the pulse (from where I want to wait 5 seconds), and how do I identify a square (rectangular) pulse in general?
How do I prevent that in the waiting time of 5 secs (after the 1st pulse) if a second square (rectangular) pulse comes, does not affect the Arduino?
Thank you...
Hi,
Second question is easy ... where does the pulse come from?
Regards.
vffgaston:
Hi,
Second question is easy ... where does the pulse come from?
Regards.
A device that transforms optical pulse to electrical pulse..
After that 5 seconds, the LED should remain on indefinitely?
Rising or falling edge of the pulse?
How long does this pulse last?
wvmarle:
After that 5 seconds, the LED should remain on indefinitely?Rising or falling edge of the pulse?
How long does this pulse last?
The LED will light ON for 1 second.
Also I forgot to mention that I want to calculate how long the pulse will be at ON (+5 Volt) value...
(The pulse will be 0Volts -> 5Volts ->0Volts)
Also I forgot to mention that I want to calculate how long the pulse will be at ON (+5 Volt) value...
To what level of accuracy? Minutes? Seconds? Milliseconds? Microseconds? Nanoseconds?
PaulS:
To what level of accuracy? Minutes? Seconds? Milliseconds? Microseconds? Nanoseconds?
The better it can be...
How long do you expect the pulse to be?
alex5678:
The better it can be...
You're not helping here.
What is sending the pulses? Why do you care how long they last? You MUST give us some clue as to how long they last.
How you measure the length of the pulse depends, to some degree, on how long the pulse lasts.
alex5678:
A device that transforms optical pulse to electrical pulse..
Hi,
Provided that the ON situation is when the optical sensor is sensing something and OFF the opposite, the falling edge would be the transition from ON to OFF.
Normally (logically) in the electrical part this would mean "1" = ON and "0" = OFF (could be exactly the opposite); such a case the falling edge would be the transition from "1" to "0".
Regards.
such a case the falling edge would be the transition from "1" to "0".
Given this, you have to decide if polling the pin will be good enough to detect "exactly" when the transition happens, or if you need to use an interrupt handler to detect "exactly" when the transition happens.
I dont't know how the other device works.. I just know it gives me a pulse... I want to measure how long it is ON, and if it is possible, it would be good to have nanoseconds, or at least microseconds accurancy...
alex5678:
I dont't know how the other device works.. I just know it gives me a pulse... I want to measure how long it is ON, and if it is possible, it would be good to have nanoseconds, or at least microseconds accurancy...
Hi,
What are the characteristics of the electrical signal (voltage, noise -if any-, ...)
Regards
In spite of its name, you're not going to get nanosecond accuracy from your nano. If you really have no idea what this pulse looks like and don't have a scope available, I'd suggest you write a minimal program to see if you can actually detect & measure it.
For a first try, digitalRead the pulse pin and note the time using micros() when it goes high. Note the time when it goes low. When you have both, print the times to the serial port.
vffgaston:
Hi,
What are the characteristics of the electrical signal (voltage, noise -if any-, ...)
Regards
It is a 0Volt, 5Volt signal (rectangular pulse). If I get more than one pulses before the LED is ON, I only care about the 1st one (and for its duration), and don't care about the other pulses...
No info about the noise...
@wildbill: Can I achieve microseconds accurancy?
Thank you..
Hi,
If your problem were one in the miliseconds scope you could just read a digital pin every loop to check if it is ON or OFF, then counting or whatever you need.
If you are ranging in the uS, perhaps you need to use interrupts.
interrupts
nS is, perhaps, too much for an arduino (may be the SAM based ones)
Regards