0
\$\begingroup\$

I want to make a homemade function generator.

I used a Wien-bridge oscillator with a UA741 to produce the sine wave, amplify it with another UA741 because it has quite low amplitude, then integrate it using a TL071 (which has a very good slew rate) to obtain the square wave.

Everything was running smoothly on simulations.

When I tried to implement the circuit I saw that even though the sine wave is fine, I can't get a square wave. The square wave integrator acts as a buffer, it doesnt affect the sine wave at all.

I use Proteus for my simulations and everything was fine in the simulations.

When I checked the simulation I realized that I havent chose the "Attach hierarchy module" for the TL071. When I checked the box I get the same result in the simulation as I get in my real circuit. I don't know what the problem is.

Circuit runs on +/-12 volts at around 16 kHz.

  • Whole circuit

Whole circuit

  • Square wave integrator part

Square wave integrator part

  • Attach hierarchy module setting

Attach hierarchy module setting

  • Attach hierarchy module checked
    • Yellow is sine wave generated by the oscillator
    • Blue is amplified sine wave
    • Purple is supposed to be square wave
    • Green is supposed to be triangle wave

Attach hierarchy module on

  • Attach hierarchy module unchecked
    • Yellow is sine wave generated by the oscillator
    • Blue is amplified sine wave
    • Purple is square wave
    • Green is triangle wave

Attach hierarchy module unchecked

\$\endgroup\$
7
  • \$\begingroup\$ What's the triangle near the top center of the page? It looks like the output of U6 is connected to it. And what else is in the circuit? Where do all of those traces go that run off the top of the schematic? \$\endgroup\$
    – ErikR
    Jun 16, 2021 at 18:34
  • 6
    \$\begingroup\$ TL071 is not connected as an integrator. I think the positive and negative inputs are accidentally swapped. \$\endgroup\$
    – Justme
    Jun 16, 2021 at 18:38
  • 1
    \$\begingroup\$ I think this explains it since you should be getting a triangle wave at the output of U6 when it is acting as an integrator, not a square wave. With the inputs reversed the op-amp is acting like a comparator. \$\endgroup\$
    – ErikR
    Jun 16, 2021 at 20:04
  • \$\begingroup\$ @ErikR Im sorry I forgot to explain them. That triangle is a sembolic output terminal with no function, you can ignore that. The traces go to the virtual oscilloscope of the Proteus. About the comparator thing, I think you might be right. Altough I dont understand why I cant maske it act like a comparator in both real life and in simülatör when the attach hierarchy module box is checked. \$\endgroup\$
    – Tombeki
    Jun 16, 2021 at 20:17
  • \$\begingroup\$ Could you explain why you're trying to generate a square wave using a sine wave, instead of just using an astable flip-flop or something like that? Or, for that matter, a saturated/clipped oscillator? Also: when you say "square wave," do you mean an infinite-bandwidth square, or do you require certain bandwidth limitations? (The Taylor or Fourier series of a "square wave," when band limited, looks very different from a "square.") \$\endgroup\$
    – Jon Watte
    Jun 16, 2021 at 20:51

2 Answers 2

2
\$\begingroup\$

If you integrate a sine wave you should get a cosine wave output. That is to say if a sine wave is input then the output of the integrator should lead the input by 90 degrees. The integration process should create 90 degrees of lag but the integrator itself is inverting hence an advance of 90 degrees overall at the output compared to the input.

I suspect in the simulation you have the "integrator's" inputs swapped over and hence it is acting as a comparator. A comparator is what you need to create a square wave from a sine wave. Just use an op amp (or better still an actual comparator for better slew rate) connect one input to ground and the other input to the amplified sine wave coming from the previous stage. The output will be a square wave but make sure that the + and - saturation limits are equal voltage limits above and below ground. If you get multiple transitions at the square wave's edges then turn the comparator into a schmitt trigger by adding hysteresis with some positive feedback.

You will need an integrator to convert the square wave to a triangle wave but add a high value resistor (eg. 1M) in parallel with the feedback cap to prevent the integrator from saturating.

Bonus information: Integrating a triangle wave produces a sine wave.

\$\endgroup\$
5
  • \$\begingroup\$ I tried it at the simulation and it didnt work. I connected the amplified sine wave to the non-inverting terminal, and inverting terminal to the ground. \$\endgroup\$
    – Tombeki
    Jun 16, 2021 at 20:25
  • 1
    \$\begingroup\$ Integrating a triangle wave does not produce a sine wave. In a triangle wave the voltage increases linearly with time. If you integrate it the voltage increases with the square of time which is not a sine wave. \$\endgroup\$
    – Barry
    Jun 16, 2021 at 22:02
  • \$\begingroup\$ @Barry My understanding of this is that when a triangle wave is applied to an integrator, which has a large resistor across its feedback capacitor, the transfer function is that of a low pass filter and so the triangle wave is low pass filtered leaving the fundamental sine wave and a few lower order harmonics. The output from the integrator is therefore a rounded form of the triangle wave which closely resembles a sine wave but is in fact not a pure sine wave. \$\endgroup\$
    – user173271
    Jun 16, 2021 at 23:43
  • \$\begingroup\$ What about the integrator? It doesnt work. \$\endgroup\$
    – Tombeki
    Jun 17, 2021 at 5:01
  • \$\begingroup\$ @Barry ....... I take your point though. The output of an integrator with a triangle wave input looks like a rounded (distorted) sine wave because the curves of the output waveform are based on x^2 rather than sin(x). As you say integral of y=x is y=0.5(x^2). \$\endgroup\$
    – user173271
    Jun 17, 2021 at 14:49
1
\$\begingroup\$

Any op-amp driven into saturation on both half-cycles will give a square wave if driven with a sine wave. It doesn't need to be an integrator.

An op-amp integrator will tend to drift into saturation at one rail if there is no resistor in parallel with the capacitor. Very few input signals will be completely free of a DC component. And even then, there is offset current to consider. If you exactly integrate a signal with a DC component, the output will not remain centered around zero, but will climb over time to one rail or the other. A resistor in parallel to the capacitor serves to drain this DC component.

So, add a resistor in parallel with the capacitor. Or replace the capacitor with a resistor completely, and just set the gain high enough to saturate the op-amp.

\$\endgroup\$
4
  • \$\begingroup\$ Yeah thats what I thought too! I thought I might just saturate the op-amp, but I am not sure whether it is good practice or not. Also I couldnt follow the part about the parallel resistor, can you explain it a little bit further? What is the purpose of the resistor? Thanks. \$\endgroup\$
    – Tombeki
    Jun 16, 2021 at 20:12
  • \$\begingroup\$ Added some clarification, perhaps not enough. \$\endgroup\$ Jun 16, 2021 at 20:21
  • \$\begingroup\$ I get it now, thanks. What do you think about using a comparator? Is it better practice? How can I make one with an op-amp? I followed James's instructions but couldnt get a result. \$\endgroup\$
    – Tombeki
    Jun 16, 2021 at 20:28
  • \$\begingroup\$ Generally speaking, op-apps make lousy comparators. A LM741 as a limiter amplifier (with diode limiter across the feedback resistor), put in front of an LM339 is a way better comparator than two LM741s in series, never mind just one. Integrating digital voltmeters often use such a gain stage in front of the comparator. The gain stage is sometimes called a slope amplifier. \$\endgroup\$ Feb 22, 2022 at 2:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.