# Phase Shifter for square wave..!!

#### naren_iisc

Joined Jan 13, 2015
21
Hello all,

I have a square wave signal of 50% duty cycle (duty cycle will remain unchanged at any time), but frequency is variable. I want to generate a 90 degree phase shifted output for this square wave. So that I can use these signals (original and phase shifted) as quadrature encoder and measure the frequency of input signal using STM32 discovery board.
How to do this?

#### t_n_k

Joined Mar 6, 2009
5,447
Perhaps a phase locked loop.

#### MrChips

Joined Oct 2, 2009
19,924
You didn't state the frequency range.

Use the STM32DISCOVERY to trigger on the reference signal and measure the frequency (actually measure the period).
Then use an internal timer to generate the new signal with desired period and phase.

#### JWHassler

Joined Sep 25, 2013
275
Hello all,

I have a square wave signal of 50% duty cycle (duty cycle will remain unchanged at any time), but frequency is variable. I want to generate a 90 degree phase shifted output for this square wave. So that I can use these signals (original and phase shifted) as quadrature encoder and measure the frequency of input signal using STM32 discovery board.
How to do this?
What's your application, frequency range and jitter tolerance?
There are many ways to do this, with outcome/effort products ranging from impossible to unnecessary.

#### crutschow

Joined Mar 14, 2008
24,109
It's difficult to do a 90 degree phase shift of a variable frequency square-wave.
The easiest way is to generate a 2X frequency square-wave and use a digital technique for the shift, such as Dick showed.

#### naren_iisc

Joined Jan 13, 2015
21

Actually I want to measure the speed of an DC motor. The motor controller IC gives the Tacho output in the form of variable frequency square wave with 50% duty cycle. The frequency range is from 0Hz to 10KHz.

Problem with using STM32 discovery timer in counter mode is that, for lower freq timer gets overflowed.

#### naren_iisc

Joined Jan 13, 2015
21
@DickCappels thanks for your great idea, but frequencies lower than 270 Hz are also very important for lower speed control. I can not ignore them. Can the frequency range of this be expanded?

#### bertus

Joined Apr 5, 2008
20,230
Hello,

What frequency range would you need?
In the schematic Dick posted the range of 270 - 4000 is given.
By changing the capacitor the range can be shifted.

Bertus

#### GopherT

Joined Nov 23, 2012
8,012

Actually I want to measure the speed of an DC motor. The motor controller IC gives the Tacho output in the form of variable frequency square wave with 50% duty cycle. The frequency range is from 0Hz to 10KHz.

Problem with using STM32 discovery timer in counter mode is that, for lower freq timer gets overflowed.
Just use your ACD and measure the motor's back emf during the zero output on the Pwm. That bEMF will be proportional to rpm.

See page 4 of this microchip application note.

Last edited:

#### cmartinez

Joined Jan 17, 2007
6,668