# Sine wave to square wave converter

Discussion in 'General Electronics Chat' started by thebombzen, Jun 3, 2013.

1. ### thebombzen Thread Starter New Member

Jun 3, 2013
4
0
I know this has been asked many times, because I googled "Sine wave to square wave converter." Most of the responses that appeared said something such as "use a 555" or "use a schmitt trigger." I know how to use a 555, but I'm trying to create an accurate clock and the high (20%) tolerance of capacitors makes this unsuitable for those purposes. I'm pretty sure that the 60 Hz coming from an outlet is pretty much exactly 60 Hz and not slightly off, so this seems suitable.

I'm using IC 7490 counters to store the time from a 555 (I want to convert it to an AC clock cause it's inaccurate), but I could use another IC(I forget the number) that could support mod-60 counting. Either way, after I did some Googling I found out that most of these ICs require a square wave input which oscillates from ground potential to VCC potential, not from -VCC to VCC in a sine wave.

As a result of this, I need to convert a +VCC to -VCC sine wave into a 0 to +VCC square wave. After some google I found "just use a schmitt trigger" but I could not figure out how to use one from google or from wikipedia.

Does anyone know how I can set up a circuit like this?

P.S. Is there an easy way to power the ICs using low-voltage AC or do I need a rectifier/capacitor?

2. ### Shagas Active Member

May 13, 2013
802
74
I do it like this :

Basically you just connect one of your inputs to a potential divider so your reference is half of VCC , in this case he connects it between two 10 k resistors . If you are using a dual power supply just connect the one input to your ground (NOT the negative voltage rail).
There is no negative feedback , in the link I sent he adds a positive feedback and that's for stability so it doesnt shoot back and forth at the crossover (I think) , but I've tried it without the positive feedback (the 100k resistor) and it works fine .
Basically when the sine wave goes slightly above the referenced output then the op amp saturates to +VCC ( - VCC if you got it connected as an inverter as in the link) and when the sine wave goes below reference voltage then the op amp saturates the other way. This happens because you have no negative feedback and the gain is huge so any slight change of voltage relative to the reference causes in immediate saturation

But this will give you a -Vcc to + Vcc square wave , I'm gna finish cleaning my room and the i'll think of how to get zero to _+Vcc

If by IC's you mean the 555 timers or Op-amps then you need a clean DC

Last edited: Jun 3, 2013
3. ### Shagas Active Member

May 13, 2013
802
74
Ok I got it ....

Feed the Op amp the -Vcc to + Vcc sine wave .
Connect the Op amp +Vcc pin to your +voltage and the - ground pin to your - Vcc (that's the important bit) .
Then connect your negative (or positive) between 10k resistors going from +Vcc to -Vcc and feed the input into the other Op amp input and you should get a square wave that you want .

But keep in mind that for the sine wave to be '+ Vcc to minus Vcc' you will have to reference it (ground it) to HALF of the voltage that you are using for the OP amp . You can do that again by using two 10k resistors as a potential divider

Ps. If you want to do it using transistors then there is a schematic for that aswell on the site that I linked in the previous post

Last edited: Jun 3, 2013
4. ### Jony130 AAC Fanatic!

Feb 17, 2009
3,990
1,115
You could also use this simply zero-crossing detector.

5. ### MrChips Moderator

Oct 2, 2009
12,624
3,451
Line frequency is not very accurate and can deviate as much as 1%.
It depends on what you want to do with it. If you wish to use it a run a 24Hr clock, then that is ok because the electricity power generating stations adjust the line frequency so that at the end of the day they output the correct number of cycles.

6. ### crutschow Expert

Mar 14, 2008
13,475
3,361
Use a 6V transformer with a bridge-rectifier, filter capacitor, and voltage regulator such as a 7805 or LM317 to get a regulated 5V.

You can then connect the Schmidt Trigger directly to the transformer output for generating the 60Hz square-wave. For safety you never want to connect directly to the mains. (Note that although the the negative bridge output is the common and the transformer output is not directly connected to common, the transformer voltage will still have a 1/2 peak AC signal with respect to common that can be converted to a square-wave by the trigger).

7. ### WBahn Moderator

Mar 31, 2012
18,085
4,917
Not any more. I believe they stopped tracking cycle count and performing time-factor corrections a year or so ago, though I think most of the power networks are still doing it just because the infrastructure is in place. But they aren't required to keep doing it and, by maintenance attrition if nothing else, it will go away over time.

Prior to that, in the Western U.S. there was a clock at Southern California Edison (I believe) that kept time according to the power grid and another that was synched to WWVB. Several times during the day a time-factor correction order would go out telling all the generating plants on the grid to speed up or slow down their generators by so many mHz for so long starting at a particular time. These were done both to correct existing errors and to anticipate future deviations as a result of loads coming on and going off over the course of the day. I was talking to the plant supervising engineer at one of the Colorado plants about two decades ago as he described this process. It was very interesting and while we were on the phone one of these orders came through and he read it off to me. I'm sure since then that they've modernized and automated the process.

Prior to that conversation I had been under the impression, since it was what I was told by one of my professors, that they adjusted the generators to achieve the exact cycle count over the course of a calendar day. Turns out this isn't the case. They simply made a steady string of adjustments in order to servo the grid-based clock back to the WWVB-based clock. Also, if the clocks ever got more than a certain amount out of agreement (generally because of power outages somewhere in the grid causing the rest of the grid to come under extra heavy loads) they simply gave up and reset the grid-based clock. I believe he said that it was a 2-minute error at which they threw in the towel.

But now that has gone away and so your cheap alarm clock that used to run for years and always be right on the money might gain or lose several minutes a day. Of course, people will notice this, but they won't know why and will probably insist that government do something about Big Clock to force the greedy capitalists to make better clocks (and for the same price, so there will be a need for a special Time Subsidy from congress).

8. ### thebombzen Thread Starter New Member

Jun 3, 2013
4
0
I think I worded my question poorly, causing you to misinterpret it. I want to turn 120V, 60Hz AC that comes out of my wall into both a 60 Hz clock signal AND a power supply for the counter ICs (e.g. 7490) and logic gate ICs (e.g. 7408). Of course, 120V is overpowered so I'd use a transformer to turn it into +5V to -5V, and possibly turn it into 5V DC if necessary.

Note that I'm pretty much a newbie when it comes to digital circuitry, most of my circuit background comes from second-semester E&M from freshman year. As an end-of-year project I made a digital clock out of a 1 Hz 555 timer and 7490 counters, but using an ammeter I determined it draws almost 500 mA of current, basically killing all batteries extremely quickly. (3000 mAh / 500 mA = 6 hours). However, 6 V at 500 mA means it only draws 3 W of power, so wall-socket AC provides way enough, which is another reason I decided to use AC.

This means I want to use a 0V to 5V square wave as a clock input to the counters, and 5V to power the digital ICs, which I assume require DC. All of these should come from -5V to 5V AC, which I know how to create using a transformer connected to a wall.

Because I'm a newbie at digital circuits, mentioning technical stuff such as "You can then connect the Schmidt Trigger directly to the transformer output for generating the 60Hz square-wave." doesn't help me because that's exactly what I'm trying to figure out how to do, because I don't know how to use a schmitt trigger. Note that the simulation above did not really help, because I've seen both 1-input and 2-input schmitt trigger images and I don't know which one to use. It also appeared to go from -5V to 5V, which (I wasn't totally clear on) isn't what I wanted.

1-input:

2-input:

Both of these images are from Wikipedia.

9. ### WBahn Moderator

Mar 31, 2012
18,085
4,917
How do you figure that the bottom one is 2-input. I see a Vin and I see a Vout.

In general, any comparator needs a reference level. After all, the name implies that the input is being compared to something! Frequently that reference level is generated internally and is typically at about half of the supply voltage range.

If come out of your AC supply and go through a bridge rectifier, then you will have one node that is + and one node that is - (which you will probably define as your circuit's "ground" and call it 0V). If you place a diode and resistor between the one of the AC inputs to your bridge and your ground, then that voltage will be a half-wave rectified signal. You can use your schmitt trigger to turn that into a timebase signal with the threshold set at about the midway point between the bridge rectifier outputs. The purpose for using a schmitt trigger and not just a comparator is that you want a clean transition that is once up and once down per cycle. The hysteresis of the schmitt trigger keeps you from getting multiple spurious bounces at each transition edge.

You said that your present 555-based clock is drawing 500mA. That has to be an error in the circuit (or perhaps a bad component), unless your display device is hogging all that current, which if it is a largish 7-seg LED display is probably possible.

10. ### ErnieM AAC Fanatic!

Apr 24, 2011
7,435
1,625
Your clock doesn't need a square wave, it needs a pulse wave, correct? It only counts on one edge, right? That's much easier.

In your power supply, do you rectify the AC as it comes from a transformer? If you do, add another diode since what comes out of the rect becomes near DC with the filter cap. That gives you a sine wave, or half sine.

Then just blast it thru a simple transistor inverter:

(I found this picture in a web search.) Just about any NPN will work... if you need resistor values 10K/10K would work too.

11. ### WBahn Moderator

Mar 31, 2012
18,085
4,917
I'm not sure that will have enough noise immunity. It might. There's quite a bit going on around that node as diodes turn on and turn off and as current rushes into feed the filter caps.

12. ### WBahn Moderator

Mar 31, 2012
18,085
4,917
I think transformerless circuits like this one are frowned upon by the forum rules.

13. ### THE_RB AAC Fanatic!

Feb 11, 2008
5,435
1,305
Very interesting! Do you have any links to back this up? Wiki says they are still correcting. FNET.com (http://fnetpublic.utk.edu/sample_events.html) are still sharting the US freq and deviation events.

Here in Australia the mains 50Hz freq stability is very good, I have done tests myself against a GPS time pulse;

http://romanblack.com/onesec/High_Acc_Timing.htm

That chart shows 17 minutes of logging the mains frequency (scale is in PPM error), as you can see the frequency corrections are about 4 times a minute, so even the short term mains frequency average is very good (averaged around 0 PPM error).

I have not seen official documents on whether they do a "once per 24 hours" correction, but I really doubt it as the 4 corrections a minute keep the frequency very tight.

(And sorry to the OP for going slightly off topic!)

(edit) There's a nice page here from a guy in Europe showing his longer-term measurements, and an "official" spec from the power company;
http://wwwhome.cs.utwente.nl/~ptdeboer/misc/mains.html

Last edited: Jun 4, 2013
14. ### Shagas Active Member

May 13, 2013
802
74
Yeah if you are pulling 500mA with a clock circuit then something is wrong there.
If you want to turn your 120volts ac into a clock signal AND a power source then you can make it like this prob

Use an op amp that can handle single supplies

15. ### WBahn Moderator

Mar 31, 2012
18,085
4,917
Actually, I think I am misremembering something. As near as I can tell, relaxing the time-keeping requirement was proposed and possibly experimented with a couple years ago, but I can't find anything that indicates that it was adopted. So I am probably misrecalling an article about it I read at the time.

16. ### THE_RB AAC Fanatic!

Feb 11, 2008
5,435
1,305
Thanks WBahn, that's good to know. I like mains-synced clocks.

It was interesting to see the mains freq accuracy and stibility in the US being lower than here in Australia, I think it's because of the multiple providers and much higher usages there in the US. Here in Australia we have a 10x lower population, and a small number of high tech power stations, for both reasons being easier to sync and keep the timing right.

Europe looks to be somewhere between.

17. ### thebombzen Thread Starter New Member

Jun 3, 2013
4
0
I'm gathering that you're saying I should take +/- 5V AC, rectify it with four power diodes, then feed it to an IC such as this one: http://www.jameco.com/Jameco/Products/ProdDS/251045TI.pdf
and that will produce a 120 Hz, wave suitable for counters?

18. ### thebombzen Thread Starter New Member

Jun 3, 2013
4
0
If someone can help me figure out what's wrong with my clock circuit (why it's drawing so much current), I uploaded a YouTube video of it in operation. The wires look like spaghetti so it'd probably be best to read the description.