<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.2.2">Jekyll</generator><link href="https://blog.mfavreaux.fr/feed.xml" rel="self" type="application/atom+xml" /><link href="https://blog.mfavreaux.fr/" rel="alternate" type="text/html" /><updated>2026-05-03T10:35:04-05:00</updated><id>https://blog.mfavreaux.fr/feed.xml</id><title type="html">Corners were cut</title><subtitle>Seriously, I don&apos;t have time for this.</subtitle><author><name>Mathieu Favréaux</name></author><entry><title type="html">How a dimmer switch works - diacs and triacs</title><link href="https://blog.mfavreaux.fr/dimmer-switch/" rel="alternate" type="text/html" title="How a dimmer switch works - diacs and triacs" /><published>2026-05-03T00:00:00-05:00</published><updated>2026-05-03T00:00:00-05:00</updated><id>https://blog.mfavreaux.fr/dimmer-switch</id><content type="html" xml:base="https://blog.mfavreaux.fr/dimmer-switch/"><![CDATA[<p>In this article, we’ll learn a bit about diacs and triacs while repairing a dimmer switch.</p>

<h2 id="initial-conditions">Initial conditions</h2>

<p>A while ago one of my house’s lamp dimmer switch died, which meant I had an excuse to dabble in electronics again, yaye!</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/dimmer/box.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/dimmer/box.jpg" alt="The patient" />
  </a>
  <figcaption>The patient
  
  </figcaption>
</figure>

<p>Opening up reveals an interesting circuit:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/dimmer/opened-up.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/dimmer/opened-up.jpg" alt="The patient's guts" />
  </a>
  <figcaption>The patient's guts
  
  </figcaption>
</figure>

<p>And quickly our attention turns to a likely failure point: a BTB600. Is it a mosfet? It’s not!</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/dimmer/triac.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/dimmer/triac.jpg" alt="The triac" />
  </a>
  <figcaption>The triac
  
  </figcaption>
</figure>

<h2 id="the-triac">The triac</h2>

<p>A quick look at this component’s datasheet reveals it’s a <a href="https://en.wikipedia.org/wiki/Triac">triac</a>.</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/dimmer/triac-symbol.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/dimmer/triac-symbol.png" alt="The triac's symbol" />
  </a>
  <figcaption>The triac's symbol
  
  </figcaption>
</figure>

<p>It’s a really fun component:</p>

<ul>
  <li>It’s a thyristor:
    <ul>
      <li>It will conduct when current is applied to its gate</li>
      <li>Unlike the transitor, it will keep conducting if current is removed from the gate – shutting it down requires stopping the current flow between its anodes.</li>
    </ul>
  </li>
  <li>It’s a double thyristor, made to work in alternating current, so its inputs are named Terminal (or Anode) 1 and 2.</li>
</ul>

<p>As a thyristor, it’s easy to test out:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/dimmer/as-thyristor.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/dimmer/as-thyristor.jpg" alt="Testing a triac on a breadboard" />
  </a>
  <figcaption>Testing a triac on a breadboard
  
  </figcaption>
</figure>

<p>The gate is the right-most pin: when connected, the LED lights up, and will stay on even if we disconnect the gate.</p>

<p>With this simple setup we test a freshly-bought triac against the one extracted from our device: the latter does not work, so it’s our failure point.</p>

<h2 id="simplified-dimmer-circuit">Simplified dimmer circuit</h2>

<p>The principle of a traditional light dimmer is that on each rise of the AC sinusoidal, a delayed trigger will start conducting out of phase, limiting the amount of total power sent to the lamp.</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/dimmer/triac-operation.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/dimmer/triac-operation.png" alt="Input (blue) / Output (red) of a typical triac circuit" />
  </a>
  <figcaption>Input (blue) / Output (red) of a typical triac circuit
  
  </figcaption>
</figure>

<p>Note: this goes to show why such dimmers cannot work on LED bulbs as-is: while a lamp will absorb the on/off periods and simply shine less bright the smaller the triac’s on-time is, an LED transfomer will not magically reduce current based on the form of its input’s wave form. Thankfully, there exists LED bulbs that do work on such dimmers, requiring more circuitry.</p>

<p>Such a typical circuit looks like this (simplified):</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/dimmer/triac-circuit.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/dimmer/triac-circuit.png" alt="A simplified dimmer circuit" />
  </a>
  <figcaption>A simplified dimmer circuit
  
  </figcaption>
</figure>

<p>This introduces a new component: the <a href="https://fr.wikipedia.org/wiki/Diac">diac</a>. It’s an AC diode that starts conducting at large-ish breakdown voltages like 30 V.</p>

<p>Hence the above circuit makes sense:</p>

<ol>
  <li>When the sinusoidal starts rising, the triac is off.</li>
  <li>Current flows through C1 limited by R + R1: the voltage across C1 rises at a rate that depends on R1.</li>
  <li>The voltage across C1 eventually reaches the diac’s breakdown voltage: C1 discharges rapidly in the triac’s gate and triggers it on.</li>
  <li>For the rest of the half-period, the triac stays on, and virtually no current passes through C1 anymore.</li>
  <li>the sinusoidal reaches 0v, the triac turns off, and the cycle repeats.</li>
</ol>

<p>And how much of the period is cut off depends on the variable resistance’s value. Neato! You can see the circuit in action over at <a href="https://www.falstad.com/circuit/">falstad.com</a>: select “Circuits” / “Misc Devices” / “DIAC TRIAC Dimmer”.</p>

<p>Something feels weird though: what happens when T2 is lower than T1 (respectively -120 and 0 V)? What is the potential of the gate? If it was related to T2, you would immediately get a large potential across the diac (from -120 V to 0 V at the start, since C1 starts with a voltage drop of 0), triggering the diac instantly, so that can’t be it.</p>

<p>Instead, my understanding is that the gate’s potential is always related to T1, hence why the capacitor + diac group is across the gate and T1, and it can trigger with either a negative of positive potiential. So a triac is not exactly the same as two thyristors glued together, and T1 and T2 are not interchageable. In our case, when T2 &lt; T1, we enter what is called quadrant 3, because the gate is also &lt; T1.</p>

<h2 id="dimmers-actual-circuit">Dimmer’s actual circuit</h2>

<p>Note we’ve looked at a simplified circuit. In the photo above we see at least one large inductor and two capacitors. The basic intention is apparently to filter the circuit, with these additions:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/dimmer/triac-circuit-filtered.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/dimmer/triac-circuit-filtered.png" alt="Filtered version of the dimmer circuit" />
  </a>
  <figcaption>Filtered version of the dimmer circuit
  
  </figcaption>
</figure>

<p>I reversed the actual circuit, which gave me something like this:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/dimmer/triac-circuit-real.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/dimmer/triac-circuit-real.png" alt="The actual dimmer circuit, reversed (may contain mistakes)" />
  </a>
  <figcaption>The actual dimmer circuit, reversed (may contain mistakes)
  
  </figcaption>
</figure>

<p>We see:</p>
<ul>
  <li>The filtered dimmer circuit above</li>
  <li>A fuse F1</li>
  <li>TS1 which I believe is a thermal switch or thermal fuse of some kind - it is glued to the coil.</li>
  <li>An LED indicator (2mA with its 120 K resistor)</li>
</ul>

<h2 id="the-repair">The repair</h2>

<p>Anyhow, replacing the triac with a newly-ordered one fixed the circuit – success!</p>]]></content><author><name>Mathieu Favréaux</name></author><category term="Electronics" /><category term="Repair" /><category term="Thyristor" /><category term="Triac" /><summary type="html"><![CDATA[Reviving a foot dimmer switch and learning about the operation of diacs and triacs in the process.]]></summary></entry><entry><title type="html">Resurecting a pair of bluetooth earbuds</title><link href="https://blog.mfavreaux.fr/bt-earbuds-battery/" rel="alternate" type="text/html" title="Resurecting a pair of bluetooth earbuds" /><published>2024-08-31T00:00:00-05:00</published><updated>2024-08-31T00:00:00-05:00</updated><id>https://blog.mfavreaux.fr/bt-earbuds-battery</id><content type="html" xml:base="https://blog.mfavreaux.fr/bt-earbuds-battery/"><![CDATA[<p>In this article, we’ll see how I revived Bluetooth earbuds from a low-voltage battery condition that rendered them unusable.</p>

<h2 id="initial-conditions">Initial conditions</h2>

<p>A while ago I started looking into Bluetooth earbuds. It was more out of necessity than anything, due to the recent industry trend of removing perfectly useful jack headphone ports from devices — see below for my thoughts on the whole thing.</p>

<p>Looking at the second-hand market, I happened to find an offer for interesting model but selling them for parts as they appeared dead and refused to charge. Looking around, it looked possible to open them up and force a charge to the battery to revive it. They were cheap enough to justify the risk, so I went for it. The model in question is Seinnheiser’s Momentum True Wireless 3.</p>

<p>Opening them up was surprisingly easy — just heat them up with a hair dryer and cut through the glue.</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/earbuds/earbuds-closed.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/earbuds/earbuds-closed.jpg" alt="One earbud, still closed" />
  </a>
  <figcaption>One earbud, still closed
  
  </figcaption>
</figure>

<p>Then gently pry them open, the cover comes off easily revealing the electronics and the tightly packaged battery.</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/earbuds/earbuds-open.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/earbuds/earbuds-open.jpg" alt="One earbud, cover detached" />
  </a>
  <figcaption>One earbud, cover detached
  
  </figcaption>
</figure>

<p>And as expected, the battery shows a very very low voltage.</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/earbuds/low-voltage.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/earbuds/low-voltage.jpg" alt="One sad, dead battery" />
  </a>
  <figcaption>One sad, dead battery
  
  </figcaption>
</figure>

<p>In this condition, the earbud can’t even power up enough to accept a charge, and so they are dead, ready to live the rest of their long, long after-life in a pretty landfill.</p>

<h2 id="manual-charging">Manual charging</h2>

<p>Thankfully, now that we have direct access to the battery, we can attempt a manual charge and see if it revives the earbuds. Because of the deep discharge, it’s possible the battery has suffered heavy damage, so it’s a bit of a gamble here.</p>

<p>The charging profile of a lithium-ion is a classic CC-CV profile:</p>
<ul>
  <li>First, charge with a Constant Current, and let the voltage ramp up to its target value.</li>
  <li>Then, limit the voltage, and let the current drop to a low threshold, at which point the charging is over.</li>
</ul>

<p>It looks like this:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/earbuds/liion-charge.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/earbuds/liion-charge.jpg" alt="Caption" />
  </a>
  <figcaption>Caption
  
  </figcaption>
</figure>

<p>It’s easy to emulate with a bench power supply: set a limit to both voltage &amp; current, and connect it. You can also use straight batteries, as they will probably limit the current to a safe-ish value for the small duration.</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/earbuds/power-supply.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/earbuds/power-supply.jpg" alt="Setting limits to the power supply" />
  </a>
  <figcaption>Setting limits to the power supply
  
  </figcaption>
</figure>

<p>Note that I should have set a voltage limit to something closer to 4.2V instead of 3.7V. Not that it matters too much in my case, because I’m not going for a full charge: I only want to revive them so that the case can detect the earbuds and take over. For this reason I limited the current to 300 mA to ensure the kick start stays gentle.</p>

<p>With this set up, connect the battery to the power supply for about 30 seconds to a minute, put the earbud back into its case, and voilà!</p>

<h2 id="results">Results</h2>

<p>I’ve been using this pair for about 2 weeks now, and they work like a charm. They last about 75% of their advertised duration on a single charge, which is good enough for 30 €.</p>

<h2 id="old-man-yell-at-cloud">Old man yell at cloud</h2>

<p>What did I learn in the end?</p>

<p>Well, I don’t deny that I enjoy having cable-less earphones, they’re great and very comfortable in many situations. But I just love love love the idea that with almost only Bluetooth at my disposal, now I get to worry about price, battery life, codec compatibility <em>and</em> latency! Because, yeah, most of these things have like a 250-ms latency (compensated for media, not so much for anything real-time), which is roughly the time it takes to ping the other end of the planet. The experience of satellite phones, right in your pocket!</p>

<p>But the best thing of all is that most of these aren’t repairable at all and that you can’t even change the battery, because those landfills aren’t gonna fill themselves!</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/earbuds/whut.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/earbuds/whut.jpg" alt="A very disappointed mother nature, in a very cringe ad" />
  </a>
  <figcaption>A very disappointed mother nature, in a very cringe ad
  
  </figcaption>
</figure>

<p>Note that some manufacturers do manage to keep theirs earphones at least semi-repairable — Fairphone’s are, of course, but apparently so are Samsung’s including their latest models… relatively speaking for their tiny tiny size of course.</p>

<p>Or, you know, I could buy yet-another adapter to replace the once-ubiquitous port that was everywhere and made plugging stuff so simple. And that gives me the option to choose which DAC is the best! Don’t we love having non-choices forced down our throats?</p>

<p>Anyway, hurray for stuff you can at least minimally maintain.</p>]]></content><author><name>Mathieu Favréaux</name></author><category term="Electronics" /><category term="Batteries" /><category term="Repair" /><summary type="html"><![CDATA[Reviving small electronics by opening them up and forcing the battery back to charge.]]></summary></entry><entry><title type="html">Designing a simple object from scratch: two-minute timer</title><link href="https://blog.mfavreaux.fr/timer/" rel="alternate" type="text/html" title="Designing a simple object from scratch: two-minute timer" /><published>2024-03-16T00:00:00-05:00</published><updated>2024-03-16T00:00:00-05:00</updated><id>https://blog.mfavreaux.fr/timer</id><content type="html" xml:base="https://blog.mfavreaux.fr/timer/"><![CDATA[<p>I recently set out to build a 2-minute timer from scratch, by designing and 3D-printing a box and the simple electronic circuit. The final result look like this:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/timer/timer.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/timer/timer.jpg" alt="The final result of this project: a two-minute timer." />
  </a>
  <figcaption>The final result of this project: a two-minute timer.
  
  </figcaption>
</figure>

<figure>
  <video controls="" height="300">
  <source src="https://blog.mfavreaux.fr/assets/timer/timer-in-action.mp4" type="video/mp4" />
  </video>
  <figcaption>The timer in action.
  
  </figcaption>
</figure>

<p>In this article I’ll describe the details of the project: the design choices and questions to be solved.</p>

<h2 id="first-design-ideas">First design ideas</h2>

<p>I wanted the timer to have:</p>
<ul>
  <li>A button that provides a satisfying click, nothing mushy</li>
  <li>A blinking light</li>
  <li>Some logo or simple image that would show when lit up.</li>
</ul>

<p>I also had multi-material printing with a single extruder and manual filament changes in mind: I had tried before with PrusaSlicer but the results weren’t great without a prime tower. I recently switched to OrcaSlicer, and wondered if what would work.</p>

<p>I also knew I could make the circuit simply based on 555 timers, and I had purchased a few a while back but never got to play with them yet.</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/timer/back_envelope_design.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/timer/back_envelope_design.jpg" alt="A literal back-of-the-envelope design." />
  </a>
  <figcaption>A literal back-of-the-envelope design.
  
  </figcaption>
</figure>

<p>In the end, while it is a very simple object on the surface, it provided just enough depth with fun questions to solve at every corner, making for a very satisfying project I could complete in a few week-ends.</p>

<h2 id="the-3d-model">The 3D model</h2>

<p>With that in mind, time to open up FreeCAD. If there’s anything I’ve learned about 3D-printing your own stuff is that you have to test absolutely every detail you solve.</p>

<h3 id="the-front-panel">The front panel</h3>

<p>As mentioned above, I wanted to use multi-material because it’s fun. I started with the following print:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/timer/multimat-test1.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/timer/multimat-test1.jpg" alt="A first multi-material print of the front panel." />
  </a>
  <figcaption>A first multi-material print of the front panel.
  
  </figcaption>
</figure>

<p>I had 2 issues:</p>
<ol>
  <li>The prime tower was <em>huge!</em></li>
  <li>The printer made awfully big blobs on the prime tower, which would get in the way in later layers and would risk damaging the printer.</li>
</ol>

<p>The prime tower size was solved with limiting flushing volumes:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/timer/orca_flushing_volumes.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/timer/orca_flushing_volumes.png" alt="Setting flushing volumes to 0." />
  </a>
  <figcaption>Setting flushing volumes to 0.
  
  </figcaption>
</figure>

<p>I resolved the second issue by writing a crude post-processing script (available <a href="https://gist.github.com/qb1/ced2ba98e6ac96b88fc1a68a7bbb7bb7">here on github</a>) to identify suspicious extrusion value and reduce them to 0.</p>

<p>With that out of the way, and a few other prints to get the first layer just right (had to re-calibrate recently), we’re good to go:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/timer/multimat-test2.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/timer/multimat-test2.jpg" alt="First layers tuned just right :chef_kiss:." />
  </a>
  <figcaption>First layers tuned just right :chef_kiss:.
  
  </figcaption>
</figure>

<h3 id="the-ligthing">The ligthing</h3>

<p>Next up is testing the lighting with some LEDs.</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/timer/lighting-test1.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/timer/lighting-test1.jpg" alt="Testing LED layouts." />
  </a>
  <figcaption>Testing LED layouts.
  
  </figcaption>
</figure>

<p>Putting the LEDs right behind the white, .4 mm-height disk doesn’t look pleasing: the light isn’t well distributed and too sharp.</p>

<p>Instead, I tried printing some form of diffuser, and hold it at about one centimeter from the front panel.</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/timer/lighting-diffuser.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/timer/lighting-diffuser.jpg" alt="Fitting a diffuser on the LEDs (spoiler, it's on the final PCB)." />
  </a>
  <figcaption>Fitting a diffuser on the LEDs (spoiler, it's on the final PCB).
  
  </figcaption>
</figure>

<p>The result is dimmer, but nicer - this is what we can see in the picture at the top of the article.</p>

<h3 id="using-screws">Using screws</h3>

<p>We need two sets of screws: one to hold the PCB, and the other to close the box. For the former, I decided to use simple M2 screws I had lying around, and screw them directly into the plastic. For the box though, I wanted to be able to open and close the lid easily, so I resorted to using screw inserts.</p>

<p>Again, instead of printing the whole model and getting it certainly wrong, I opted to print a minimal test, and fix issues there.</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/timer/screw-test.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/timer/screw-test.jpg" alt="Testing the screw fittings." />
  </a>
  <figcaption>Testing the screw fittings.
  
  </figcaption>
</figure>

<h3 id="the-back-panel">The back panel</h3>

<p>I wondered how I would hold the batteries. I have a few battery holders for 2 AAs, and decided to use them directly as-is instead of designing my own and wasting time there. Still, they represent most of the box’s weight, so they must be fixed and ideally close to the bottom.</p>

<p>As a first simple solution, I tried to print a cradle and see how well that would hold:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/timer/cradle-test.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/timer/cradle-test.jpg" alt="Testing the cradle for the battery holder." />
  </a>
  <figcaption>Testing the cradle for the battery holder.
  
  </figcaption>
</figure>

<p>And it fits perfectly, is easy to remove but still holds well. Perfect!</p>

<h3 id="fitting-it-all-with-the-pcb">Fitting it all with the PCB</h3>

<p>As I experimented with the PCB, I realized I wasn’t too sure where I could place the components. Moreover, to print the LED diffuser or PCB mounts, I must know the exact placement of components with regard to each other.</p>

<p>What I ended up doing was creating a sketch with holes spaced by 2.54 mm (.1 inch). I printed it on paper for reference, and fixed the dimensions until they fit the real object I had.</p>

<p>Then, using this sketch as reference throughout the design, I could place my elements properly and make sure I would get a fit on the first print.</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/timer/pcb_as_ref_freecad.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/timer/pcb_as_ref_freecad.png" alt="Using the PCB as reference." />
  </a>
  <figcaption>Using the PCB as reference.
  
  </figcaption>
</figure>

<h3 id="final-design">Final design</h3>

<p>This was my most complicated object with FreeCAD yet: a combination of Sketches, Part Design workbench, and Part workbench for boolean operations where needed.</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/timer/final_design_freecad.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/timer/final_design_freecad.png" alt="The final design in FreeCAD." />
  </a>
  <figcaption>The final design in FreeCAD.
  
  </figcaption>
</figure>

<p>It might be interesting to talk a bit about FreeCAD here: I’m incredibly grateful this wonderful piece of open-source software exists, I feel I can learn it and rely on it in the years to come, which is worth a bit of a learning curve.</p>

<p>That being said, there are some annoying bits that just hurt the workflow:</p>
<ul>
  <li>Editing the PCB sketch, with its thousands of constraints, was super slow (think 20-30s per operation). However, once closed, it didn’t slow down anything anymore, so FreeCAD was smart there.</li>
  <li>I created a first sketch for the front plate, which I then used as a reference for later sketches. Going back to the first one and adding fillets wrecked havoc on the references, and I had start from scratch. Fillets are a pain to reference, to, so it might be smart to wait until the end and apply them in the Part workbench instead.</li>
  <li>Reusing sketches for multiple shapes is sketchy (pun intended): you can’t select part of the sketch for the operation, so you have to create a new sketch, reproduce a similar shape referencing the source sketch manually, then use that.</li>
  <li>When using a sketch as reference for further shapes — which as we’ve seen with the previous item, you end up doing <em>a lot</em> — there are multiple ways to combine references (“the circle here is centered on that circle in the reference sketch”) and local constraints (“and it touches this line that already exists”) to make a viable sketch. However, some are better than others: you might end up with partially redundant constraints, or suddenly with redundant constraints which aren’t obviously solvable unless you go a completely different route. I think this is where I spent most of my time in the tool, finding new and minimalist ways to use the reference sketch, and use local constraints as much as possible.</li>
  <li>Finally, it did crash a few times, which doesn’t feel nice, but usually recovery takes you but a few steps back so that was fine.</li>
</ul>

<p>In the end: I save often, I save copies, I learn along the way, I’m grateful of what it enables me to do. But I probably would not use it in a professional capacity.</p>

<p>Anyway now we can print it all, and look at the circuit.</p>

<h2 id="the-circuit">The circuit</h2>

<p>Nothing too fancy here:</p>
<ul>
  <li>A pre-built DC-DC boost converted to reach 5V from 2 AA batteries.</li>
  <li>A 1st 555 timer in <a href="https://en.wikipedia.org/wiki/555_timer_IC#Monostable">monostable</a> configuration to count up to 2 minutes.</li>
  <li>A 2nd 555 timer in <a href="https://en.wikipedia.org/wiki/555_timer_IC#Astable">astable</a> configuration to flash the LEDs.</li>
  <li>A button to trigger the whole thing up.</li>
  <li>4 LEDs &amp; their current-limiting resistor.</li>
</ul>

<p>The 555s are used in cascade, with the output of the first being the second’s VCC. That incurred a noticeable voltage drop, but wasn’t a problem in the end.</p>

<p>The 555 circuits look like the following:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/timer/555_Monostable.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/timer/555_Monostable.png" alt="555 in monostable configuration." />
  </a>
  <figcaption>555 in monostable configuration.
  
  </figcaption>
</figure>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/timer/555_Astable_Diagram.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/timer/555_Astable_Diagram.png" alt="555 in astable configuration." />
  </a>
  <figcaption>555 in astable configuration.
  
  </figcaption>
</figure>

<p>I won’t dwell on how these work, these circuits as extremely common and there are far better resources than my poor explanations, starting with the Wikipedia links above.</p>

<p>Being an analog circuit, the values of resistors and capacitors depend on the desired behavior. The formulas aren’t too hard, but you can also use a calculator such as <a href="https://www.build-electronic-circuits.com/circuit-calculator-conversion/555-timer-calculator/">this one</a>. Still, I found that the values are just a starting point: you need flexibility to change values in your circuit to properly set it to your desired values.</p>

<p>I built the circuit in stages and checked it along the way. That was a good idea, as I messed up the monostable part and it took me a bit to realize I had mounted the 555 backward… Ahem. Also, I had to change the resistor values I used as the timing I got where different on the protoboard than they were on the breadboard, and I wanted it to be just right.</p>

<p>Moreover, I had to mind the depth of my assembly, and wanted to minimize it: for this reason I located both large capacitors in a corner of the PCB, where they wouldn’t get in the way of the battery holder.</p>

<p>An hour or so of soldering and tinkering later, and we have a functioning circuit:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/timer/soldering.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/timer/soldering.jpg" alt="Soldering job done." />
  </a>
  <figcaption>Soldering job done.
  
  </figcaption>
</figure>

<h2 id="final-assembly">Final assembly</h2>

<p>And now for the big moment!</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/timer/ready_for_assembly.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/timer/ready_for_assembly.jpg" alt="Everything ready for assembly." />
  </a>
  <figcaption>Everything ready for assembly.
  
  </figcaption>
</figure>

<p>During testing, I noticed quite a lot of light leakage to I added a bit of aluminum foil to the light cover:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/timer/aluminum-foil.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/timer/aluminum-foil.jpg" alt="Aluminum foil on the light cover for better isolation." />
  </a>
  <figcaption>Aluminum foil on the light cover for better isolation.
  
  </figcaption>
</figure>

<p>Note the protrusion under the plate’s button to make it reach the actual button on the PCB. The result feels right, with very little space between the two, and a light press immediately produces a nice click.</p>

<p>The assembly went well and the first print fit well! 2 small issues:</p>
<ul>
  <li>I must have forgotten to update the holes for PCB screws in the PCB mounts, and had to drill them to size.</li>
  <li>The space between these mounts was ever so slightly too large (by about .5-1mm): it did fit but barely. Maybe my (paper) printer’s scale isn’t perfect, and the adjustments I made weren’t necessary after all. I’ll have to check that next time.</li>
</ul>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/timer/timer.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/timer/timer.jpg" alt="Once more for good measure." />
  </a>
  <figcaption>Once more for good measure.
  
  </figcaption>
</figure>

<p>I’m really happy at how the project turned out: fun questions to solve, learned a few things along the way, didn’t drag out for months on end, and the final customer got its tooth-brushing-time timer delivered swiftly!</p>

<p><em>There might be more on this subject later on, as I ordered a bunch of ATtiny85…</em></p>]]></content><author><name>Mathieu Favréaux</name></author><category term="3D&amp;#8209;print" /><category term="Electronics" /><summary type="html"><![CDATA[The details of my latest short project, where I design and 3D-print the case and create a PCB on a protoboard for a two-minute timer.]]></summary></entry><entry><title type="html">Using Blender for editing STL 3D‑print models</title><link href="https://blog.mfavreaux.fr/blender-stl-3d-print/" rel="alternate" type="text/html" title="Using Blender for editing STL 3D‑print models" /><published>2024-01-26T00:00:00-06:00</published><updated>2024-01-26T00:00:00-06:00</updated><id>https://blog.mfavreaux.fr/blender-stl-3d-print</id><content type="html" xml:base="https://blog.mfavreaux.fr/blender-stl-3d-print/"><![CDATA[<p>In this article, we’ll talk about a few ways to use blender effectively to edit STL files for 3D‑printing, as I found it wasn’t a completely smooth process. Especially, we’ll use the 3D‑print add‑on, boolean modifiers, and see how manual operations can be needed for model clean-up.</p>

<h2 id="whats-the-excuse-this-time">What’s the excuse this time?</h2>

<p>A while ago I stumbled upon <a href="https://www.make.do/">Makedo</a>, which offers awesome kits of screws &amp; tools for children to create stuff with cardboard: a safe saw, big chunky screws, a key and a pointy bit to punch holes. Simple enough, yet a fairly cool activity for my kids to do, either with us or in autonomy.</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/cad/makedo.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/cad/makedo.jpg" alt="An example of cardboard construction with Makedo screws" />
  </a>
  <figcaption>An example of cardboard construction with Makedo screws
  
  </figcaption>
</figure>

<p>But first I will have a bit of fun of my own, as this is a very good excuse to do some CAD, so let’s warm up the 3D printer and see if there already exists some open models we can tweak. I found a few things, and settled on <a href="https://www.printables.com/model/330729-handtool-for-cardboard-screws/files">this set</a> as a starting point.</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/cad/starting_set.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/cad/starting_set.jpg" alt="Our starting set, 3D printed" />
  </a>
  <figcaption>Our starting set, 3D printed
  
  </figcaption>
</figure>

<p>Because here we start with a mesh from the STL file, I won’t use FreeCAD as I’m vaguely used to, but I will try using Blender directly.</p>

<h2 id="first-things-first-the-add-on">First things first, the add-on</h2>

<p>Because we’ll want to produce valid STL, we <strong>must</strong> use the appropriate 3D‑printing add-on to check our files, otherwise the slicer will produce garbage. Fortunately, that add-on is shipped with Blender directly, so all we have to do is go to “Edit” -&gt; “Preferences” -&gt; “Add-ons”, search for “print” and check “3D‑Print Toolbox”. We can close the window.</p>

<p>However, the toolbox is really hidden… Look for a small arrow at the top right corner of the viewport:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/cad/blender_seriously.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/cad/blender_seriously.png" alt="Blender's hidden toolbox access" />
  </a>
  <figcaption>Blender's hidden toolbox access
  
  </figcaption>
</figure>

<p>Click &amp; drag left to reveal a toolbox (magic!), then select the “3D‑Print” tab.</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/cad/blender_hidden_toolbox.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/cad/blender_hidden_toolbox.png" alt="Blender's hidden toolbox revealed" />
  </a>
  <figcaption>Blender's hidden toolbox revealed
  
  </figcaption>
</figure>

<p>We’ll use that “Check all” button after each complex step to fix our model along the way.</p>

<h2 id="a-few-guidelines-to-follow">A few guidelines to follow</h2>

<p>During this project I did quite a bit of experimenting which I won’t detail entirely. In the following sections you’ll find a summary of a few interesting steps. However, here I compiled a few guidelines that I found useful:</p>
<ul>
  <li>Don’t trust Blender to keep your model valid, it won’t! Check it regularly, clean it as you go<sup id="fnref:clean-as-you-go" role="doc-noteref"><a href="#fn:clean-as-you-go" class="footnote" rel="footnote">1</a></sup>.
    <ul>
      <li>Temporarily keeping non-manifold edges resulting in missing faces is OK or even desirable, if you do so to avoid later intersections.</li>
      <li>Non-flat faces are simply solved with “Triangulate Faces” when necessary. Use within reason.</li>
      <li>Bad Continuous Edges seems to have to do with normals. Select all, then go to “Mesh” -&gt; “Normals” -&gt; “Recalculate Outside”, this gets rid of the problem.</li>
      <li>Other issues are either solved with automatic vertex merging (see below), or with manual editing of the geometry to make your model one single solid again.</li>
    </ul>
  </li>
  <li>Manual cleaning is often necessary. Make sure your model stays simple, remove spurious edges or vertices.</li>
  <li>Use vertex merging when possible to keep the model simple. Use the “By distance” merge to automatically clean up some obvious issues, check the bottom status bar to see how many vertices are affected.</li>
  <li>Because we work with meshes directly, it’s not always trivial to edit parameters after the fact. For example, making something bigger might completely mess up connected edges. In these cases, it’s way less painful to roll back and do again.</li>
  <li>Because of the above point, save often and keep your history! You’ll be glad to be able come back to a clean version, especially as the history in Blender doesn’t go that deep by default.</li>
</ul>

<p>Do note that I use Cura, which requires clean models to start from. It seems other slicers might be more tolerant of some types errors — I’ve notably had errors in the past with overlapping volumes which are fine elsewhere, but still an issue in Cura as seen in this <a href="https://github.com/Ultimaker/Cura/issues/15191">Github issue</a>.</p>

<h2 id="shortening-the-screw-bisect">Shortening the screw: bisect</h2>

<p>The first issue I want to solve is that the screw in the 3D model is longer than is necessary to assemble 2 pieces of cardboard, so I want to make it shorter.</p>

<p>Let’s open the STL file in Blender: simply create a new empty project, delete the default cube, then “File” -&gt; “Import” -&gt; “Stl” and select the scren file.</p>

<p>At the top left of the viewport, change “Object mode” into “Edit mode”, so we can work on the mesh.</p>

<p>We can cut the screw halfway using the <a href="https://docs.blender.org/manual/en/4.0/modeling/meshes/editing/mesh/bisect.html#bisect">Bisect</a> tool:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/cad/blender_bisect.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/cad/blender_bisect.png" alt="Bisect in action" />
  </a>
  <figcaption>Bisect in action
  
  </figcaption>
</figure>

<p>At this point we could recreate the top cone.</p>

<h2 id="fixing-the-screw-boolean-intersect">Fixing the screw: boolean intersect</h2>

<p>However, further testing of the screws reveals that the tip of the thread is too large and requires a lot of force or twisting around to properly get in the cardboard. Normal screws avoid that with a cone-like shape, so instead we’ll cut a shape in our screw to both make it shorter &amp; more conical at the same time. To do so we’ll use a boolean operation on the objects with “Intersect”, to instruct Blender to cut our mesh so it stays inside another mesh.</p>

<p>First, let’s create our bounding meshes with a cone and a cylinder, as separate objects. Go back to object mode, then “Add”, “Mesh”, “Cone” or “Cylinder”. You’ll end up with something like this:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/cad/blender_bounding_shapes.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/cad/blender_bounding_shapes.png" alt="Bounding shapes created" />
  </a>
  <figcaption>Bounding shapes created
  
  </figcaption>
</figure>

<p>Then, merge these 2 new objects into one with a first boolean operation:</p>

<ol>
  <li>Select the cone.</li>
  <li>In the “Properties” panel, find the “Modifier” tabs.</li>
  <li>Click on “Add Modifier”, “Generate”, “Boolean”.</li>
  <li>Select “Union”, then in the object field enter your cylinder.</li>
  <li>Apply with Ctrl+A (the “Apply” action is, again, hidden in the combo-box menu right above the “Intersect / Union / Difference” selection buttons).</li>
</ol>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/cad/blender_union.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/cad/blender_union.png" alt="Setting up the union of the two bounding objects" />
  </a>
  <figcaption>Setting up the union of the two bounding objects
  
  </figcaption>
</figure>

<p><em>Note: it might do to simply join the two meshes, but I’m not sure the later Intersect operation would work properly.</em></p>

<p>Once applied, the result is stored in the current object, but the cylinder object still exists and overlaps: delete it.</p>

<p>Next, we’ll do the intersect:</p>

<ol>
  <li>Select the screw object.</li>
  <li>Similarly, create a boolean modifier with “Intersect”.</li>
  <li>Select the bounding object (called “Cone” even if it’s not a cone anymore).</li>
  <li>Before applying, if you want to check the results, you should hide the Cone object.</li>
  <li>Apply, delete the cone object, and voilà!</li>
</ol>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/cad/blender_good_screw.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/cad/blender_good_screw.png" alt="Result of the Intersect operation: a nice conic screw" />
  </a>
  <figcaption>Result of the Intersect operation: a nice conic screw
  
  </figcaption>
</figure>

<p>Use the 3D‑print toolbox’s “Check all” to make sure there are no issues (overhang faces are usually OK, your slicer will be a better judge of that), but it should be OK as we only removed geometry.</p>

<p>Finally, save your model for future reference, export it as STL, and print away!</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/cad/printed_screws.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/cad/printed_screws.jpg" alt="Our remixed screw model 3D printed" />
  </a>
  <figcaption>Our remixed screw model 3D printed
  
  </figcaption>
</figure>

<h2 id="the-key">The key</h2>

<p>Similarly the key isn’t perfect:</p>
<ul>
  <li>I find the punching tool too blunt, which is good for safety, but it requires too much force. It is also too thin, and the resulting hole is too small to fit the screw.</li>
  <li>The 90° edges make it a bit uncomfortable to hold.</li>
  <li>I don’t see the point in having through holes, they probably make printing slower and again, 90° edges.</li>
</ul>

<h2 id="cleaning-up-the-pointy-side-of-the-key">Cleaning up the pointy side of the key</h2>

<p>First, let’s clean that side:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/cad/blender_key_bad_pointy.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/cad/blender_key_bad_pointy.png" alt="The side we want to clean up" />
  </a>
  <figcaption>The side we want to clean up
  
  </figcaption>
</figure>

<p>Using the selection in vertices mode, I removed everything but what is stricly necessary to make the edge again:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/cad/blender_key_bad_pointy_cleaned.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/cad/blender_key_bad_pointy_cleaned.png" alt="Removed vertices" />
  </a>
  <figcaption>Removed vertices
  
  </figcaption>
</figure>

<p>If we use “Check all” at this stage, we’ll have a few non-manifold edges: our model isn’t solid anymore. Don’t create the missing face! if you do, it’ll intersect with the rest of the model and you’ll have to remove it afterwards.</p>

<h2 id="spin-extruding-a-round-side">Spin: extruding a round side</h2>

<p>Now we’ll extrude a half circle. First we must define the center of the spining extrusion:</p>
<ol>
  <li>Select the 8 vertices in view.</li>
  <li>Shift-S: “Cursor to selected” to place the cursor at the center of the selection.</li>
</ol>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/cad/blender_key_back_cursor.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/cad/blender_key_back_cursor.png" alt="Cursor at the center" />
  </a>
  <figcaption>Cursor at the center
  
  </figcaption>
</figure>

<p>Now for the extrusion:</p>
<ol>
  <li>Now select only 4 vertices from one side</li>
  <li>Select the <a href="https://docs.blender.org/manual/en/4.0/modeling/meshes/tools/spin.html">Spin</a> tool</li>
  <li>Make the angle 180°</li>
</ol>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/cad/blender_key_back_extrusion.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/cad/blender_key_back_extrusion.png" alt="Extrusion from a set of vertices" />
  </a>
  <figcaption>Extrusion from a set of vertices
  
  </figcaption>
</figure>

<p>At this point, let’s check our model with “Check All”. 3 intersect faces! What? Manual cleaning is required:</p>
<ol>
  <li>Select all vertices with “A”.</li>
  <li>Select “Mesh” -&gt; “Merge” (“M”), then “By distance”.</li>
  <li>On this model, a distance of 0.1m is necessary.</li>
  <li>The status bar should indicate that a few vertices are merged.</li>
</ol>

<p>Check the model again: the issues are solved. Phew, we dodged a bullet here.</p>

<p>Our model isn’t air-tight yet. Select all vertices in the hole above and press “F” (“New face from vertices”). Do the same with the bottom hole.</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/cad/blender_key_back_air_tight.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/cad/blender_key_back_air_tight.png" alt="Making a face from vertices to make the model air-tight" />
  </a>
  <figcaption>Making a face from vertices to make the model air-tight
  
  </figcaption>
</figure>

<p>“Check All”: all good!</p>

<h2 id="bevels">Bevels</h2>

<p>A simple way to make the edges less sharp is to use the <a href="https://docs.blender.org/manual/en/4.0/modeling/meshes/editing/edge/bevel.html">Bevel Edges</a> tool.</p>

<p>Use the edge selection mode (see the 3 icons at top of the viewport, next to the “Edit mode” combox box to change between selection modes) to select the edges on one side of the key side.</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/cad/blender_key_front_select_edges.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/cad/blender_key_front_select_edges.png" alt="Selected edges ready to be beveled" />
  </a>
  <figcaption>Selected edges ready to be beveled
  
  </figcaption>
</figure>

<p>Use the bevel tool, and select the desired width:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/cad/blender_key_front_bevel_edges.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/cad/blender_key_front_bevel_edges.png" alt="Edges beveled" />
  </a>
  <figcaption>Edges beveled
  
  </figcaption>
</figure>

<p>Check your model again. Horror! Again, merge vertices by distance, this solves most issues. Non-flat faces are simply fixed by selecting them (click on the “Non-Flat Faces button”) &amp; triangulating (“Ctrl+T”)</p>

<h2 id="boolean-union-cleaning-up-required">Boolean union: cleaning up required</h2>

<p>As we did before, we can add back a pointy bit by creating a separate object and merging it with a union boolean modifier.</p>

<p>However, I found that this operation often resulted in redundant geometry or faces, creating problems with the model. Sometimes cleaning up is as simple as automatic vertices merge, or deleting a few faces, but oftentimes simplifying the geometry manually is required.</p>

<p>Thankfully, at least when working with low-poly models, that’s not too hard. Let’s take the example below where we have a redundant vertex we want to remove.</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/cad/blender_too_complex.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/cad/blender_too_complex.png" alt="A (simple) example of redundant geometry automatically generated" />
  </a>
  <figcaption>A (simple) example of redundant geometry automatically generated
  
  </figcaption>
</figure>

<p>We could simply delete the vertex &amp; recreate the face from the vertices around, but it is usually less cumbersome to manuall merge the vertex with another one. Let’s say we need to merge it with the vertex at the lower left corner. We have to:</p>

<ol>
  <li>Select the destination vertex.</li>
  <li>Move the cursor there with Shift+S then 2 (“Set cursor to selected”).</li>
  <li>Select both vertices, press M to merge, and select “At cursor”.</li>
</ol>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/cad/blender_too_complex_simplified.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/cad/blender_too_complex_simplified.png" alt="Simplified geommetry after vertex merging at cursor" />
  </a>
  <figcaption>Simplified geommetry after vertex merging at cursor
  
  </figcaption>
</figure>

<p>Rince and repeat as necessary.</p>

<h2 id="separating-part-of-the-mesh-into-a-new-object">Separating part of the mesh into a new object</h2>

<p>One final thing I learned was while trying to edit the resulting form, specifically the pointy bit I had merged was too thin. If you’ve read my guidelines above, you know I should have restored a previous version and started from scratch but I persisted.</p>

<p>Notably, at one point it looked like this:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/cad/blender_oh_no.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/cad/blender_oh_no.png" alt="How to fix this mess?" />
  </a>
  <figcaption>How to fix this mess?
  
  </figcaption>
</figure>

<p>Everything we see here belongs to the same mesh. Must we merge all these vertices by hand? Thankfully, no. Instead, we can:</p>
<ol>
  <li>Select all faces from our disconnected pointy bit as seen above.</li>
  <li>Press P and use “Selection” to separate the bit into a separate mesh.</li>
  <li>Make both models solid by adding the missing faces.</li>
  <li>Use a Union boolean modifier again to merge the objects properly.</li>
</ol>

<p>Phew!</p>

<h2 id="the-results">The results</h2>

<p>I found that after a slight learning curve Blender was perfectly usable in this context, at least on low-poly models since much manual editing is required. It’s also entirely possible that there are more effective ways to do what I did. In any case, the software certainly went a long way since its early days, and I remember a very different experience with its UI years ago.</p>

<p>In the end, I created 3 new objects:</p>
<ul>
  <li>I made the pointy bit into its own tool to have two sides with different sizes.</li>
  <li>The key doesn’t need a pointy bit anymore, and it feels better in the hand like this.</li>
  <li>I created a saw that is somewhat good enough for cardboard, time will tell if it is really useful.</li>
</ul>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/cad/results.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/cad/results.jpg" alt="The final toolset" />
  </a>
  <figcaption>The final toolset
  
  </figcaption>
</figure>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/cad/in_action.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/cad/in_action.jpg" alt="Review process by the client" />
  </a>
  <figcaption>Review process by the client
  
  </figcaption>
</figure>

<p>The set can be found on <a href="https://www.printables.com/model/739295-cardboard-toolset">Printables</a>.</p>
<div class="footnotes" role="doc-endnotes">
  <ol>
    <li id="fn:clean-as-you-go" role="doc-endnote">
      <p>Channel your inner Irish mother: <a href="https://youtu.be/_yInR3ywVjk?t=31">Foil Arms and Hog on Youtube</a> <a href="#fnref:clean-as-you-go" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
  </ol>
</div>]]></content><author><name>Mathieu Favréaux</name></author><category term="3D&amp;#8209;print" /><category term="Blender" /><summary type="html"><![CDATA[A few tips & tricks on how to use blender effectively to produce valid STL files for 3D&#8209;printing that I learned while creating models for tools I want to give to my kids.]]></summary></entry><entry><title type="html">OVH apache logs fetch and analysis</title><link href="https://blog.mfavreaux.fr/apache-logs/" rel="alternate" type="text/html" title="OVH apache logs fetch and analysis" /><published>2023-08-28T00:00:00-05:00</published><updated>2023-08-28T00:00:00-05:00</updated><id>https://blog.mfavreaux.fr/apache-logs</id><content type="html" xml:base="https://blog.mfavreaux.fr/apache-logs/"><![CDATA[<p>TL;DR:</p>
<ul>
  <li>I created a simple tool to download the apache logs of a web-hosting OVH account available on <a href="https://github.com/qb1/ovhlogs">github</a>.</li>
  <li>I analyzed the logs of my low-traffic blog to reveal a more accurate count of total readers.</li>
</ul>

<p>As of 2023, this blog is hosted on a OVH web-hosting instance. This comes with simple analytics tools, which aren’t really satisfying: they do not successfully filter out all bot noise, and bogus malicious queries tend to drown out legitimate user traffic. Moreover, I do not use any JS analytics engine, as I want to keep this mostly tracking-free. As a result, it’s impossible to currently evaluate the readership, especially in a very low-volume website such as this one.</p>

<p>Because of this, I was drawn to taking a look at the raw Apache logs, and try to build a quick ad-hoc filter to get a more realistic estimate of the readership. This article is the result of this attempt.</p>

<h2 id="ovh-apache-logs">OVH apache logs</h2>

<p>OVH allows direct access to the hosting logs via its web interface. While this is a good starting point, there is no batch option - and there’s no way I’m manually triggering hundreds of downloads.</p>

<p>Fortunately, it’s easy to automate. A quick search didn’t reveal existing tooling for this specific use case, so let’s build our own.</p>

<p>The URL for a daily log looks like this:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>https://logs.clusterXXX.hosting.ovh.net/partiallogin.clusterXXX.hosting.ovh.net/logs/logs-08-2023/partiallogin.clusterXXX.hosting.ovh.net-26-08-2023.log.gz
</code></pre></div></div>

<p>The <code class="language-plaintext highlighter-rouge">partiallogin</code> appears to be similar to the FTP username, while <code class="language-plaintext highlighter-rouge">clusterXXX</code> is probably a physical instance somewhere. It’s apparently the only two parameters to locate the logs, along with the current date.</p>

<p>On the other hand, the current day’s partial log is not compressed and is stored in a different location:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>https://logs.clusterXXX.hosting.ovh.net/partiallogin.clusterXXX.hosting.ovh.net/osl/partiallogin.clusterXXX.hosting.ovh.net-27-08-2023.log
</code></pre></div></div>

<p>Finally, these URLs are protected behind a Basic HTTP auth. When using the web interface the mechanism is unclear - it seems like accessing the log site will generate a temporary access credential? In any case, the Web UI gives us the option to create a specific account for log viewing - this is a more secure way to access these.</p>

<p>I started experimenting in python, but in the end decided it would be a good way to start using some rust again and properly publish a tool others might genuinly find useful. The repo is available on <a href="https://github.com/qb1/ovhlogs">github</a>.</p>

<h2 id="using-existing-tools">Using existing tools</h2>

<p>There are multiple tools that we can feed these logs into. I tried two of them:</p>
<ul>
  <li><a href="https://awstats.sourceforge.io/">awstats</a></li>
  <li><a href="https://goaccess.io/">GoAccess</a></li>
</ul>

<p>Both provide a nice view into the daily activity and various reports, but it was obvious the noise from bots was still drowning actual user traffic, and I couldn’t trust the total visitor count to be an actual human count. Moreover, I couldn’t easily select a user session to verify it, follow it, see which pages were accessed, etc.</p>

<h2 id="custom-report">Custom report</h2>

<p>Instead I started filtering the logs manually. Removing most of the noise from bots is not too hard, as their user agent is pretty explicit. I assume the tools mentionned above do so as well.</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">bots_keys</span> <span class="o">=</span> <span class="p">[</span><span class="s">"bot"</span><span class="p">,</span> <span class="s">"spider"</span><span class="p">,</span> <span class="s">"crawler"</span><span class="p">,</span> <span class="s">"dataprovider"</span><span class="p">,</span> <span class="s">"anthropic-ai"</span><span class="p">,</span> <span class="s">"googleother"</span><span class="p">,</span> 
             <span class="s">"nbertaupete95"</span><span class="p">,</span> <span class="s">"github-camo"</span><span class="p">,</span> <span class="s">"facebookexternalhit"</span><span class="p">]</span>
</code></pre></div></div>

<p>Now, most of the noise came from multiple sources, mainly:</p>
<ul>
  <li>Obviously malicious queries such as queries ending in <code class="language-plaintext highlighter-rouge">?variables=complexquery</code>. These usually end up as 404, so they’re pretty easy to filter</li>
  <li>Regular accesses to <code class="language-plaintext highlighter-rouge">feed.xml</code> get a special mention - those get counted separately to figure out the RSS readers</li>
  <li>Access to key files, that tools or websites are likely to do themselves: <code class="language-plaintext highlighter-rouge">sitemap.xml</code>, favicons, the avatar, <code class="language-plaintext highlighter-rouge">.map</code> files, this kind of things.</li>
  <li>Accesses with, surprisingly, an empty User Agent.</li>
</ul>

<p>Moreover, strangely I had to ignore visitors doing only a single queries - I’ve seen what I assume are bots (but which don’t advertise themselves as such) slowly but surely scraping the site, one query after another, using different IPs, in the span of days. Very strange.</p>

<p>Finally, I found that quite a few visits did query the links from the main page but not their resources (article’s images, etc.). I’m not sure what this is but I suspect browsers preemptively query urls in various situations, so I don’t count them as a proper human visit either.</p>

<h2 id="final-results">Final results</h2>

<p>Once this is all filtered out, I can:</p>
<ul>
  <li>Look at the human-readable results and monitor individual visits to the website</li>
  <li>Pipe the filtered raw results into one of the tools above, and actually get meaningful reports:</li>
</ul>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/meta/logs-2023-08.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/meta/logs-2023-08.png" alt="Filtered report on daily activity since blog creation" />
  </a>
  <figcaption>Filtered report on daily activity since blog creation
  
  </figcaption>
</figure>

<p>It seems we’ve had about 100 readers so far. This sounds way more reasonable than the ~700 generally reported by GoAccess and others, even when ignoring bots crawlers as much as possible.</p>

<p>Note: if you’re curious you can find the resulting notebook (in a <code class="language-plaintext highlighter-rouge">.py</code> form) <a href="https://blog.mfavreaux.fr/assets/meta/analyze_logs.py">here</a> but be warned that it is very bespoke to this site, and probably not very reusable.</p>]]></content><author><name>Mathieu Favréaux</name></author><category term="ovh" /><category term="hosting" /><category term="logs" /><category term="python" /><category term="rust" /><summary type="html"><![CDATA[A bit of a meta entry where we build a tool to fetch OVH apache logs, analyze the blog's logs and filter them to get a more realistic user count.]]></summary></entry><entry><title type="html">MIDI to SN76489 to chip music, part 3: putting it all together</title><link href="https://blog.mfavreaux.fr/midi-to-sn76489-part3/" rel="alternate" type="text/html" title="MIDI to SN76489 to chip music, part 3: putting it all together" /><published>2023-03-02T00:00:00-06:00</published><updated>2023-03-02T00:00:00-06:00</updated><id>https://blog.mfavreaux.fr/midi-to-sn76489-part3</id><content type="html" xml:base="https://blog.mfavreaux.fr/midi-to-sn76489-part3/"><![CDATA[<p>This article is part 3 (see <a href="/midi-to-sn76489-part1/">part 1</a>, <a href="/midi-to-sn76489-part1b/">part 1-B</a>, <a href="/midi-to-sn76489-part2/">part 2</a>) in a series were we try to build a MIDI instrument from a bunch of <a href="https://en.wikipedia.org/wiki/Texas_Instruments_SN76489">SN76489</a>s, which is the sound chip used in the Sega Game Gear, the BBC Micro, the Neo Geo Pocket and <a href="https://en.wikipedia.org/wiki/Texas_Instruments_SN76489#Usage">quite a few others</a>.</p>

<p>It is time to make our instrument a bit more permanent than letting it sit on a breadboard. Moreover, I want to max out the Arduino’s pins and connect it to 4 chips together.</p>

<p>The latter is rather trivial to do: the next 3 chips can share most of the Arduino’s output pins already used for the first one. The only pin that must be separately controlled is <span style="text-decoration:overline"><code class="language-plaintext highlighter-rouge">CE</code></span> (Chip Enable): by pulling only one to true at a time, we can make sure only one chip listens to its input at any given time. Alternatively, we can also pull them all to true to send the same command to all 4 chips in one go, for instance to quickly turn them off.</p>

<p>I did a layout on paper which has since been lost to time, dusted off my cheapo soldering iron and went on for a long and quiet evening:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/4-chips-top.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/4-chips-top.jpg" alt="4 chips on a protoboard with an Arduino" />
  </a>
  <figcaption>4 chips on a protoboard with an Arduino
  
  </figcaption>
</figure>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/bad-soldering.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/bad-soldering.jpg" alt="Nightmarish soldering" />
  </a>
  <figcaption>Nightmarish soldering
  
  </figcaption>
</figure>

<p>Please disregard the sub-optimal soldering job I did there. Note I used 30 AWG (0.25 mm) wire to solder the common data pins, otherwise I don’t see how I could have crammed it all to the same small protoboard. I opted for regular wire for the rest: first, to make it easier to distinguish what is going on; second, so there isn’t too much resistance for the <code class="language-plaintext highlighter-rouge">Vcc</code> and ground; finally and most importantly, because the thin wires are very easy to break.</p>

<h2 id="designing-the-mixing-circuit">Designing the mixing circuit</h2>

<p>Now that we have 4 chips we have 4 outputs, and we need a way to mix them together. Since the signal is a variation of voltage, what we need is effectively a voltage adder.</p>

<p>The simplest circuit we could use is a passive resistor network, where the output voltage <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>V</mi><mi>o</mi></msub></mrow><annotation encoding="application/x-tex">V_o</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">o</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> is composed of equal proportions of the input voltages <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>V</mi><mrow><mi>i</mi><mi>x</mi></mrow></msub></mrow><annotation encoding="application/x-tex">V_{ix}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3117em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">i</span><span class="mord mathnormal mtight">x</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>. For N inputs, all connected to the same resistance value <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>R</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">R_i</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3117em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>, we have:</p>

<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi>V</mi><mi>o</mi></msub><mo>=</mo><mfrac><mrow><msub><mi>V</mi><mrow><mi>i</mi><mn>1</mn></mrow></msub><msub><mi>R</mi><mi>i</mi></msub></mrow><mrow><mi>N</mi><msub><mi>R</mi><mi>i</mi></msub></mrow></mfrac><mo>=</mo><mfrac><msub><mi>V</mi><mrow><mi>i</mi><mn>1</mn></mrow></msub><mi>N</mi></mfrac></mrow><annotation encoding="application/x-tex">V_o = { V_{i1} R_i \over {N R_i} } = { V_{i1} \over {N} }</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">o</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:2.1963em;vertical-align:-0.836em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3603em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3117em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3117em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">i</span><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3117em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.836em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:2.0463em;vertical-align:-0.686em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3603em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.10903em;">N</span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3117em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">i</span><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.686em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></span></span>

<p>This works well enough for testing purposes, however I see two issues:</p>
<ol>
  <li>Obviously, the voltage of each input to our mixing circuit is divided by the number of inputs, so this will require more amplification on the output which will generate unnecessary noise.</li>
  <li>This provides the same impedance on the input &amp; output side. My crude understanding here is that we want stages to be high-enough input impedance (so as not to require too much power from the previous stage, in our case the TI chips) and low output impedance (so we can drive lowish impedance loads if necessary).</li>
</ol>

<p>The solution I settled on is, again, certainly very obvious to anyone with any knowledge of electronics - I used an active mixing circuit based on operational amplifiers.</p>

<p>In theory it looks like this:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/mixer-schematic.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/mixer-schematic.png" alt="Schematic of a voltage adder" />
  </a>
  <figcaption>Schematic of a voltage adder
  
  </figcaption>
</figure>

<p>I’m not going to go over the usage of an op-amp here, because there are many resources on the subject. The important points here are:</p>

<ul>
  <li>The op-amp inputs sink virtually no current.</li>
  <li>The op-amp will keep both of its inputs at the same voltage, as long as possible, by varying the voltage on its output.</li>
  <li>This makes our inverting input a virtual ground (albeit one that sits at 2.5V, because I don’t have a negative rail so I want my signal to oscillate around mid-voltage, not 0V). Because of this:
    <ul>
      <li>The resistor network to the left does not act as a voltage divider anymore.</li>
      <li>On the other hand, there is a voltage divider between each input and the resistor across the op-amp, and since both <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>R</mi><mi>i</mi></mrow><annotation encoding="application/x-tex">Ri</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="mord mathnormal">i</span></span></span></span> and <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>R</mi><mn>3</mn></mrow><annotation encoding="application/x-tex">R3</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="mord">3</span></span></span></span> are identical, <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>V</mi><mn>1</mn></msub><mo>=</mo><mo>−</mo><msub><mi>V</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">V_1 = -V_i</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord">−</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3117em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> (again, not really, it’s actually mirrored around 2.5V, stay with me here). Note we could vary the resistor values to multiply the voltage by a different factor than 1.</li>
    </ul>
  </li>
</ul>

<p>On the impedance side of things<sup id="fnref:opamp-imp" role="doc-noteref"><a href="#fn:opamp-imp" class="footnote" rel="footnote">1</a></sup>, I think we have an input impedance of <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>R</mi><mrow><mi>i</mi><mi>n</mi></mrow></msub><mo>=</mo><msub><mi>R</mi><mn>1</mn></msub></mrow><annotation encoding="application/x-tex">R_{in} = R_1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3117em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">in</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> and and an output <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>R</mi><mrow><mi>o</mi><mi>u</mi><mi>t</mi></mrow></msub><mo>=</mo><msub><mi>R</mi><mrow><mi>o</mi><mi>p</mi><mo>−</mo><mi>o</mi><mi>u</mi><mi>t</mi></mrow></msub><mo>=</mo><mn>125</mn><mi mathvariant="normal">Ω</mi></mrow><annotation encoding="application/x-tex">R_{out} = R_{op-out} = 125\Omega</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.2806em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">o</span><span class="mord mathnormal mtight">u</span><span class="mord mathnormal mtight">t</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.9694em;vertical-align:-0.2861em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.2806em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">o</span><span class="mord mathnormal mtight">p</span><span class="mbin mtight">−</span><span class="mord mathnormal mtight">o</span><span class="mord mathnormal mtight">u</span><span class="mord mathnormal mtight">t</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.2861em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord">125Ω</span></span></span></span><sup id="fnref:out-imp" role="doc-noteref"><a href="#fn:out-imp" class="footnote" rel="footnote">2</a></sup>.</p>

<h2 id="building-the-circuit">Building the circuit</h2>

<p>Now that we have our circuit in theory, we can start testing it on the breadboard.</p>

<h3 id="a-bit-about-tooling">A bit about tooling</h3>

<p>When I started experimenting a bit on the breadboard, I realized how absolutely necessary it is to be able to measure things up, otherwise you’re just shooting in the dark. As a complete beginner I lacked all basic equipment: all I had was a multimeter.</p>

<p>Still I couldn’t justify to invest too much at this stage, so I bought an <a href="https://espotek.com/labrador/">EspoTek board</a>:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/espotek.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/espotek.jpg" alt="The EspoTek Labrador: a small all-in-one lab" />
  </a>
  <figcaption>The EspoTek Labrador: a small all-in-one lab
  
  </figcaption>
</figure>

<p>We already used it in back <a href="/midi-to-sn76489-part1b/">part 1-B</a> of this series to do various measurements. It provides a variable voltage source, a signal generator and a digital oscilloscope all in one single board. Of course, due to its accessible price, it comes with significant compromises:</p>

<ul>
  <li>The voltage source cannot source a lot of current — still, it was enough for my needs.</li>
  <li>The oscilloscope’s measured frequency ceiling is the in hundreds of Khz — again, enough for measuring sound frequencies.</li>
  <li>The voltage resolution is quite poor, even if you can effectively double it up by cheating a little bit. I think this is the most problematic item on the list, and one that will probably justify going with more expensive equipment in the future.</li>
</ul>

<h3 id="noise-noise-and-more-noise">Noise, noise and more noise</h3>

<p>During testing, I realized how much noise there was on my chip’s outputs. It was so loud I was afraid it was going to make the whole thing unusable for actual recordings. Unfortunately, looking at the signal didn’t really make obvious what the frequency was, nor did poking around reveal the source.</p>

<p>So I tried to make a filter to block it out: I tried simple RC filters and made multiple unfruitful attempts. Then I started trying semi-random things, and of course nothing worked until magically, putting a small cap on the op-amp’s feedback significantly reduced the noise. Hurray! Not the most formal approach, but hey it worked.</p>

<p>Still, it’s not all gone. Connecting that thing to my desktop results in a different, but again very present noise. For this reason, I’m quite sure the source of the noise was and still is the power supply: the chips are getting their juice from the Arduino, which is itself powered from USB… And if you look closely (not), you may notice a <em>subtle</em> bit of hot glue. What?</p>

<p>Well, the micro USB connector on these Arduino clone boards is absolute garbage, and despite my carefulness, broke loose after about 3 manipulations. What you see is my heavy-handed attempt at securing the even worse repair job I did by soldering a USB cable’s wire directly to the surface-mounted component next to the connector. However, in my desperate surgery, I had to solder <em>after</em> the component - I believe I may have bypassed some crucial filtering there… I could always replace the Arduino, but hey, where’s the fun in that.</p>

<p>In the meantime, any proper recording from this finished instrument will have to be made from my laptop where the USB bus is very quiet to get a nice and quiet recording.</p>

<h3 id="keeping-options-open">Keeping options open</h3>

<p>Now let’s skip the various other digressions that I went through<sup id="fnref:digression-pedal" role="doc-noteref"><a href="#fn:digression-pedal" class="footnote" rel="footnote">3</a></sup>, and jump straight to the end. This is what the final circuit looks like:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/mixer-schematic-full.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/mixer-schematic-full.png" alt="The mixer's schematic" />
  </a>
  <figcaption>The mixer's schematic
  
  </figcaption>
</figure>

<p>Note there are 2 outputs, and more than 4 inputs in total. The reason for this is that I wanted to keep a bit of adaptability: I have an external sound card that can capture two inputs, so maybe I’ll apply different filters to different voices in the DAW. But I’m not sure which voice I want to send to either output: do I want 1 chip optimized for bass sounds and the rest flat? Do I want two chips with reverb and two without? Do I want simple left / right channels? With the configuration above, I can do 4/0, 3/1 or 2/2, so I’ve got all the options covered.</p>

<p>Here is what it looks like now:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/mixer-protoboard.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/mixer-protoboard.jpg" alt="The mixer soldered on a protoboard" />
  </a>
  <figcaption>The mixer soldered on a protoboard
  
  </figcaption>
</figure>

<h2 id="putting-it-all-in-a-box">Putting it all in a box</h2>

<p>Nothing fancy here — I grabbed a cheapo plastic electrical box, a few spacers, some black paint and forgot that varnish was even a thing. I drilled a few holes and voilà:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/box-open.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/box-open.jpg" alt="The final box open" />
  </a>
  <figcaption>The final box open
  
  </figcaption>
</figure>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/box-closed.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/box-closed.jpg" alt="The final box closed" />
  </a>
  <figcaption>The final box closed
  
  </figcaption>
</figure>

<p>I don’t care, I absolutely love it. Beauty is in the eye of the beholder.</p>

<p>… OK but now what? We’re done?</p>

<h2 id="the-quest-for-color">The quest for color</h2>

<p>Oh no we aren’t, because now we can sorta make chip music with it! And I’m really keen on experimenting with what sort of sounds we can get out of this thing. That also means improving the software in the Arduino following what we need.</p>

<p>I’ve said it before, I have no illusion about my composing skills. Besides, I want to focus on testing and playing with the instrument, and the frustration of (failing at) trying to compose a track would just get in the way.</p>

<p>For this reason, I started working on covering tracks I loved (or should we call that “porting”?), and I had to implement the following:</p>

<h3 id="fast-arpeggios">Fast arpeggios</h3>

<p>This is the definitive signature sound of chip music: instead of playing chords, which require many simultaneous voices, we play the chord’s notes sequentially, on a single voice, very fast. This provides harmony at no cost.</p>

<p>They sound like this:</p>

<figure>
  <audio controls="" ref="An example of fast arpeggios." src="https://blog.mfavreaux.fr/assets/sn76489/audio/BlogSoundExamples1.mp3">
    Your browser does not support the audio tag."
  </audio>
  <figcaption>An example of fast arpeggios.
  
  </figcaption>
</figure>

<p>And I have found them sometimes used to provide some rythmic background as well:</p>

<figure>
  <audio controls="" ref="Fast arpeggios as rythmic element." src="https://blog.mfavreaux.fr/assets/sn76489/audio/BlogSoundExamples2.mp3">
    Your browser does not support the audio tag."
  </audio>
  <figcaption>Fast arpeggios as rythmic element.
  
  </figcaption>
</figure>

<p>I didn’t have to do anything to implement arpeggios as Bitwig supports them already (and keeps them correctly in tempo).</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/bitwig-arpeggiator.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/bitwig-arpeggiator.png" alt="The arpeggiator in Bitwig" />
  </a>
  <figcaption>The arpeggiator in Bitwig
  
  </figcaption>
</figure>

<h3 id="vibrato">Vibrato</h3>

<p>Vibrato is a small variation in the note’s pitch, like on a violin. This is a cheap way to bring expression. I sneaked an example in the previous’ article:</p>

<figure>
  <audio controls="" ref="An example of vibrato." src="https://blog.mfavreaux.fr/assets/sn76489/audio/BlogSoundExamples3.mp3">
    Your browser does not support the audio tag."
  </audio>
  <figcaption>An example of vibrato.
  
  </figcaption>
</figure>

<p>And it’s easy enough to implement: just vary the channel frequency of a small percentage towards the next or previous note. We control this variation with a dedicated MIDI channel.</p>

<p>Careful readers will remember that we have little precision on high notes: the vibrato won’t work well (or at all) there.</p>

<h3 id="tremolo">Tremolo</h3>

<p>On the other hand, we can vary the channel’s volume to bring a similar type of expression. Similar implementation, and it sounds like this:</p>

<figure>
  <audio controls="" ref="An example of tremolo." src="https://blog.mfavreaux.fr/assets/sn76489/audio/BlogSoundExamples4.mp3">
    Your browser does not support the audio tag."
  </audio>
  <figcaption>An example of tremolo.
  
  </figcaption>
</figure>

<p>Interestingly, I found that introducing a fast tremolo also provided some texture to the voice, almost like distortion, which I quite liked in certain situations:</p>

<figure>
  <audio controls="" ref="An example of fast tremolo bringing distortion." src="https://blog.mfavreaux.fr/assets/sn76489/audio/BlogSoundExamples5.mp3">
    Your browser does not support the audio tag."
  </audio>
  <figcaption>An example of fast tremolo bringing distortion.
  
  </figcaption>
</figure>

<h3 id="portamento">Portamento</h3>

<p>Finally, the portamento is a glissando from one note to another. It’s generally triggered in MIDI by starting the next note prior to releasing the previous one (similarly for legato), and the glissando speed is controlled by a separate MIDI channel.</p>

<figure>
  <audio controls="" ref="An example of portamento." src="https://blog.mfavreaux.fr/assets/sn76489/audio/BlogSoundExamples6.mp3">
    Your browser does not support the audio tag."
  </audio>
  <figcaption>An example of portamento.
  
  </figcaption>
</figure>

<h3 id="putting-it-all-together">Putting it all together</h3>

<p>Here is a typical screen of Bitwig:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/bitwig-full-voices.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/bitwig-full-voices.png" alt="Typical screen in Bitwig with all 8 voices used" />
  </a>
  <figcaption>Typical screen in Bitwig with all 8 voices used
  
  </figcaption>
</figure>

<p>With 4 chips, I have quite a few voices at my disposal. In my typical setup, I ended up mirroring voices on the left &amp; right channels, allowing for some stereo separation, that I mixed it a bit more in the center in Bitwig so it’s not 100% left or 100% right. On each side, I get:</p>
<ul>
  <li>1 polyphonic channel with up to 2 voices (so I can play 2 notes at the same time).</li>
  <li>2 monophonic channel2 which I can use for simple voices or arpeggios.</li>
  <li>1 polyphonic drum channel with up to 2 voices, and each drum voice also eats up 1 regular oscillator voice as we’ve seen before.</li>
</ul>

<p>That’s a total of 8 oscillator voices &amp; 4 drums simultaneously. It is really cheating at this point, compared to what these chips are originally intended for. But it’s plenty of fun!</p>

<h2 id="conclusion">Conclusion</h2>

<p>So far I ported 3 tracks, and it was a really interesting exercise. You can find them on <a href="https://qbimusic.bandcamp.com/album/squared-ep">Bandcamp</a> or in the embedded player below. Maybe I’ll port other tracks if I feel like it, but no constraints.</p>

<p align="center">
<iframe style="border: 0; width: 400px; height: 241px;" src="https://bandcamp.com/EmbeddedPlayer/album=58418419/size=large/bgcol=ffffff/linkcol=e99708/artwork=small/transparent=true/" seamless=""><a href="https://qbimusic.bandcamp.com/album/squared-ep">Squared by qbi</a></iframe>
</p>

<p>And with this, our little series ends! We dabbed in electronics, theory and practice, and also into chip music &amp; DAWs! It was quite a fun project, that lasted for more than a year.</p>
<div class="footnotes" role="doc-endnotes">
  <ol>
    <li id="fn:opamp-imp" role="doc-endnote">
      <p><a href="http://www.ittc.ku.edu/~jstiles/412/handouts/2.2%20The%20Inverting%20Configuration/Ri%20and%20Ro%20of%20the%20Inverting%20Amplifier%20lecture.pdf">Rin and Rout of the Inverting Amplifier</a> — Jim Stiles from the University of Kansas. <a href="#fnref:opamp-imp" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:out-imp" role="doc-endnote">
      <p><a href="https://www.ti.com/lit/ds/symlink/tl072h.pdf?ts=1661158060675">TL072 datasheet</a> lists the open-loop output impedance page 18 — I’m not 100% sure this is exactly what we would measure <em>in-situ</em> since we are sourcing current. <a href="#fnref:out-imp" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:digression-pedal" role="doc-endnote">
      <p>Such as playing with diodes to make the signal clip like a guitar pedal - very fun, A+++ would do again. <a href="#fnref:digression-pedal" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
  </ol>
</div>]]></content><author><name>Mathieu Favréaux</name></author><category term="sn76489" /><category term="electronics" /><summary type="html"><![CDATA[It is now time to take this project to the next level: soldering 4 chips to a protoboard, adding an Arduino, a mixing circuit, putting it all into a box, and making music! Finally!.]]></summary></entry><entry><title type="html">MIDI to SN76489 to chip music, part 2: from noise to music</title><link href="https://blog.mfavreaux.fr/midi-to-sn76489-part2/" rel="alternate" type="text/html" title="MIDI to SN76489 to chip music, part 2: from noise to music" /><published>2022-08-24T00:00:00-05:00</published><updated>2022-08-24T00:00:00-05:00</updated><id>https://blog.mfavreaux.fr/midi-to-sn76489-part2</id><content type="html" xml:base="https://blog.mfavreaux.fr/midi-to-sn76489-part2/"><![CDATA[<p>This article is part 2 (see <a href="/midi-to-sn76489-part1/">part 1</a>, <a href="/midi-to-sn76489-part1b/">part 1-B</a>, then <a href="/midi-to-sn76489-part3/">part 3</a>) in a series were we try to build a MIDI instrument from a bunch of <a href="https://en.wikipedia.org/wiki/Texas_Instruments_SN76489">SN76489</a>s, which is the sound chip used in the Sega Game Gear, the BBC Micro, the Neo Geo Pocket and <a href="https://en.wikipedia.org/wiki/Texas_Instruments_SN76489#Usage">quite a few others</a>.</p>

<p>At this point in the project, we have reliable communication with one SN76489 chip on the breadboard and some form of sound output. In this article, we’ll make it play its first note, control it from a computer, and start improving its musicality.</p>

<h2 id="playing-notes">Playing notes</h2>

<p>First we need to solve a detail we’ve overlooked in part 1: how do we specify a note’s pitch?</p>

<p>According to the <a href="https://ftp.whtech.com/datasheets%20and%20manuals/Datasheets%20-%20TI/SN76489.pdf">specification</a>, we must send a 10-bit number to set the frequency. That number won’t be in hertz, but rather a division of the input clock: with <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>N</mi></mrow><annotation encoding="application/x-tex">N</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span></span></span></span> the clock’s frequency, <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi></mrow><annotation encoding="application/x-tex">n</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.4306em;"></span><span class="mord mathnormal">n</span></span></span></span> the 10-bit number passed as “Tone frequency” and <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>f</mi></mrow><annotation encoding="application/x-tex">f</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span></span></span></span> the resulting note’s frequency, we have:</p>

<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>f</mi><mo>=</mo><mfrac><mi>N</mi><mrow><mn>32</mn><mi>n</mi></mrow></mfrac></mrow><annotation encoding="application/x-tex">f = { N \over 32 n }</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:2.0463em;vertical-align:-0.686em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3603em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">32</span><span class="mord mathnormal">n</span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.10903em;">N</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.686em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></span></span>

<p>This <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi></mrow><annotation encoding="application/x-tex">n</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.4306em;"></span><span class="mord mathnormal">n</span></span></span></span> being limited to 10 bits means there is a limited range of frequency that will be available to us, and for two reasons:</p>
<ul>
  <li>First, the ratio between lowest and highest frequency will be 1023</li>
  <li>Second, in the low <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi></mrow><annotation encoding="application/x-tex">n</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.4306em;"></span><span class="mord mathnormal">n</span></span></span></span> region (higher frequencies), the jump between 2 consecutive <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi></mrow><annotation encoding="application/x-tex">n</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.4306em;"></span><span class="mord mathnormal">n</span></span></span></span> values will result in huge jumps in resulting frequencies, making it hard to get a precise pitch. The higher the note, the bigger the step, the more out-of-tune it will be.</li>
</ul>

<p>To find a good balance, let’s calculate the target <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi></mrow><annotation encoding="application/x-tex">n</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.4306em;"></span><span class="mord mathnormal">n</span></span></span></span> for the entire MIDI notes range. Moreover, we need a measure how out-of-tune notes are. For this, we’ll calculate the error the rounding of <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi></mrow><annotation encoding="application/x-tex">n</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.4306em;"></span><span class="mord mathnormal">n</span></span></span></span> produces by comparing the error in the obtained frequency with the step in frequency from the previous semi-tone.</p>

<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>E</mi><mi>r</mi><mi>r</mi><mi>o</mi><mi>r</mi><mo>=</mo><mfrac><mrow><mi>a</mi><mi>b</mi><mi>s</mi><mo stretchy="false">(</mo><msub><mi>f</mi><mrow><mi>o</mi><mi>b</mi><mi>t</mi><mi>a</mi><mi>i</mi><mi>n</mi><mi>e</mi><mi>d</mi></mrow></msub><mo>−</mo><msub><mi>f</mi><mrow><mi>t</mi><mi>a</mi><mi>r</mi><mi>g</mi><mi>e</mi><mi>t</mi></mrow></msub><mo stretchy="false">)</mo></mrow><mrow><mi>a</mi><mi>b</mi><mi>s</mi><mo stretchy="false">(</mo><msub><mi>f</mi><mrow><mi>p</mi><mi>r</mi><mi>e</mi><mi>v</mi><mi>s</mi><mi>e</mi><mi>m</mi><mi>i</mi><mi>t</mi><mi>o</mi><mi>n</mi><mi>e</mi></mrow></msub><mo>−</mo><msub><mi>f</mi><mrow><mi>t</mi><mi>a</mi><mi>r</mi><mi>g</mi><mi>e</mi><mi>t</mi></mrow></msub><mo stretchy="false">)</mo></mrow></mfrac></mrow><annotation encoding="application/x-tex">Error = { { abs(f_{obtained} - f_{target}) } \over { abs(f_{prevsemitone} - f_{target}) } }</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord mathnormal" style="margin-right:0.05764em;">E</span><span class="mord mathnormal" style="margin-right:0.02778em;">rror</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:2.3991em;vertical-align:-0.9721em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.427em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathnormal">ab</span><span class="mord mathnormal">s</span><span class="mopen">(</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3117em;"><span style="top:-2.55em;margin-left:-0.1076em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">p</span><span class="mord mathnormal mtight">re</span><span class="mord mathnormal mtight" style="margin-right:0.03588em;">v</span><span class="mord mathnormal mtight">se</span><span class="mord mathnormal mtight">mi</span><span class="mord mathnormal mtight">t</span><span class="mord mathnormal mtight">o</span><span class="mord mathnormal mtight">n</span><span class="mord mathnormal mtight">e</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.2861em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.2806em;"><span style="top:-2.55em;margin-left:-0.1076em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">t</span><span class="mord mathnormal mtight">a</span><span class="mord mathnormal mtight" style="margin-right:0.02778em;">r</span><span class="mord mathnormal mtight" style="margin-right:0.03588em;">g</span><span class="mord mathnormal mtight">e</span><span class="mord mathnormal mtight">t</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.2861em;"><span></span></span></span></span></span></span><span class="mclose">)</span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathnormal">ab</span><span class="mord mathnormal">s</span><span class="mopen">(</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.1076em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">o</span><span class="mord mathnormal mtight">b</span><span class="mord mathnormal mtight">t</span><span class="mord mathnormal mtight">ain</span><span class="mord mathnormal mtight">e</span><span class="mord mathnormal mtight">d</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.2806em;"><span style="top:-2.55em;margin-left:-0.1076em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">t</span><span class="mord mathnormal mtight">a</span><span class="mord mathnormal mtight" style="margin-right:0.02778em;">r</span><span class="mord mathnormal mtight" style="margin-right:0.03588em;">g</span><span class="mord mathnormal mtight">e</span><span class="mord mathnormal mtight">t</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.2861em;"><span></span></span></span></span></span></span><span class="mclose">)</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.9721em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></span></span>

<p>Remember that in part 1, we assumed the maximum possible clock frequency for the chip, at 4 Mhz. Let’s start from this clock value and see what we get:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/notes-precision.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/notes-precision.png" alt="Note frequencies obtained with n parameter and clock at 4&nbsp;MHz, with error as fraction of a local semitone" />
  </a>
  <figcaption>Note frequencies obtained with n parameter and clock at 4&nbsp;MHz, with error as fraction of a local semitone
  
  </figcaption>
</figure>

<p>This graph outlines the 3 regions we mentionned:</p>
<ul>
  <li>To the left, the innaccessible low notes where <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi><mo>&gt;</mo><mn>1023</mn></mrow><annotation encoding="application/x-tex">n &gt; 1023</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.5782em;vertical-align:-0.0391em;"></span><span class="mord mathnormal">n</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">&gt;</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.6444em;"></span><span class="mord">1023</span></span></span></span>. The error on the frequency is of course huge.</li>
  <li>In the middle, the valid range with an acceptable error. I arbitrarily set the threshold to 10% of a semitone.</li>
  <li>To the right, the out-of-tune higher pitches. Even though the frequency error is barely visible on the blue frequency curve, the bottom graph shows that it is very hearable.</li>
</ul>

<p>This balance is not good, because B2 being our lowest note is not very satisfying — going lower would provide much nicer bass sounds. However, if we reach the lowest possible MIDI notes, then the precision error creeps very quickly at ranges we definitely want to use! This 10-bit precision is not very good, and it seems other chips do better in that regard: the <a href="https://en.wikipedia.org/wiki/General_Instrument_AY-3-8910">AY-3-8910</a> is a very similar chip, but has a 12-bit divider.</p>

<p>In the end, I settled on E1 being my lowest note. Highs get a little out of tune but that’s bearable. We reach this by applying using a timer step of 5, giving us a clock frequency of 1.33 MHz.</p>

<p>Here are the error graphs for the initial 4 MHz situation, the corrected 1.33 MHz clock, and a 4 MHz but with 12 bits of precision of the AY-3-8910 which we wish we got:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/notes-precision-comparison.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/notes-precision-comparison.png" alt="Comparison of frequency error in 3 situations &mdash; middle is our pick" />
  </a>
  <figcaption>Comparison of frequency error in 3 situations &mdash; middle is our pick
  
  </figcaption>
</figure>

<p>In the middle graph, we see we get about 4 usable octaves, starting in the middle of octave 1 up to the middle of octave 5. Starting octave 4, it will start to sound a tad out of tune, but that should be acceptable.</p>

<h2 id="setting-up-midi">Setting up MIDI</h2>

<p>The simplest way to go about controlling this from a computer is to use the <a href="https://en.wikipedia.org/wiki/MIDI">MIDI protocol</a>.</p>

<h3 id="what-is-midi">What is MIDI</h3>

<p>You’ve probably heard about MIDI at least in the form of <code class="language-plaintext highlighter-rouge">.mid</code> files: lightweight files that can be played, and the ouptut is often a very computer-y sound, but quite comprehensive with various instruments available. If you’re old enough, you might even fondly remember the good old <a href="https://archive.org/details/TripThroughTheGrandCanyoncanyon.mid">🎵 Canyon.mid</a>!</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/canyon.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/canyon.png" alt="Canyon.mid playing on Windows 3.1's media player" />
  </a>
  <figcaption>Canyon.mid playing on Windows 3.1's media player
  
  </figcaption>
</figure>

<p>These <code class="language-plaintext highlighter-rouge">.mid</code> files contain MIDI commands such as notes with pitches for instruments, or modulation values. The instrument “patches” (instrument sets) are standardized, and nowadays every system under the sun can generate the appropriate sound for these commands.</p>

<p>These files are now a bit obsolete, because size &amp; compute power is not an issue anymore. However, the protocol itself was initially designed to communicate with external instruments, and that’s where it still lives and thrives.</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/midi-connector.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/midi-connector.jpg" alt="Typical connectors on digital keyboards &mdash; notice the MIDI In &amp; Out DIN 5 connectors" />
  </a>
  <figcaption>Typical connectors on digital keyboards &mdash; notice the MIDI In &amp; Out DIN 5 connectors
  
  </figcaption>
</figure>

<p>The protocol even got updated recently with new additions such as MPE (midi polyphonic expression) that basically allows more control over individual notes. You can see an example of <a href="https://www.youtube.com/watch?v=bUYsfITLir8">Jordan Rudess demoing such a keyboard</a>. I especially love how the vibrato works on this.</p>

<h3 id="midi-with-arduino">MIDI with Arduino</h3>

<p>MIDI is well-supported in the Arduino environment, either through the usual MIDI serial connection or via its more modern USB layer. Because I don’t have a USB-MIDI adapter, we’ll go for the USB solution with the library <code class="language-plaintext highlighter-rouge">MIDIUSB</code>.</p>

<p>This library does not work on my old trusty Arduino Duelaminove, because it requires control over the actual USB connection (whereas mine is using a USB-serial chip). Instead, we can use an Arduino Micro or one of its clones.</p>

<p>Receiving MIDI events over USB is incredibly easy to setup, with the basic skeleton looking as follows:</p>

<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp">#include</span> <span class="cpf">&lt;Arduino.h&gt;</span><span class="cp">
#include</span> <span class="cpf">"MIDIUSB.h"</span><span class="cp">
</span>
<span class="kt">void</span> <span class="nf">setup</span> <span class="p">()</span> <span class="p">{}</span>

<span class="kt">void</span> <span class="nf">loop</span><span class="p">()</span> <span class="p">{</span>
  <span class="n">midiEventPacket_t</span> <span class="n">rx</span> <span class="o">=</span> <span class="n">MidiUSB</span><span class="p">.</span><span class="n">read</span><span class="p">();</span>

  <span class="k">switch</span> <span class="p">(</span><span class="n">rx</span><span class="p">.</span><span class="n">header</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">case</span> <span class="mi">0</span><span class="p">:</span>
      <span class="k">break</span><span class="p">;</span> <span class="c1">//No pending events</span>

    <span class="k">case</span> <span class="mh">0x9</span><span class="p">:</span>
      <span class="n">noteOn</span><span class="p">(</span>
        <span class="n">rx</span><span class="p">.</span><span class="n">byte1</span> <span class="o">&amp;</span> <span class="mh">0xF</span><span class="p">,</span>  <span class="c1">//channel</span>
        <span class="n">rx</span><span class="p">.</span><span class="n">byte2</span><span class="p">,</span>        <span class="c1">//pitch</span>
        <span class="n">rx</span><span class="p">.</span><span class="n">byte3</span>         <span class="c1">//velocity</span>
      <span class="p">);</span>
      <span class="k">break</span><span class="p">;</span>

    <span class="c1">// [...]</span>
  <span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Note how the library is rather low level when it comes to the protocol itself: you have to know byte values and how to extract the message’s content. In reality, there aren’t that many different types of messages, and you can use the <a href="https://www.midi.org/specifications-old/item/table-1-summary-of-midi-message">MIDI 1.0 specifications</a> for that.</p>

<p>The next step is to connect these <code class="language-plaintext highlighter-rouge">noteOn</code> and <code class="language-plaintext highlighter-rouge">noteOff</code> functions to the proper output for our SN76489 chip. MIDI provides up to 15 independent channels, so we can easily control our 3 square oscillators separately.</p>

<p>An now we can connect the thing to your computer, fire up <a href="https://vmpk.sourceforge.io/">VMPK</a>, and you can test individual channels &amp; notes.</p>

<p>At the risk of making this section read a bit like “draw the rest of the owl”, I won’t get into much more details about the plumbing because it is not that interesting to talk about. In any case, the code is in a public repo at <a href="https://github.com/qb1/midi2sn76489">midi2sn76489</a>. Note that at some point in the project I switched over to <a href="https://docs.platformio.org/en/stable/integration/ide/vscode.html">PlatformIO</a> for VSCode, because I don’t really like the vanilla Arduino environment for more than trivial sketches.</p>

<h3 id="a-first-tune">A first tune</h3>

<p>For the demonstration here, I use a simple setup where <code class="language-plaintext highlighter-rouge">aplaymidi</code> will ouptut the commands from a <code class="language-plaintext highlighter-rouge">.mid</code> file to the MIDI hardware:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">&gt;</span> aplaymidi <span class="nt">-l</span>
 Port    Client name                      Port name
 14:0    Midi Through                     Midi Through Port-0
 24:0    SparkFun Pro Micro               SparkFun Pro Micro MIDI 1
128:0    VMPK Input                       <span class="k">in</span>
<span class="o">&gt;</span> aplaymidi <span class="nt">-p</span> 24:0 totoro.mid
</code></pre></div></div>

<p>And the output sounds like this:</p>

<figure>
  <audio controls="" ref="Our first real tune output." src="https://blog.mfavreaux.fr/assets/sn76489/audio/3osc-totoro.mp3">
    Your browser does not support the audio tag."
  </audio>
  <figcaption>Our first real tune output.
  
  Source: <a href="http://www.midishrine.com/index.php?id=172">My Neighbour Totoro &mdash; Stroll</a>
  
  </figcaption>
</figure>

<p>That’s one heck of a milestone!</p>

<h2 id="envelope">Envelope</h2>

<p>Now that we can play notes, the next step we can take to make it sound a bit more natural is to implement an envelope. This is to mimic real-world sounds, where the amplitude (volume) is not constant for the whole note’s duration.</p>

<h3 id="adsr">ADSR</h3>

<p>A commonly found envelope model is ADSR for Attack, Decay, Sustain, Release:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/adsr-parameter.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/adsr-parameter.png" alt="ADSR envelope: note's amplitude vs time." />
  </a>
  <figcaption>ADSR envelope: note's amplitude vs time.
  
  Source: <a href="https://commons.wikimedia.org/wiki/File:ADSR_parameter.svg">Wikipedia</a>
  
  </figcaption>
</figure>

<p>Sustain is measured as a fraction of the amplitude, while the other parameters are time based.</p>

<p>In this model, a piano note would have a very short attack and decay, a reasonable sustain and  a short release when the key is released (assuming no sustain pedal). Note this is an approximation, as a piano note cannot be sustained forever - we would need the sustain phase to be a downward slope but that’s not part of the ADSR envelope.</p>

<script src="https://blog.mfavreaux.fr/assets/js/animate-cursor.js">
</script>

<figure>
  <div style="display: inline-block; position: relative;">
    <svg id="piano-envelope" width="300" height="150" xmlns="http://www.w3.org/2000/svg">
      <line id="path_0" x1="5" y1="194" x2="10" y2="10" stroke="green" stroke-width="4" stroke-linecap="round" />
      <line id="path_1" x1="10" y1="10" x2="50" y2="90" stroke="orange" stroke-width="4" stroke-linecap="round" />
      <line id="path_2" x1="50" y1="90" x2="250" y2="90" stroke="blue" stroke-width="4" stroke-linecap="round" />
      <line id="path_3" x1="250" y1="90" x2="295" y2="145" stroke="purple" stroke-width="4" stroke-linecap="round" />
      <circle id="cursor" cx="-10" cy="-10" r="7" fill="red" />
    </svg>
    <button style="position: absolute;top: 0;right: 0;" class="play-button" onclick="document.querySelector(`#piano-audio`).play()">🎵</button>
  </div>
    <audio id="piano-audio" controls="" ref="piano note" src="https://blog.mfavreaux.fr/assets/sn76489/audio/piano-a3.mp3" onplay="animate_svg_paths('piano-envelope', 'cursor', 'path_', [20, 100, 900, 200], () =&gt; { return document.querySelector('#piano-audio').currentTime * 1000 })">
    </audio>
  <figcaption>Piano note being held a short while.</figcaption>
</figure>

<script>
/* When JS is activated, hide controls so sync with audio control is easy */
window.addEventListener('load', (event) => {
  document.querySelector(`#piano-audio`).removeAttribute("controls");
});
</script>

<p>On the other hand, a bowed instrument played in a mellow fashion has a longer attack, no decay, a high sustain, and a moderate release:</p>

<script src="https://blog.mfavreaux.fr/assets/js/animate-cursor.js">
</script>

<figure>
  <div style="display: inline-block; position: relative;">
    <svg id="violin-legato-envelope" width="300" height="150" xmlns="http://www.w3.org/2000/svg">
      <line id="path_0" x1="5" y1="194" x2="130" y2="10" stroke="green" stroke-width="4" stroke-linecap="round" />
      <line id="path_1" x1="130" y1="10" x2="130" y2="10" stroke="orange" stroke-width="4" stroke-linecap="round" />
      <line id="path_2" x1="130" y1="10" x2="270" y2="10" stroke="blue" stroke-width="4" stroke-linecap="round" />
      <line id="path_3" x1="270" y1="10" x2="295" y2="145" stroke="purple" stroke-width="4" stroke-linecap="round" />
      <circle id="cursor" cx="-10" cy="-10" r="7" fill="red" />
    </svg>
    <button style="position: absolute;top: 0;right: 0;" class="play-button" onclick="document.querySelector(`#violin-legato-audio`).play()">🎵</button>
  </div>
    <audio id="violin-legato-audio" controls="" ref="violin-legato note" src="https://blog.mfavreaux.fr/assets/sn76489/audio/violin-legato-a4.mp3" onplay="animate_svg_paths('violin-legato-envelope', 'cursor', 'path_', [1000, 0, 1000, 200], () =&gt; { return document.querySelector('#violin-legato-audio').currentTime * 1000 })">
    </audio>
  <figcaption>Violin note with a slow attack.</figcaption>
</figure>

<script>
/* When JS is activated, hide controls so sync with audio control is easy */
window.addEventListener('load', (event) => {
  document.querySelector(`#violin-legato-audio`).removeAttribute("controls");
});
</script>

<p>You can also play bowed strings staccato, with much shorter attacks — a drum kick would have a very similar envelope:</p>

<script src="https://blog.mfavreaux.fr/assets/js/animate-cursor.js">
</script>

<figure>
  <div style="display: inline-block; position: relative;">
    <svg id="violin-staccato-envelope" width="300" height="150" xmlns="http://www.w3.org/2000/svg">
      <line id="path_0" x1="5" y1="194" x2="30" y2="10" stroke="green" stroke-width="4" stroke-linecap="round" />
      <line id="path_1" x1="30" y1="10" x2="60" y2="145" stroke="orange" stroke-width="4" stroke-linecap="round" />
      <line id="path_2" x1="60" y1="145" x2="60" y2="145" stroke="blue" stroke-width="4" stroke-linecap="round" />
      <line id="path_3" x1="60" y1="145" x2="295" y2="145" stroke="purple" stroke-width="4" stroke-linecap="round" />
      <circle id="cursor" cx="-10" cy="-10" r="7" fill="red" />
    </svg>
    <button style="position: absolute;top: 0;right: 0;" class="play-button" onclick="document.querySelector(`#violin-staccato-audio`).play()">🎵</button>
  </div>
    <audio id="violin-staccato-audio" controls="" ref="violin-staccato note" src="https://blog.mfavreaux.fr/assets/sn76489/audio/violin-staccato-a4.mp3" onplay="animate_svg_paths('violin-staccato-envelope', 'cursor', 'path_', [100, 200, 0, 1], () =&gt; { return document.querySelector('#violin-staccato-audio').currentTime * 1000 })">
    </audio>
  <figcaption>Staccato violin note.</figcaption>
</figure>

<script>
/* When JS is activated, hide controls so sync with audio control is easy */
window.addEventListener('load', (event) => {
  document.querySelector(`#violin-staccato-audio`).removeAttribute("controls");
});
</script>

<p>As we can see, it’s a simple model but versatile enough for our needs.</p>

<h3 id="implementation">Implementation</h3>

<p>Again, the plumbing itself isn’t that fascinating: the volume must change with time, following various slopes. Let’s highlight a few notable details though:</p>

<p>To implement the envelope, we must control the volume of the oscillators with the 4-bit register <code class="language-plaintext highlighter-rouge">Attenuation</code> — as we’ve seen in part 1, this register goes from 0 (maximum sound amplitude) to 15 (channel is off). This resolution is not great, especially when we’ll want to control quiet sounds, but we’ll have to do with it.</p>

<p>Moreover, we should take a look at the MIDI specification a little closer:</p>

<table>
  <tbody>
    <tr>
      <td>1001nnnn</td>
      <td>0kkkkkkk<br /> 0vvvvvvv</td>
      <td>Note On event.<br />This message is sent when a note is depressed (start). (kkkkkkk) is the key (note) number. (vvvvvvv) is the velocity.</td>
    </tr>
  </tbody>
</table>

<p>As you see, incoming notes carry their pitch along with a parameter called <code class="language-plaintext highlighter-rouge">velocity</code> — this is basically the strength of the note, or quite litteraly the velocity of the keyboard key.</p>

<p>Not knowing any better, I decided to use the <code class="language-plaintext highlighter-rouge">velocity</code> paramater as a factor applied to the envelope’s amplitude, so both the attack peak and the sustain are impacted. It works well enough.</p>

<p>Here is the same tune as above, this time with the ADSR envelope and velocity implemented:</p>

<figure>
  <audio controls="" ref="Same tune, now with envelope &amp; velocity." src="https://blog.mfavreaux.fr/assets/sn76489/audio/3osc-totoro-env.mp3">
    Your browser does not support the audio tag."
  </audio>
  <figcaption>Same tune, now with envelope &amp; velocity.
  
  Source: <a href="http://www.midishrine.com/index.php?id=172">My Neighbour Totoro &mdash; Stroll</a>
  
  </figcaption>
</figure>

<h2 id="drums">Drums</h2>

<p>Ah, drums. There we are. The SN76489 is a bit poor when it comes to drums. Where other chips get away with the situation by providing a crude PCM channel, we are limited to one noise channel.</p>

<h3 id="noise-channel">Noise channel</h3>

<p>First, we can choose which type of noise we use: either periodic or white noise. Then we are provided with 3 basic input frequencies: <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>N</mi><mi mathvariant="normal">/</mi><mn>512</mn></mrow><annotation encoding="application/x-tex">N / 512</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="mord">/512</span></span></span></span>, <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>N</mi><mi mathvariant="normal">/</mi><mn>1024</mn></mrow><annotation encoding="application/x-tex">N / 1024</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="mord">/1024</span></span></span></span>, <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>N</mi><mi mathvariant="normal">/</mi><mn>2048</mn></mrow><annotation encoding="application/x-tex">N / 2048</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.10903em;">N</span><span class="mord">/2048</span></span></span></span>. These options sound like this:</p>

<figure>
  <audio controls="" ref="Basic noise sounds available to us." src="https://blog.mfavreaux.fr/assets/sn76489/audio/drums-basic.mp3">
    Your browser does not support the audio tag."
  </audio>
  <figcaption>Basic noise sounds available to us.
  
  </figcaption>
</figure>

<p>In my tests, I found that I needed to use higher frequencies than what was provided, especially to reproduce something like a hit-hat. Fortunately, the last option is to use the 3rd oscillator’s output as an input frequency to the noise channel. This means we can essentially sacrifice one oscillator output for better noise control. Combining this with envelopes, I got to the following set of sounds:</p>

<figure>
  <audio controls="" ref="Sacrificing Osc 3 for more diversity." src="https://blog.mfavreaux.fr/assets/sn76489/audio/drums-osc3.mp3">
    Your browser does not support the audio tag."
  </audio>
  <figcaption>Sacrificing Osc 3 for more diversity.
  
  </figcaption>
</figure>

<p>That’s… let’s go with “charming”? Creative people would probably squeeze way more, but so far that’s the best I managed to find. Here is what it sounds like in context<sup id="fnref:no-drummer" role="doc-noteref"><a href="#fn:no-drummer" class="footnote" rel="footnote">1</a></sup>:</p>

<figure>
  <audio controls="" ref="A cheesy drum loop." src="https://blog.mfavreaux.fr/assets/sn76489/audio/cheesy-drum-pattern.mp3">
    Your browser does not support the audio tag."
  </audio>
  <figcaption>A cheesy drum loop.
  
  </figcaption>
</figure>

<p>You might be surprised that I would willingly sacrifice a whole tone channel. However, you’ll see in part 3 that this is an acceptable compromise because we’ll have tone channels to spare.</p>

<h3 id="kick">Kick</h3>

<p>But still, can’t we do juuuust a bit more? <em>Famous last words</em></p>

<p>Looking around I learned that certain games targetting this chip emulated PCM playback<sup id="fnref:pcm-playback" role="doc-noteref"><a href="#fn:pcm-playback" class="footnote" rel="footnote">2</a></sup>. I assume that is how they produced that “SEGA” sound at the start of the console. However, they seem to use a mode where a frequency parameter of 1 would keep the output pin high, which effectively does not work on my version of the chip<sup id="fnref:pin-1" role="doc-noteref"><a href="#fn:pin-1" class="footnote" rel="footnote">3</a></sup>. Moreover, while that may be one way to get more diversity, why use the chip at all when the arduino has a few output pins available? I feel that this option would be pushing the project’s boundary a bit too far, so I won’t go that way.</p>

<p>Still, I found that the thing I missed the most was a punchy kick sound.</p>

<figure>
  <audio controls="" ref="A kick sound." src="https://blog.mfavreaux.fr/assets/sn76489/audio/kick.mp3">
    Your browser does not support the audio tag."
  </audio>
  <figcaption>A kick sound.
  
  </figcaption>
</figure>

<p>Here’s what this sound looks like:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/kick-wav.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/kick-wav.png" alt="A kick sound viewed in Audacity" />
  </a>
  <figcaption>A kick sound viewed in Audacity
  
  </figcaption>
</figure>

<p>Couldn’t we mimick this with a single square wave? We can imagine reproducing this by carefuly controlling one of the oscillators. Before we commit to coding, let’s simulate that first.</p>

<p>We’ll iterate through a frequency range going from 150 Hz to 20 Hz. To keep this simple yet smooth, we’ll wait for a full period before changing to the next frequency:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">T</span> <span class="o">=</span> <span class="mf">0.25</span>      <span class="c1"># Duration of sample, in seconds
</span><span class="n">samples</span> <span class="o">=</span> <span class="p">[]</span>  <span class="c1"># List of sample points, that we'll use in the Arduino code
</span>
<span class="n">t</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">while</span> <span class="n">t</span> <span class="o">&lt;</span> <span class="n">T</span><span class="p">:</span>
    <span class="n">amplitude</span> <span class="o">=</span> <span class="n">curve</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">T</span><span class="p">,</span> <span class="n">t</span><span class="p">)</span>
    <span class="n">freq</span> <span class="o">=</span> <span class="n">curve</span><span class="p">(</span><span class="mi">150</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="n">T</span><span class="p">,</span> <span class="n">t</span><span class="p">)</span>
    <span class="n">period</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">/</span> <span class="n">freq</span>
    <span class="n">samples</span><span class="p">.</span><span class="n">append</span><span class="p">((</span><span class="n">freq</span><span class="p">,</span> <span class="n">amplitude</span><span class="p">,</span> <span class="n">period</span><span class="p">))</span>

    <span class="n">t</span> <span class="o">+=</span> <span class="n">period</span>
</code></pre></div></div>

<p>In the above code, <code class="language-plaintext highlighter-rouge">curve</code> is simply a function that will return a value between the first 2 parameters based on <code class="language-plaintext highlighter-rouge">t</code>, in a <code class="language-plaintext highlighter-rouge">1/x</code>-type curve.</p>

<p>We can then create the actual PCM data based on this, and output that into <code class="language-plaintext highlighter-rouge">matplotlib</code> and <code class="language-plaintext highlighter-rouge">IPython.display.Audio</code>:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">IPython.display</span> <span class="k">as</span> <span class="n">ipd</span>
<span class="kn">import</span> <span class="nn">math</span>

<span class="n">sr</span> <span class="o">=</span> <span class="mi">44100</span>        <span class="c1"># sample rate of the output PCM audio data
</span><span class="n">pcm_samples</span> <span class="o">=</span> <span class="p">[]</span>  <span class="c1"># List of PCM samples
</span>
<span class="k">for</span> <span class="n">freq</span><span class="p">,</span> <span class="n">amplitude</span><span class="p">,</span> <span class="n">delay</span> <span class="ow">in</span> <span class="n">samples</span><span class="p">:</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">sr</span> <span class="o">*</span> <span class="n">delay</span><span class="p">)):</span>
        <span class="n">t</span> <span class="o">=</span> <span class="n">i</span> <span class="o">/</span> <span class="n">sr</span>
        <span class="n">value</span> <span class="o">=</span> <span class="n">math</span><span class="p">.</span><span class="n">sin</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">math</span><span class="p">.</span><span class="n">pi</span><span class="o">*</span><span class="n">freq</span><span class="o">*</span><span class="p">(</span><span class="n">t</span><span class="p">))</span>
        <span class="n">pcm_samples</span><span class="p">.</span><span class="n">append</span><span class="p">(</span><span class="n">amplitude</span> <span class="o">*</span> <span class="p">(</span><span class="mi">1</span> <span class="k">if</span> <span class="n">value</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="o">-</span><span class="mi">1</span><span class="p">))</span>

<span class="n">ipd</span><span class="p">.</span><span class="n">display</span><span class="p">(</span><span class="n">ipd</span><span class="p">.</span><span class="n">Audio</span><span class="p">(</span><span class="n">pcm_samples</span><span class="p">,</span> <span class="n">rate</span><span class="o">=</span><span class="n">sr</span><span class="p">))</span>
<span class="n">plt</span><span class="p">.</span><span class="n">plot</span><span class="p">(</span><span class="n">samples</span><span class="p">)</span>
</code></pre></div></div>

<p>This made it easy to experiment a bit with various curves and frequency ranges. Below are the results I settled on:</p>

<figure>
  <audio controls="" ref="A simulated, square-wave-based kick sound." src="https://blog.mfavreaux.fr/assets/sn76489/audio/kick-sim.mp3">
    Your browser does not support the audio tag."
  </audio>
  <figcaption>A simulated, square-wave-based kick sound.
  
  </figcaption>
</figure>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/kick-sim.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/kick-sim.png" alt="Graphical representation of a simulated, square-wave-based kick sound." />
  </a>
  <figcaption>Graphical representation of a simulated, square-wave-based kick sound.
  
  </figcaption>
</figure>

<p>That sounds like a very distorted kick. It’s not exactly was I was going for, but it’s going in a very usable direction, I like it!</p>

<p>At this point the Arduino code is really not suited for this kind of “sample” (or rather, controlled) playback, but hacking the implementation is quite easy:</p>
<ul>
  <li>We don’t need to update at a rate of 11025 kHz or more like we would if we were playing samples — we simply have to change the oscillator’s frequency &amp; volume periodically. We already have facilities in place for the envelope, we just need special cases.</li>
  <li>We’re already sacrificing oscillator 3 to control the noise channel anyway, so we can use it for playback of this kick sound (and mute the noise channel while doing so).</li>
  <li>We can easily store the data in the Arduino’s flash.</li>
</ul>

<p>With this new sound under our belt, let’s change our little loop above to use this kick instead:</p>

<figure>
  <audio controls="" ref="A cheesy drum loop, now with a kick." src="https://blog.mfavreaux.fr/assets/sn76489/audio/cheesy-drum-pattern-kick.mp3">
    Your browser does not support the audio tag."
  </audio>
  <figcaption>A cheesy drum loop, now with a kick.
  
  </figcaption>
</figure>

<p>I’m pretty satisfied with how this sounds.</p>

<h2 id="some-music">Some music</h2>

<p>With everything we’ve built so far, it’s time to have some fun and make some music! This will also drive new features as we try to make it sound interesting, as there are a few obvious things missing.</p>

<p>I experimented with multiple DAWs &amp; other software, including <a href="https://www.reaper.fm/">REAPER</a> and <a href="https://www.rosegardenmusic.com/">Rosegarden</a>. For now I settled on the 8-track edition of <a href="https://www.bitwig.com/">Bitwig</a>:</p>
<ul>
  <li>It’s quite straightforward to get the live sound output from the hardware instrument back to the DAW and apply filters to it, then output it back to your sound card. Plus, finding out the latency between MIDI &amp; sound input is just a click away.</li>
  <li>The UI is quite easy to discover.</li>
  <li>The separation between individual loops on one side &amp; general sequencer on the other felt like a natural workflow.</li>
  <li>Arpeggiator!</li>
  <li>Finally, it’s the only tool that silently reconnected to my MIDI hardware after each of the <em>numerous</em> firmware updates — every other tool required some manual action after uploading a patch to the Arduino, which was seriously cumbersome.</li>
</ul>

<h3 id="starting-a-cover">Starting a cover</h3>

<p>I want to start small and have fun quickly, so let’s cover some songs. That, and I don’t know how to make music, so, you know.</p>

<p>For my first dab at this I copied a fun track from the <a href="https://www.youtube.com/channel/UCjFaPUcJU1vwk193mnW_w1w">Modern Vintage Gamer</a> channel. Here is a screenshot of the projet:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/bitwig-mvg-simple.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/bitwig-mvg-simple.png" alt="Screenshot of a project in Bitwig." />
  </a>
  <figcaption>Screenshot of a project in Bitwig.
  
  </figcaption>
</figure>

<p>And it sounds like this:</p>

<figure>
  <audio controls="" ref="Start of a song's cover." src="https://blog.mfavreaux.fr/assets/sn76489/audio/MVG-Pacific-Drive-sample.mp3">
    Your browser does not support the audio tag."
  </audio>
  <figcaption>Start of a song's cover.
  
  Source: <a href="https://modernvintagegamer.bandcamp.com/track/pacific-drive">MVG&mdash;Pacific Drive.</a>
  
  </figcaption>
</figure>

<p>That’s almost usable now! The timbre of the melody long-held notes sounds a bit flat and boring, while in the original there is a nice filter on top to make it interesting. We’ll make this better<sup id="fnref:cheat" role="doc-noteref"><a href="#fn:cheat" class="footnote" rel="footnote">4</a></sup>.</p>

<h2 id="whats-next">What’s next</h2>

<p>In this article we’ve really brought our project forward, from making random noises up to something usable: we’ve sent the first notes, integrated the MIDI protocol, implemented a basic ADSR envelope and programmed some drums.</p>

<p>Theoretically though, at this point the chip is still sitting on a breadboard. In part 3, we’ll make something more permanent, integrate multiple SN76489 chips together, and build a case for it all. Finally, we’ll implement more features. See you then!</p>
<div class="footnotes" role="doc-endnotes">
  <ol>
    <li id="fn:no-drummer" role="doc-endnote">
      <p>I have no idea what I’m doing. <a href="#fnref:no-drummer" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:pcm-playback" role="doc-endnote">
      <p>See <a href="https://www.smspower.org/Development/SamplePlayback">here</a> for example. <a href="#fnref:pcm-playback" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:pin-1" role="doc-endnote">
      <p>I tested this value and got the expected frequency output following the formulas above, at about 40 kHz. <a href="#fnref:pin-1" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:cheat" role="doc-endnote">
      <p>Noticed the sneak peek of what’s coming in the next part? I used the modulation wheel to control the vibrato on the last notes. <a href="#fnref:cheat" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
  </ol>
</div>]]></content><author><name>Mathieu Favréaux</name></author><category term="sn76489" /><category term="electronics" /><category term="midi" /><summary type="html"><![CDATA[At this point in the project, we have reliable communication with one SN76489 chip on the breadboard and some form of sound output. In this article, we'll make it play its first note, control it from a computer, and start improving its musicality.]]></summary></entry><entry><title type="html">MIDI to SN76489 to chip music, part 1-B: diving into an amplifier circuit</title><link href="https://blog.mfavreaux.fr/midi-to-sn76489-part1b/" rel="alternate" type="text/html" title="MIDI to SN76489 to chip music, part 1-B: diving into an amplifier circuit" /><published>2022-05-22T00:00:00-05:00</published><updated>2022-05-22T00:00:00-05:00</updated><id>https://blog.mfavreaux.fr/midi-to-sn76489-part1b</id><content type="html" xml:base="https://blog.mfavreaux.fr/midi-to-sn76489-part1b/"><![CDATA[<p>This article is part 1-B (see <a href="/midi-to-sn76489-part1/">part 1</a>, then <a href="/midi-to-sn76489-part2/">part 2</a>, <a href="/midi-to-sn76489-part3/">part 3</a>) in a series were we try to build a MIDI instrument from a bunch of <a href="https://en.wikipedia.org/wiki/Texas_Instruments_SN76489">SN76489</a>s, which is the sound chip used in the Sega Game Gear, the BBC Micro, the Neo Geo Pocket and <a href="https://en.wikipedia.org/wiki/Texas_Instruments_SN76489#Usage">quite a few others</a>.</p>

<p>If you’ve read the previous installment, you may have noticed this little aggregation of curious things:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/amp-breadboard.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/amp-breadboard.jpg" alt="Itty bitty amplifier on the breadboard" />
  </a>
  <figcaption>Itty bitty amplifier on the breadboard
  
  </figcaption>
</figure>

<p>That’s an amplifier, that’s what! Although a pretty bad one. In this article we’ll dive into the design I used here, and start exploring the fascinating, daunting, seemingly-infinite territory of how transistors work.</p>

<p><em>Note before we start: I’m really out of my depth here, and just trying to have fun. I’ve completely forgotten the little formal training I might have ever had in electronics. I don’t know what I’m talking about, so don’t quote me on anything. You have been warned.</em></p>

<h2 id="why-an-amplifier">Why an amplifier</h2>

<p>The SN76489 chip can output up to 10 mA, which while enough to drive a small load for test purposes, begs for some amplification. Moreover, a few components I had bought or salvaged<sup id="fnref:salvaged-cap" role="doc-noteref"><a href="#fn:salvaged-cap" class="footnote" rel="footnote">1</a></sup> a while ago were looking at me with begging eyes, so this provided a good excuse to indulge and build an amplifier. However, we only need it for testing and we’ll drop it pretty soon: it does not have to be perfect, and only has to drive my little speaker.</p>

<p>This article will actually be a bit of a time warp: at the time when I actually build the amplifier, I did not have any measurement tools so I couldn’t validate nor understand what this was really doing. This was a bit frustrating. Since then though, I bought a little <a href="https://espotek.com/labrador/product/espotek-labrador-board/">EspoTek Labrador</a>, so we can now take on the challenge.</p>

<h2 id="quick--dirty-design">Quick &amp; dirty design</h2>

<p>I settled on the simplest-looking<sup id="fnref:simplest-not-simple" role="doc-noteref"><a href="#fn:simplest-not-simple" class="footnote" rel="footnote">2</a></sup> amplifier design I could get my hands on<sup id="fnref:amp-design-source" role="doc-noteref"><a href="#fn:amp-design-source" class="footnote" rel="footnote">3</a></sup>, which you can see below. It’s pretty bad (for multiple reasons), and <em>will damage your speaker if left on for too long</em>. Thankfully this is only for testing, so that’s OK. It looks like this:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/amp-schematic.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/amp-schematic.png" alt="Amplifier schematic. It's a bad design, don't use it for real applications." />
  </a>
  <figcaption>Amplifier schematic. It's a bad design, don't use it for real applications.
  
  </figcaption>
</figure>

<p>What do we have here? From left to right:</p>
<ul>
  <li>A signal source. We’ll simulate our TI chip here as a 1 KHz sine<sup id="fnref:why-sine" role="doc-noteref"><a href="#fn:why-sine" class="footnote" rel="footnote">4</a></sup> wave signal.</li>
  <li><code class="language-plaintext highlighter-rouge">R2</code>: a current-limiting resistor to simulate the limited current.</li>
  <li><code class="language-plaintext highlighter-rouge">C1</code>: coupling capacitor.</li>
  <li><code class="language-plaintext highlighter-rouge">R1</code>: resistor for biasing the transistor. Its exact value isn’t too clear, some use 2 KΩ. We’ll talk about that.</li>
  <li><code class="language-plaintext highlighter-rouge">Q1</code>: transistor to provide the amplification.</li>
  <li><code class="language-plaintext highlighter-rouge">SPKR</code>: either a speaker or a funny hat, you decide. Most speakers are about 4 Ω or 8 Ω, but not mine, no sir. 52 Ω for you.</li>
  <li>And to the right, our voltage source to feed the amplification. It’s only 5 V so I can power it from the Arduino.</li>
</ul>

<h3 id="input-stage">Input stage</h3>

<p>Let’s look at the input stage first:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/input-schematic.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/input-schematic.png" alt="Zoom on the input part" />
  </a>
  <figcaption>Zoom on the input part
  
  </figcaption>
</figure>

<p>I configured the signal generator to output a 2 V amplitude sinewave. Combined with the 5 KΩ resistor, we get a current amplitude of 0.4 mA. That’s small, but since the usual <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>β</mi></mrow><annotation encoding="application/x-tex">\beta</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span></span></span></span> factor for current amplification is around 100, we get a maximum amplitude of 40 mA.</p>

<p>However, just as is the case with the TI chip, the generated signal is not centered on zero but always positive. To remove that positive bias and get a nice AC signal, we must use a <a href="https://en.wikipedia.org/wiki/Capacitive_coupling">coupling capacitor</a>. Now, while this is again super common stuff, I found that notion interesting enough to warrant its own measurement:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/unbiasing-input.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/unbiasing-input.png" alt="Measurements before / after the capacitor on a 3 V signal" />
  </a>
  <figcaption>Measurements before / after the capacitor on a 3 V signal
  
  </figcaption>
</figure>

<p>On the left is the signal voltage, while on the right we have the voltage at the terminals of <code class="language-plaintext highlighter-rouge">R2</code>. The signal looks cut at the bottom, but I think that’s an artifact of my signal generator, or of my setup here.</p>

<p>Note that even without this DC bias from the input source, the coupling capacitor would have been required anyway to block the bias we’ll apply on the transistor’s base.</p>

<h3 id="a-word-about-transistors">A word about transistors</h3>

<p>Throughout this article, we’ll focus on NPN <a href="https://en.wikipedia.org/wiki/Bipolar_junction_transistor">BJT</a> transistors and ignore the other categories.</p>

<p>An transistor allows a certain current through its collector based on the current flowing through its base (both flow to the emitter). Note I’m talking about current only: this is probably more complicated than that, but transistors are inherently current devices. I found it easier to reason about current first, and introduce voltage only where necessary.</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/transistor-drawing.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/transistor-drawing.png" alt="Transistor with its voltages" />
  </a>
  <figcaption>Transistor with its voltages
  
  </figcaption>
</figure>

<p>You get <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mi>c</mi></msub><mo>=</mo><mi>β</mi><msub><mi>I</mi><mi>b</mi></msub></mrow><annotation encoding="application/x-tex">I_c = \beta I_b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">c</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>, which is why you can amplify a signal: small signal in input, bigger signal in output, <em>mostly</em> constant factor between the two.</p>

<p>There is a minimum <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mi>c</mi></msub></mrow><annotation encoding="application/x-tex">I_c</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">c</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> for the transistor to turn on. When this threshold is reached, <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>V</mi><mrow><mi>b</mi><mi>e</mi></mrow></msub></mrow><annotation encoding="application/x-tex">V_{be}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">b</span><span class="mord mathnormal mtight">e</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> is at its maximum (≅0.7 V) and mostly stays there, and the transistor starts allowing current through the collector. In a real circuit, this will result in variations of <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>V</mi><mrow><mi>c</mi><mi>e</mi></mrow></msub></mrow><annotation encoding="application/x-tex">V_{ce}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">ce</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>, to respect the above relationship between <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mi>c</mi></msub></mrow><annotation encoding="application/x-tex">I_c</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">c</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> &amp; <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mi>b</mi></msub></mrow><annotation encoding="application/x-tex">I_b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>. However, the transistor only <em>allows</em> current through the collector, it does not <em>create</em> current: if not enough can be provided by whatever source is connected to the collector, <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>V</mi><mrow><mi>c</mi><mi>e</mi></mrow></msub></mrow><annotation encoding="application/x-tex">V_{ce}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">ce</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> reaches a minimum (≅0.3 V) — this condition is called <em>saturation</em>.</p>

<p>It must be noted that <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>β</mi></mrow><annotation encoding="application/x-tex">\beta</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span></span></span></span> varies a lot with operating conditions (<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mi>b</mi></msub></mrow><annotation encoding="application/x-tex">I_b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>, temperature, etc.) and with transistors (even within the same model you get different values). It seems common to assume a value of 100, at least for a start. It can easily vary between 50 and 300, so good circuits are designed as to not depend on the exact value too much.</p>

<h3 id="biasing-the-transistors-base">Biasing the transistor’s base</h3>

<p>We want to amplify a signal that varies between -1 V and 1 V. When amplifying a signal we must bias the base of the transistor up (meaning, apply a DC voltage) for two reasons:</p>
<ul>
  <li>First a transistor only works one way, so AC signals are a no-go — we must get a positive signal only. Thanks to our coupling capacitor <code class="language-plaintext highlighter-rouge">C1</code>, applying a voltage will not alter the signal: it simply moves it up, exactly how we moved it around 0 in the section above.</li>
  <li>Second, even if our signal is 0-2 V, our transistor will constantly turn off when reaching 0 V and then back on — this would heavily distort the signal. 
Hence, we want to positively bias the transistor so our lower input value will still keep the transistor on.</li>
</ul>

<p>This is the reason we have <code class="language-plaintext highlighter-rouge">R1</code>, to force a DC voltage at the base. The input signal will then pull or push current at this same point, influencing <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mi>b</mi></msub></mrow><annotation encoding="application/x-tex">I_b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>, which in turn will influence <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mi>c</mi></msub></mrow><annotation encoding="application/x-tex">I_c</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">c</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>. Magic!</p>

<p>This is also one of the reason why this particular amplifier design is bad: when on, even without signal, we’ll always have some current running through our speaker. Better designs work around that issue with a different placement of the speaker allowing the use of another coupling capacitor.</p>

<h3 id="initial-current-values">Initial current values</h3>

<p>We will talk in more details about the exact value and effect of <code class="language-plaintext highlighter-rouge">R1</code> in a section below, because it is a treat. Notably, I’ve seen a value of 2 KΩ used here and there, but at this point we have no idea why.</p>

<p>What we do know is that a value too great will not let enough current through to turn the transistor on. So for a start, let’s choose a big value as a potential maximum and calculate its current in the circuit in normal operation mode, if only to check that there is enough to turn the transistor on in the first place.</p>

<p>Let’s start simple: while the transistor is off, no current flows through the collector so we have both <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mi>c</mi></msub><mo>=</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">I_c = 0</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">c</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.6444em;"></span><span class="mord">0</span></span></span></span> and <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mi>b</mi></msub><mo>=</mo><msub><mi>I</mi><mrow><mi>R</mi><mn>1</mn></mrow></msub><mo>=</mo><msub><mi>I</mi><mrow><mi>s</mi><mi>p</mi><mi>k</mi><mi>r</mi></mrow></msub></mrow><annotation encoding="application/x-tex">I_b = I_{R1} = I_{spkr}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3283em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.00773em;">R</span><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.9694em;vertical-align:-0.2861em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">s</span><span class="mord mathnormal mtight">p</span><span class="mord mathnormal mtight" style="margin-right:0.03148em;">k</span><span class="mord mathnormal mtight" style="margin-right:0.02778em;">r</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.2861em;"><span></span></span></span></span></span></span></span></span></span>.</p>

<p>In turn, the base current is <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mi>b</mi></msub><mo>=</mo><mfrac><mrow><msub><mi>V</mi><mrow><mi>R</mi><mn>1</mn></mrow></msub><mo>+</mo><msub><mi>V</mi><mrow><mi>s</mi><mi>p</mi><mi>k</mi><mi>r</mi></mrow></msub></mrow><mrow><msub><mi>R</mi><mn>1</mn></msub><mo>+</mo><msub><mi>R</mi><mrow><mi>s</mi><mi>p</mi><mi>k</mi><mi>r</mi></mrow></msub></mrow></mfrac><mo>=</mo><mfrac><mrow><msub><mi>V</mi><mrow><mi>c</mi><mi>c</mi></mrow></msub><mo>−</mo><msub><mi>V</mi><mrow><mi>b</mi><mi>e</mi></mrow></msub></mrow><mrow><msub><mi>R</mi><mn>1</mn></msub><mo>+</mo><msub><mi>R</mi><mrow><mi>s</mi><mi>p</mi><mi>k</mi><mi>r</mi></mrow></msub></mrow></mfrac></mrow><annotation encoding="application/x-tex">I_b = {V_{R1} + V_{spkr} \over {R_1 + R_{spkr}}} = {V_{cc} - V_{be} \over {R_1 + R_{spkr}}}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1.5395em;vertical-align:-0.5481em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.9914em;"><span style="top:-2.655em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3173em;"><span style="top:-2.357em;margin-left:-0.0077em;margin-right:0.0714em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.143em;"><span></span></span></span></span></span></span><span class="mbin mtight">+</span><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3448em;"><span style="top:-2.3488em;margin-left:-0.0077em;margin-right:0.0714em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">s</span><span class="mord mathnormal mtight">p</span><span class="mord mathnormal mtight" style="margin-right:0.03148em;">k</span><span class="mord mathnormal mtight" style="margin-right:0.02778em;">r</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.2901em;"><span></span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.5131em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3448em;"><span style="top:-2.3567em;margin-left:-0.2222em;margin-right:0.0714em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.00773em;">R</span><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.1433em;"><span></span></span></span></span></span></span><span class="mbin mtight">+</span><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3448em;"><span style="top:-2.3488em;margin-left:-0.2222em;margin-right:0.0714em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">s</span><span class="mord mathnormal mtight">p</span><span class="mord mathnormal mtight" style="margin-right:0.03148em;">k</span><span class="mord mathnormal mtight" style="margin-right:0.02778em;">r</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.2901em;"><span></span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.5481em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1.4423em;vertical-align:-0.5481em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8942em;"><span style="top:-2.655em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3173em;"><span style="top:-2.357em;margin-left:-0.0077em;margin-right:0.0714em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.143em;"><span></span></span></span></span></span></span><span class="mbin mtight">+</span><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3448em;"><span style="top:-2.3488em;margin-left:-0.0077em;margin-right:0.0714em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">s</span><span class="mord mathnormal mtight">p</span><span class="mord mathnormal mtight" style="margin-right:0.03148em;">k</span><span class="mord mathnormal mtight" style="margin-right:0.02778em;">r</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.2901em;"><span></span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.4159em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1645em;"><span style="top:-2.357em;margin-left:-0.2222em;margin-right:0.0714em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">cc</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.143em;"><span></span></span></span></span></span></span><span class="mbin mtight">−</span><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3448em;"><span style="top:-2.3488em;margin-left:-0.2222em;margin-right:0.0714em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">b</span><span class="mord mathnormal mtight">e</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.1512em;"><span></span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.5481em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></span>. The lowest current we can get at the base while the transistor stays off is when <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>V</mi><mrow><mi>b</mi><mi>e</mi></mrow></msub></mrow><annotation encoding="application/x-tex">V_{be}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">b</span><span class="mord mathnormal mtight">e</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> approaches 0.7 V.</p>

<p>We have <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>V</mi><mrow><mi>c</mi><mi>c</mi></mrow></msub><mo>=</mo><mn>5</mn><mtext> </mtext><mi mathvariant="normal">V</mi></mrow><annotation encoding="application/x-tex">V_{cc} = 5\,\mathrm{V}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">cc</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord">5</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm" style="margin-right:0.01389em;">V</span></span></span></span>. Let’s take a big <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>R</mi><mn>1</mn></msub><mo>=</mo><mn>10</mn><mtext> </mtext><mrow><mi mathvariant="normal">K</mi><mi mathvariant="normal">Ω</mi></mrow></mrow><annotation encoding="application/x-tex">R_1 = 10\,\mathrm{K\Omega}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord">10</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord"><span class="mord mathrm">KΩ</span></span></span></span></span> as a starting point. This also makes <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>R</mi><mrow><mi>s</mi><mi>p</mi><mi>k</mi><mi>r</mi></mrow></msub></mrow><annotation encoding="application/x-tex">R_{spkr}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.9694em;vertical-align:-0.2861em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">s</span><span class="mord mathnormal mtight">p</span><span class="mord mathnormal mtight" style="margin-right:0.03148em;">k</span><span class="mord mathnormal mtight" style="margin-right:0.02778em;">r</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.2861em;"><span></span></span></span></span></span></span></span></span></span> above small enough to ignore.</p>

<p>We get: <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mi>c</mi></msub><mo>=</mo><mfrac><mn>4.3</mn><mn>10000</mn></mfrac><mo>=</mo><mn>0.43</mn><mtext> </mtext><mrow><mi mathvariant="normal">m</mi><mi mathvariant="normal">A</mi></mrow></mrow><annotation encoding="application/x-tex">I_c = {4.3 \over 10000} = 0.43\,\mathrm{mA}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">c</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1.1901em;vertical-align:-0.345em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8451em;"><span style="top:-2.655em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">10000</span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.394em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">4.3</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.345em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord">0.43</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord"><span class="mord mathrm">mA</span></span></span></span></span>. This is above <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>0.1</mn><mtext> </mtext><mrow><mi mathvariant="normal">m</mi><mi mathvariant="normal">A</mi></mrow></mrow><annotation encoding="application/x-tex">0.1\,\mathrm{mA}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord">0.1</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord"><span class="mord mathrm">mA</span></span></span></span></span> which the <a href="http://web.mit.edu/6.101/www/reference/2N2222A.pdf">2N2222A’s datasheet</a> seems to imply as the minimum base current, so we’re good: we can turn the transistor on.</p>

<h3 id="operating-current-values">Operating current values</h3>

<p>But wait! Now that current is flowing through the collector, a significant portion of <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mrow><mi>s</mi><mi>p</mi><mi>k</mi><mi>r</mi></mrow></msub></mrow><annotation encoding="application/x-tex">I_{spkr}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.9694em;vertical-align:-0.2861em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">s</span><span class="mord mathnormal mtight">p</span><span class="mord mathnormal mtight" style="margin-right:0.03148em;">k</span><span class="mord mathnormal mtight" style="margin-right:0.02778em;">r</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.2861em;"><span></span></span></span></span></span></span></span></span></span> is diverted away from the base, and the whole situation has changed. So the above calculation, while a nice way to get us warmed up, is just not valid — at least not while operating the transistor.</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/start-operation.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/start-operation.png" alt="Transistor now turned on" />
  </a>
  <figcaption>Transistor now turned on
  
  </figcaption>
</figure>

<p>Let’s start again with this new condition and see if we can solve it easily:</p>

<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi>V</mi><mrow><mi>b</mi><mi>e</mi></mrow></msub><mo>+</mo><msub><mi>V</mi><mrow><mi>R</mi><mn>1</mn></mrow></msub><mo>+</mo><msub><mi>V</mi><mrow><mi>s</mi><mi>p</mi><mi>k</mi><mi>r</mi></mrow></msub><mo>=</mo><msub><mi>V</mi><mrow><mi>c</mi><mi>c</mi></mrow></msub></mrow><annotation encoding="application/x-tex">V_{be} + V_{R1} + V_{spkr} = V_{cc}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">b</span><span class="mord mathnormal mtight">e</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3283em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.00773em;">R</span><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.9694em;vertical-align:-0.2861em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">s</span><span class="mord mathnormal mtight">p</span><span class="mord mathnormal mtight" style="margin-right:0.03148em;">k</span><span class="mord mathnormal mtight" style="margin-right:0.02778em;">r</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.2861em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">cc</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span></span>

<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi>I</mi><mi>b</mi></msub><mo>+</mo><msub><mi>I</mi><mi>c</mi></msub><mo>=</mo><msub><mi>I</mi><mrow><mi>s</mi><mi>p</mi><mi>k</mi><mi>r</mi></mrow></msub></mrow><annotation encoding="application/x-tex">I_b + I_c = I_{spkr}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">c</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.9694em;vertical-align:-0.2861em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">s</span><span class="mord mathnormal mtight">p</span><span class="mord mathnormal mtight" style="margin-right:0.03148em;">k</span><span class="mord mathnormal mtight" style="margin-right:0.02778em;">r</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.2861em;"><span></span></span></span></span></span></span></span></span></span></span>

<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi>I</mi><mi>c</mi></msub><mo>=</mo><mi>β</mi><msub><mi>I</mi><mi>b</mi></msub></mrow><annotation encoding="application/x-tex">I_c = \beta I_b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">c</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span></span>

<p>We’re trying to determine <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mi>c</mi></msub></mrow><annotation encoding="application/x-tex">I_c</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">c</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>, and we know <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>V</mi><mrow><mi>c</mi><mi>c</mi></mrow></msub></mrow><annotation encoding="application/x-tex">V_{cc}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">cc</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> and some of the resistances so let’s start from there and make <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mi>b</mi></msub></mrow><annotation encoding="application/x-tex">I_b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> pop in every non-constant:</p>

<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi>V</mi><mrow><mi>b</mi><mi>e</mi></mrow></msub><mo>+</mo><msub><mi>R</mi><mn>1</mn></msub><msub><mi>I</mi><mi>b</mi></msub><mo>+</mo><msub><mi>I</mi><mrow><mi>s</mi><mi>p</mi><mi>k</mi><mi>r</mi></mrow></msub><msub><mi>R</mi><mrow><mi>s</mi><mi>p</mi><mi>k</mi><mi>r</mi></mrow></msub><mo>=</mo><msub><mi>V</mi><mrow><mi>c</mi><mi>c</mi></mrow></msub></mrow><annotation encoding="application/x-tex">V_{be} + R_1 I_b + I_{spkr} R_{spkr} = V_{cc}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">b</span><span class="mord mathnormal mtight">e</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.9694em;vertical-align:-0.2861em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">s</span><span class="mord mathnormal mtight">p</span><span class="mord mathnormal mtight" style="margin-right:0.03148em;">k</span><span class="mord mathnormal mtight" style="margin-right:0.02778em;">r</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.2861em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">s</span><span class="mord mathnormal mtight">p</span><span class="mord mathnormal mtight" style="margin-right:0.03148em;">k</span><span class="mord mathnormal mtight" style="margin-right:0.02778em;">r</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.2861em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">cc</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span></span>

<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi>V</mi><mrow><mi>b</mi><mi>e</mi></mrow></msub><mo>+</mo><msub><mi>R</mi><mn>1</mn></msub><msub><mi>I</mi><mi>b</mi></msub><mo>+</mo><mo stretchy="false">(</mo><msub><mi>I</mi><mi>b</mi></msub><mo>+</mo><mi>β</mi><msub><mi>I</mi><mi>b</mi></msub><mo stretchy="false">)</mo><msub><mi>R</mi><mrow><mi>s</mi><mi>p</mi><mi>k</mi><mi>r</mi></mrow></msub><mo>=</mo><msub><mi>V</mi><mrow><mi>c</mi><mi>c</mi></mrow></msub></mrow><annotation encoding="application/x-tex">V_{be} + R_1 I_b + (I_b + \beta I_b) R_{spkr} = V_{cc}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">b</span><span class="mord mathnormal mtight">e</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1.0361em;vertical-align:-0.2861em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mclose">)</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">s</span><span class="mord mathnormal mtight">p</span><span class="mord mathnormal mtight" style="margin-right:0.03148em;">k</span><span class="mord mathnormal mtight" style="margin-right:0.02778em;">r</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.2861em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">cc</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span></span>

<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi>I</mi><mi>b</mi></msub><mo>=</mo><mfrac><mrow><msub><mi>V</mi><mrow><mi>c</mi><mi>c</mi></mrow></msub><mo>−</mo><msub><mi>V</mi><mrow><mi>b</mi><mi>e</mi></mrow></msub></mrow><mrow><msub><mi>R</mi><mn>1</mn></msub><mo>+</mo><mo stretchy="false">(</mo><mn>1</mn><mo>+</mo><mi>β</mi><mo stretchy="false">)</mo><msub><mi>R</mi><mrow><mi>s</mi><mi>p</mi><mi>k</mi><mi>r</mi></mrow></msub></mrow></mfrac></mrow><annotation encoding="application/x-tex">I_b = {V_{cc} - V_{be} \over {R_1 + (1 + \beta) R_{spkr}}}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:2.3324em;vertical-align:-0.9721em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3603em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mopen">(</span><span class="mord">1</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span><span class="mclose">)</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">s</span><span class="mord mathnormal mtight">p</span><span class="mord mathnormal mtight" style="margin-right:0.03148em;">k</span><span class="mord mathnormal mtight" style="margin-right:0.02778em;">r</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.2861em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">cc</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">b</span><span class="mord mathnormal mtight">e</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.9721em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></span></span>

<p>Which gives us now:</p>

<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi>I</mi><mi>b</mi></msub><mo>=</mo><mfrac><mrow><mn>5</mn><mo>−</mo><mn>0.7</mn></mrow><mrow><mn>10000</mn><mo>+</mo><mo stretchy="false">(</mo><mn>1</mn><mo>+</mo><mn>100</mn><mo stretchy="false">)</mo><mn>52</mn></mrow></mfrac><mo>≈</mo><mn>0.28</mn><mtext> </mtext><mrow><mi mathvariant="normal">m</mi><mi mathvariant="normal">A</mi></mrow></mrow><annotation encoding="application/x-tex">I_b = {5 - 0.7 \over {10000 + (1 + 100) 52}} \approx 0.28\,\mathrm{mA}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:2.2574em;vertical-align:-0.936em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3214em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">10000</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mopen">(</span><span class="mord">1</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mord">100</span><span class="mclose">)</span><span class="mord">52</span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">5</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mord">0.7</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.936em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">≈</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord">0.28</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord"><span class="mord mathrm">mA</span></span></span></span></span></span>

<p>Hurray! That’s still above <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>0.1</mn><mtext> </mtext><mrow><mi mathvariant="normal">m</mi><mi mathvariant="normal">A</mi></mrow></mrow><annotation encoding="application/x-tex">0.1\,\mathrm{mA}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord">0.1</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord"><span class="mord mathrm">mA</span></span></span></span></span> with a nice margin.</p>

<p>Before we move on, let’s get a feeling of what the above equation for <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mi>b</mi></msub></mrow><annotation encoding="application/x-tex">I_b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> implies:</p>
<ul>
  <li>The lower the resistance <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>R</mi><mn>1</mn></msub></mrow><annotation encoding="application/x-tex">R_1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>, the greater the base current.</li>
  <li>Similarly, the lower the resistance <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>R</mi><mrow><mi>s</mi><mi>p</mi><mi>k</mi><mi>r</mi></mrow></msub></mrow><annotation encoding="application/x-tex">R_{spkr}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.9694em;vertical-align:-0.2861em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">s</span><span class="mord mathnormal mtight">p</span><span class="mord mathnormal mtight" style="margin-right:0.03148em;">k</span><span class="mord mathnormal mtight" style="margin-right:0.02778em;">r</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.2861em;"><span></span></span></span></span></span></span></span></span></span>, the greater the current in the circuit, so the greater the base current.</li>
  <li>Interestingly, the greater the <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>β</mi></mrow><annotation encoding="application/x-tex">\beta</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span></span></span></span>, the more diverted current into the collector, so the lower the base current.</li>
</ul>

<h2 id="in-operation-without-signal">In operation without signal</h2>

<p>Now that we have our circuit and sort-of understand how this is supposed to work, let’s build it and start measuring. As opposed to the above section, let’s start with a small <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>R</mi><mn>1</mn></msub></mrow><annotation encoding="application/x-tex">R_1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> because at this point, I figure the lower the bias resistor, the greater the base current, the better (<em>spoiler alert: this is wrong</em>).</p>

<p>Will we get the expected results according to the equation above?</p>

<p>Well, close but not exactly.</p>

<h3 id="first-measurements">First measurements</h3>

<p>Confounded by the early results, I decided to do measurements with 2 <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>R</mi><mn>1</mn></msub></mrow><annotation encoding="application/x-tex">R_1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> values. Here are the results:</p>

<table>
  <thead>
    <tr>
      <th> </th>
      <th><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>R</mi><mn>1</mn></msub><mo>=</mo><mn>1</mn><mtext> </mtext><mrow><mi mathvariant="normal">K</mi><mi mathvariant="normal">Ω</mi></mrow></mrow><annotation encoding="application/x-tex">R_1 = 1\,\mathrm{K\Omega}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord">1</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord"><span class="mord mathrm">KΩ</span></span></span></span></span></th>
      <th><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>R</mi><mn>1</mn></msub><mo>=</mo><mn>4.7</mn><mtext> </mtext><mrow><mi mathvariant="normal">K</mi><mi mathvariant="normal">Ω</mi></mrow></mrow><annotation encoding="application/x-tex">R_1 = 4.7\,\mathrm{K\Omega}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord">4.7</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord"><span class="mord mathrm">KΩ</span></span></span></span></span></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mrow><mi>s</mi><mi>p</mi><mi>k</mi><mi>r</mi></mrow></msub></mrow><annotation encoding="application/x-tex">I_{spkr}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.9694em;vertical-align:-0.2861em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">s</span><span class="mord mathnormal mtight">p</span><span class="mord mathnormal mtight" style="margin-right:0.03148em;">k</span><span class="mord mathnormal mtight" style="margin-right:0.02778em;">r</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.2861em;"><span></span></span></span></span></span></span></span></span></span></td>
      <td><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>75</mn><mtext> </mtext><mrow><mi mathvariant="normal">m</mi><mi mathvariant="normal">A</mi></mrow></mrow><annotation encoding="application/x-tex">75\,\mathrm{mA}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord">75</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord"><span class="mord mathrm">mA</span></span></span></span></span></td>
      <td><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>60</mn><mtext> </mtext><mrow><mi mathvariant="normal">m</mi><mi mathvariant="normal">A</mi></mrow></mrow><annotation encoding="application/x-tex">60\,\mathrm{mA}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord">60</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord"><span class="mord mathrm">mA</span></span></span></span></span></td>
    </tr>
    <tr>
      <td><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mi>b</mi></msub></mrow><annotation encoding="application/x-tex">I_b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span></td>
      <td><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>0.40</mn><mtext> </mtext><mrow><mi mathvariant="normal">m</mi><mi mathvariant="normal">A</mi></mrow></mrow><annotation encoding="application/x-tex">0.40\,\mathrm{mA}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord">0.40</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord"><span class="mord mathrm">mA</span></span></span></span></span></td>
      <td><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>0.26</mn><mtext> </mtext><mrow><mi mathvariant="normal">m</mi><mi mathvariant="normal">A</mi></mrow></mrow><annotation encoding="application/x-tex">0.26\,\mathrm{mA}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord">0.26</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord"><span class="mord mathrm">mA</span></span></span></span></span></td>
    </tr>
    <tr>
      <td><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>β</mi></mrow><annotation encoding="application/x-tex">\beta</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span></span></span></span></td>
      <td><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>187</mn></mrow><annotation encoding="application/x-tex">187</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6444em;"></span><span class="mord">187</span></span></span></span></td>
      <td><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>233</mn></mrow><annotation encoding="application/x-tex">233</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6444em;"></span><span class="mord">233</span></span></span></span></td>
    </tr>
  </tbody>
</table>

<p>Wow, OK, our assumption of <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>β</mi><mo>=</mo><mn>100</mn></mrow><annotation encoding="application/x-tex">\beta = 100</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.6444em;"></span><span class="mord">100</span></span></span></span> was way off. And this factor does indeed vary a lot. However, if we use the corrected <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>β</mi></mrow><annotation encoding="application/x-tex">\beta</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span></span></span></span> value in the equations above, we do get the correct relationship between <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mi>b</mi></msub></mrow><annotation encoding="application/x-tex">I_b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> and <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>R</mi><mn>1</mn></msub></mrow><annotation encoding="application/x-tex">R_1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> so at least we’re good here.</p>

<p>However something really strange happened: when testing both circuit, I got a clearly stronger amplification with the biggest <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>R</mi><mn>1</mn></msub></mrow><annotation encoding="application/x-tex">R_1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>. Why is this?</p>

<p>We see in the table that <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>β</mi></mrow><annotation encoding="application/x-tex">\beta</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span></span></span></span> looks higher with a greater resistance. Could this be the reason (<em>Spoiler alert: nope</em>)? And if so, what is the biggest value we can get?</p>

<h3 id="exploring-beta">Exploring Beta</h3>

<p>I got all worked up about this <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>β</mi></mrow><annotation encoding="application/x-tex">\beta</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span></span></span></span> thing, so let’s measure it on our transistor.</p>

<p>It’s not too hard to do: with the signal generator, I can create a voltage sweep from 0 V up, and through a fixed resistor create a known <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mi>b</mi></msub></mrow><annotation encoding="application/x-tex">I_b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>. Then, supplying a small load at the Collector with a fixed voltage, I can measure the resulting voltage drop across the load and deduce <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mi>c</mi></msub></mrow><annotation encoding="application/x-tex">I_c</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">c</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>.</p>

<p>This looks like this:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/beta-measurement-setup.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/beta-measurement-setup.png" alt="Beta measurement setup schematic" />
  </a>
  <figcaption>Beta measurement setup schematic
  
  </figcaption>
</figure>

<p>Or like this on my breadboard with a nut for, ah, scale:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/beta-measurement-setup-photo.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/beta-measurement-setup-photo.jpg" alt="Beta measurement setup photo" />
  </a>
  <figcaption>Beta measurement setup photo
  
  </figcaption>
</figure>

<p>Note I dropped the speaker for an actual resistor: the speaker was causing too much noise when the transistor suddenly turned on.</p>

<p>Out of this, we get the following voltage measurements:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/beta-measurements-V.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/beta-measurements-V.png" alt="Beta Measurements of a 2N2222A: voltages" />
  </a>
  <figcaption>Beta Measurements of a 2N2222A: voltages
  
  </figcaption>
</figure>

<p>You can’t see it too well, but <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>V</mi><mrow><mi>R</mi><mn>1</mn></mrow></msub></mrow><annotation encoding="application/x-tex">V_{R1}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3283em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.00773em;">R</span><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> starts with a plateau, were most of the voltage drop is (I guess) eaten up by the base’s diode, and very little current is passing through. Then, we get a nice linear-ish relationship, until we approach saturation and <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>V</mi><mrow><mi>l</mi><mi>o</mi><mi>a</mi><mi>d</mi></mrow></msub></mrow><annotation encoding="application/x-tex">V_{load}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.01968em;">l</span><span class="mord mathnormal mtight">o</span><span class="mord mathnormal mtight">a</span><span class="mord mathnormal mtight">d</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> plateaus again.</p>

<p>What we really want to observe are the currents and resulting <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>β</mi></mrow><annotation encoding="application/x-tex">\beta</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span></span></span></span> values. However the measurements are very noisy: the Espotek’s resolution isn’t too great<sup id="fnref:espo-res" role="doc-noteref"><a href="#fn:espo-res" class="footnote" rel="footnote">5</a></sup>, so we need to average the heck out of this:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/beta-measurements-I.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/beta-measurements-I.png" alt="Beta measurements of a 2N2222A: averaged currents" />
  </a>
  <figcaption>Beta measurements of a 2N2222A: averaged currents
  
  </figcaption>
</figure>

<p>We get similar-looking current curves, and a beta approximation. Again, the spikes at the beginning are probably due to the measurement resolution, which is not sufficient at the start of the graph even when averaged. The low resolution really hurts when the values are small.</p>

<p>While the exact <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>β</mi></mrow><annotation encoding="application/x-tex">\beta</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span></span></span></span> values are not too exploitable, this tells me a great deal about this parameter:</p>
<ul>
  <li>It does vary, especially (as expected) when nearing saturation.</li>
  <li>A value between 150 and 250 is to be expected at low currents, although huge variations are indistinguishable from measurement errors.</li>
  <li>It seems to drop a little when the base current gets higher, before saturation — although again it’s hard to tell if it’s just the error factor getting lower.</li>
</ul>

<p>However, this does not tell much about the difference in sound output relative to <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>R</mi><mn>1</mn></msub></mrow><annotation encoding="application/x-tex">R_1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>. I suspect the variations we were observing previously are measurement errors that don’t explain the significant difference in power output I was hearing.</p>

<p>We need more measurements while the thing is operating.</p>

<h2 id="in-operation-with-signal">In operation with signal</h2>

<p>Let’s measure the influence of the input signal on the output, and try to understand it.</p>

<h3 id="initial-assumptions">Initial assumptions</h3>

<p>Let’s be naive for a moment. If we consider the current amplitude of the input signal applied to the base, the amplitude of the output should be relative to <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>β</mi></mrow><annotation encoding="application/x-tex">\beta</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span></span></span></span>, right? We apply a <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>2</mn><mtext> </mtext><mi mathvariant="normal">V</mi></mrow><annotation encoding="application/x-tex">2\,\mathrm{V}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord">2</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm" style="margin-right:0.01389em;">V</span></span></span></span> amplitude to a <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>R</mi><mn>2</mn></msub><mo>=</mo><mn>4.7</mn><mtext> </mtext><mrow><mi mathvariant="normal">K</mi><mi mathvariant="normal">Ω</mi></mrow></mrow><annotation encoding="application/x-tex">R_2 = 4.7\,\mathrm{K\Omega}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord">4.7</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord"><span class="mord mathrm">KΩ</span></span></span></span></span> resistance: we expect <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mrow><mi>a</mi><mi>m</mi><mi>p</mi><msub><mi>l</mi><mi>c</mi></msub></mrow></msub><mo>=</mo><mi>β</mi><msub><mi>I</mi><mrow><mi>a</mi><mi>m</mi><mi>p</mi><msub><mi>l</mi><mi>b</mi></msub></mrow></msub><mo>=</mo><mn>200</mn><mo>∗</mo><mrow><mn>2</mn><mi mathvariant="normal">/</mi><mn>4700</mn></mrow><mo>≈</mo><mn>85</mn><mtext> </mtext><mrow><mi mathvariant="normal">m</mi><mi mathvariant="normal">A</mi></mrow></mrow><annotation encoding="application/x-tex">I_{ampl_c} = \beta I_{ampl_b} = 200* {2/ 4700} \approx 85\,\mathrm{mA}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.9694em;vertical-align:-0.2861em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">am</span><span class="mord mathnormal mtight">p</span><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.01968em;">l</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1645em;"><span style="top:-2.357em;margin-left:-0.0197em;margin-right:0.0714em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mathnormal mtight">c</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.143em;"><span></span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.2861em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.9805em;vertical-align:-0.2861em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">am</span><span class="mord mathnormal mtight">p</span><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.01968em;">l</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3448em;"><span style="top:-2.3488em;margin-left:-0.0197em;margin-right:0.0714em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.1512em;"><span></span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.2861em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.6444em;"></span><span class="mord">200</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">∗</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord">2/4700</span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">≈</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord">85</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord"><span class="mord mathrm">mA</span></span></span></span></span> of current amplitude in the output.</p>

<p>To actually measure the output signal, we’ll measure the voltage drop across multiple points, and get the bias &amp; the amplitudes. We’ll repeat the operation with multiple <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>R</mi><mn>1</mn></msub></mrow><annotation encoding="application/x-tex">R_1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> values.</p>

<p>Here is a plot of the output currents. I also added their measured ranges, along with the naively expected ranges and a percentage of the former over the latter:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/Iload-measurements.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/Iload-measurements.png" alt="Output amplitude measurements with multiple R1" />
  </a>
  <figcaption>Output amplitude measurements with multiple R1
  
  </figcaption>
</figure>

<p><em>Note Iload is considered interchangeable with Ic for simplicity in this graph, but this does not change the results too much</em></p>

<p>This invalidates our naive calculation above, and confirms what I was hearing: while a lower <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>R</mi><mn>1</mn></msub></mrow><annotation encoding="application/x-tex">R_1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> values drives the mean current lower (as expected), the amplitude gets bigger so the sound is louder. Why is that?</p>

<h3 id="negative-feedback">Negative feedback</h3>

<p>Well, poking around in the circuit, I finally got the answer. It turns out the approach above completely overlooks the fact that the transistors varies the voltage at the collector to regulate the current, which influences R1, and in the end its base current. Let’s see what it looks like:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/negative-feedback.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/negative-feedback.png" alt="Influence of signal (yellow) over collector voltage (blue)." />
  </a>
  <figcaption>Influence of signal (yellow) over collector voltage (blue).
  
  </figcaption>
</figure>

<p>In the above image, we see the input signal vs. the collector voltage (from which the bias current is derived). Their phases are opposed, ain’t that a treat? The more current must get drawn into the collector, the lower <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>V</mi><mrow><mi>c</mi><mi>e</mi></mrow></msub></mrow><annotation encoding="application/x-tex">V_{ce}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">ce</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> must be, so less voltage drop is available for the biasing resistor. The bias goes against the signal, which dampens the effect of the latter. I guess that this is textbook negative feedback, and that it’s been painfully obvious for a while for the more electronic-savvy of our readers.</p>

<p>I may be completely off the mark with what’s about to follow, but let’s try to calculate all that. Let’s start from <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mrow><mi>R</mi><mn>1</mn></mrow></msub></mrow><annotation encoding="application/x-tex">I_{R1}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3283em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.00773em;">R</span><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>, dropping the assumption that it is equal to <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mi>b</mi></msub></mrow><annotation encoding="application/x-tex">I_b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>:</p>

<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi>I</mi><mrow><mi>R</mi><mn>1</mn></mrow></msub><mo>=</mo><mfrac><mrow><msub><mi>V</mi><mrow><mi>c</mi><mi>e</mi></mrow></msub><mo>−</mo><msub><mi>V</mi><mrow><mi>b</mi><mi>e</mi></mrow></msub></mrow><msub><mi>R</mi><mn>1</mn></msub></mfrac><mo>=</mo><mfrac><mrow><msub><mi>V</mi><mrow><mi>c</mi><mi>c</mi></mrow></msub><mo>−</mo><msub><mi>R</mi><mrow><mi>l</mi><mi>o</mi><mi>a</mi><mi>d</mi></mrow></msub><msub><mi>I</mi><mrow><mi>l</mi><mi>o</mi><mi>a</mi><mi>d</mi></mrow></msub><mo>−</mo><msub><mi>V</mi><mrow><mi>b</mi><mi>e</mi></mrow></msub></mrow><msub><mi>R</mi><mn>1</mn></msub></mfrac></mrow><annotation encoding="application/x-tex">I_{R1} = { { V_{ce} - V_{be} } \over R_1 } = { { V_{cc} - R_{load} I_{load} - V_{be} } \over R_1 }</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3283em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.00773em;">R</span><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:2.1963em;vertical-align:-0.836em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3603em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">ce</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">b</span><span class="mord mathnormal mtight">e</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.836em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:2.1963em;vertical-align:-0.836em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3603em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">cc</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.01968em;">l</span><span class="mord mathnormal mtight">o</span><span class="mord mathnormal mtight">a</span><span class="mord mathnormal mtight">d</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.01968em;">l</span><span class="mord mathnormal mtight">o</span><span class="mord mathnormal mtight">a</span><span class="mord mathnormal mtight">d</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">b</span><span class="mord mathnormal mtight">e</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.836em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></span></span>

<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi>I</mi><mrow><mi>R</mi><mn>1</mn></mrow></msub><mo>=</mo><mfrac><mrow><msub><mi>V</mi><mrow><mi>c</mi><mi>c</mi></mrow></msub><mo>−</mo><msub><mi>R</mi><mrow><mi>l</mi><mi>o</mi><mi>a</mi><mi>d</mi></mrow></msub><mo stretchy="false">(</mo><msub><mi>I</mi><mi>b</mi></msub><mi>β</mi><mo>+</mo><msub><mi>I</mi><mrow><mi>R</mi><mn>1</mn></mrow></msub><mo stretchy="false">)</mo><mo>−</mo><msub><mi>V</mi><mrow><mi>b</mi><mi>e</mi></mrow></msub></mrow><msub><mi>R</mi><mn>1</mn></msub></mfrac></mrow><annotation encoding="application/x-tex">I_{R1} = { { V_{cc} - R_{load} (I_b \beta + I_{R1}) - V_{be} } \over R_1 }</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3283em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.00773em;">R</span><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:2.263em;vertical-align:-0.836em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.427em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">cc</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.01968em;">l</span><span class="mord mathnormal mtight">o</span><span class="mord mathnormal mtight">a</span><span class="mord mathnormal mtight">d</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3283em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.00773em;">R</span><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">b</span><span class="mord mathnormal mtight">e</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.836em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></span></span>

<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mo stretchy="false">(</mo><mn>1</mn><mo>+</mo><mfrac><msub><mi>R</mi><mrow><mi>l</mi><mi>o</mi><mi>a</mi><mi>d</mi></mrow></msub><msub><mi>R</mi><mn>1</mn></msub></mfrac><mo stretchy="false">)</mo><msub><mi>I</mi><mrow><mi>R</mi><mn>1</mn></mrow></msub><mo>=</mo><mfrac><mrow><msub><mi>V</mi><mrow><mi>c</mi><mi>c</mi></mrow></msub><mo>−</mo><msub><mi>V</mi><mrow><mi>b</mi><mi>e</mi></mrow></msub></mrow><msub><mi>R</mi><mn>1</mn></msub></mfrac><mo>−</mo><mi>β</mi><mfrac><msub><mi>R</mi><mrow><mi>l</mi><mi>o</mi><mi>a</mi><mi>d</mi></mrow></msub><msub><mi>R</mi><mn>1</mn></msub></mfrac><msub><mi>I</mi><mi>b</mi></msub></mrow><annotation encoding="application/x-tex">(1 + {R_{load} \over R_1})I_{R1} = { { V_{cc} - V_{be} } \over R_1} - \beta { R_{load} \over R_1 } I_b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord">1</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:2.1963em;vertical-align:-0.836em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3603em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.01968em;">l</span><span class="mord mathnormal mtight">o</span><span class="mord mathnormal mtight">a</span><span class="mord mathnormal mtight">d</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.836em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span><span class="mclose">)</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3283em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.00773em;">R</span><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:2.1963em;vertical-align:-0.836em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3603em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">cc</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">b</span><span class="mord mathnormal mtight">e</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.836em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:2.1963em;vertical-align:-0.836em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3603em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.01968em;">l</span><span class="mord mathnormal mtight">o</span><span class="mord mathnormal mtight">a</span><span class="mord mathnormal mtight">d</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.836em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span></span>

<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi>I</mi><mrow><mi>R</mi><mn>1</mn></mrow></msub><mo>=</mo><mfrac><mrow><msub><mi>V</mi><mrow><mi>c</mi><mi>c</mi></mrow></msub><mo>−</mo><msub><mi>V</mi><mrow><mi>b</mi><mi>e</mi></mrow></msub></mrow><mrow><msub><mi>R</mi><mn>1</mn></msub><mo>+</mo><msub><mi>R</mi><mrow><mi>l</mi><mi>o</mi><mi>a</mi><mi>d</mi></mrow></msub></mrow></mfrac><mo>−</mo><mi>β</mi><mfrac><msub><mi>R</mi><mrow><mi>l</mi><mi>o</mi><mi>a</mi><mi>d</mi></mrow></msub><mrow><msub><mi>R</mi><mn>1</mn></msub><mo>+</mo><msub><mi>R</mi><mrow><mi>l</mi><mi>o</mi><mi>a</mi><mi>d</mi></mrow></msub></mrow></mfrac><msub><mi>I</mi><mi>b</mi></msub></mrow><annotation encoding="application/x-tex">I_{R1} = { { V_{cc} - V_{be} } \over { R_1 + R_{load} } } - \beta { R_{load} \over { R_1 + R_{load} } } I_b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3283em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.00773em;">R</span><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:2.1963em;vertical-align:-0.836em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3603em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.01968em;">l</span><span class="mord mathnormal mtight">o</span><span class="mord mathnormal mtight">a</span><span class="mord mathnormal mtight">d</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">cc</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">b</span><span class="mord mathnormal mtight">e</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.836em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:2.1963em;vertical-align:-0.836em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3603em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.01968em;">l</span><span class="mord mathnormal mtight">o</span><span class="mord mathnormal mtight">a</span><span class="mord mathnormal mtight">d</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.01968em;">l</span><span class="mord mathnormal mtight">o</span><span class="mord mathnormal mtight">a</span><span class="mord mathnormal mtight">d</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.836em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span></span>

<p>Let’s assume that <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>R</mi><mn>1</mn></msub><mo>≫</mo><msub><mi>R</mi><mrow><mi>l</mi><mi>o</mi><mi>a</mi><mi>d</mi></mrow></msub></mrow><annotation encoding="application/x-tex">R_1 \gg R_{load}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">≫</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.01968em;">l</span><span class="mord mathnormal mtight">o</span><span class="mord mathnormal mtight">a</span><span class="mord mathnormal mtight">d</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> so we can gain some clarity without losing too much precision :</p>

<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi>I</mi><mrow><mi>R</mi><mn>1</mn></mrow></msub><mo>=</mo><mfrac><mrow><msub><mi>V</mi><mrow><mi>c</mi><mi>c</mi></mrow></msub><mo>−</mo><msub><mi>V</mi><mrow><mi>b</mi><mi>e</mi></mrow></msub></mrow><msub><mi>R</mi><mn>1</mn></msub></mfrac><mo>−</mo><mi>β</mi><mfrac><msub><mi>R</mi><mrow><mi>l</mi><mi>o</mi><mi>a</mi><mi>d</mi></mrow></msub><msub><mi>R</mi><mn>1</mn></msub></mfrac><msub><mi>I</mi><mi>b</mi></msub></mrow><annotation encoding="application/x-tex">I_{R1} = { { V_{cc} - V_{be} } \over R_1 } - \beta { R_{load} \over R_1 } I_b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3283em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.00773em;">R</span><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:2.1963em;vertical-align:-0.836em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3603em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">cc</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">b</span><span class="mord mathnormal mtight">e</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.836em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:2.1963em;vertical-align:-0.836em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3603em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.01968em;">l</span><span class="mord mathnormal mtight">o</span><span class="mord mathnormal mtight">a</span><span class="mord mathnormal mtight">d</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.836em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span></span>

<p>This hints at the relationship we observed above: <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mrow><mi>R</mi><mn>1</mn></mrow></msub></mrow><annotation encoding="application/x-tex">I_{R1}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3283em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.00773em;">R</span><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> shrinks as <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mi>b</mi></msub></mrow><annotation encoding="application/x-tex">I_b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> grows, by a value inversely proportional to the <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>R</mi><mn>1</mn></msub></mrow><annotation encoding="application/x-tex">R_1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> resistance value.</p>

<p>Let’s now try to see the influence of the signal. At any point in time, we can express <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mi>b</mi></msub><mo stretchy="false">(</mo><mi>t</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">I_b(t)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord mathnormal">t</span><span class="mclose">)</span></span></span></span> as a function of the current pushed (or pulled) by the input signal <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mi>s</mi></msub><mo stretchy="false">(</mo><mi>t</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">I_s(t)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">s</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord mathnormal">t</span><span class="mclose">)</span></span></span></span>:</p>

<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi>I</mi><mi>b</mi></msub><mo stretchy="false">(</mo><mi>t</mi><mo stretchy="false">)</mo><mo>=</mo><msub><mi>I</mi><mrow><mi>R</mi><mn>1</mn></mrow></msub><mo stretchy="false">(</mo><mi>t</mi><mo stretchy="false">)</mo><mo>+</mo><msub><mi>I</mi><mi>s</mi></msub><mo stretchy="false">(</mo><mi>t</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">I_b(t) = I_{R1}(t) + I_s(t)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord mathnormal">t</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3283em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.00773em;">R</span><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord mathnormal">t</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">s</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord mathnormal">t</span><span class="mclose">)</span></span></span></span></span>

<p>Which we can expand as:</p>

<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi>I</mi><mi>b</mi></msub><mo stretchy="false">(</mo><mi>t</mi><mo stretchy="false">)</mo><mo>=</mo><mfrac><mrow><msub><mi>V</mi><mrow><mi>c</mi><mi>c</mi></mrow></msub><mo>−</mo><msub><mi>V</mi><mrow><mi>b</mi><mi>e</mi></mrow></msub></mrow><msub><mi>R</mi><mn>1</mn></msub></mfrac><mo>−</mo><mi>β</mi><mfrac><msub><mi>R</mi><mrow><mi>l</mi><mi>o</mi><mi>a</mi><mi>d</mi></mrow></msub><msub><mi>R</mi><mn>1</mn></msub></mfrac><msub><mi>I</mi><mi>b</mi></msub><mo stretchy="false">(</mo><mi>t</mi><mo stretchy="false">)</mo><mo>+</mo><msub><mi>I</mi><mi>s</mi></msub><mo stretchy="false">(</mo><mi>t</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">I_b(t) = { { V_{cc} - V_{be} } \over R_1 } - \beta { R_{load} \over R_1 } I_b(t) + I_s(t)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord mathnormal">t</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:2.1963em;vertical-align:-0.836em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3603em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">cc</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">b</span><span class="mord mathnormal mtight">e</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.836em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:2.1963em;vertical-align:-0.836em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3603em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.01968em;">l</span><span class="mord mathnormal mtight">o</span><span class="mord mathnormal mtight">a</span><span class="mord mathnormal mtight">d</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.836em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord mathnormal">t</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">s</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord mathnormal">t</span><span class="mclose">)</span></span></span></span></span>

<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi>I</mi><mi>b</mi></msub><mo stretchy="false">(</mo><mi>t</mi><mo stretchy="false">)</mo><mo stretchy="false">(</mo><mn>1</mn><mo>+</mo><mi>β</mi><mfrac><msub><mi>R</mi><mrow><mi>l</mi><mi>o</mi><mi>a</mi><mi>d</mi></mrow></msub><msub><mi>R</mi><mn>1</mn></msub></mfrac><mo stretchy="false">)</mo><mo>=</mo><mfrac><mrow><msub><mi>V</mi><mrow><mi>c</mi><mi>c</mi></mrow></msub><mo>−</mo><msub><mi>V</mi><mrow><mi>b</mi><mi>e</mi></mrow></msub></mrow><msub><mi>R</mi><mn>1</mn></msub></mfrac><mo>+</mo><msub><mi>I</mi><mi>s</mi></msub><mo stretchy="false">(</mo><mi>t</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">I_b(t) (1 +  \beta { R_{load} \over R_1 }) = { { V_{cc} - V_{be} } \over R_1} + I_s(t)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord mathnormal">t</span><span class="mclose">)</span><span class="mopen">(</span><span class="mord">1</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:2.1963em;vertical-align:-0.836em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3603em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.01968em;">l</span><span class="mord mathnormal mtight">o</span><span class="mord mathnormal mtight">a</span><span class="mord mathnormal mtight">d</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.836em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:2.1963em;vertical-align:-0.836em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3603em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">cc</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">b</span><span class="mord mathnormal mtight">e</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.836em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">s</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord mathnormal">t</span><span class="mclose">)</span></span></span></span></span>

<p>Let’s rename the constants to make this readable:</p>

<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>A</mi><mo>=</mo><mfrac><mrow><msub><mi>V</mi><mrow><mi>c</mi><mi>c</mi></mrow></msub><mo>−</mo><msub><mi>V</mi><mrow><mi>b</mi><mi>e</mi></mrow></msub></mrow><mrow><msub><mi>R</mi><mn>1</mn></msub><mo>+</mo><mi>β</mi><msub><mi>R</mi><mrow><mi>l</mi><mi>o</mi><mi>a</mi><mi>d</mi></mrow></msub></mrow></mfrac><mo separator="true">,</mo><mi>B</mi><mo>=</mo><mn>1</mn><mo>+</mo><mi>β</mi><mfrac><msub><mi>R</mi><mrow><mi>l</mi><mi>o</mi><mi>a</mi><mi>d</mi></mrow></msub><msub><mi>R</mi><mn>1</mn></msub></mfrac></mrow><annotation encoding="application/x-tex">A = { { V_{cc} - V_{be} } \over { R_1 +  \beta R_{load} } }, B = 1 +  \beta { R_{load} \over R_1 }</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord mathnormal">A</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:2.2408em;vertical-align:-0.8804em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3603em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.01968em;">l</span><span class="mord mathnormal mtight">o</span><span class="mord mathnormal mtight">a</span><span class="mord mathnormal mtight">d</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">cc</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.2222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">b</span><span class="mord mathnormal mtight">e</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.8804em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathnormal" style="margin-right:0.05017em;">B</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.7278em;vertical-align:-0.0833em;"></span><span class="mord">1</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:2.1963em;vertical-align:-0.836em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3603em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.01968em;">l</span><span class="mord mathnormal mtight">o</span><span class="mord mathnormal mtight">a</span><span class="mord mathnormal mtight">d</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.836em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></span></span>

<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi>I</mi><mi>b</mi></msub><mo stretchy="false">(</mo><mi>t</mi><mo stretchy="false">)</mo><mo>=</mo><mrow><mi>A</mi><mo>+</mo><mfrac><mn>1</mn><mi>B</mi></mfrac><msub><mi>I</mi><mi>s</mi></msub><mo stretchy="false">(</mo><mi>t</mi><mo stretchy="false">)</mo></mrow></mrow><annotation encoding="application/x-tex">I_b(t) = { A + { 1 \over B } I_s(t) }</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord mathnormal">t</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:2.0074em;vertical-align:-0.686em;"></span><span class="mord"><span class="mord mathnormal">A</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3214em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.05017em;">B</span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.686em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">s</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord mathnormal">t</span><span class="mclose">)</span></span></span></span></span></span>

<p>Again, this confirms that the influence of <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mi>s</mi></msub><mo stretchy="false">(</mo><mi>t</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">I_s(t)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">s</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord mathnormal">t</span><span class="mclose">)</span></span></span></span> over <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mi>b</mi></msub><mo stretchy="false">(</mo><mi>s</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">I_b(s)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">b</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord mathnormal">s</span><span class="mclose">)</span></span></span></span> (and so over <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>I</mi><mi>c</mi></msub><mo stretchy="false">(</mo><mi>t</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">I_c(t)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:-0.0785em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">c</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord mathnormal">t</span><span class="mclose">)</span></span></span></span>) is relative to the value of <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>R</mi><mn>1</mn></msub></mrow><annotation encoding="application/x-tex">R_1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> — the greater the <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>R</mi><mn>1</mn></msub></mrow><annotation encoding="application/x-tex">R_1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span>, the lesser the input signal is dampened (up to no dampening at all when <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>R</mi><mn>1</mn></msub></mrow><annotation encoding="application/x-tex">R_1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> reaches <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="normal">∞</mi></mrow><annotation encoding="application/x-tex">\infty</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.4306em;"></span><span class="mord">∞</span></span></span></span>), and the greater the output’s current amplitude.</p>

<p>Let’s plot that to compare against our previous measurements:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/Iload-measurements-2.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/Iload-measurements-2.png" alt="Output amplitude measurements with multiple R1 - fixed calculated expectations" />
  </a>
  <figcaption>Output amplitude measurements with multiple R1 - fixed calculated expectations
  
  </figcaption>
</figure>

<p>Not too far off! Again, I have no idea if the calculations above are anything correct but this is encouraging. I’ll consider that good enough for now.</p>

<p>In any case we understand why going with a greater <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>R</mi><mn>1</mn></msub></mrow><annotation encoding="application/x-tex">R_1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3011em;"><span style="top:-2.55em;margin-left:-0.0077em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span></span> helps: it limits the negative feedback that is dampening the signal’s influence on the output. Also, it reduces the constant current applied to the speaker which, while this whole thing is definitely a bad design anyway, helps a little.</p>

<h2 id="conclusion">Conclusion</h2>

<p>And there we go! We started with a completely unknown amplification circuit diagram and managed not only to make it work, but understand and visualize the use of each of its components. We took a detour to measure the <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>β</mi></mrow><annotation encoding="application/x-tex">\beta</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.05278em;">β</span></span></span></span> factor of our transistor. We also dug into the negative feedback applied to the transistor’s bias, and managed to find a calculation that reproduces our measurements.</p>

<p>Now this raises some questions:</p>
<ul>
  <li>Why not connect <code class="language-plaintext highlighter-rouge">R1</code> from the voltage source directly instead of at the collector?</li>
  <li>Could we place the speaker somewhere else so it does not suffer from the constant DC voltage even without signal?</li>
</ul>

<p>Well, I would guess that’s why an actual <a href="https://www.electronics-tutorials.ws/amplifier/amp_5.html">Class A amplifier</a> looks the way it does. And no, I’m not going to build one, that’s a rabbit hole for another time. It’s time to go back to our project.</p>

<p>See you in <a href="/midi-to-sn76489-part2/">part 2</a>.</p>
<div class="footnotes" role="doc-endnotes">
  <ol>
    <li id="fn:salvaged-cap" role="doc-endnote">
      <p>Salvaged from an oven circuit board that fried when I spilled milk on it, but life, huh, finds a way. For capacitors, at least. <a href="#fnref:salvaged-cap" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:simplest-not-simple" role="doc-endnote">
      <p>I would not necessarily make the very same choice now: simple-looking does not necessarily equate to easily understandable. <a href="#fnref:simplest-not-simple" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:amp-design-source" role="doc-endnote">
      <p>There are good, simple amplifier designs to be found everywhere, along with tons of details &amp; explanations. Notably, <a href="https://www.electronics-tutorials.ws/amplifier/amp_5.html">Electronics Tutorials</a> is probably a source I’ll get back to in the future. However, as a complete neophyte, I found the <a href="https://www.youtube.com/c/SimplyPut">Simply Put</a> YouTube channel to provide a very approachable perspective when trying to form an intuitive understanding of what’s where and why. His <a href="https://www.youtube.com/watch?v=o1yLQSD57GI">Simple and Quick Audio Amplifier</a> presents the design I copied here. <a href="#fnref:amp-design-source" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:why-sine" role="doc-endnote">
      <p>I chose a sine signal instead of a square signal because this makes it much easier to visualize distortion and clipping in the output signal. <a href="#fnref:why-sine" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:espo-res" role="doc-endnote">
      <p>As we can see in the documentation, there is a mode to get a 12-bit resolution using both inputs at the same time in the <a href="https://github.com/EspoTek/Labrador/wiki#multimeter">Multimeter mode</a>, but I couldn’t manage to export a <code class="language-plaintext highlighter-rouge">csv</code> file to exploit the values, so I’m stuck 2 channels, 8 bits. I guess that’s kind of fitting for this project, though. <a href="#fnref:espo-res" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
  </ol>
</div>]]></content><author><name>Mathieu Favréaux</name></author><category term="sn76489" /><category term="electronics" /><summary type="html"><![CDATA[The TI chip can output up to 10&nbsp;mA, which begs for some amplification. A few components I had bought or salvaged a while ago were looking at me with begging eyes, so this provided a good excuse to indulge.]]></summary></entry><entry><title type="html">MIDI to SN76489 to chip music, part 1: setting things up</title><link href="https://blog.mfavreaux.fr/midi-to-sn76489-part1/" rel="alternate" type="text/html" title="MIDI to SN76489 to chip music, part 1: setting things up" /><published>2022-05-15T00:00:00-05:00</published><updated>2022-05-15T00:00:00-05:00</updated><id>https://blog.mfavreaux.fr/midi-to-sn76489-part1</id><content type="html" xml:base="https://blog.mfavreaux.fr/midi-to-sn76489-part1/"><![CDATA[<p>A while back, I started playing with <a href="https://en.wikipedia.org/wiki/Texas_Instruments_SN76489">SN76489</a> chips<sup id="fnref:prior-works" role="doc-noteref"><a href="#fn:prior-works" class="footnote" rel="footnote">1</a></sup>. I’ve always been a bit fascinated with chip music, old 8-bit era computers and electronics, but never seriously dabbed into any of these things. So what began as a playful experiment quickly started to scratch some pretty serious itches.</p>

<p>This series (see <a href="/midi-to-sn76489-part1b/">part 1-B</a>, <a href="/midi-to-sn76489-part2/">part 2</a>, <a href="/midi-to-sn76489-part3/">part 3</a>) will be a sort of idealized recollection of what took place over the past 6 months or so, where I tried to make music with these things. Apologies for the relative lack of pictures — I did not think for a moment that I would actually go anywhere with this.</p>

<p>There is a lot to talk about, so this will be split up: in this part 1, we will concentrate on setting up communication with a common SN76489 chip and getting some sound out of it. In part 2, we will start playing notes and we will set up MIDI control of the various channels. In part 3, we stick multiple chips together, build a mixer circuit and a case for our contraption and add even more features to our synth to make some music with it.</p>

<h2 id="chip-music">Chip music?</h2>

<p>I guess we should start here. My understanding of what is called <a href="https://en.wikipedia.org/wiki/Chiptune">chip music</a> today is music made at least partly with a set of simple waveforms such as pulse waves (square waves), triangle waves, and noise channels. We can probably throw FM synthesis in the mix as well. This is a legacy from 8-bit-era video games &amp; computer systems: the limited capacity of the machines required the use of <a href="https://en.wikipedia.org/wiki/Programmable_sound_generator">programmable sound generators</a> (to which the CPU sends notes). Moreover, the cost constraints meant using few, basic chips. As a result, you get simplistic sounds on very few parallel voices.</p>

<p>Here are a few examples<sup id="fnref:vgmrips" role="doc-noteref"><a href="#fn:vgmrips" class="footnote" rel="footnote">2</a></sup>:</p>

<ul>
  <li><a href="https://vgmrips.net/packs/pack/1942-arcade">1942</a>’s Main background music (BGM) — or rather ambience made with percussive elements:</li>
</ul>

<figure>
  <audio controls="" ref="1942's BGM." src="https://blog.mfavreaux.fr/assets/sn76489/audio/1942-main-bgm.mp3">
    Your browser does not support the audio tag."
  </audio>
  <figcaption>1942's BGM.
  
  Source: <a href="https://vgmrips.net/packs/pack/1942-arcade">VGMRips</a>
  
  </figcaption>
</figure>

<ul>
  <li><a href="https://vgmrips.net/packs/pack/clean-sweep-vectrex">Clean Sweep</a>’s Sound 1 for background sound effects:</li>
</ul>

<figure>
  <audio controls="" ref="Clean Sweep's Sound 1." src="https://blog.mfavreaux.fr/assets/sn76489/audio/clean-sweep-sound-1.mp3">
    Your browser does not support the audio tag."
  </audio>
  <figcaption>Clean Sweep's Sound 1.
  
  Source: <a href="https://vgmrips.net/packs/pack/clean-sweep-vectrex">VGMRips</a>
  
  </figcaption>
</figure>

<ul>
  <li><a href="https://vgmrips.net/packs/pack/donkey-kong-nes">Donkey Kong</a>’s Game start with some triangle wave bass to keep you on your toes:</li>
</ul>

<figure>
  <audio controls="" ref="DonkeyKong Game Start." src="https://blog.mfavreaux.fr/assets/sn76489/audio/donkey-kong-game-start.mp3">
    Your browser does not support the audio tag."
  </audio>
  <figcaption>DonkeyKong Game Start.
  
  Source: <a href="https://vgmrips.net/packs/pack/donkey-kong-nes">VGMRips</a>
  
  </figcaption>
</figure>

<p>These constraints, as is often the case, meant that talented people started to work around the limitations to get more and more juice out of these systems. A typical sound started to emerge, a kind of “scene” grew out of isolated silos, and you get gems everywhere you look. It’s fascinating.</p>

<ul>
  <li><a href="https://vgmrips.net/packs/pack/silver-surfer-nes">Silver Surfer</a>’s BGM on NES — arpeggios, fast rhythms, tone sweeps, the works:</li>
</ul>

<figure>
  <audio controls="" ref="Silver Surfer BGM 1." src="https://blog.mfavreaux.fr/assets/sn76489/audio/silver-surfer-bgm-1.mp3">
    Your browser does not support the audio tag."
  </audio>
  <figcaption>Silver Surfer BGM 1.
  
  Source: <a href="http://www.midishrine.com/index.php?id=172">VGMRips</a>
  
  </figcaption>
</figure>

<ul>
  <li><a href="https://vgmrips.net/packs/pack/bomb-jack-nintendo-game-boy">Bomb Jack</a>’s on Game Boy — different platform, different sound but similar principles:</li>
</ul>

<figure>
  <audio controls="" ref="Bomb Jack Bonus." src="https://blog.mfavreaux.fr/assets/sn76489/audio/bomb-jack-bonus.mp3">
    Your browser does not support the audio tag."
  </audio>
  <figcaption>Bomb Jack Bonus.
  
  Source: <a href="https://vgmrips.net/packs/pack/bomb-jack-nintendo-game-boy">VGMRips</a>
  
  </figcaption>
</figure>

<p>Nowadays I guess this sound is 100% associated with old video games. However, chip music is still being made today, sometimes on real hardware<sup id="fnref:DMG-LSDJ" role="doc-noteref"><a href="#fn:DMG-LSDJ" class="footnote" rel="footnote">3</a></sup>, sometimes more as a reference incorporated into more complex songs. Here are two examples of the former:</p>

<ul>
  <li>
    <p>🎵 <a href="https://chipzel.co.uk/track/focus-3">Chipzel - Focus</a> on bandcamp — <a href="https://superhexagon.com/">Super Hexagon</a>’s soundtrack</p>
  </li>
  <li>
    <p>🎵 <a href="https://kommisarchiptune.bandcamp.com/track/the-maid-and-the-pocket-watch-of-blood">Kommisar - The Maid and the Pocket Watch of Blood</a> on bandcamp.</p>
  </li>
</ul>

<p>I just scratched the surface here, and I could not be thorough even if I tried anyway. Hopefully that’s enough to give an idea. If you want to know more about the old days of chip music and its creators on the Japanese side of things, I found the documentary <a href="https://www.redbull.com/ca-en/shows/diggin-in-the-carts">Diggin’ in the Carts</a> to be interesting and approachable.</p>

<h2 id="the-sn76489-chip">The SN76489 chip</h2>

<p>Let’s get back to business.</p>

<p>This TI chip and its variants were used in various computers &amp; game systems from that era: from arcade games, to the BBC Micro, to the Sega Master System &amp; Game Gear. It has 4 channels: 3 square wave &amp; 1 noise. It it sounds similar to what we’ve listen to above, but even more limited: no sample playback, no triangle wave, 50 % duty cycle pulse wave only.</p>

<p>They are still pretty easy to find today, and on some rainy day I purchased a batch on eBay. I settled on the AN variant, which accepts a 4-MHz clock.</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/sn76489-batch.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/sn76489-batch.jpg" alt="A few SN76489AN chips" />
  </a>
  <figcaption>A few SN76489AN chips
  
  </figcaption>
</figure>

<h2 id="first-stages-of-communication-sending-bytes">First stages of communication: sending bytes</h2>

<p>We need to try to talk to this thing, so let’s take a look at the chip’s <a href="https://ftp.whtech.com/datasheets%20and%20manuals/Datasheets%20-%20TI/SN76489.pdf">datasheet</a>.</p>

<h3 id="pin-layout">Pin layout</h3>

<p>This is the chip’s layout:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/sn76489-top-view.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/sn76489-top-view.png" alt="Datasheet's top view" />
  </a>
  <figcaption>Datasheet's top view
  
  </figcaption>
</figure>

<p>First, the data bus is made up of pins D0-D7. The chips needs an external clock signal, not only for operation but also as a way to derive the notes frequency — that’s on pin 14. The sound signal is then output on pin 7.</p>

<p>The remaining pins are used for synchronization:</p>

<ul>
  <li><span style="text-decoration:overline"><code class="language-plaintext highlighter-rouge">CE</code></span> on pin 6 (inverse logic): Chip Enable, unless pulled to ground the chip will ignore what’s happening on the data bus. It’s weirdly spelled OE in the above picture, but later referred to as CE.</li>
  <li><span style="text-decoration:overline"><code class="language-plaintext highlighter-rouge">WE</code></span> on pin 5 (inverse logic): Write Enable, to be pulled to ground when data is ready on the bus.</li>
  <li><code class="language-plaintext highlighter-rouge">READY</code> on pin 4: high when the chip is done reading data.</li>
</ul>

<p>The inverse logic thing means that the voltage you set is opposed to the logic: pull low for true, and high for false.</p>

<p>Ergo, sending a byte to the chip is a matter of:</p>

<ol>
  <li>Setting <span style="text-decoration:overline"><code class="language-plaintext highlighter-rouge">CE</code></span> to true to select the chip (this can be wired to ground if there’s only one chip)</li>
  <li>Putting our data byte on <code class="language-plaintext highlighter-rouge">D0</code> to <code class="language-plaintext highlighter-rouge">D7</code>.</li>
  <li>Setting <span style="text-decoration:overline"><code class="language-plaintext highlighter-rouge">WE</code></span> to true to indicate that data is ready.</li>
  <li>Waiting for <code class="language-plaintext highlighter-rouge">READY</code> to be true.</li>
</ol>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/data-transfer-timing.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/data-transfer-timing.png" alt="Data transfer timing" />
  </a>
  <figcaption>Data transfer timing
  
  </figcaption>
</figure>

<p>Vague memories from school 15 years ago tells me this is pretty standard stuff. So, time to get the Arduino out?</p>

<h3 id="data-layout">Data layout</h3>

<p>Wait! What should we send?</p>

<p>The chip is controlled by setting its internal registers, which is done by talking a simple protocol on the data bus. There are 8 registers:</p>

<ul>
  <li>10-bit registers for channel 0-2’s frequency control.</li>
  <li>a 3-bit register for channel 3 noise type.</li>
  <li>4-bit registers for each channel’s attenuation (volume).</li>
</ul>

<p>In order to set a register value, the most significant bit (MSB) is set to 1, the 3 next bits select the register, and the rest is devoted to the register’s content. For the 10-bit registers, data is sent in two stages, and the MSB is set to 0 to indicate the second stage.</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/register-sending-format.png" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/register-sending-format.png" alt="Register's sending format" />
  </a>
  <figcaption>Register's sending format
  
  </figcaption>
</figure>

<p>Note how D7 is the LSB and D0 the MSB, “big-endian” fashion.</p>

<h3 id="clock">Clock</h3>

<p>We also need a clock signal for this whole thing to work. I don’t have a quartz around, and I sure don’t know how to make a proper clock circuit, so I looked for other options.</p>

<p>It turns out<sup id="fnref:forum-clock" role="doc-noteref"><a href="#fn:forum-clock" class="footnote" rel="footnote">4</a></sup> the Arduino’s SoC is quite flexible and you can use it to generate pretty fast signals with counters &amp; interrupts. Let’s get a deeper look at the <a href="https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf">ATmega328P datasheet</a> to see precisely what we can do.</p>

<p>The ATmega328P has multiple internal timers, with different resolutions and functionalities. They can be configured to trigger interrupts on delays, compare values, generate waves via PWM, at high frequencies (close to the SoC clock) while letting the CPU do something else. Timer 0 is used by regular Arduino functions such as <code class="language-plaintext highlighter-rouge">delay</code>, so we must leave it alone. However Timer 1 and 2 are up for grabs.</p>

<p>Timer 1 supports a mode called <a href="https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf">Clear Timer on Compare Match</a> (CTC). When properly configured, we can get the following behavior:</p>
<ul>
  <li>The timer increments a counter in <code class="language-plaintext highlighter-rouge">TCNT1</code> at each clock cycle</li>
  <li>When the value reaches a top value stored in <code class="language-plaintext highlighter-rouge">OCR1A</code>:
    <ul>
      <li>The counter <code class="language-plaintext highlighter-rouge">TCNT1</code> is set back to 0.</li>
      <li>The timer event happens: in our case, we want the output pin <code class="language-plaintext highlighter-rouge">OC1A</code> to be toggled.</li>
    </ul>
  </li>
</ul>

<p>The maximum output frequency can therefore be obtained by setting <code class="language-plaintext highlighter-rouge">OCR1A</code> (the top value) to 0: the output pin gets toggled at each clock cycle, so a full period takes 2 cycles. Hence, the maximum clock we can generate is 8 MHz on our 16 MHz SoC. In our case we want to generate a 4 MHz clock signal: we must set the top value <code class="language-plaintext highlighter-rouge">OCR1A</code> to 1 so the timer is reset every other clock cycle.</p>

<p>In the general case, the output signal’s frequency will be <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>f</mi><mrow><mi>o</mi><mi>u</mi><mi>t</mi></mrow></msub><mo>=</mo><mfrac><msub><mi>f</mi><mrow><mi>S</mi><mi>o</mi><mi>C</mi></mrow></msub><mrow><mn>2</mn><mo stretchy="false">(</mo><mn>1</mn><mo>+</mo><mrow><mi>O</mi><mi>C</mi><mi>R</mi><mn mathvariant="italic">1</mn><mi>A</mi></mrow><mo stretchy="false">)</mo></mrow></mfrac></mrow><annotation encoding="application/x-tex">f_{out} = \frac{f_{SoC}}{2(1 + \mathit{OCR1A})}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.2806em;"><span style="top:-2.55em;margin-left:-0.1076em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">o</span><span class="mord mathnormal mtight">u</span><span class="mord mathnormal mtight">t</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1.4522em;vertical-align:-0.52em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.9322em;"><span style="top:-2.655em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">2</span><span class="mopen mtight">(</span><span class="mord mtight">1</span><span class="mbin mtight">+</span><span class="mord mtight"><span class="mord mathit mtight">OCR1A</span></span><span class="mclose mtight">)</span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.4461em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.10764em;">f</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3448em;"><span style="top:-2.3567em;margin-left:-0.1076em;margin-right:0.0714em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style="margin-right:0.05764em;">S</span><span class="mord mathnormal mtight">o</span><span class="mord mathnormal mtight" style="margin-right:0.07153em;">C</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.1433em;"><span></span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.52em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span><sup id="fnref:ref-timer-ctc" role="doc-noteref"><a href="#fn:ref-timer-ctc" class="footnote" rel="footnote">5</a></sup>.</p>

<p>To configure this mode properly, according to the datasheet we need the following parameters:</p>
<ul>
  <li><code class="language-plaintext highlighter-rouge">WGM1 (4 bits) = 4 = 0b0100</code> for CTC mode compared against <code class="language-plaintext highlighter-rouge">OCR1A</code><sup id="fnref:ref-timer-ctc:1" role="doc-noteref"><a href="#fn:ref-timer-ctc" class="footnote" rel="footnote">5</a></sup></li>
  <li><code class="language-plaintext highlighter-rouge">COM1A1 (1 bit) = 1</code> for toggling the output on compare match<sup id="fnref:ref-timer-ctc:2" role="doc-noteref"><a href="#fn:ref-timer-ctc" class="footnote" rel="footnote">5</a></sup></li>
  <li>Disable the interrupts that could be generated to the CPU<sup id="fnref:ref-timer-ctc:3" role="doc-noteref"><a href="#fn:ref-timer-ctc" class="footnote" rel="footnote">5</a></sup> — simply have the signal on the output pin.</li>
  <li><code class="language-plaintext highlighter-rouge">CS1 (3 bits) = 1 = 0b001</code> to disable the prescaler<sup id="fnref:ref-timer-prescaler" role="doc-noteref"><a href="#fn:ref-timer-prescaler" class="footnote" rel="footnote">6</a></sup> that can change the incrementing speed, but is too coarse for our use.</li>
</ul>

<p>Those values are spread over multiple registers, so we must set bits individually:</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">TCCR1A</code> stores COM1A1 and WGM1 bit 0 &amp; 1<sup id="fnref:ref-tccr1a" role="doc-noteref"><a href="#fn:ref-tccr1a" class="footnote" rel="footnote">7</a></sup>,</li>
  <li><code class="language-plaintext highlighter-rouge">TCCR1B</code> stores CS1 and WGM1 bit 2 &amp; 3<sup id="fnref:ref-tccr1b" role="doc-noteref"><a href="#fn:ref-tccr1b" class="footnote" rel="footnote">8</a></sup>,</li>
  <li><code class="language-plaintext highlighter-rouge">TIMSK1</code> stores the various interrupt enable flags<sup id="fnref:ref-timsk1" role="doc-noteref"><a href="#fn:ref-timsk1" class="footnote" rel="footnote">9</a></sup>.</li>
</ul>

<p>In the end, we need something like the following code:</p>

<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kt">void</span> <span class="nf">setupClock</span><span class="p">()</span>
<span class="p">{</span>
    <span class="c1">// Setup the clock to drive the SN76489</span>
    <span class="n">pinMode</span><span class="p">(</span><span class="n">clockOutputPin</span><span class="p">,</span> <span class="n">OUTPUT</span><span class="p">);</span>

    <span class="c1">// Set Timer 1 CTC mode with no prescaling.  OC1A toggles on compare match</span>

    <span class="c1">// WGM1 = 0100: CTC Mode against OCR1A</span>
    <span class="c1">// WGM1 bits 1 and 0 are in TCCR1A</span>
    <span class="c1">// WGM1 bit 2 and 3 are in TCCR1B</span>

    <span class="c1">// COM1A0 sets OC1A (arduino pin 9) to toggle on compare match</span>
    <span class="n">TCCR1A</span> <span class="o">=</span> <span class="p">(</span> <span class="p">(</span><span class="mi">1</span> <span class="o">&lt;&lt;</span> <span class="n">COM1A0</span><span class="p">));</span>

    <span class="c1">// Set Timer 1  No prescaling</span>
    <span class="n">TCCR1B</span> <span class="o">=</span> <span class="p">((</span><span class="mi">1</span> <span class="o">&lt;&lt;</span> <span class="n">WGM12</span><span class="p">)</span> <span class="o">|</span> <span class="p">(</span><span class="mi">1</span> <span class="o">&lt;&lt;</span> <span class="n">CS10</span><span class="p">));</span>
    <span class="c1">// Make sure Compare-match register A interrupt for timer1 is disabled</span>
    <span class="n">TIMSK1</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
    <span class="c1">// Counter top value</span>
    <span class="n">OCR1A</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>

<h3 id="testing-setup">Testing setup</h3>

<p>Finally, we can get the Arduino out.</p>

<p>Setting up a data bus on a breadboard is easy to get wrong, so at this stage we want to keep things simple to test our setup. We’ll simply set channel 3 to max volume, and then cycle between noise values 0 to 7 with a small delay in-between. This means we’ll send the following commands:</p>

<table>
  <tbody>
    <tr>
      <td>Hex</td>
      <td>MSB</td>
      <td>Register</td>
      <td>Value</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">0xF0</code></td>
      <td><code class="language-plaintext highlighter-rouge">0b1</code></td>
      <td><code class="language-plaintext highlighter-rouge">0b111</code>: Noise Attenuation</td>
      <td><code class="language-plaintext highlighter-rouge">0b0000</code>: 0 (max volume)</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">0xE0</code></td>
      <td><code class="language-plaintext highlighter-rouge">0b1</code></td>
      <td><code class="language-plaintext highlighter-rouge">0b110</code>: Noise</td>
      <td><code class="language-plaintext highlighter-rouge">0b0000</code>: Periodic, N/512</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">0xE1</code></td>
      <td><code class="language-plaintext highlighter-rouge">0b1</code></td>
      <td><code class="language-plaintext highlighter-rouge">0b110</code>: Noise</td>
      <td><code class="language-plaintext highlighter-rouge">0b0001</code>: Periodic, N/1024</td>
    </tr>
    <tr>
      <td> </td>
      <td><code class="language-plaintext highlighter-rouge">0b1</code></td>
      <td>[…]</td>
      <td> </td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">0xE7</code></td>
      <td><code class="language-plaintext highlighter-rouge">0b1</code></td>
      <td><code class="language-plaintext highlighter-rouge">0b110</code>: Noise</td>
      <td><code class="language-plaintext highlighter-rouge">0b0111</code>: White, Tone Generator #3 output</td>
    </tr>
    <tr>
      <td> </td>
      <td><code class="language-plaintext highlighter-rouge">0b1</code></td>
      <td>Cycle back…</td>
      <td> </td>
    </tr>
  </tfoot>
</table>

<p>Here is one picture I took of the setup in a flash of clarity of mind:</p>

<figure>
  <a href="https://blog.mfavreaux.fr/assets/sn76489/images/arduino-setup-noise.jpg" target="_blank">
    <img src="https://blog.mfavreaux.fr/assets/sn76489/images/arduino-setup-noise.jpg" alt="First tests on the breadboard" />
  </a>
  <figcaption>First tests on the breadboard
  
  </figcaption>
</figure>

<p>You can barely make out the pin layout, but it does not matter too much: there are enough pins on a simple Arduino to dedicate one to each chip’s pin. Note I decided to revert the big-endian-looking data bus into little endian on the Arduino side, because my brain is wired that way and the code looks simple to me:</p>

<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kt">void</span> <span class="nf">writeByte</span><span class="p">(</span><span class="n">byte</span> <span class="n">value</span><span class="p">)</span>
<span class="p">{</span>
  <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="mi">8</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
    <span class="n">digitalWrite</span><span class="p">(</span><span class="n">DATA_BUS_PIN0</span> <span class="o">+</span> <span class="n">i</span><span class="p">,</span> <span class="p">(</span><span class="n">value</span> <span class="o">&gt;&gt;</span> <span class="n">i</span><span class="p">)</span> <span class="o">&amp;</span> <span class="mi">1</span><span class="p">);</span> 
  <span class="p">}</span>

  <span class="c1">// [...] Wait for write enable</span>
</code></pre></div></div>

<p>One trivial detail: I pulled <span style="text-decoration:overline"><code class="language-plaintext highlighter-rouge">CE</code></span> to ground via a <a href="https://en.wikipedia.org/wiki/Pull-up_resistor">pull-down resistor</a>. I think it was 4.7 KΩ? At 5 V, a value of ~5 K drains an acceptable ~1 mA, and this value seems to work well.</p>

<p>And finally, this is what is sounds like through the feeble speaker you see on the picture:</p>

<figure>
  <audio controls="" ref="First noise successful test." src="https://blog.mfavreaux.fr/assets/sn76489/audio/noise-test-1.mp3">
    Your browser does not support the audio tag."
  </audio>
  <figcaption>First noise successful test.
  
  </figcaption>
</figure>

<p>Our first milestone has been reached!</p>

<h2 id="mistakes-were-made">Mistakes were made</h2>

<p>Now, don’t think for a minute that this went smoothly. It did not, and I did a fair share of rookie mistakes.</p>

<p>First, notice how pin 0 &amp; 1 are not wired on the Arduino? That’s because pin 0 &amp; 1 on the Arduino are <em>dedicated</em> to the serial transmission if you set it up (which I did, because logs). So of course, if you wire them up to the chip, you’re going to have a bad time. This is reflected in the actual <code class="language-plaintext highlighter-rouge">writeByte</code> code.</p>

<p>A second, big issue I had was with dealing with the READY signal. I could not, for the life of me, see it pull up! It was just… standing there, flapping in the breeze. I’m probably missing something trivial though. I may revisit this in the future, if I put a chip back on the breadboard. In any case, after a while I decided to cut my losses and ignore the signal, use a delay instead, and move on.</p>

<h2 id="next-steps">Next steps</h2>

<p>We’d now be ready to make the chip play some simple tunes on one of the other channels, or do some cool sweep. In part 2, we’ll set up the MIDI side of things so we can control the board from a keyboard or a DAW, and improve from there.</p>

<p>But first, in <a href="/midi-to-sn76489-part1b/">part 1-B</a>, we’ll dive into the little amplifier you can vaguely see on the picture above.</p>
<div class="footnotes" role="doc-endnotes">
  <ol>
    <li id="fn:prior-works" role="doc-endnote">
      <p>I’m certainly not the first one to do so! There are plenty of examples to be found:</p>
      <ul>
        <li><a href="https://mansfield-devine.com/speculatrix/2019/11/fun-with-chips-2-sn76489-sound-generator-ic/">Fun with chips #2</a> by Steve Mansfield-Devine was certainly an inspiration to go through this first phase of the project.</li>
        <li><a href="https://www.reddit.com/r/beneater/comments/f4z3ct/weekend_project_playing_with_an_sn76489an_sound/">Weekend project</a> by transitorykris.</li>
        <li><a href="https://www.youtube.com/watch?v=lfL9NdnNNGM">SN76489AN demo</a> by James Dalton.</li>
      </ul>
      <p><a href="#fnref:prior-works" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:vgmrips" role="doc-endnote">
      <p>There are a few communities dedicated to extracting &amp; preserving these artifacts in the form of, for example, <a href="https://vgmrips.net/wiki/VGM_Specification">VGM files</a>. <a href="https://vgmrips.net">VGMRips</a> is a good starting point. In this page, I reproduced short samples of mp3s you can listen to there, in the hope that it’s OK. <a href="#fnref:vgmrips" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:DMG-LSDJ" role="doc-endnote">
      <p>The original GameBoy is especially appreciated for its versatility &amp; textures, and got popular notably through <a href="https://www.littlesounddj.com/lsd/index.php">LSDJ</a>, a tracker made for the hardware. <a href="#fnref:DMG-LSDJ" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:forum-clock" role="doc-endnote">
      <p>This <a href="https://forum.arduino.cc/t/best-way-to-generate-a-clock-signal-with-arduino-mega/320522/2">thread</a> on the Arduino forum was the trigger. <a href="#fnref:forum-clock" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:ref-timer-ctc" role="doc-endnote">
      <p><a href="https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf#G1188567">§15.9.2 Clear Timer on Compare Match (CTC) Mode</a> page 100-101. <a href="#fnref:ref-timer-ctc" class="reversefootnote" role="doc-backlink">&#8617;</a> <a href="#fnref:ref-timer-ctc:1" class="reversefootnote" role="doc-backlink">&#8617;<sup>2</sup></a> <a href="#fnref:ref-timer-ctc:2" class="reversefootnote" role="doc-backlink">&#8617;<sup>3</sup></a> <a href="#fnref:ref-timer-ctc:3" class="reversefootnote" role="doc-backlink">&#8617;<sup>4</sup></a></p>
    </li>
    <li id="fn:ref-timer-prescaler" role="doc-endnote">
      <p><a href="https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf#G1191397">§16.1 Timer/Counter0 and Timer/Counter1 Prescalers: Internal Clock Source</a> page 114. <a href="#fnref:ref-timer-prescaler" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:ref-tccr1a" role="doc-endnote">
      <p><a href="https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf#G1189341">§15.11.1 TCCR1A</a> <a href="#fnref:ref-tccr1a" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:ref-tccr1b" role="doc-endnote">
      <p><a href="https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf#G1190212">§15.11.2 TCCR1B</a> <a href="#fnref:ref-tccr1b" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:ref-timsk1" role="doc-endnote">
      <p><a href="https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf#G1191133">§15.11.8 TIMSK1</a> <a href="#fnref:ref-timsk1" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
  </ol>
</div>]]></content><author><name>Mathieu Favréaux</name></author><category term="sn76489" /><category term="electronics" /><category term="chiptune" /><summary type="html"><![CDATA[The first installment in a series were we build a MIDI instrument from a bunch of SN76489s. In this article, we concentrate on setting up communication with a an SN76489 and getting some sound out of it.]]></summary></entry></feed>