High Precision Analog IO With Digital Pins

Reading the temperature of your environment is pretty easy right? A quick search suggests the utterly ubiquitous DHT11, which speaks a well documented protocol and has libraries for every conceivable microcontroller and platform. Plug that into your Arduino and boom, temperature (and humidity!) readings. But the simple solution doesn’t hit every need, sometimes things need to get more esoteric.

The technique summarized by an image from Microchip Appnote AN685

For years we’ve been watching [Edward]’s heroic efforts to build accessible underwater sensing hardware. When we last heard from him he was working on improving the accuracy of his Arduino’s measurements of the humble NTC thermistor. Now the goal is the same but he has an even more surprising plan, throw the ADC out entirely and sample an analog thermistor using digital IO. It’s actually a pretty simple trick based on an intuitive observation, that microcontrollers are better at measuring time than voltage. 

The basic circuit

The circuit has a minimum of four components: a reference resistor, the thermistor, and a small capacitor with discharge resistor. To sense you configure a timer to count, and an edge interrupt to capture the value in the timer when its input toggles. One sensing cycle consists of discharging the cap through the discharge resistor, enabling the timer and interrupt, then charging it through the value to measure. The value captured from the timer will be correlated to how long it took the cap to charge above the logic-high threshold when the interrupt triggers. By comparing the time to charge through the reference against the time to charge through the thermistor you can calculate their relative resistance. And by performing a few calibration cycles at different temperatures ([Edward] suggests at least 10 degrees apart) you can anchor the measurement system to real temperature.

For all the gory details, including tips for how to save every last joule of energy, check out [Edward]’s post and the Microchip appnote AN685 he references. Besides this series [Edward]’s Cave Pearl Project has already yielded an impressive number of Hackday posts. For more great hardware writeups check out a general hardware build for a single sensing node, or the “temperature sensor” [Edward] made with no external parts at all!

An Epic Tale Of Thermistors: Tricks For Much Better Temperature Sensing

For years [Edward] has been building professional grade underwater sensing nodes at prices approachable for an interested individual without a government grant. An important component of these is temperature, and he has been on a quest to get the highest accuracy temperature readings from whatever parts hit that sweet optimum between cost and complexity. First there were traditional temperature sensor ICs, but after deploying numerous nodes [Edward] was running into the limit of their accuracy. Could he use clever code and circuitry to get better results? The short answer is yes, but the long answer is a many part series of posts starting in 2016 detailing [Edward]’s exploration to get there.

Orange is 12 bits, red is 24

The first step is a thermistor, a conceptually simple device: resistance varies with temperature (seriously, how much more simple can a sensor get?). You can measure them by tapping the center of a voltage divider the same way you’d measure any other resistance, but [Edward] had discarded this idea because the naive approach combined with his Arduino’s 10 bit ADC yielded resolution too poor to be worthwhile for his needs. But by using the right analog reference voltage and adjusting the voltage divider he could get a 20x improvement in resolution, down to 0.05°C in the relevant temperature range. This and more is the subject of the first post.

What comes next? Oversampling. Apparently fueled by a project featured on Hackaday back in 2015 [Edward] embarked on a journey to applying it to his thermistor problem. To quote [Edward] directly, to get “n extra bits of resolution, you need to read the ADC four to the power of n times”. Three bits gives about an order of magnitude better resolution. This effectively lets you resolve signals smaller than a single sample but only if there is some jitter in the signal you’re measuring. Reading the same analog line with no perturbation gives no benefit. The rest of the post deals with the process of artificially perturbing the signal, which turns out to be significantly complex, but the result is roughly 16 bit accuracy from a 10 bit ADC!

What’s the upside? High quality sensor readings from a few passives and a cheap Arduino. If that’s your jam check out this excellent series when designing your next sensing project!

Visualizing LEDs For More Efficient Pin Packing

The archetypal “blink an LED” is a great starter project on any platform, but once the bug takes hold that quickly turns into an exploration of exactly how many LEDs a given microcontroller can drive. And that often leads to Charlieplexing. A quick search yields many copies of The Table describing how many LEDs can be driven by a given number of pins but that’s just the most rudimentary way to describe it. Way back in 2013 [M Rule] developed a clever trick to describe the number of LED matrices which can be driven by a Charlieplexed array of a given size that makes this process much more intuitive. The post may be old, but we promise the method is still fresh.

[M Rule] was specifically looking to drive those big, cheap single color LED matrices which are often used to make scrolling signs and the like. These parts are typically a matrix of LEDs with a row of common cathodes and one of common anodes. Internally they are completely dumb and can be driven by row/column scanning, or any other way a typical matrix can be controlled. The question is, given known matrix sizes, how many can be driven with a a number of Charlieplexed LED drive pins?

The first step is to visualize the 1D array of available pins as a 2D matrix, as seen to the right. Note each numbered pin is the same on the X and Y, thus the black exclusion zone of illegal drive pin combinations slicing across the graph (you can’t drive an LED connected to one pin twice). The trick, if one were to say it resides in a single place, would be titling the axis anode and cathode, representing two “orientations” the drive pins can be put in. With this diagram [M Rule] observed you can simply drop a matrix into the array. If it fits outside the exclusion zone, it can be driven by those pins!

To the left is what this looks like with two 8×8 matrices, one connected between pins 1-8 and 9-16, the other connected between 9-16 and 1-8. This isn’t terribly interesting, but the technique works just as well with single LEDs and any size matrix, including 7-segment displays. Plus as long as an element doesn’t overlap itself it can wrap around the edges leading to some wild visuals, like 14 RGB LEDs on seven pins to the right.

The most extreme examples are pretty exotic. Check out [M Rule]’s post for the crown jewel; 18 pins to drive six 5×7 modules, six 7-segment displays, 12 single LEDs, and 18 buttons!

If this color coded diagram seems familiar, you may be remembering [openmusiclabs]’ excellent diagram describing ways to scan many of buttons. Or our coverage of another trick of matrix topology by [M Rule] from a few weeks ago.

Homemade Magic Makes The Metcal Go

First soldering irons are often of the Radioshack or Maplin firestarter variety. They’re basically wall power shorted across a nichrome heater or similar with some inline resistance to make it harder to burn down the house. You plug them in, the current flows, and they get hot. Done.

If you stick with the hobby for a while, these eventually get replaced with something like the venerable HAKKO FX-888D or that one Weller everyone likes with the analog knob. These are much improved; having temperature control leads to a more consistently heated tip and much improved soldering experience.

Entering the electronics workplace one comes across the next level of quality soldering iron: high end HAKKOs, Metcals, JBCs, and the like. Using one of these irons is practically a religious experience; they heat in a flash and solder melts while you blink. They even turn off when you put the handpiece down! But they’re expensive to buy (hint: think used). What’s a hobbyist to do?

[SergeyMax] seems to have had this problem. He bit the bullet, figured out how the Metcal works, and made his own base. This is no mean feat as a Metcal might look like a regular iron but it’s significantly more complex than ye olde firestarter. The Metcal magic is based on a oscillating magnetic fields (notice the handpiece is connected via BNC?) interacting with a tip bearing a special coating. In the presence of the changing field the tip heats up until it hits its Curie temperature, at which point it stops interacting with the magnetic field and thus stops heating.

When the user solders, the tip cools by sinking its heat into the part and drops below the Curie temperature again, which starts the heating again. It’s like temperature control with the sensor placed absolutely as close to the part as possible and a nearly instant response time, without even a control loop! [SergeyMax] has a much more thorough description of how these irons work, which we definitely recommend reading.

So what’s the hack? Based on old schematics and some clever reverse engineering from photos [SergeyMax] built a new base station! The published schematic is as rich with capacitors and inductors as one could hope. He didn’t post source or fab files but we suspect the schematic and photos of the bare board combined with some tinkering are enough for the enterprising hacker to replicate.

The post contains a very thorough description of the reverse engineering process and related concerns in designing a cost efficient version of the RF circuitry. Hopefully this isn’t the last Metcal replacement build we see! Video “walkthrough” after the break.

Edit: I may have missed it, but eagle eyed commentor [Florian Maunier] noticed that [SergeyMax] posted the sources to this hack on GitHub!

Continue reading “Homemade Magic Makes The Metcal Go”

Tokyo Mechanical Keyboard Meetup Knocks Our Clacks Off

Just a few days ago, on the other side of the planet from this author, there was a mechanical keyboard meetup in Tokyo. Fortunately through the magic of the Internet we can all enjoy the impressive collection of devices people brought, and boy were there some interesting specimens. There were certainly the inevitable collections of strange artisan keycaps, unusual handmade switches, and keycap sets only available in one group buy five years ago in Nicaragua. But among the bright colors were some truly unique custom designs the likes of which we haven’t see before. A single source is hard to credit, you could check the hashtag #tokyomk6 on Twitter, or [obra]’s thread of photos, or this great blog post (video walkthroughs and photos included) from [romly].

Speaking of [romly], one of their designs stands out as particularly unusual. There are a few things to note here. One is the very conspicuous surface profile of the (clearly totally custom) keycaps themselves. Instead of flat or cylindrical or spherical, these are round. Round like the outside of a log. If we didn’t know better it might look like the entire thing was sculpted or extruded as a single unit. And just below the deck are the perpendicular thumb clusters. Frankly we aren’t sure how to refer to this design feature. The switches are mounted at right angles facing inward so the user places a thumb inside it in a style reminiscent of the DataHand. It’s quite interesting, and we’d be love to know more about what specific functionality it provides.

Another interesting entrant is this keyboard with unusually staggered switches and hexagonal caps (check out the individual markings!). Very broadly there are two typical keyboard layout styles; the diagonal columns of QWERTY (derived from a typewriter in the 1800’s) or the non slanted columns of an “ortholinear” or matrix style layout. By those metrics this is something like an ortholinear keyboard in that its switches overlap their neighbors by half, but the edge to edge close packed caps imply that it might be something else.  We’d be very interested to know how typing on this beast would be!

There were so many more awesome designs present at the meetup that this would never end if we tried to document them all. Take a look through the posts and call out anything else too excellent to go unnoticed!

Thanks [obra] for Tweeting about this so we could discover it.

Lateral Thinking For An Easier Charlieplex

In the practical world we live in, PCBs are often rectangles (or rectangles with rectangles, it’s just rectangles all the way down). When a designer goes to schematic capture things are put down on nice neat grid intersections; and if there isn’t a particular demand during layout the components probably go on a grid too. Routing even the nastiest fractal web of traces is mostly a matter of layers and patience. But if the layout isn’t being done in a CAD tool and needs to be hand assembled free-form this isn’t always as simple. [M Rule] had this very problem and discovered a clever solution, turning things diagonal.

They changed the fitness criteria to the optimization problem that is controlling a lot of LEDs. Instead of minimum pins to drive the goal became “easiest assembly”, which meant avoiding wires snaking back and forth across the layout, a big source of frustration in a big Charlieplexed design. The observation was that if they turned the a rectilinear LED matrix by 45° and wrapped each connection around at the edges it formed what was essentially a large multiplexed matrix. The topology is pretty mind bending, so take a minute to study the illustration and build your mental model.

It looks a little strange, but this display works the same way a normal multiplexed display does but with the added benefit that each trace flows from one side to the other without turning back on itself at any point. To light any LED set the right row/column pair as source/sink and it turns on!

What if you actually need a rectangular display? Well that’s no problem, the matrix can be bent and smooshed as desired to change its shape. At the most extreme the possible display topologies get pretty wild! We’re sure to try thinking laterally next time we need to design an unusual display, maybe there is a more efficient matrix to be found.

Analog Failures On RF Product Cause Production Surprise

A factory is a machine. It takes a fixed set of inputs – circuit boards, plastic enclosures, optimism – and produces a fixed set of outputs in the form of assembled products. Sometimes it is comprised of real machines (see any recent video of a Tesla assembly line) but more often it’s a mixture of mechanical machines and meaty humans working together. Regardless of the exact balance the factory machine is conceived of by a production engineer and goes through the same design, iteration, polish cycle that the rest of the product does (in this sense product development is somewhat fractal). Last year [Michael Ossmann] had a surprise production problem which is both a chilling tale of a nasty hardware bug and a great reminder of how fragile manufacturing can be. It’s a natural fit for this year’s theme of going to production.

Surprise VCC glitching causing CPU reset

The saga begins with [Michael] receiving an urgent message from the factory that an existing product which had been in production for years was failing at such a high rate that they had stopped the production line. There are few worse notes to get from a factory! The issue was apparently “failure to program” and Great Scott Gadgets immediately requested samples from their manufacturer to debug. What follows is a carefully described and very educational debug session from hell, involving reverse engineering ROMs, probing errant voltage rails, and large sample sizes. [Michael] doesn’t give us a sense for how long it took to isolate but given how minute the root cause was we’d bet that it was a long, long time.

The post stands alone as an exemplar for debugging nasty hardware glitches, but we’d like to call attention to the second root cause buried near the end of the post. What stopped the manufacturer wasn’t the hardware problem so much as a process issue which had been exposed. It turned out the bug had always been reproducible in about 3% of units but the factory had never mentioned it. Why? We’d suspect that [Michael]’s guess is correct. The operators who happened to perform the failing step had discovered a workaround years ago and transparently smoothed the failure over. Then there was a staff change and the new operator started flagging the failure instead of fixing it. Arguably this is what should have been happening the entire time, but in this one tiny corner of the process the manufacturing process had been slightly deviated from. For a little more color check out episode #440.2 of the Amp Hour to hear [Chris Gammell] talk about it with [Michael]. It’s a good reminder that a product is only as reliable as the process that builds it, and that process isn’t always as reliable as it seems.