Glen Akins Is Back Again with Even More Custom USB Peripheral Goodness!

Akins has become our go-to-guy for great-looking USB gadgets. This time, he's built a set of analog panel meters using the EFM8.

Tom Fleet
a month agoHW101 – Deprecated

With our previous coverage of the wonderful work of Glen Akins only having just cleared the editor, it is with delight that we are yet again thrown back into the world of weird and wacky custom USB peripherals, this time, in the form of some antiquated analog panel meters — the holy grail of CPU load counters (or whatever other system level metrics you want to keep tabs on!)

Digital to analog...

If you're a fresh face on the hardware scene — with age still on your side — it's entirely reasonable that although you might have seen such moving-coil gauges on older equipment, you may not have yet been tasked with making that analog needle dance to your tune.

Where as modern panel meters might have a bank of seven-segment displays, with an accompanying MCU to take care of the analog to digital conversion, scaling and more, these gauges are an entirely analog affair.

At the heart of a moving coil meter, is well, just that — a moving coil, not at all dissimilar to those found in a speaker cone.

You probably know the basic operation of a speaker — a wound coil sits around a permanent magnet. If you've ever played with coils of wire, maybe one wrapped around a nail, you will know that when an electric current is passed through said coil, a electromagnetic force is developed — this is the basis of an electromagnet.

When you combine the two — both permanent magnets and electromagnets — you effectively end up with an actuator, the movement of which will be proportional to the direction, and amount of current passing through the coil of the electromagnet.

If the signal to the coil is AC modulated, say by an audio signal, the resultant movement of the cone that is attached to the coil will generate vibrations, resulting in an audible recreation of the signal feeding the coil!

The same principles apply to a moving coil magnet. The only real difference is that the signal is usually far less dynamic (variable) and current usually flows in one direction only — a meter sits at zero, and an amount of current is passed through the coil to deflect the needle along the scale.

Double dual DACs...

So, with a crash course in coils and current flow, we can take a look at how Akins is able to pass a current of his choosing through the coils of the metric-monitoring meters. Perhaps having started with the coils themselves, it makes sense to move backwards through the rest of the circuit — so we'll go from coils, all the way to the USB-C connector, bit by bit, starting with the key component: the digital to analog converters that take a digital bitstream, and output a correlating voltage resultingly.

Let's take a look at what is needed to implement a single coil meter, with the circuit excerpt below.

At the heart of the circuit, sits a TLV5626 DAC, from Texas Instruments. This device has a SPI interface on one side, and a pair of analog outputs on the other.

Let's take a look at the internals of the device first, as this will help us understand it's implementation later on.

Data is shifted into the serial interface of the part over SPI — a total of 16 bits per update, with the ability to write information to either of the two DACs, or, an internal buffer — useful for pre-loading the next value in higher-speed applications.

The output of the DAC is then buffered against either an internally generated, or externally supplied reference voltage.

The resultant voltage on the output of the channel of each DAC can therefore be calculated using the following datasheet segment.

The TLV5626 has an internal 2X output buffer, so that explains the multiplier at the start of the calculation.

"Ref" is the voltage applied as a reference — in the case of Akins' work, he has programmed the part to use it's internal 2.048V reference voltage.

Finally, 'CODE' is the value of 0x000 to 0xFF0, used to control the actual DAC voltage output. I hear your cries, "This is an 8-bit DAC though, 0xFF0 is way higher than a full 8-bit value of 255!"

You are quite correct! if we look at the jumble of wording below the output calculation however, the datasheet has chosen quite a verbose way of saying "the eight-bit data must be left shifted by four."

I've used these DACs some years ago, and I'll be honest, the datasheet took a few reads before my novice mind appreciated the full control word structure!

So, knowing the internal structure, the applied voltage reference, and the equation above, in the case of Akins, the DACs can be configured to output a range spanning from 0V, up to 4.080V, in steps of 16mV (4.080V / 255).

PHEW! That was a bit of a deep dive in itself, but we aren't done just yet.

These coils require a varying current flow, rather than a varying voltage. In hugely oversimplified terms, the strength of an electromagnet is proportional to the current passing through the coil.

In order to convert the varying voltage output of the DAC into that of a varying current output, the solution is as simple as a resistor.

Firstly, the signal is buffered by an operational amplifier, configured for unity gain. Rather than acting as an amplifier, here, the op-amp has a gain of 1. The purpose of this part of the circuit is to take the relatively high-impedance output of the DAC, which can provide very little current, and to buffer the signal, resulting in a low-impedance source, suitable for driving a higher-current load.

The low impedance of the buffer is fed directly into the base of an NPN transistor, where the varying voltage of will control the amount of current that is able to flow between the collector and emitter terminals.

With the base of the transistor driven with the full scale output of the buffered DAC, and the device effectively being fully "ON," the amount of current that can flow between the two terminals of the meter is governed by the 402 ohm resistor at the top of the chain — this results in a "full scale" current of 10.15mA, with the DAC set to it's maximum value.

We can imagine that the full scale deflection of the meter needle will likely be some 10mA — that extra 0.15mA is likely a bit of design insurance — in the case that a meter is not exactly to spec!

Copy, paste, and then copy and paste again!

This circuit is implemented for both channels of each of the TLV5626 DACs, for a total of four circuits, each able to drive its own moving coil meter.

Top left of the circuit, we see a newfamiliar friend in the form of the SN74LVC8T245PW — an eight-bit bidirectional level shifter — once again, configured to operate in one direction only. There is no feedback from the DAC circuitry, so it's fine to just sling control bits at them without any data needing to come back the other way!

We're seeing this part here, as the analog stage of the circuity is specified to operate at 5V, where as the MCU portion of the circuit is running at 3.3V.

We won't touch too much on the MCU segment of the design. If you'd like a closer look at how Akins has implemented a solid, robust USB-HID (or other) peripheral interface, we suggest having a look through previous articles covering his works — indeed, Akins is no stranger to these parts.

With all of this bought together at the schematic level, the next stage is obviously to lay out the circuit onto a rather neatly thought out PCB.

Clarity of thought can often manifest itself through PCB layout. Taking the time to not only consider the optimum pin assignment of the flexible "crossbar" I/O of the EFM8 MCU pins, but also the general layout and rotation of parts connected to said pins can result in the beautiful simplicity of the tracking we see in the layout above.


The Crossbar I/O found on the EFM8 parts can often be found on other modern MCU parts, albeit under different names.

CubeMX allows ST users to do similar pin/peripheral mappings, and users of the Microchip Arm (formerly Atmel SAM parts) will perhaps know of the SERCOM multiplexing capabilities.

However you call it, the idea is usually that you can arrange the location of a MCU peripheral to one of several possible sites, and sometimes, even arrange the ordering of pins within a specific site, such that you can optimize the pin ordering to match whatever you are wiring your peripheral to!

With the exception of the un-populated I2C constant current LED driver, there is almost a 1:1 mapping of pins, in the physical order that is constrained by the pin locations on the DAC packages.

Taking the time to think about a circuit layout from the ground up, in that level of detail, is sometimes the only way you will arrive at a layout that doesn't drive you loopy, tracking... well, loops, to get your signals connected, where they need to be.

The results of this effort speak for themselves — the finished board looks just fantastic — even with a chunk of the parts selectively non-populated (Akins eventually decided against working backlighting into this project).

Akins has an absolutely wonderful project write-up of this work over on his site, where he does an incredible job of documenting absolutely every single bit of information that you would need to build this project yourself, as is, or to modify it to suit the needs of your own specific analog moving coil meters!

For the most part, that should just be a case of swapping out that low-side 402 ohm resistor we mentioned back in the analog section of this writeup!

If you're the type to just jump straight in, and want a set of board to play with, the full design sources are available on Akins' GitHub project repo, here, where he also includes the software sources not only for the EFM8 code, but also the accompanying host-side code, to communicate with the device from a Linux computer.

Tom Fleet
Hi, I'm Tom! I create content for Hackster News, allowing us to showcase your latest and greatest projects for the world to see!
Related articles
Sponsored articles
Related articles