Ac to square wave. - Page 1
Forum section: electronics / beginners

author: neo
author_rank: Super Contributor
timestamp: May 02, 2017, 04:42:47 am
content: Does the circuit below make sense? It works on paper and it seems to work in practice but my scope does not tell me if it goes negative or not, which is the concern here it cannot go negative. This is an experiment in turning ac into a square wave that i can then divide and use as a time base in a clock.

author: BrianHG
author_rank: Super Contributor
timestamp: May 02, 2017, 05:14:29 am
content: With that circuit, you need to place a parallel resistor on-top of the zener diode to prevent a negative shot.How many volts is your source?Are you using a 4.7v zener diode.Maybe a NPN transistor, say 2N3904, used as a switch will give you a nice clean square wave.

author: rdl
author_rank: Super Contributor
timestamp: May 02, 2017, 05:27:56 am
content: How are you powering the clock? If from mains with transformer/rectifier/caps/regulator just tap the AC before the rectifier and connect to ground on the other side.

author: BrianHG
author_rank: Super Contributor
timestamp: May 02, 2017, 06:02:03 am
content: Quote from: rdl on May 02, 2017, 05:27:56 amGood question! Depending on the power supply connection and how the GND may be a center-tap, or, a common from a full wave bridge rectifier, this could mess up the output waveform or even make no wave at all.

author: JPortici
author_rank: Super Contributor
timestamp: May 02, 2017, 06:08:37 am
content: why not use an optocoupler? you get also points for safety

author: BrianHG
author_rank: Super Contributor
timestamp: May 02, 2017, 06:10:32 am
content: Quote from: neo on May 02, 2017, 04:42:47 amTry changing your top diode for a 0.1uf cap. That should give you a close to square wave if the AC voltage is much larger than the voltage of the Zener.Say you use a 3.3v zener, 12 to 24vac source, this circuit will output an almost square wave from -0.7v to +3.3v with a 0.1uf cap. Make the resistor 10k, 1k is a little overkill. -0.7v should be safe for the MCU input, though a second series resistor at the output with a really weak pullup can fix this.

author: rdl
author_rank: Super Contributor
timestamp: May 02, 2017, 06:18:12 am
content: This is close to how my clock is at the moment. The little drawing of the waveform is pretty accurate. I just dug it out of the storage box and plugged it in. It's about 3 volts p-p (1 to 4 volts). Seems to work fine.

author: BrianHG
author_rank: Super Contributor
timestamp: May 02, 2017, 06:43:47 am
content: The op-amp/comparitor is cheating.... Ok, I guess you can do it that way. I used to use a 74HC14, with a cap, zd, and 2 resistors.

author: Ian.M
author_rank: Super Contributor
timestamp: May 02, 2017, 06:50:05 am
content: I hope you've got some hysteresis on the 'Sine to Square' part, otherwise it will mess up if there is significant noise near the zero crossings, and the resulting glitches can result in your clock gaining time.One easy option is to use a CMOS 555 as a comparator. Input through a resistor and DC blocking capacitor to Trigger and Threshold in parallel, biassed to Vcc/2 with a 100K + 100K potential divider. Add a cap from that point to ground to filter impulse noise.

author: rdl
author_rank: Super Contributor
timestamp: May 02, 2017, 06:59:12 am
content: I haven't actually worked on that clock in almost 4 years. Since it says "placeholder part", I'm pretty sure I must have had something else planned, but now I've forgotten what it was.

author: rs20
author_rank: Super Contributor
timestamp: May 02, 2017, 07:07:58 am
content: Absolutely, hysteresis is a must here to prevent noise from producing false clocks. A 555 as already suggested, or just simply any logic circuit with a Schmitt input. Schmitt inverter, or schmitt buffer, whatever you want. Or any jellybean op-amp or comparator withpositivefeedback makes a Schmitt trigger too.

author: neo
author_rank: Super Contributor
timestamp: May 02, 2017, 01:46:27 pm
content: 12v zener 20 volt transformer tap, if i have to start going down the road of complex circuitry to get the frequency i may as well just put an arduino nano into it.

author: rdl
author_rank: Super Contributor
timestamp: May 02, 2017, 06:17:55 pm
content: With respect to your original post, the circuit I posted does not go negative. The sine to square wave conversion needs improvement for certain, though it does well enough for working on the counting logic. I think a Schmitt trigger inverter as suggested by BrianHG is the way I'll go as a start because I may have a use for the leftover inverters.There is one part missing in my schematic that I did not notice until this morning. There is a 10nf cap across the zener diode in the built circuit. It works without it, but the output wave form is a lot noisier and goes down to about 80 mV instead of the 1 volt minimum with it.One thing I don't understand, probably because I never used a zener before, is why the output isn't closer to 5.1 volts. I tried reducing the resistor value, but it never gets there before blowing the zener.

author: BrianHG
author_rank: Super Contributor
timestamp: May 02, 2017, 06:42:16 pm
content: Quote from: neo on May 02, 2017, 01:46:27 pmJust feed your AC through a 10k or 100k resistor into a 2N3904's Base. Connect the emitter to GND. Connect the Collector to your clock logic input with a 10k pullup to VCC, whatever the VCC for your clock chip may be. If you need to clean up the waveform, you may add a 1000pf cap on the output. (This 3 part version prefers a center-tap AC transformer with the center at GND)No zener needed.If your supply uses a full wave bridge rectifier, add a 0.1uf cap in series with the 10k or 100K resistor to the Base & add a 1N914 diode between the Base & GND. (These extra 2 parts will work under any AC transformer wiring configurations.)This 3 or 5 part circuit will make you a 50/60hz 50/50% duty cycle square wave even if your AC supply is only 6v.

author: james_s
author_rank: Super Contributor
timestamp: May 02, 2017, 06:58:48 pm
content: On the clocks that I've built, I feed the AC prior through a resistor and then have a 5V zener to ground with a 100n capacitor in parallel to the zener. That then directly connects to the interrupt pin on the microcontroller. It works fine, a couple of the clocks have been running now for more than 16 years without issues.

author: Zero999
author_rank: Super Contributor
timestamp: May 02, 2017, 07:44:26 pm
content: Quote from: neo on May 02, 2017, 04:42:47 amYour oscilloscope should tell you if it goes negative or not. It's quite likely you're not measuring it properly.Please post a schematic and picture, showing how you have it hooked up to the 'scope.

author: neo
author_rank: Super Contributor
timestamp: May 02, 2017, 08:28:14 pm
content: Below is how i had it hooked up, i cant take a picture because i already disconnected it. It doesn't show or tell me if its negative because the line moves on the screen when i turn the ac to this circuit on. As for the schmitt trigger recommendations the cd4017 has it on its clock input.

author: StillTrying
author_rank: Super Contributor
timestamp: May 02, 2017, 10:15:41 pm
content: Why do all the diagrams just leave the input floating during the low part of the cycle, it doesn't seem to be the best way to produce a reliable clock signal.

author: Zero999
author_rank: Super Contributor
timestamp: May 02, 2017, 10:20:33 pm
content: Quote from: neo on May 02, 2017, 08:28:14 pmIf you switch the probe to the ground position, or simply connect the probe to the ground clip, move the solid line to the middle of the screen, then switch the input back on again, you'll be able to tell whether it goes negative or not. If the lowest point of the signal, is below the line where it was when it was grounded, then it will be negative.Going by the circuit, yes it will go negative by around 0.6V. If it's a problem, a Schottky diode can be placed in parallel with the zener diode. The few hundred mV negative voltage will not do any harm to your circuit. If you're still worried about it, then a pull-up resistor and diode will get rid of the tiny negative voltage.

author: rdl
author_rank: Super Contributor
timestamp: May 02, 2017, 11:11:40 pm
content: Quote from: Hero999 on May 02, 2017, 10:20:33 pmThen I don't understand why my circuit does not go negative. It is essentially the same except for the value of the resistor.(ignoring the op amp, of course)edit: Never mind. I don't know what's up with the 60 Hz AC going to ground, but that much is different.

author: neo
author_rank: Super Contributor
timestamp: May 03, 2017, 02:19:35 am
content: Quote from: rdl on May 02, 2017, 11:11:40 pmIt is the same, the ac source has one end tied to ground, in your circuit its real world so ground comes out of rectifier in the simulator that it was drawn in ground is just simply 0 volts so any ground is circuit ground.

author: neo
author_rank: Super Contributor
timestamp: May 04, 2017, 02:25:21 am
content: I found the source of all my problems, its a little thing called physics. I used a full wave bridge rectifier and instantly i have the signal on the oscilloscope i was looking for.

author: rs20
author_rank: Super Contributor
timestamp: May 04, 2017, 03:54:05 am
content: Quote from: neo on May 04, 2017, 02:25:21 amJust be aware that you're going to get 120 (or 100) pulses per second instead of the 60 (or 50) that you might be expecting. And also, if you haven't included hysteresis anywhere, you may get a few bonus clocks per second from noise.

author: neo
author_rank: Super Contributor
timestamp: May 04, 2017, 05:07:25 pm
content: Quote from: rs20 on May 04, 2017, 03:54:05 amI expected the doubling of frequency, as for the noise the frequency division circuit (two 4017 chips) have schmitt trigger input.

author: james_s
author_rank: Super Contributor
timestamp: May 04, 2017, 05:13:35 pm
content: This is still way more complicated than necessary. All you need is a resistor, a zener diode and a capacitor, it works fine, at least with AVR microcontrollers. I speak from experience.