Generate two 100kHz square waves with 180 degrees phase shift

Hello everyone,

I need to generate two 100kHz square waves using Arduino Uno. The waves need to have a phase shift of 180 degrees between them. I need to control the duty cycle using a potentiometer. So, the frequency and the phase shift are fixed and the duty cycle no.

I already got how to generate the waves and control the duty cicle, but I am not been able to adjust the phase shift. I used the PWM.h library to define the frequency and then analogWrite to change the duty cycle.

I was wondering if I could use delayMicroseconds, but that doesn't seen to work.

Do you guys have any idea about what I can do?

All help is appreciated.

Thank you all very much.

If you succeed in getting at 100 kHz square wave signal on pin X, then a 180 degree phase shift is simply obtained by inverting the output of pin X, say with a pnp transistor. At least, so I understand it. 100000kHz has a period of 10 microseconds (very small for an Arduino). There is not much scope for manipulation of this in software.

a [u]74L04[/u] inverter will give you an output that's inverted/opposite of whatever you feed in.

Another hardware solution would be a flip-flop wired as a Type-T flip-flop. A Type-T flip-flop will cut the frequency in half (so you'd feed-in 200kHz) and it will create a square wave (even if you feed-in a non-square pulse) and it has two opposite-state outputs (Q and Q-not).

edit: I misunderstood what you meant by “square” wave.

DVDdoug:
a [u]74L04[/u] inverter will give you an output that’s inverted/opposite of whatever you feed in.

It would - almost - but it is not CMOS compatible and essentially obsolete.

I think you really mean a 74HC14.

Or just a simple transistor.
Simple inverter.jpg

CrossRoads:
Or just a simple transistor.
Simple inverter.jpg

Poor slew rate on the output.

Nonsense. 4.7K pullup will bring the low-high edge up nice & quick, just like I2C.

What is the application? It really seems that what you may need is complimentary PWM with deadtime control. If this is the case, then inverting wouldn't work, however the Due does have this mode.

Can you please attach a drawing of the wave form you would like to see?

Hi, Are you trying to make a DC to AC power inverter using a Modified Square Wave to regulate the AC output?

Tom... :)