Hi, im new to arduino and im working on a project to generate 2 pulses that may overlap in the microseconds scale.
I need to generate a pulse of certain width (square wave), then a variable delay (the delay changes each cycle by a certain amount, and then another pulse of another certain width.
then repeat the whole process after a second.
The thing is that i cannot use the dealy function if i want to overlap pulses aparently, and the professor said we should try using the direct pin control command.
im reading about ddrd and stuff but i would love some help or a link if a project like this already exist
thanks in advance and i apologize for my english.
Please state the required pulse lengths and delays in microseconds.
They need to be a variable. Its something like setting an integer at the begining called pulse lenght. Anothet called delay and another called second pulse lenght so it can be modified later
Or something like that?
Its not a fixed value. Each experiment might have settings
Lets start with maybe a 3000us pulse. Then a 2000us delay for the second pulse counting from the beginig of the first pulse. And the second pulse is 20us wide
Are these pulses supposed to be on two different output pins?
Yes they are
if you are looking for generation of pulses to microsecond accuracy have a look at the Arduino Due and the tc_lib (https://github.com/antodom/tc_lib) library
Regular Arduino using timer interrupts should be able to get microsecond accuracy. The ISR can be super short as it just has to set a PORT, total 10-20 instructions which is about 1 µs on a 16 MHz Arduino.
Do look at the port manipulation reference (https://www.arduino.cc/en/Reference/PortManipulation). The direct port manipulation is the easy part. The timing is the hard part.
If you want fast interrupt response, you MUST avoid using attachInterrupt(), as described here (https://billgrundmann.wordpress.com/2009/03/02/the-overhead-of-arduino-interrupts/).