# Simple Square Wave Oscillator

Tags: oscillator, simple, square, wave
 P: 238 Hi, I promise I did search for this before posting what I thought would have been something which had been answered before. Can anyone tell me how to build a simple square wave oscillator? Do I need a differentiator to get the straight vertical lines? I'd appreciate any help anyone could offer me. Please also remember I'm a novice, thanks
 PF Patron Sci Advisor Emeritus P: 10,400 Most people just buy them for a couple cents a piece -- they're called crystal oscillator modules. Is there a reason why you want to develop your own from scratch? If so, the easiest method is to make a simple resonant circuit that produces a sine wave, and then use that to drive a digital inverter. The output of the inverter will be a square wave. - Warren
P: 238
 Quote by chroot Most people just buy them for a couple cents a piece -- they're called crystal oscillator modules. Is there a reason why you want to develop your own from scratch? If so, the easiest method is to make a simple resonant circuit that produces a sine wave, and then use that to drive a digital inverter. The output of the inverter will be a square wave. - Warren
Ah apologies I did not know they were so cost effective. Thanks for that. Out of curiousity I'm working with AC so the sine profile is already there so would it possible for me to customize it a bit more using a digital inverter, or would I now need to just buy a digital inverter due to my input being a sine wave from the mains?

Sorry for so many questions.

PF Patron
Emeritus
P: 10,400

## Simple Square Wave Oscillator

Hey, we love answering questions!

If you already have a suitable 60 Hz sine wave, you could indeed just pass it through an inverter to obtain a 60 Hz square wave. You could use a very cheap chip, like the 7400, which has six inverters on it.

Be careful, though -- chips like the 7400 can only tolerate voltages between 0V and 5V, which means you'd need to find some way to scale your sine wave down so it has an average value of 2.5V, and goes no lower than 0V and no higher than 5V. This can be done with a couple of resistors and a single capacitor, so it's pretty easy.

I have to issue the standard boilerplate warning though: why are you working with the mains? You can hurt yourself pretty badly with mains voltages, so be very careful! Circuits that use such high voltages require a lot of expertise to avoid injury or fire. I strongly advise that you use a transformer or some other pre-made device to drop mains voltage down to something safer before playing with it.

- Warren
 P: 30 If your sinewave is 0-5 volts you may want to use a schmitt trigger or J-K Flip Flop to make a square wave, but with both of the devices there may be some phase change due to how they are being changed from a sine wave to a square wave.
P: 238
 Quote by chroot I have to issue the standard boilerplate warning though: why are you working with the mains? You can hurt yourself pretty badly with mains voltages, so be very careful! Circuits that use such high voltages require a lot of expertise to avoid injury or fire. I strongly advise that you use a transformer or some other pre-made device to drop mains voltage down to something safer before playing with it. - Warren
Nice one mate thank you Don't worry about the mains stuff I'm a qualified spark and the application is for a small portable device so there won't be too much potential for danger especially as all the work will be done with the 50Hz 240V supply disconnected

Great technical advice on the chip
P: 238
 Quote by chroot Be careful, though -- chips like the 7400 can only tolerate voltages between 0V and 5V, which means you'd need to find some way to scale your sine wave down so it has an average value of 2.5V
I was thinking of a good potential divider using power resistors. The output then being fed into the inverter then being feed into the base of a transistor. Of course due to the motor being there I need a diode to sink the inductive load on permanent switch off.

 Quote by chroot and goes no lower than 0V and no higher than 5V. This can be done with a couple of resistors and a single capacitor, so it's pretty easy.
What would I need the capacitor for by the way? As a filter perhaps?

Thanks.
P: 238
 Quote by Emicro If your sinewave is 0-5 volts you may want to use a schmitt trigger or J-K Flip Flop to make a square wave, but with both of the devices there may be some phase change due to how they are being changed from a sine wave to a square wave.
Hi that's probably not an issue given the rudimentary nature of the device being worked on.
PF Patron
Emeritus
P: 10,400
 Quote by Adder_Noir I was thinking of a good potential divider using power resistors. The output then being fed into the inverter then being feed into the base of a transistor. Of course due to the motor being there I need a diode to sink the inductive load on permanent switch off.
You don't need power resistors, since you don't intend for the resistors to actually dissipate any power. You just need two very very large-valued resistors with the right ratio, used as a voltage divider to scale down your sine wave so that it's 5V peak-to-peak. It'll still be centered around 0V, though, which is not going to work.

Next, you need to shift this up 2.5V. You can make another resistor divider between +5V and 0V to get 2.5V. Finally, you can couple the sine wave to this divider with a capacitor. (Capacitors "pass" AC, but "block" DC.) The result is a 5V peak-to-peak sine wave, centered around 2.5V.

- Warren
 P: 238 Thanks Warren that's great I'll post up a prelimnary sketch later this week. Nice one pal thanks a bundle
 PF Patron Sci Advisor Emeritus P: 10,400 Keep in mind that all of this circuitry will result in a square wave from 0V to 5V. It also will require a +5V DC power supply. If that's not the kind of square wave you want, let us know. - Warren
P: 238
 Quote by chroot Keep in mind that all of this circuitry will result in a square wave from 0V to 5V. It also will require a +5V DC power supply. If that's not the kind of square wave you want, let us know. - Warren
Thanks again. Here's a rough attempt at a design. I haven't drawn in where the +5V bit should go (I think on the second divider as a bias for the sine wave to ride on?). This is also I believe a half wave rectified circuit. Not sure if that's needed but can't see how the transistor bit will work any other way. Also managed to get my protection diode in too!

Have a look please just dont' shoot it down in flames too much lol

http://i207.photobucket.com/albums/b...r6/circuit.jpg
 PF Patron Sci Advisor Emeritus P: 10,400 Well, the capacitor should be between the midpoint of the mains divider and the midpoint of the 5V divider. And both dividers need to be connected to ground at the bottom. - Warren
 P: 238 I see, I'll change those for the next go. Thanks. *Done* http://i207.photobucket.com/albums/b.../circuit-1.jpg I assume that if I made the initial signal voltage divider resistors too high then not enough current would flow through the base to turn on the transistor. Can anyone recommend some values? Several hundred k's perhaps?
PF Patron