cheap analog square function?

Feb 09, 2026 Last reply: 5 months ago 64 Replies

It has the advantage that the analog switch and passive low pass filter don't affect the DC performance, so long as you can afford the settling time of the filter.

The hassle of trying to kludge cheap parts into decent multipliers, particularly ones with decent DC performance, and keep the signal path totally analog is that every cheap op amp and resistor you add to try to correct for the deficiency of all the other cheap parts tends to add noise and offset and soon enough you lose more than you gain.

It has the advantage that the analog switch and passive low pass filter don't affect the DC performance, so long as you can afford the settling time of the filter.

The hassle of trying to kludge cheap parts into decent multipliers, particularly ones with decent DC performance, and keep the signal path totally analog is that every cheap op amp and resistor you add to try to correct for the deficiency of all the other cheap parts tends to add noise and offset and soon enough you lose more than you gain.

The PWM thing I suggested should be pretty good. But we don't have firm requirements for range, accuracy, or speed.

Cheap opamps can have sub-millivolt offsets, and 1% resistors cost less than a penny nowadays. We don't even buy 5% resistors.

My PWM circuit doesn't much care about resistor tolerances.

John Larkin Highland Tech Glen Canyon Design Center Lunatic Fringe Electronics

JL has beaten me to it. In full detail: imagine the sawtooth or triangle wave swings between 0V and 1V and is nicely linear, i.e. straight sloped. The comparator in my circuit (A) compares that with the input voltage to be squared Vx. When Vx is 0 the output is always low; when Vx is 1V the output is always high; and when Vx is 0.5V the output is toggling with 50% duty cycle. This pulse width modulation can then be used to switch the desired output between input Vx and 0V so when Vx is

0V then output is zero, when Vx is 1V the output is Vx and when Vx is 0.5V the output is 50% of the time that 0.5V and 50% of the time zero or in other words an average of 0.25V. The low pass filter averages the pulsating output to a steady level.

In circuit (A) the switching isn't done by an explicit analog switch but by shorting the output to ground - very conveniently done by choosing a comparator with open-drain output.

I had multiple square and root channels so it made sense to have one common triwave generator serve them all. Instead of 1V full scale unity I scaled to use 5V so ordinary comparators can be used. If you had no other need for a sawtooth/triwave elsewhere one could build a self-oscillating PWM generator and use that to drive the chopper. Let me know if you want that detailed more fully.

piglet

You can do a pretty good voltage-to-PWM with a single opamp and a few passives.

John Larkin Highland Tech Glen Canyon Design Center Lunatic Fringe Electronics

Yep, a comparator will do too and avoid opamp slew rate.

piglet

Use your LM386 and a JFET between pin 1 and 8 (feedback resistor) signal on input and JFET gate.

2 dollies

exact square ? play a bit with bias perhaps.

2 dollies and 2 cents

Circuit explanation: when input voltage rises gain also rises (JFET impedance goes down, feedback reduces, gain increases). Have not tried it of course :-) Maybe some buddy can spice it. I mostly use pepper salt chili garlic onion and some.. BEEP AI

For the OP's problem I could just use a PIC 18F14K22, Use one of its analog input channels and its DAC, or a simple 8 bit R2R DAC with resistors on its output pins as DAC. Do a muliply in software / asm Even done low frequency audio with it! Singe chip 3 dollies 50 cents solution, extremely accurate. DIL package! Why analog?

<snip>

In the early 70's I worked on a paper machine with some components dating back to Edinburgh 1880's.

The machine tenders had 30yrs+ experience running the thing, as it got longer, taller and faster. Main drive shaft and adjustible belts, pumps and heater stacks.

Each tender had their own way of doing things, depending on source material, grade/weight, power, time from last shutdown and weather.

Heavy use of recycled materials from all sources to produce high grade output.

Never lost money, but stole business from larger concerns, who eventually shut it down.

RL

We're building a product line around the Raspberry Pi RP2040 chip. Dual-core ARM with tons of goodies, 75 cents in any quantity.

A string of dumb

setport high setport low setport high setport low

instrucions, in the most obvious c code, executes every 7 ns, making a

70 MHz square wave. Unless you overclock, which works fine.

We use the RP400 as our dev/debug system.

But learning analog electronics makes sense. AI will kill circuit design last, if ever.

John Larkin Highland Tech Glen Canyon Design Center Lunatic Fringe Electronics

I grew up with analog, so for me.. 'computer' came much later, nevertheless there is a vague transfer between analog and computers via 'digital' I once made a nice audio signal generator with a 4046 as as variable oscillator driving a 4040 binary counter that had an EPROM with a sine table connected to it into a DAC.

Not a real 'computer' but analog going digital ;-)

I think good programmers are hard to come by these days too, so many use strange (at least to me) computer languages that are so 'bloated' that for the program to say 'hello world' it takes 300 MB memory and a 6 GHz multi-core ;-) I like C and asm

Analog is fun, worked in analog TV broadcasting, you would not believe what equipment and solutions there are / where from so many manufacturers I had to fix and maintain all, design what was needed and did not exist. And fix things in seconds when when on air. Plus run the studio and controlroom at times. Have done movies too, Eurovision network.. You cannot expect a student to know even a fraction of that world. Had a TV repair shop for some years, worked in basic research (particle accelerator), army, space... power stations. ? medical... I am curious, still drives me. Curiosity :-) Travelled the world, if I needed money I just applied for a job, picked oranges too in Florida... Hippy days...

So, some get stuck into some fixed office job, Maybe soon replaced by AI ? As to the OP's analog problem, I have made some suggestion. But first question should be 'what do you want to use it for?' As that sets accuracy and maybe gives a thousand other simpler solutions..

You are right, learning by building things is good, Knowing how to handle a soldering iron is neat too. And know how to use a scope and multimeter. Better design you own scope and meter.. I did as a kid. _See_ what you do with them electrons. In those days we had good magazines.. All paper seems to be gone now, but internet and google and AI search shows a lot of circuits and solutions

So ... But 'hands on' is a must.

I did not mention Spices' on purpose. Almost like the fishicks math crap spouted here.

BTW I did TV repair in California too, LA.

Been almost all over the globe :-) Airplanes is interesting too, forgot: worked in design in the big airport here too. Am getting older, 80 in a few month.. But still playing and writing code, designing..

This neural net is still learning!

BEEP!!

Sure, I am running 4 Raspies 24/7

Am posting this from a Pi4 8 GB: raspberrypi: ~ # uname -a Linux raspberrypi 5.15.32-v7l+ #1538 SMP Thu Mar 31 19:39:41 BST 2022 armv7l GNU/Linux

With the Usenet news reader I wrote:

formatting link
Have not released the Raspberry version yet.. Will I ever?
formatting link
So much stuff, spectrum analyzer, uirc client, audio equalizer, all at once :
formatting link
As to AI will kill... There waa that movie about a plane crashing in the desert On board was a hobby plane tinkerer, he modified that wreckage to a new plane, it actully took of and saved them. They later found out he only had build model airplanes :-)

So, keep playing !

Nuke wars, Sun spots, can bring down the electric grid, now even snow in the US.. AI consumes insane amounts of power... The human brain can do a lot. But if all you have ever done is let AI do things for you then there is a looming threat for humanity to fall back into the stone age.

formatting link

The Flight of the Phoenix (1965 film)

formatting link
In the movie they has a working radio receiver (how they knew the search was looking in the wrong place) plus power (hand crank?) and lights at night. They should have been rescued shortly after the storm was over -- just build a spark gap transmitter. They had wire & power..

formatting link

Okay, thank you. I think I grasp the core idea now.

My THAT comes with a few comparators, but already less than I need for other things, so I don't want to use those. But I've got a lot of 741 op amps to spare.

I do have access to a good benchtop signal generator, which I could use for generating the triangle wave. But having a separate triangle wave generator built in to the project also has some appeal.

I had a few follow questions, if you please, regarding the PWM squarer (circuit A):

- Does this circuit work in quadrant one only? If so, would any slight modification of the circuit allow for handling negative input voltages also?

- Could you please tell me a little bit more about the low pass filter portion of the circuit? Does that particular configuration have a name?

The circuit I showed gives output of zero for negative inputs (the input would always be below even the lowest point of the ramp so the comparator output would always be low).

To handle negative inputs precede it with a precision full wave rectifier aka absolute value circuit.

Good place to look for examples:

formatting link

Any low pass filter would do, right up from a single stage RC to as high order super steep as you want. It has to reduce the chopping rate from the sawtooth or triangle wave switching to a residual ripple low enough for your accuracy needs. Getting high precision and with low ripple to follow fast changing inputs will demand high frequencies and steeper filtering. The dynamics compromises happen there.

For example my units used a tri wave at 50-60kHz and I happened to use a second order 2kHz filter. That topology shewn is called Sallen & Key but there are many others. I chose those values for no particular reason, it was good enough for the job. Desirable is the filter has high input impedance and probably low output impedance, depending on what the next stage is.

One (of many) good places to read more:

formatting link

piglet

The 741 isn't a particularly good op amp. Back in the day Bob Widlar did better with the LM307. The later LM356 was faster and had a higher input impedance. The even later LT1028 is a lot quieter and quite a bit faster.

formatting link
It's not the easiest op amp to use - I earned some brownie point once by recommending the

formatting link
which uses ion-implanted pnp transistors to give you a better behaved (if more expensive) device.

Back around 1987 I wrote a short guide to op amps which managed to mention 159 different parts. A good many of them are now obsolete, but a whole more have become avaiable.

It's pretty trivial exercise. Go for polypropylene film capacitors - they have less charge soak than polycarbonate parts.

You can make four quadrant pulse-width modulation multipliers. How good they are depends on your circuit design skills.

formatting link

Most active filters use the Sallen-Keys configuration. You'd want a low pass filter response that settles rapidly, without ringing.

The simplest unity gain versions need carefully trimmed capacitor values to offer this. Adding a little bit of gain - 20% to 40% - can give you a fast settling response with equal value capacitors if you set the gain close to exactly right (which is easy enough with E96 resistor values).

The "Electronic Filter Design Handbook" by Williams and Taylor ISBN

0-07-070430-9 - third edition - is frequently recommended here. It's not easy reading, but it is pretty comprehensive.

And it's a really bad comparator.

John Larkin Highland Tech Glen Canyon Design Center Lunatic Fringe Electronics

Am 17.02.26 um 18:34 schrieb Phil Hobbs:

Renesas HFA3046, HFA3096, HFA3127, HFA3128

I got them even space-proof, but not really cheap..

Gerhard

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required