# Sine Wave to Square Wave converter retaining original P-to-P

Discussion in 'General Electronics Chat' started by jarek319, Aug 19, 2010.

1. ### jarek319 Thread Starter New Member

Jan 24, 2010
18
0
I have an audio project that I'm working on. My guitar pickup outputs a sine wave anywhere from .05 to 1 V Peak to Peak, from 200Hz to 20Khz (haven't found the actual upper limit, using theoretical limits). I want to convert this to a square wave, retaining both the frequency and voltage of the original signal.

I've found zero crossing detectors that solve the frequency problem, however they output at only the voltage given to the comparator. There were a few 'self powered' sine to square converters, but they required a minimum of .75mV.

Does anyone have any ideas? Ideally it would be a chip powered by 3 AA batteries, or even self-powered with a voltage multiplier.

2. ### marshallf3 Well-Known Member

Jul 26, 2010
2,358
201
Amp + Schmidt trigger + amp?

3. ### Wendy Moderator

Mar 24, 2008
20,735
2,499
If you want to maintain the RMS value make a simple amplifier with a gain of 0.707 to feed the square wave through.

4. ### Potato Pudding Well-Known Member

Jun 11, 2010
684
92
First thought.

I thought you need to lag 90° or 180° out of phase to do it.

You need to start a period capture circuit to measure from the crossing to peak. Then you need to capture and hold the peak value, start decomposing the period capture while starting another period capture that ends when the signal recrosses zero. Keep holding the peak while you finish the first period capture and if the second period capture is finished you start to decompose it. If it was not complete then you start another period capture and keep doing so until one of the period captures finishes with the signal recrossing zero.

Meanwhile I think if the waveform complex bumps to a higher peak you need to capture that peak so the signal can escalate. I don't think the symmettry to declining peaks is asked for.

It is going to be 180° out of phase if you don't want to accept escalating peaks.

Second thought try detecting narrow averaged signal level and using an AGC to have that matched by the square waved (clipper circuit signal throughput) reamped output.

5. ### eblc1388 Senior Member

Nov 28, 2008
1,542
102
How this gonna work for a square wave of constant amplitude?

To get a square wave, the sin input signal of varying amplitude has to go through a zero crossing comparator and this gives a constant amplitude square wave as output.

6. ### Wendy Moderator

Mar 24, 2008
20,735
2,499
If both peak to peak values are to the power supply I give it a good chance...

7. ### daviddeakin Active Member

Aug 6, 2009
207
27
Use a peak-level detector to measure the amplitude (envelope) of the audio signal.
Convert the audio to a square wave of constant amplitude.
Feed the square wave to a voltage-controlled gain stage (e.g., LM13700) whose gain is controlled by the audio envelope.

8. ### jarek319 Thread Starter New Member

Jan 24, 2010
18
0
Thank you for the LM13700 tip! I'm going to look into that chip and put it down on my next digikey order. Since I'm going to be using a peak detector anyway, it would be easy to feed the peak into two different chips.

9. ### tom66 Senior Member

May 9, 2009
2,613
213
I've been thinking on how to implement this, and I came up with this pretty basic idea. I'm not sure if it's been suggested before, or if this circuit already exists - I independently designed this.

The input op-amp acts as a peak detector to figure out peak amplitude. The capacitor can be adjusted; a bigger value means less output ripple, but also means that the output takes longer to change between levels. Note the input signal *must* be ac coupled.

The second and third op-amps from the left act respectively as buffers and as inverting buffers. The second op-amp can be omitted if it is known that there is not going to be much load on the output (i.e. it's going into an amplifier stage.)

The fourth op-amp acts as a zero crossing detector. A comparator can (and probably should) be substituted here for high speed operation. Slew rate limitations of this op-amp WILL get into the output.

This entire arrangement can be implemented using a quad op-amp and uses very few parts.

The transistor and resistor arrangement is a low cost way of amplifying the signal within a Vp-p bound. You can't draw much from this due to the 100k resistor. It works very similar to an open collector output. It is normally high at V+, but applying a signal greater than about 0.7V to the base (relative to the emitter) of the transistor causes it to "pull down" the V+ signal through the 100k resistor to V-. It works from a low to a high voltage with virtually no distortion. For higher output current, and op-amp follower or power amplifier should be used. Note the output is about 20mV less than the peak, I am not entirely sure what causes this.

So you can simulate it, I have provided the import text. Use Falstad's circuit simulator (falstad.com/circuit) to import. Go to File > Import, and paste the text below.

Code ( (Unknown Language)):
1.
2. \$ 1 5.0E-6 35.60246606707791 50 5.0 50
3. a 208 192 304 192 1 15.0 -15.0 1000000.0
4. d 304 192 352 192 1 0.805904783
5. c 352 240 352 320 0 4.7E-5 4.9644452371188965
6. g 352 320 352 336 0
7. w 416 240 352 240 0
8. w 352 240 208 240 0
9. w 208 240 208 208 0
10. w 352 192 352 240 0
11. R 208 176 176 176 0 1 40.0 5.0 0.0 0.0 0.5
12. a 464 256 560 256 1 15.0 -15.0 1000000.0
13. w 464 304 464 272 0
14. r 416 240 416 336 0 47000.0
15. r 464 336 560 336 0 47000.0
16. w 560 336 560 384 0
17. w 464 368 464 336 0
18. w 464 368 416 368 0
19. w 416 368 416 336 0
20. w 560 256 560 304 0
21. w 560 304 464 304 0
22. w 464 240 416 240 0
23. w 560 256 608 256 0
24. w 560 384 608 384 0
25. g 464 400 464 416 0
26. O 608 224 656 224 1
27. O 608 416 656 416 1
28. a 464 384 560 384 0 15.0 -15.0 1000000.0
29. a 560 144 656 144 1 15.0 -15.0 1000000.0
30. g 560 160 544 160 0
31. w 208 128 208 176 0
32. t 720 304 752 304 0 1 -19.96473829888124 -10.035996765514113 100.0
33. w 608 256 608 224 0
34. w 656 144 672 144 0
35. w 672 144 672 304 0
36. r 672 304 720 304 0 10000.0
37. w 752 256 752 288 0
38. w 752 320 752 384 0
39. w 752 384 608 384 0
40. w 608 416 608 384 0
41. r 704 256 752 256 0 100000.0
42. w 704 256 608 256 0
43. w 752 256 800 256 0
44. w 560 128 208 128 0
45. o 8 64 0 291 9.353610478917778 9.765625E-55 0 -1
46. o 40 64 0 291 9.831615282070846 0.0 1 -1
47.
An image is attached.

Note: this circuit works down to about 5mV to 10mV before the output transistor stops pulling the negative rail enough and the negative rail starts floating towards V+. Substituting the NPN for an NMOS transistor allows the circuit to work as low as 700µV.

• ###### Screenshot-Circuit Simulator v1.5j-4.png
File size:
16.4 KB
Views:
89
Last edited: Aug 30, 2010
jarek319 likes this.
10. ### jarek319 Thread Starter New Member

Jan 24, 2010
18
0
Wow, that simulation is exactly what I've been trying to do! I'm going to put it together tonight with an LM339 and post back with results. Thank you for your effort!

11. ### tom66 Senior Member

May 9, 2009
2,613
213
You can't use an LM339 (except for the zero crossing detection); you must use an op-amp.

12. ### tom66 Senior Member

May 9, 2009
2,613
213
I came up with a better 'front end' for it. It involves many more components. It's so big you'll need to paste it in and use the Drag tool (Alt-Drag or under Other on the right click menu.) This version changes much quicker than the other version and has almost no ripple.

Code ( (Unknown Language)):
1.
2. \$ 1 5.0E-6 6.724437240923179 50 5.0 50
3. a 160 368 256 368 0 15.0 -15.0 1000000.0
4. r 96 352 160 352 0 1000.0
5. d 160 320 256 320 1 0.805904783
6. d 256 368 304 368 1 0.805904783
7. r 160 288 304 288 0 1000.0
8. g 160 384 160 400 0
9. w 160 352 160 320 0
10. w 160 320 160 288 0
11. w 256 320 256 368 0
12. w 304 368 304 288 0
13. r 304 368 304 448 0 100000.0
14. g 304 448 304 464 0
15. R 48 320 16 320 0 1 40.0 15.0 0.0 0.0 0.5
16. w 96 352 96 416 0
17. a 416 384 512 384 1 15.0 -15.0 1000000.0
18. w 416 432 416 400 0
19. c 512 432 512 512 0 1.0000000000000001E-7 0.7771022728570868
20. g 512 512 512 528 0
21. d 512 384 512 432 1 0.805904783
22. w 416 432 512 432 0
23. g 416 512 416 528 0
24. w 416 448 416 432 0
25. w 416 480 416 512 0
26. a 128 176 224 176 0 15.0 -15.0 1000000.0
27. g 128 192 128 208 0
28. 154 288 128 400 128 0 2 5.0
29. 154 464 96 576 96 0 2 0.0
30. w 288 112 288 80 0
31. r 400 128 464 128 0 1000.0
32. g 464 176 464 192 0
33. c 464 128 464 176 0 3.3E-7 4.99999995815831
34. w 464 80 288 80 0
35. w 464 112 464 128 0
36. g 288 144 288 160 0
37. w 288 80 256 80 0
38. w 256 80 256 176 0
39. r 576 96 576 160 0 1000.0
40. r 256 176 256 240 0 100000.0
41. g 256 240 256 256 0
42. d 224 176 256 176 1 0.805904783
43. w 128 160 96 160 0
44. w 96 160 96 352 0
45. f 368 464 416 464 0 1.5
46. w 576 160 576 224 0
47. w 576 224 352 224 0
48. w 352 224 352 464 0
49. w 352 464 368 464 0
50. w 416 368 304 368 0
51. g 592 352 576 352 0
52. a 592 368 688 368 0 15.0 -15.0 1000000.0
53. d 688 368 752 368 1 0.805904783
54. g 752 416 752 432 0
55. r 752 368 752 416 0 1000.0
56. c 816 368 816 416 0 1.0E-8 14.300403998053547
57. g 816 416 816 432 0
58. r 752 368 816 368 0 1000.0
59. w 1200 336 1248 336 0
60. w 1104 384 1104 416 0
61. w 1104 352 1104 336 0
62. g 1104 416 1104 432 0
63. w 1104 336 1200 336 0
64. d 1200 288 1200 336 1 0.805904783
65. g 1200 416 1200 432 0
66. c 1200 336 1200 416 0 1.0000000000000002E-6 0.7771752295008041
67. w 1104 336 1104 304 0
68. a 1104 288 1200 288 1 15.0 -15.0 1000000.0
69. f 1056 368 1104 368 0 1.5
70. w 512 384 592 384 0
71. w 512 432 544 432 0
72. w 544 432 544 272 0
73. g 944 416 944 432 0
74. c 880 368 944 368 0 6.800000000000001E-7 6.247627442147326E-12
75. I 816 368 880 368 0 0.5
76. r 944 368 944 416 0 1000.0
77. g 1024 416 1024 432 0
78. d 944 368 1024 368 1 0.805904783
79. r 1024 368 1024 416 0 1000.0
80. w 1104 272 544 272 0
81. w 1056 368 1024 368 0
82. 174 48 320 96 384 0 1000.0 0.9455000000000001 Volts p-p
83. g 48 384 48 400 0
84. o 13 64 0 291 5.0 9.765625E-5 0 -1
85. o 56 64 0 35 1.1692013098647223 9.765625E-55 1 -1
86.

jarek319 likes this.
13. ### jarek319 Thread Starter New Member

Jan 24, 2010
18
0
I'm not sure where to place the scope so I can get a reading on this one. I tried placing it on the end of the circuit, but it doesn't seem to be oscillating...

14. ### tom66 Senior Member

May 9, 2009
2,613
213
What op-amp are you using?

Make sure you have a proper ac-coupled input. The circuit will not normally oscillate, unless there is a problem. The output should be the same frequency as the input.

15. ### jarek319 Thread Starter New Member

Jan 24, 2010
18
0
I meant on the simulation, the second one you provided. I loaded it into the java applet, and I tried attaching the software scope to the little wire on the far right, but it doesn't show up as a wave.

16. ### tom66 Senior Member

May 9, 2009
2,613
213
That one won't oscillate. It's only a small part of a yet to be completed circuit. It was a replacement for the original peak detection front end. I agree it's a monster, so that's why I recommend you use the original; only use this front end if you want the circuit to adjust very fast and if ripple is a problem.

jarek319 likes this.
17. ### jarek319 Thread Starter New Member

Jan 24, 2010
18
0
I'm using the first circuit currently, and it sounds really good. I'm playing with cap values now to get the best sound, but so far i can't beat the 47uF. It's supposed to be a larger dielectric cap right? I couldn't find a monolithic like in the circuit in that size lying around.

18. ### DonQ Active Member

May 6, 2009
320
11
I can't see your second circuit, so excuse me if this repeats...

Here is a full-wave rectifier and averaging circuit that I've been using since... well, check the original publication date of the Ap-note. It wasn't long after that!

Figure 25. http://www.national.com/an/AN/AN-20.pdf (A good resource in general.)

It's a clever circuit. The second diode is not what provides the full-wave rectification. It only keeps the amplifier from saturating when the other diode is reverse biased. Many amplifiers behave poorly when saturated and this stops that. This simple mod could (should) also be applied to your first circuit.

Then use the same 'this voltage and its inverse as limits for a square wave circuit' like before...

19. ### tom66 Senior Member

May 9, 2009
2,613
213
I don't know. I chose the value because I liked that value and it worked. There was no methodology behind it.