Blog as you go: sigma delta DAC

I have some piezo speakers from another project. That one used a bi-level amp to drive them. I figured it would  be fun to try a tri-level drive, using an H bridge allows you to have +, – and 0V across the device. And for fun, why not make it a direct sigma delta encoder?

It’s going to run on a microcontroller (an arduino). It’ll need very precise timings, so I’ll not be using the arduino environment.

Here’s a first pass in C++ for linux:

#include <iostream>
#include <cmath>
#include <utility>

using namespace std;

float signal(int t)
	//Roughly 0-1
	return (1 + sin(t/20. - 1))/2.1;

float quantize(float f, int levels)
	return min(levels-1.f, max(0.f, floor(f*levels)))/(levels-1);

int main()

	float integral = 0;

	for(int i=0; i < 200; i++)
		float output = quantize(integral, 3);
		float difference = signal(i) - output;
		integral += difference;

		cout << signal(i) << " " << output << endl;


And this produces output like this (mildly prettified):

Which looks about right. The code will pretty much stink on an arduino since it’s all floating point. It’s easy to convert to integer code though:

#include <iostream>
#include <cmath>
#include <utility>

using namespace std;

uint16_t signal(int t)
	//Roughly 0-1
	return 65535 * (1 + sin(t/20. - 1))/2.1;

uint16_t quantize(int32_t i)
	if(i < 21845)
		return 0;
	else if (i < 43690)
		return 32768;
		return 65535;

int main()

	int32_t integral = 0;

	for(int i=0; i < 200; i++)
		uint16_t output = quantize(integral);
		float difference = signal(i) - output;
		integral += difference;

		cout << signal(i) << " " << integral << " " << output << endl;


I’ve used a uint16_t for the value, which will effectively represent both positive and negative levels with 32768 being the zero point. Note that the error integral must be both signed and wider since the errors can grow beyond the signal range:


Now to port to the arduino. So, I’ll get my Makefile from here.

I’m going to pick pins 8 and 9 on the UNO, that is PB0,1 on the chip for my outputs. and here’s how you get 3 way opposed outputs as +/-/0. To demo, I connected a pair of LEDs in parallel but facing the other way:

#include <avr/io.h>
#include <util/delay.h>
int main()
	int i=0;

			DDRB = 3;
			PORTB = 1;
		else if(i==1)

			DDRB = 3;
			PORTB = 2;
			PORTB = 0;

		if(i > 2)


So I started the port and BOOM! 😦

It stopped working. The reason was simple: the simple makefile takes one object file and converts it to HEX. Since I’m using sin(), we actually need to link the .o and .a into a .elf file, then convert THAT to HEX. The snippet is:

%.hex: %.elf
avr-objcopy -j .text -j .data -O ihex $< $@

prog.elf: delta_sigma.o
avr-gcc $(FLAGS) -o prog.elf delta_sigma.o -lm

Obvious, really, in hindsight…

So, OK, now to convert the modulator code to the arduino. Lots of things went wrong. But first, here’s the code:

#include <math.h>
#include <stdint.h>
#include <avr/io.h>

uint16_t signal(int32_t t)
	float u = t / 1024.f;

	//Roughly 0-1
	return 65535 * (1 + sin(2*3.151592f*u))/2.1;


uint16_t quantize(int32_t i)
	if(i < 21845)
		return 0;
	else if (i < 43690)
		return 32768;
		return 65535;

int main()

	int32_t integral = 0;


	for(uint32_t i=0; ; i++)
		uint16_t output = quantize(integral);
		int32_t difference = (int32_t)signal(i) - output;
		integral += difference;

		if(output == 0)
			PORTB=1; //Output 1 0
		else if(output == 65535)
			DDRB =255;
			PORTB=2; //Output 0 1
			PORTB=0; //Output 0 0

What didn’t go wrong? Nothing! I wasn’t nearly careful enough with my ints (only 16 bits on AVR), ints of specific width, overflow and that sort of thing. Also, initially, I decided to output a 0 level by tri-stating the two outputs, so they both float to the middleish. Turns out that didn’t work well since they float extremely slowly (not surprising really!). Forcing them both down to 0 worked much better.

After all that, I then connected a simple RC filter across it so you an see the results:

That’s actually a pretty nice sine wave there! It ought to be: there’s really not much room for nonlinearity and other distortions to creep in. I’ve zoomed in a few levels so you can see how it looks in detail.

It is however really really slow. I’m using full floating point, and a transcendental operation every iteration of the sigma delta encoder. That is really slowing down the cycle time since the AVR isn’t very fast. That accidentally solves the other problem which I’ve made no attempt to make sure every path takes the same number of cycles. But that sin() is dominating so heavily that it doesn’t matter.

And that’s it for part 1: a working sigma delta encoder. For part 2, I’ll make it fast enough to generate audio tones which aren’t simply the sigma-delta encoder transitions (I hope).

Oh also here’s tehe obligatory github link.



How bad is switch bouncing really?

TL;DR: it’s worse.

ETA: I think every electronic engineer goes through this at one time or another. You have a switch that bounces, so you debounce it. I mean every knows that switches bounce. The code doesn’t work 100%, so you fix all the bugs and it still doesn’t work. So then you break out the scope and hells bells! How can it be that bad?! I mean everyone says it’s bad and you knew it was bad but it’s BAAAAAAD.

So, I recently had a switch which needed debouncing. It happens to be a Marquardt (seems to be a good brand) microswitch. In terms of current it’s massively overspecced (16A, 250V), but it turned out to be ideal for the combination of size, button stroke, force and of course price. I guess that sort of switch is used for mains interlocks or something, but I’m using it to switch a GPIO input to a raspberry pi.

Here’s how it’s connected up:


I’d like to say I connected it to both power rails to show how the different contacts bounce. Actually my brain disconnected and that’s how I originally connected up the switch in my project. It’s a terrible idea because you get bouncing from both sets of contacts for twice the fun. The potential divider pulls the middle up to half the voltage so you can see which contacts are bouncing and when.

On the plus side, it’s great for illustrating bouncing…

Here’s what the setup looks like:


I use the mini vice (which I’m quite unreasonably proud of) to close the switch really, really slowly. And this is what pushing the switch looks like:


(Note: I can’t figure out how to take a screenie without the annoying “take a screenshot” dialog showing…)

It’s quite amazing. Note the “pre-bounce” where a disconnect happens 225ms before the switching starts. In fairness, I couldn’t reliably reproduce that, but it does happen occasionally. Thar main transition looks suspicious though:


That’s semi-horrid. The 0V contact opening is pretty clean. It then takes about 9ms for the + contact to start closing. It bounces all over the place, and even after the main bounce has stopped, it still takes 4ms for the voltage to stabilise. I guess connecting only 0V and a pullup would work much better. And here’s the bounces in detail:


Horrible, but par for the course. You can see it’s not settling cleanly on the contact in between the bounces. And here’s a different one for comparison (RTFM n00b, the fine manual says how to sake screenies properly):


This is bad in a rich and interesting variety of different ways. Like the vast majority of traces, there’s no awful pre-bounce. However, the disconnect is unclean and takes 10ms before it starts to rise properly. After the bouncing nominally finishes, it still takes a whopping 100ms to really settle.


Here’s some samples to fill you with horror as well as a couple of fairly standard ones. Some of them have a longer timebase to show a 200ms settling time.

Some of them have some really weird behaviour as they open. I haven’t figured why and the speed at which I actuate the switch doesn’t seem to affect things much. The same can’t be said for releasing the switch. The slower you release it, the gungier it is. See the enormous 100ms timebase:

yuck yuck yuck 😦 Faster actuation (and the actual bouncing) looks much as you’d expect:


though, the time between the break and make is rather shorter.

Either way, the +V contact (the one connected by closing the switch) seems surprisingly much worse than the 0V one. We can of avoid that contact by connecting the switch as a single throw one with a pullup:


And if I’m quick, I can manage to get an open and close on the screen with a 10ms timebase:


The push still has some pre-bounce, but it’s nothing like as bad as from the other contact. For the switch being pushed, there is on bounce whatsoever; it’s astonishingly fast:


for the release, there’s a bit of bouncing as expected.

Conclusion: don’t connect up switches in a silly way like I did!

Can it be true? That I hold here in my mortal hands, a splat of purest crud?

Today, a semi-successful experiment. I tried to make a small arc furnace using an arc welder, a graphite crucible and some inanimate carbon gouging rods. The goal was to melt aluminium successfully enough to do some casting. The idea behind using the arc welder is that it’s accessible and doesn’t require faffing around with fire, and getting the consumables brought in (gas, for example). The whole thing ought to be less messy and quicker to set up and tear down.

The furnace consists of a solid, 4kg sized graphite crucible (remarkably inexpensive) sitting in a badly welded, but very stable steel holder steel holder:


An arc furnace. The white stuff on the inside is alumina fumes which settled on the side.

The idea was to strike an arc with the crucible and a copper clad carbon rod (a gouging electrode). It kinda worked, but the arc was pretty unreliable and surprisingly weedy even on the highest setting on the welder. I had much better luck striking the arc between two carbon rods and moving that around as a heat source.


The rods are very much a consumable!

That kinda worked, and I was certainly able to get some melting (as you can see in the splat). Enough to prove the principle but not enough to actually do some casting. The summary is kind of:

  • Someone stole my flux (own brand lo-salt), so I got a lot of aluminium oxide for my troubles.
  • The welder doesn’t like the 16A breaker for the outdoor power socket. Works fine on the other 16A breaker in the basement but keeps tripping out.
  • Not enough insulation, a rather large crucible, repeated cutouts and cold weather meant I couldn’t retain enough heat to make a pour.

The thing to do now it appears is to make the furnace by hollowing out an alumina firebrick. They’re very porous and so excellent insulators (one video has the person picking up his brick with bare hands with a pool of molten aluminium in the central hole).

Nonetheless, it proves the principle. The 400 and 600A (one of each) crocodile clip style rod holders hold the carbon rods well. The rods work, strike an arc and provide aluminium melting heat.


Adventures in gluing

The thing I’m working on has some metal parts glued into a plastic case. The plastic is smooth (the mould is finished to the “Society of Plastics Engineers” 600 paper spec), and the metal is shiny chrome plated brass. I never considered either of those to be especially hard to glue, so I went for a pretty straightforward epoxy, Loctite 5 minute instant mix clear. It’s a decent enough go-to, much like any other random 5 minute clear epoxy. The short curing time is great for the impatient (me) and the clear finish is great because you can be a bit lax about the cleanup, which is especially important given the short curing time.

So, I splurged some on the metal part, shoved it in the hole and wiped off any egregious amount of excess with white spirit. A week later, I was fiddling with the part seeing how strong it was and was kind of surprised/distressed about how easily the joint broke. Like, really far too easily. And incidentally always the same way: the glue detaching from the plastic.

Then it got me thinking. I had a vague recollection that 5 minute epoxies kind of suck and come to think of it, so do clear ones. In a sort of ad-hoc way I think I’d come up with this:

Ed’s  rule of glue

Every feature added to glue makes it worse.

Fast curing? worse. Non, tinted transparent? That’ll cost you. Conductive? [sucks air through teeth]. It kind of makes sense, you can’t optimize everything at once.

That’s not to say you should never use that glue, it’s still perfectly fine for a lot of stuff, but slower curing and/or those ones that cure a nasty brown colour will almost certainly perform better. So, anyway, I tried  some polyurethane glue I had lying around and it seemed to be a bit better.

Time to experiment!

So,  which one to use? So first, the selection. There’s roughly an infinite number of glues out there, give or take a few. Some have wild and wacky properties, but even if you stick to the middle ground of generally gluing stuff to other stuff, there’s still a large selection.

So, I picked some somewhat arbitrary criteria and selected some glues that generally fitted:

  1. Specced to glue metal to plastic, bonus points for having ABS in the list.
  2. Available from local shops or next day delivery from RS
  3. Reasonable curing time to handling strength.
  4. Auto mixer if possible where applicable (better for large volumes).
  5. Not wildly expensive.
  6. Decent brands and available in the US (I’d normally be happy with RS pro stuff, but I need to be able to get it abroad easily).

The brands are mostly big, well known ones. 3M is always good. Loctite likewise seems fine. The other one, Araldite, I have a particular soft spot for. For years in the home gamer space it was pretty much synonymous with epoxy. My old DT teacher was a huge fan (rightly so) because you could fix all manner of sins with it. Countless projects were rescued with Araldite at my school.

And so, I came up with the following list:

  1. Loctite 5 minute instant mix. That’s the baseline, and my gut feeling says that other clear, fast setting epoxies won’t differ wildly.
  2. Araldite Standard. Bog-standard DIY shop glue. Slow setting (pot time of an hour, high strength in 24), dries kind of opaque yellowish.
  3. Araldite 2011. One of about a billion varieties. Similar to 2, but dries clear yellow. Allegedly slightly stronger on ABS. Also a pro glue, so comes in pro packaging which means you need one of those applicator guns and a clip on mixing nozzle for the auto mixer.
  4. Loctite 330. It’s an acrylic glue which I didn’t even know was a thing before today. You put glue on one surface an spray the activator on the other surface and put them together. Datasheet specifies 7387 or 7386 activator, but Loctite actually sell it packaged with 7388 of course. Fast cure time (30 mins to half strength) , and almost indefinite pot time, which is handy, since you don’t mix it with the activator. Not much by the way of instructions though.
  5. Araldite 2028. OK, I lied about not bothering with other fast curing clear epoxies. This one claims excellent performance on ABS, not so much in the datasheet which is not anywhere official I could find, but in this handy selection guide, which has a mysteriously chosen subset of the glues on offer. Also pro packaging with an auto-mixer.
  6. 3M ScotchWeld DP8005. Now I’ve heard about acrylic adhesives, I’m on a roll. Also RS had a relatively small selection of 3M and I felt things wouldn’t be complete without one. Claims to work well on ABS. Has an annoyingly short pot life (3 minutes and they’re not messing around).
  7. Everbuild gator glue. Bog standard polyurethane glue (basically the same as Gorilla

    I love the logo too!

    Glue). Generally considered OK for metal and plastic. Reasonable pot life and cure time. Single part, so no mixing needed. Also expands as it cures. This is not (as is popularly thought) useful for filling gaps since it expands as foam when the pockets of glue get too large. However, it does slightly splurge out so if you miss small areas, they get filled from the nearby ones. If you’re not familiar with British knock off brands, Everbuild is basically an adhesive company which makes cheaper versions of the well known stuff. So Gator glue/Gorilla glue, One Strike Filler/Pollyfilla, Stixall/No More Nails, etc etc. They also sell the delightfully named ASBO brand anti climb paint and anti graffiti painting. That makes me chuckle every time.

  8. Polycaprolacetone. I remember that sticking to everything really hard when I tried to use it. Applying it as an acetone based slurry, then reflowing it thermally after it’s dried. This is basically me messing around.


    White crud on the two snaps on the right hand side. No glue was applied there.

  9. Cyanoacrylate (generic brand). Another baseline, known to be strong and effective, but outgasses this white crud everywhere which is electrically insulating and has to be cleaned off.

Oh and the surface prep. Did I mention I forgot the surface prep before?

  1. Clean both surfaces with IPA (isopropyl alcohol).
  2. The full monty: clean with IPA, sand with 400 grit paper (3M as it happens), then clean again with IPA.
  3. As-is, with whatever crud and release agent is left on by the moulding processes.

And it’s arrived!

Swag! Lots of glue arrived


Check out the swag, including a spiffy (and necessary) applicator gun, because as you can see, the pro packages don’t have full syringes. And 3 hours of cleaning, sanding, mixing, gluing and wiping off the excess, I present:


That’s a lot of gluing and there’s more to come.

So now, I need some way to measure the force required to eject the metal bits from a case. Naturally, since I’m doing the whole thing at short notice and in rather a hurry,  I had to cobble together something with whatever was lying around or could buy locally. My solution is to go to a local DIY shop and enter a kind of trance until a solution based on the weird selection on offer presents itself. The result was this:


After a few iterations, I settled on pushing down on a set of old kitchen scales held down with cable ties and string. The lever is 4x and the scales go to 5Kg, and the extra weights on the end are 2.5Kg at 5x. Maximum force it can apply is 32.5Kgf.

It’s basically a parallel action mechanism with a long lever. I balanced it to make it neutral and marked graduations on the lever so I can put a weight at a known position to apply a known force. You can’t see the M4 screw on the underside which is embedded into the pressing bit with some brass threaded inserts. I used some 5 minute epoxy (surprise!) to glue them in, but not a clear one and the horrendous brown colour made me think I should have tried it too. Though being nasty coloured and fast curing (hard to clean off) is not a great combo. The big M10 studding isn’t going into bare pine. The holes are lined with some sort of plastic tubing which felt a lot like HDPE. Naturally it was 15mm, and they only had 14 and 16mm drills, so a lot of sanding was involved (later I found just hacking off the outer layer with a Stanley knife was faster. Oh well). It’s also quite loose (inner diameter 11mm), which is good because I can’t drill straight apparently.

Oh, also, I glued on the main pillar upside-down first time (look: it’s not symmetric) at the other end with the Gator glue (scar is visible just by the pliers). I realised after about 20 minutes and that was enough that one of the end grain to long grain joints was already stronger than the wood. Even if I find doesn’t measure up here, I’ve become a fan of the speed of polyurethane glue and strength on end grain for woodworking

Oh and check out how straight the pillar is 8-). There’s nothing to keep it straight except for the square planed end. I’m excessively pleased about that.

RTFM, n00b.

So the spare DP8005 didn’t cure in a nice solid lump, at least in not in a few hours, and it’s meant to have a pot time of about 3 minutes. I think it was a mixing problem. I’m not 100% sure I got the right nozzles and since it’s a 10:1 mix, that really matters. So I mixed some by hand, too (strongly not recommended) and tried that. But since mixing is slow and it has a short pot time, I didn’t have a chance to glue up all variants. When it’s properly mixed, this stuff sets FAST.

The first results.

Thoughts so far during gluing:

  1. The Loctite 330 activator is this yellow gunk that has to be cleaned off. It’s pretty nasty and it’s more or less impossible to clean it off interestingly shaped surfaces.
  2. Scotchweld DP8005 is made by 3M and being 3M they’ve really put the effort into the packaging. It reseals really well by plugging up the holes (unlike the Araldite which has a simple cap), with a keyed cap, so you don’t mix the two sides. Also it’s gritty! That’s apparently to keep the surfaces apart by the minimum spacing. 3M think of everything.
  3. Cyanoacrylate is and always will be a pain in the neck.
  4. My lab now smells of glue and solvents. Niiiice.

Anyway, I left them curing for 36 hours in my lab. Then I spent I don’t know how long pressing snaps out of cases and writing down the results. And then some awk code to collate and prettyprint the results of course.


                        Surface prep||     IPA clean     |clean, sand, clean |       none        
Glue                                ||    ave     min    |    ave     min    |    ave     min    
Loctite instant mix 5 minuted epoxy ||    14.7    8.8    |    12.1    9.2    |     9.1    8.0    
Araldite standard                   ||*    7.9    5.6    |*   11.2   10.0    |*    4.8    4.0    
Araldite 2011                       ||*    6.5    4.8    |    11.5   11.2    |     5.4    5.2    
Loctite 330                         ||*   12.3    7.2    |*   16.3   14.4    |*   13.6   10.4    
Araldite 2028                       ||     7.1    5.6    |     6.9    6.4    |     5.9    5.2    
Scotchweld DP8005 badly mixed       ||*    4.4    3.6    |*    4.1    4.0    |*    4.5    4.4    
Scotchweld DP8005                   ||    22.1   20.0    |                   |    17.5   13.6    
Gator glue (no water)               ||*   11.7   11.2    |*    7.5    4.8    |*    9.7    8.8    
PCA                                 ||     3.2    2.8    |     5.1    3.6    |     3.0    2.0    
Cyanoacrylate                       ||    21.0   15.7    |    22.6   18.4    |    21.6   19.7    

* = Clean off excess glue with IPA


And… ehhhhhh.

It’s a bit mediocre.

Well OK. I’ve established that it’s really important to clean the parts before gluing. Sanding seems to help a bit, mostly, but to be honest I didn’t do a great job of it.

The 5 minute epoxy came out pretty strong comparatively and although it seems strong enough it’s not exactly decisive. The CA is strong (as expected), but has outgassing problems. The DP8005 is excellent if done properly, but I think it cures a bit fast to be useful for this application. The Loctite 330 is decent, but that spray is just too horrible for this application.

My ad-hoc experiments earlier had Gator Glue doing better relative to the Loctite epoxy. I think something might be wrong there.

And wow, Araldite, you kinda suck 😦 Is this the end of my fond childhood memories?

No, seriously, RTFM, n00b.

OK, so I forgot a bunch of stuff. I forgot to dampen one of the surfaces with the polyurethane glue (Gator Glue). That might explain the so-so results. Time to repeat the experiment. This time, I also switched to genuine Gorilla glue, not because I expect it to be better, but because the results are going to be used in the US and Gator glue isn’t available there.

Also, the lumps of left over araldite 2011 seemed kinda not fully cured even after 36 hours. I mean they’re sort of hard, but not really solid like I’d expect. The data sheet claims it cures at 10 degrees C (colder than the room I used) but rather sneakily, the strengths are not listed for low curing temperatures.

Double also, in the DP8005 datasheet, it mentions that you should discard the first bit out of the nozzle because it won’t be properly mixed. Not only did I not do that either, but it seems like a really good idea for the other auto mixers as well.

Round 2. Fight!

I’m only re-testing the ones which (a) didn’t seem to come out quite as expected (b) won’t cause massive wastage and (c)  don’t have other issues. So, I’m doing Araldite 2011 with a bake at 80 degrees C for an hour (far more than enough) and Gorilla glue with a water spray. I’m also going to be a bit more generous with the Araldite and apply it to both surfaces. I chose 80 based on a kind of gut feeling compromise: the datasheet listed curing times up to 100, but 80 still cured fast and the plastic starts to soften slightly at 85.

For surface prep I’m only doing the IPA clean since it works well, but not the sanding since it’s variable, hard to do and possibly too awkward to be good in production.

The only thing I am varying consistently is whether or not  to wipe off any excess with IPA.


                        Surface prep||     IPA clean     
Glue                                ||    ave     min    
2011, both sides, bake              ||*   20.7   16.8    
2011, both sides, bake              ||    26.9   19.7    
Gorilla Glue, wipe after            ||*   19.9   17.6    
Gorilla Glue                        ||    17.2   15.6    
Scotchweld DP8005                   ||    22.1   20.0    

* = Clean off excess glue with IPA

Well, that’s a bit better.  The Araldite 2011 is the clear winner in strength terms. One measurement actually hit the maximum 32.5Kg the default setup of the press could reach and tore a chunk of the chrome plating off the underlying brass of the snaps . And the Gorilla Glue puts in a very respectable showing. Not quite as strong, but the worst cases are pretty similar. I’m pretty confident now that either of these will do in the final application with the correct surface prep.






That wasn’t in the (LMC555) datasheet :(

So I was making an one-off circuit to drive some things from an RPi and I needed a level shifter. Turns out that a CMOS 555 (on paper) looks like a pretty good bet if you need an ad-hoc solution with mild performance requirements. The TI LMC555 runs all the way down to 3V or so, and can source 100mA from the output. Being CMOS, the output goes more or less to the rails.

So far so good. The way to set it up is to power it off the high side, wire it in Schmitt trigger configuration (pin 6 to pin 2), and set the control voltage at 2/3 of the lower level. And that works just fine.

One problem, it seems that despite being specced to run off 3V, the current sourcing capability drops drastically under about 6V, to the point where at 5V it will only source about 12mA! That’s something of a pity because I needed those 100mA, or more than 12 at any rate, and annoyingly it doesn’t appear to be mentioned anywhere in the datasheet.


On the other hand, I’m glad I bought those jellybeans a while back. I replaced the 555 with a high side PNP switch (a now discontinued BC638 in a small TO92 from one of those Maplin grab bags)  who’s base is driven from a chunky STP55 (a giant TO220) since the latter switches adequate current at only 1V. The 2N7000 is kind of marginal for getting the high base current required to get a low saturated Vce when driven from  3.3V.

So, mission accomplished, but I’m still annoyed about the serious derating. I’ll make a graph when I figure out how to get my scope to act as a data logger.

EDIT: That was way easier than I thought. You can save traces via rather awkward interface to a USB stick in the front panel. So, I set up a 555 to output high into a 10 Ohm load and cranked the supply voltage by hand, measuring the supply and drop across the load. And here’s the result:

The LMC555 hist 100mA at 12V compared to 3 for the LM555

Graph of output pin current into a 10 Ohm load against supply voltage

Well, turns out the LMC555 has a rather high output resistance. The bipolar LM555 on the other hand is a bit of a beast and will give tons of current if you don’t mind the quite high (over a volt) drop at the output.


I’m low on parts and it’s time to restock. I’m after jellybean prototyping parts—generic ones without any surprising properties. The criteria are they are (a) reasonably cheap (b) available from RS, (c) through hole, (d) available in sensible quantities.


High power

STMicroelectronics STP55NF06L. Excellent logic level (50A at 3V, over 1A at 2V, something down to 1V), 55A/60V. (about 20p)

Low power

On Semi 2N7000. Logicish level, (50mA at 3V, not much below that), 200mA, 7p.

No outstanding low switching voltage small MOSFETS seem to exist as jellybean parts.


OK so everyone says the 741 is too old school and there are opamps better across the board. They’re also 24p which while cheap is actually more expensive than rather better amps. And there are way cheaper ones too.

Super generic

Taiwan Semiconductor TS358CD, 1MHz mostly because it’s 6p. Worse than the 741 in most ways, but 6p! For 2! That’s 3p each! Also, single supply down to 3V. Stretching the definition of jellybean a bit, since it’s so low end, but they’re still going to be fine for basic stuff and if they’re rubbish, well I didn’t lose much. Also did I mention they’re 6p?

Standard voltage

Texas Instruments TIL081, 3MHz, normal voltage range, FET input (33p). A drop-in replacement for a 741, slightly pricier, but better in every single spec. Similar to the LF411 recommended by H&H, not quite as good apparently, but about a tenth of the price.

RRIO, low voltage

Microchip MCP6002-I/P, 1MHz,   1.8V, 100uA single supply, FET? input (1pA) (20p)


Microchip MCP6291, 10MHz, 2.4V single supply,  1mA, RRIO, probably FET input (50pA) (35p).

Voltage Regulators

3.3v for things like bluetooth chips and other MCUs. 5V for obvious things and the 317 for everything else.

STMicroelectronics L78L33ACZ, 100mA (14p)

STMicroelectronics L7805CV-DG, 1.5A (9p)

Texas Instruments LM317KTC, 1.5A (15p)


I’ve never tried any of these particular variety of 555s before, but how bad can they be, eh? 🙂 Also yes, I know that an arduino/MCU can do a better job of a timer, but 555s do a bunch of stuff plus there’s always the “what weird things can I do with a 555” game.

Texas Instruments LMC555CN/NOPB, CMOS, 3MHz (74p, kinda expensive for a jellybean, CMOS and fast!)

Texas Instruments NE555P (22p – that’s more like it! Bog standard 555)


louder, Louder, LOUDER! (or: more dead bugging)

Sometimes someone makes a chip to do just what you want.

I’ve recently been needing to generate beeps from a BLE113 module (it’s a CC2541) which runs off a CR2032 coin cell at a nominal 3V, but more like 2 to 2.5 in practice. The speaker of choice is a surface mount piezo sounder which are small (9mm square) and unlike the discs don’t require mounting on a sounding board to get sound out. I’ve not idea if those Murata ones are the best, but it’s a respectable brand and those are the first I found that seemed to meet the spec.

They’re not especially loud, only 65dB at 1.5V pk-pk. The microcontroller I’m using has 4 useful channels on timer 1 for this application, and of course the outputs are totem pole outputs. So, driving it with two PWM channels in opposition is driving it with an H bridge which gives the full 2-3V pk-pk swing (depending on the battery voltage).

That makes it little louder, but not an awful lot. The datasheet says that the sounders can be driven at up to 12V pk-pk without damage. The datasheet however merely notes that it is “probable” that increasing the voltage will increase the volume, which is a bit unhelpful, though it has a graph for one (not the one I want) showing an increase with voltage exactly as you’d expect.The question then is how to generate a higher voltage for the buzzer. I had lots of ideas:

    Boost / switched capacitor converter and another H bridge (impractical–too many components)A miniature transformer (none quite small enough or with the right turns ratio)A miniature autotransformer (closer, but still the same problem)Something cunning with an inductor—some sort of ad-hoc boost thing which generates spikes rather than a square wave. Idea not really fully formed.

None of them are really any good. They’re either require impractically large number of components, components that either don’t exist (or I can’t find) or are vague and ill formed and I don’t have the parts to test the idea and anyway I’d probably end up busting up the chip with voltage spikes.

Fortunately it appears that someone thought of this already. It turns out the PAM8904 already does exactly this. It’s a switched capacitor converter with an H bridge, that takes a digital signal in, precisely for the application of driving piezo sounders from low power microcontrollers. Which is nice.

Except I’m not very trusting, and I’ve no idea if it’s worth the effort. I don’t want to order a circuit board and then fiddle around hand soldering QFNs (I’ve seen it done, I’d rather use a stencil) for a one off test. Like so many chips, it’s QFN only now. So the obvious thing to do is to buy one and deadbug it.

I figured I’d try the nice fine hookup wire I’ve got. The colours make it a bit easier to follow which wire is which. Next time, I’d try the same soldering job with enamelled wire. It’s harder to strip and tin, but the insulation doesn’t get in the way. The key to getting the soldering to work in the end was to tape down the wires with masking tape (3M blue tape) as I went along. Even with that it’s two steps forward, one back as you accidentally desolder wires when trying to attach new ones. Here it is!


(OK, not as good as this, or this, or this—hey that socket is a really nice idea!)

Spot the schoolboy error? I remembered to check continuity between neighbouring pins, but I forgot to pot it or otherwise protect the wires and so some of them fell off when I tried to change the boost voltage selection. And then another 4 wires fell off when I was taking it out. The connection area is tiny and the solder work is frankly not that good, so the joints are amazingly fragile. It’s what I should have done first time, doubly so because the bits of stiff wire for the breadboard really get in the way.


Well, it seems to operate correctly, but I think I’d do it differently next time. A chip socket or veroboard with .1″ header soldered in is a much better choice than flying wires. Potting makes it as robust, but you have to pot it before you know it works.

It’s always a bit hard to tell volume because ears have a logarithmic response and at 4kHz the sound is quite directional. Nonetheless it’s noticeably louder. Yay 🙂