It's hard to build an oscillator

(lcamtuf.substack.com)

209 points | by chmaynard 15 hours ago

32 comments

  • ErroneousBosh 12 hours ago
    > There’s an old electronics joke that if you want to build an oscillator, you should try building an amplifier

    It's funny, I was just thinking this morning about an old article in (I think) Television magazine that I read in the 80s when I was getting into electronics. The author was talking about some service notes he'd received for a particular model of Philips radio, which had just come out, and it was when shops tended to have their own service department that would repair things right there in the shop - and also, apply any "factory fixes".

    One such fix was described as "Fix VIUPS", and involved changing a couple of resistors and adding a couple of capacitors. Not really any difference, but the author did think it seemed to make the amp a bit more stable and less inclined to make squealy ploppy noises at high volume when the battery was low. But, curiosity got the better of him, so he rang the Philips rep - what's this "VIUPS"?

    No idea. But I'll get hold of someone at head office you can ring. Okay, what's this "VIUPS" thing? No idea, said the head office guy, but I can put you in touch with one of the factory engineers in Eindhoven.

    So, a call came in, an international call! Quite a big deal in the 80s. "What's this VIUPS Fix thing in the service notes?" he asked the guy.

    "Aha yes", he said in a heavy Dutch accent, "the VIUPS is the noise the set makes when the fault is present."

    VIUPS VIUPS VIUPS. Yup.

    • severak_cz 40 minutes ago
      > There’s an old electronics joke that if you want to build an oscillator, you should try building an amplifier

      This can be easily demonstrated using so called no-input technique[0] which basically means that you patch audio mixer output to it's input and it starts feedbacking and you can create some tones from this. Note that this needs to be done carefully.

      [0]: https://www.youtube.com/watch?v=H-7kQmpjBds&t=2s

    • buescher 7 hours ago
      > There’s an old electronics joke that if you want to build an oscillator, you should try building an amplifier

      The way I heard it was "amplifiers oscillate and oscillators don't".

      • dbcurtis 6 hours ago
        The way I've heard it is: Being a microwave engineer is the easiest job in world. You basically only do two things, design oscillators and design amplifiers. What's the worst thing that can happen to an amplifier? It oscillates! And what's the worst thing that can happen to an oscillator? It won't start, but it's usually still a pretty good amplifier. Win-win!
      • B1FF_PSUVM 17 minutes ago
        "The fears of a designer are amplifiers that oscillate and oscillators that don't."
    • nullorempty 5 hours ago
      Yea, that resonates!
    • Zardoz84 10 hours ago
      > There’s an old electronics joke that if you want to build an oscillator, you should try building an amplifier

      The most easy way to annoy a neighbor using AM radios, it's using a regenerative AM receptor with too high gain. Could oscillate and begin to emit noise at the same freq that are you tuning. Adding a simple carbon microphone to it, and setting the gain to the max, was a very easy way of building a AM radio emitter.

      • ErroneousBosh 55 minutes ago
        I once made a guitar amp that oscillated pretty well at around 100MHz, sufficient to wipe out one of the FM radio stations for about half a mile radius.
      • IAmBroom 9 hours ago
        Pretty sure just blasting that rock and roll "music" out the window is easier.

        Damn hippies.

  • dvh 13 hours ago
    It's super easy to build LC oscillator.

    I made a program that generate random topology and uses spice simulation to find if it oscillate. The goal was to find some novel LC oscillators. It worked, it found many different oscillators. I let it ran for a while and soon I found out that the simplest possible LC oscillator has 1 inductor, 2 capacitors, 1 resistor and 1 transistor. I found many different variations of it, I called this class of oscillators "LCCRT oscillator" and it also always had 2 internal nodes so that's not very large search space (40000 combinations) so I generated all possible combinations and I found out there are exactly 12 distinct LCCRT topologies.

    Basically any time cap connects to a rail it can be placed to other rail as well, and any time one rail connects via resistor, the resistor can also be moved to other rail. This creates 12 possible combinations. I tested them in real life and they are stable, even used one in metal detector.

    Of course it found many different topologies. Some times they were unique, other times they could be simplified into already found oscillator. It can also use multiple transistors not just one. You can find entire project on github, it is a ngspicejs script: https://github.com/dvhx/lc-oscillator-finder

    • seg_lolr 12 hours ago
      "Novel". Those are all Collpits LC oscillator variants, circa 1918. All LC oscillator topologies were thoroughly investigated more than a century ago, hundreds of books have been written about them. A little more humility please
      • ofalkaed 10 hours ago
        Passive circuits have been novel for a long time now, or at least very very quaint. It is hard to put much stock in a coil when it is banal to walk around with 100 billion transistors in your pocket.

        One of my favorite books is Tremaine's Passive Audio Network Design, seems appropriate right now. Passive circuit design is great fun and a lost art.

        • goopypoop 7 hours ago
          "novel" means new, not rare
          • ofalkaed 1 hour ago
            Novel is considerably more complex than just new and even new is more nuanced; your new car could be as old as the Colpitts oscillator. Novel carries with it the unfamiliar and how that unfamiliarity alters our perception of what was once familiar. When you drive about in your new Model T everything is different, you are sitting considerably higher than you do in your old 240Z that you have driven since 1973 and its vertical windshield gives a far more limited view, its lack of power steering makes you aware of how sharp those curves in the road are and everyone notices you when you drive by. Then you take you old Datsun on a milk run and now it is more familiar than it was, you are aware of how intimately you respond to it and it responds to you but also of how its power steering removes some of the intimacy of driving and people stop talking to you about what you are driving because you have been driving that car since 1973 and everyone knows you as the person who has driven the same car since 1973, they ask you how your day is instead of complimenting your antique car. But the novelty eventually wears off and the old Model T becomes as familiar as your 240z.

            Most in electronics never learn to drive without power steering, they view passive circuits as simple little things that need active components between them so they don't interact with each other in maddening ways but those interactions are not maddening once you understand them and learn to exploit them.

            I don't think anyone used novel to mean rare.

    • jfengel 8 hours ago
      As a CS guy who got the absolute bare minimum introduction to electronics: why isn't the article about LC oscillators?

      I get the impression that there was some requirement to use transistors that I was missing. The article briefly mentions some kind of inductor as a rare component.

      • tlb 1 hour ago
        Inductors (the L of LC) are large and expensive except at very high frequencies. So audio circuits are normally designed with just resistors and capacitors.

        And you always need an active component like a transistor. A pure LC can oscillate for hundreds of cycles but not indefinitely.

      • the__alchemist 7 hours ago
        Hah! As an IC baby, I assumed it would be about what goes on inside crystal oscillators, TCXOs, MEMS oscillators, the difference between the one that you add 2 caps to with in and out vs the ones that don't need In and use a single bypass cap.
    • amelius 13 hours ago
      Nice! Perhaps you could sort them based on Q-factor.
    • achr2 6 hours ago
      This is really great, both from a specific application perspective, but also the approach. Really enjoyed looking through the repo and was inspired by your work.
    • webdevver 13 hours ago
      this is always the risk of posting on hackernews: a random commentator absolutely iq mogs the op.
  • ofalkaed 13 hours ago
    When I was starting out in electronics I found the easiest way to build an oscillator was to build an amplifier and the easiest way to build an amplifier was to build an oscillator. I guess the trick is to be 7 years old and have far more ambition than skill. Couldn't guess at how many tries it took me to make an amplifier that didn't oscillate and when I moved onto oscillators, they never oscillated but they did amplify. In that first year or so, I couldn't actually read resistor color codes, but I thought I could.
    • fallous 11 hours ago
      If you combine a 3 year-old, whose favorite word is "why?", and the ambition of a 7 year-old you might just end up with the most productive genius possible.
      • IAmBroom 7 hours ago
        Add the social insecurity of a pubescent, and you suddenly have a madman knowitall (with almost no actual knowledge) that slows that learning to a drip.

        It's a miracle high schools are able to achieve anything, really.

    • seg_lol 12 hours ago
      > the trick is to be 7 years old and have far more ambition than skill

      Never lose this

      • hollerith 12 hours ago
        Apologies for my bluntness, but in my humble opinion, American society would be better if it had fewer adults like this.
        • JKCalhoun 10 hours ago
          You are likely talking about a different aspect of child-mindedness than the person you were responding to.
        • HeyLaughingBoy 1 hour ago
          Ambition should always outpace skill. Otherwise, how would we get anywhere?
        • ofalkaed 12 hours ago
          Being able to enjoy and find worth in the process regardless of the outcome is bad? Are we man-children if we don't treat everything as if it were as serious as cancer? I'm not really sure what you are trying to say.
        • eru 9 hours ago
          Why talk about Americans now?
          • hollerith 8 hours ago
            Only because I don't know the rest of the world well enough to say.
        • jacquesm 11 hours ago
          Yes, but then again, we could make a very similar comment about Hackernews.
        • immibis 12 hours ago
          Ambition develops skill. One of the problems with American society is people thinking they have skill when they don't. If people knew they had ambition and no skill, they'd try things and learn.
          • majorchord 8 hours ago
            Dunning-Kruger actually applies to everyone, especially to people who openly and over-generalizingly criticize an entire nation's supposed lack of skill.
        • taneq 11 hours ago
          I think the scenario of childlike wonder and limitless ambition is a little different to the scenario of embraced ignorance and wilful misrepresentation of any surviving facts in furtherance of the agenda du jour.
        • fragmede 12 hours ago
          that's a helluva thing to just drop. What are your priors? Are you American yourself, or living in or near it? In what way would it be better? How so?
          • hollerith 5 hours ago
            Yes, American citizen living in the SF Bay Area.
        • fuzzfactor 8 hours ago
          Wait until you see what some of the people in other countries do when they try to imitate Americans.

          It makes you think, why even bother?

          Not my downvote BTW.

    • taneq 11 hours ago
      Often the biggest thing holding you back from doing something is the sensible, mature understanding that it’s impossible.
      • dylan604 6 hours ago
        Growing up, I never had the budget of a real TV studio, but had equipment that would approximate a real TV studio. I would come up with ways to recreate what they were doing because it could clearly be done, but by using totally different equipment that only looked like it was up for the task. Asking the real TV people if it could be done, they'd say no. I'd say hide and watch (too young to have a beer to ask them to hold).

        Sometimes, the box a degree stuffs you into with all of that learning often means losing some creative out-of-the-box thinking abilities. I get away with things all the time because I didn't know you weren't supposed to not do this, yet now that I have, it works just fine.

  • summa_tech 4 hours ago
    I wanted to give a quick explanation of the odd and off-hand "lightbulb" comment in the article. Why would an oscillator need a lightbulb? Especially since the article does not get into the weeds of building oscillators that would actually care about this.

    A somewhat difficult part of making (moderate-frequency) analog oscillators is getting a clean sinewave without harmonics. It sounds like the easiest thing in the world: a delay, a low-pass filter, a linear amplifier that compensates for the loss in the delay and filter, and boom, sinewave. You can even put the low-pass filter and the delay in a single phase shifter circuit.

    The difficulty is hidden in the "compensates for the loss" language. If you amplify too little, your oscillation will decay. If you amplify too much, you will inevitably saturate the amplifier, introducing lots of harmonics (like a squarewave output in the article). So you need some way to stabilize your gain at exactly the right level.

    A lightbulb is an interesting device: it is a very linear resistor at short timescales, but nonlinear at long timescales. As the filament heats up, resistance rises. The thermal constant can be fairly substantial, certainly more than kHz or MHz oscillator frequencies. So you can exploit this sweet and clean nonlinearity to produce an oscillator that self-stabilizes!

    Design your circuit so that the amplifier gain is controlled by lightbulb's resistance (which is quite easy: you use the lightbulb as one of the gain-setting resistors). And boom, pretty much a perfect sinewave.

  • kurthr 14 hours ago
    Building an oscillator is "just" putting some gain around a large enough phase delay (>90deg). The challenge is in making the oscillator predictable and STABLE.

    You want a frequency generator that oscillates with a constant period/frequency. Even an unbalanced oscillator can just be divided by two to provide uniformity. However, it turns out that building something that is not sensitive to any outside inputs (temperature, strain, voltage, time, etc) is really hard to do over a very wide frequency range (from ~DC to many MHz), but from that you can build a stable clock.

    Look up Allan Variance, if you're looking for bit of a rabbit hole on clocks and oscillators and other sensors.

    • fuzzfactor 8 hours ago
      Exactly, all that you needed to do was "draw the rest of the owl".

      >It's hard to build an oscillator

      It took a long time, too, after the invention of the vacuum tube.

      Finally one day they had some remarkable success using circuitry more reliable than ever before.

      It seemed so promising that a startup really could be based on technology like that, so that's what was happening.

      Unless you were intrigued by relatively high-voltage analog electronics, it was just another boring engineering company. Even though they were very creative, their little company was simply named after the founders like many others.

      That's why they called their startup Hewlett-Packard.

  • dragontamer 2 hours ago
    Oscillators are hard because our specs on oscillators are absurd.

    Let's take the common watch circuit. Conceptually it's just like 5 components: crystal, a few capacitors, a NOT gate/transistor/amplifier. Introduce 180-degree phase shift at the 32.768k target frequency and bam, oscillator.

    Except not really. A clock is expected to have a drift in the region of 100 ppm (or 0.001% error), or lose a second per day or so. That's the hard part, building something that accurate and consistent.

    There are also startup specs, power specs (less power is harder. More power helps startup....) etc. etc.

    -------

    If you just need something to oscillate back and forth randomly, try making a noise generator lol, it will oscillate wildly at many frequencies, one of which might have been the frequency you wanted.

    ---------

    The 555 timer is perhaps the easiest oscillator for a beginner if you are willing to put up with +/-10% drift. It's honestly good enough for far more applications than you might expect.

    Even without the premade chip, a 555 timer is just 2x comparators (analog version of an If statement), a 33%/33%/33% voltage divider, and a capacitor. If Voltage > 66% input voltage, remove power from capacitor. If Voltage < 33% input voltage, add power to capacitor. Bam, you now have an oscillator that is accurate to the +/-10% capacitance values of your electronics kit.

    Alas, modern circuits need to be faster and more accurate than the humble 555. But a beginner article about oscillators should be about the 555, rather than about opamp or transistor based oscillators.

  • highspeedbus 9 hours ago
    I've build a signal injector to debug a guitar pedal that was not working. It was a nice little journey in itself. The astable multivibrator produces so much harmonics that I could hear it all the way back from the input jack, where it was supposed to be silent. Heck, I could hear it just by putting the probe nearly close to the circuit. The signal pushed through the circuit like Juggernaut breaking walls. Learned a lot about filters and was able to produce a nice sine wave out of it, it worked great.
  • ErroneousBosh 12 hours ago
    Two things not mentioned - hey maybe I should blog about these myself and post them up?

    The first being the "Two Transistor Metronome" that I can't even remember where I saw first - possibly Electronics Today International or Hobby Electronics, although Practical Electronics was a contender - we didn't get that one much though. I remember my dad and I building this when I was probably about seven or eight, and I've built loads since.

    https://tinyurl.com/22qjecj7

    It's a relaxation oscillator where the two transistors form more-or-less an SCR, which fires when its (negative-going) gate voltage exceeds its anode voltage. Kind of.

    A similar circuit using three transistors and a diode is used in the oscillators in the Roland TB303 and Korg MS10/20/50 series, with a current source used to set the capacitor charging time so you get a nice linear sawtooth. Conveniently the expo converter turns an incoming control voltage into an exponentially-rising current, which is just what you need!

    • JKCalhoun 10 hours ago
      I was thinking Astable Multivibrators. Probably the same as your Metronome. The circuit I usually see uses two NPN transistors instead of the PNP+NPN your metronome does: https://www.electronics-tutorials.ws/waveforms/astable.html
      • ErroneousBosh 56 minutes ago
        It's a different principle, although I have a Ladybird Book of Electronics that my dad gave me when I was just about the age my son is now, that shows how to make a thing that flashes two lightbulbs using that astable circuit (and a few other things).

        The two-transistor metronome one really is working more like an SCR, that rapidly charges the capacitor and allows it to discharge again.

  • stevetron 8 hours ago
    In some reading I did several (decades) years ago, I read how the invention of the oscillator was an accident. Someone was building an amplifier, and made a wiring error that was described as connecting the amplifier's input to the amplifier's output and it produced a squeal.

    Up until that time, radio frequency carriers were produced with AC Generators designed for a high-frequency (> 60 Hz) output. That is in part why it took so long for things like music to be broadcast by radio: you needed a high-frequency carrier. Generators were topping out at about 15K Hz according to the old article I read.

    So once they had the accidental circuit that squealed, it was studied and expermented upon (trial and etrror modifications), and that is where all the 'classic' oscillator circuits originate.

    Essentially, an oscillator is an amplifier with positive feedback. Amplifiers that are amplifiers sometimes have negative feedback.

  • lm2s 12 hours ago
    For anyone interested in this kind of stuff with a music oriented gist, a while ago I found this awesome YouTube channel: https://www.youtube.com/@MoritzKlein0/
    • jnovek 9 hours ago
      I couldn’t see the whole link on my phone but I knew it would be Moritz Klein.
  • eternauta3k 14 hours ago
    I was hoping this would go more into startup and amplitude control, which are for me the tricky parts of building a phase shift oscillator (because you have to analyze the non-linear behavior).

    I guess hobbyists nowadays are just using SI5351 and calling it a day.

    • Joel_Mckay 13 hours ago
      Most use GPSDO references for equipment, as they are inexpensive. Even miniature TCXO tend to still offer quite good value these days. =3
  • ur-whale 25 minutes ago
    My all time favorite analog oscillator is the Twin-T (the one with a BJT) [1]

    It was hard to get a proper intuition of how and why it works, but when you finally do ... fireworks!

    Another thing that's real fun with oscillators is to try and build a true chaotic oscillator, but only with R+C+BJT

    Not easy, but can be done [2]

    [1] https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj...

    [2] https://www.instructables.com/A-Simple-Chaos-Generator/

  • a5c11 13 hours ago
    One of my favorite is an RC circuit with a Schmitt triggered inverter. So simple and ingenious.
    • Marazan 2 hours ago
      It is beautifully simple and a classic building bloc of Lunetta music synths
  • IsTom 13 hours ago
    I wish Esaki oscillator was mentioned. It's a funny bit of trickery.
  • Mizza 13 hours ago
    Never found it hard to build an oscillator, the hard part is musical voltage per octave. 3340 repro chips are the way to go, the best non-3340 circuit I've seen is this one and it's still temperature-sensitive: https://www.youtube.com/watch?v=FiCMjt0mqvI
    • ofalkaed 13 hours ago
      Temperature sensitivity only matters in polysynths where you don't have easy access to per-oscillator tuning. It is not difficult to build an oscillator with better pitch stability than a guitar, even my VCOs with no temperature compensation require less tuning than any guitar I have owned.
      • Mizza 12 hours ago
        But that's for synths where the oscillators are ICs. I'm talking about simple oscillators from basic components
        • ofalkaed 12 hours ago
          My VCOs which lack temperature compensation are oscillators built from basic components. The closest I have to oscillator on an IC these days, are the VCOs in my Moog Prodigy which use a quad OPAmp and a 3086 transistor array, it is far more stable than any guitar string.
    • elihu 3 hours ago
      3340s are great. I've also heard good things about the SSI2130 and 2131 chips as a more modern alternative to 3340.

      3340s are more DIY-friendly though, as they're DIP packages.

  • parsimo2010 7 hours ago
    It's great to do experimentation because you get to learn a lot, but at the end of the day stick with well-studied designs if you're making a something you want to use. The oscillators mentioned below all have well known strengths and weaknesses:

    The author mentions that they consider a center-tapped inductor to be "fancy," but if you consider a regular inductor to be fair game, then the Colpitts oscillator is a good choice. And I suppose you could build a Hartley oscillator with two inductors rather than one center-tapped inductor.

    If you consider op-amps to be fair game even though it is made from multiple transistors, then you might consider digital logic to also be fair game and should consider a Pierce oscillator. I'm also assuming that a crystal is also fair game, but those are quite cheap.

    Side note- these oscillators are all part of the exam material for the Extra class amateur radio license in the USA. If you find lcamtuf's Substack interesting, then amateur radio might be for you.

  • crmd 5 hours ago
    The bring up of seemingly every tube guitar amp i’ve ever built starts with wild oscillation due to negative feedback from the wrong transformer secondary, aka positive feedback. Gets me every time.
  • JJMcJ 3 hours ago
    Also if it oscillates does it oscillate at the frequency you want?
  • kazinator 5 hours ago
    It's not hard to build an oscillator. Just focus on designing an amplifier, and stop chasing oscillation.
  • reactordev 13 hours ago
    As someone with a CS degree and not an EE degree, this is fascinating. I tried a decade ago to build some simple RC lights controller circuit that would operate off of a PWM signal and failed. Hats off to you hardware folks. Manipulating atoms and electrons and building circuits that allow us to play games, build businesses, communicate with loved ones, and write this post.
  • jhallenworld 9 hours ago
    Easy negative resistance oscillator: a neon bulb in parallel with a capacitor connected to a DC power supply through a resistor.
  • fjfaase 12 hours ago
    I remember creating an oscilator by soldering a transistor onto an inductor with two windings in series with loudspeaker an battery.
  • atoav 14 hours ago
    Coincidentally I thought a class of art students just yesterday how to build oscillators. And it is not hard at all. Take a logic inverter IC (CD40106 Schmitt-Trigger Hexinverter) pick a single gate, connect the output to the input, add a capacitor from the input to ground. That is it. Three parts and you got a Relaxation Oscillator. And then you have 5 inverter gates left.. But of course one could argue ICs are cheating, since any PLL-IC would have an oscillator onboard.

    Why the first two circuits fail is also pretty obvious without derper circuit analysis: to get reliable oscillation you don't only need amplification, you also need some time setting element, usually in the form of a capacitor (or involuntary capacitance).

    • eternauta3k 14 hours ago
      Relaxation oscillators are easy, good phase shift oscillators are an art.
  • temp0826 12 hours ago
    As the famous one-liner from EE goes- if you want to build an oscillator, build an amplifier; if you want to build an amplifier, build an oscillator.
  • Zardoz84 10 hours ago
    > The circuit can be simplified to two transistors at the expense of readability, but if you need an analog oscillator with a lower component count, an operational amplifier is your best bet.

    Well... Using a NOT (really a NAND) gate was a very classic way of generate clocks for discrete logic.

    • fsckboy 4 hours ago
      he said "if you need an analog oscillator". (yes, digital signals are analog signals and analog signals are digital signals, but...)
  • ZyanWu 12 hours ago
    What intrigued me was the "just use a microcontroller" comment at the bottom of the page - I genuinely don't know if it was pinned because it's a joke, a genius idea or just top 10 dumbest comments of 2025
    • dgacmu 10 hours ago
      The comment is by the author. And it's not wrong! You can get super cheap microcontrollers for pennies that will act as an easy to use programmable oscillator, if that's what you want. And more to the point, you usually want an oscillator to _do something_, not just to wiggle in isolation, and the cheap microcontroller lets you skip the middleman in many cases.

      Yes, you're using a million transistors to do something you could have done with a couple of discrete passives, but it will often result in a lower total BoM and development time. Not always.

      • ZyanWu 12 minutes ago
        Well, it's a bit of a chicken and the egg, no? Microcontroller won't work without a (most likely) crystal oscillator or something to act as a clock signal.

        Now that I think about it, no, it's not even cheaper as XTALs are quite pricy compared to other discrete components.

        I didn't mean to be rude - I interpreted the comment as "Would you like to build an (insert random object here)? Well, you can just BUY it and be done with it" - may not be as I put it (dumb) but certainly... simplistic and purpose-defeating

    • mindcrime 7 hours ago
      • ZyanWu 9 minutes ago
        Yes but DDS doesn't use a uController and still needs a stable reference clock/frequency/oscillator
  • jason-richar15 4 hours ago
    [dead]
  • tony-john12 8 hours ago
    [dead]
  • readingnews 7 hours ago
    It is hard to put into words how so many people "out there" can print things, have people read them, and they are so worded that the average person is probably reading this as "the truth".

    > but it’s rather difficult to build a good analog oscillator from scratch. The most common category of oscillators you can find on the internet are circuits that simply don’t work. This is followed by approaches that require exotic components, such as center-tapped inductors or incandescent lightbulbs.

    It is not hard to build a good analog oscillator from scratch, we have been doing this for decades. Secondly, while an incandescent _might_ be considered exotic, and completely unnecessary for an oscillator, a center tapped inductor is totally not exotic, and also, not really necessary for an oscillator.

    As others have noted, it is simple to build a really good analog oscillator. This article is blah, and "meh" at best.