generate a square wave with double pulse using arduino

Thread Starter

Tarek1266

Joined Oct 18, 2019
59
Hi everyone ,

I would like to generate a square wave with double pulse like the one shown in the figure using arduino. any help ?

Regards,

1600194719093.png
 

Papabravo

Joined Feb 24, 2006
21,159
Give us an order of magnitude for the time intervals and some idea of the precision you need.
Are you familiar with how an "Output Compare" module works?
If you are and you have one available, then this sort of thing is pretty easy.
If not you have to work a bit harder.
 

Thread Starter

Tarek1266

Joined Oct 18, 2019
59
Give us an order of magnitude for the time intervals and some idea of the precision you need.
Are you familiar with how an "Output Compare" module works?
If you are and you have one available, then this sort of thing is pretty easy.
If not you have to work a bit harder.
the amplitude is 5V the frequency of the low frequency is 100Hz and the high one is 5kHz both with duty 50%
 

Rasterist

Joined Sep 15, 2020
4
I'm not going to write the code, but why not just set the pin high or low as necessary and wait the prescribed amount of time (t1, t2, or tb) before toggling it? Be sure to use the micros() command and not delay(). Since testing micros() will incur a small delay, this will take some fine-tuning.
 

Papabravo

Joined Feb 24, 2006
21,159
the amplitude is 5V the frequency of the low frequency is 100Hz and the high one is 5kHz both with duty 50%
I still think you should use an the output compare module with maybe a 500 kHz clock. 50 ticks will get you 100 µsec and 5,000 ticks will get you 10 msec. Is that about right?
 

MrChips

Joined Oct 2, 2009
30,720
Transitions occur at 100μs marks.
Set the timer to interrupt every 100μs and use a phase counter to determine what to do at the output pin.
 
Top