Arduino Forum

Topics => Science and Measurement => Topic started by: gabe83 on Jun 02, 2018, 06:03 pm

Title: Help with pulse generation
Post by: gabe83 on Jun 02, 2018, 06:03 pm
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.

(https://imgur.com/o7nHMvf)
Title: Re: Help with pulse generation
Post by: jremington on Jun 02, 2018, 09:16 pm
Please state the required pulse lengths and delays in microseconds.
Title: Re: Help with pulse generation
Post by: gabe83 on Jun 03, 2018, 02:45 am
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

Its understandable?
Title: Re: Help with pulse generation
Post by: jremington on Jun 03, 2018, 05:09 pm
Are these pulses supposed to be on two different output pins?
Title: Re: Help with pulse generation
Post by: gabe83 on Jun 04, 2018, 07:24 am
Yes they are
Title: Re: Help with pulse generation
Post by: horace on Jun 04, 2018, 09:11 am
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
Title: Re: Help with pulse generation
Post by: wvmarle on Jun 05, 2018, 03:00 pm
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.
Title: Re: Help with pulse generation
Post by: jremington on Jun 05, 2018, 11:27 pm
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/).