No DAC? Try PDM

Ever notice that the ESP32-S3 doesn’t have a digital-to-analog converter? [Chris] did and asserts that he doesn’t care because he can just use the PDM system to get the same result. PDM — pulse density modulation — is similar to PWM and, like PWM, requires a filter that could range from a simple RC network to an active filter. You can see the result in the video below.

There are several ways [Chris] could produce the output he wanted. PWM was one choice, and some example code uses a timer to do PDM. However, that is not very efficient. The other alternative is to use the I2S output. However, this does require a few workarounds.

In particular, the I2S output is always stereo and incorporates a clock output that isn’t needed for this application. [Chris] simply output the same value on both channels and routed the clock to some pins that are normally used for startup options. That means they can’t easily be used for your own inputs, but it’s OK to use them for unimportant outputs.

We always enjoy seeing solutions like this because it can give you ideas for use in your own projects. Of course, this won’t apply to every project where you need a DAC, but it still might give you some ideas.

We have looked at PDM before. You could, too, build your own DAC hardware.

Continue reading “No DAC? Try PDM”

Cockpit Instrument Respectfully Retasked As A Clock

How do you convert an old cockpit instrument into a clock? Easy: just build a circuit that convinces it it’s in the air, and the rest will take care of itself.

Now obviously, little about [porkfreezer]’s conversion of King KI 266 DME into a clock was actually easy; working with avionics rarely is. DME stands for “Distance Measuring Equipment,” an instrument that’s part of the radio navigation suite of many aircraft. DME measures the line-of-sight distance of a plane to a ground station by measuring the time it takes for a signal to return after the plane interrogates it. The plane-mounted equipment includes a UHF transceiver and a display for the cockpit instrument panel, which accepts an analog voltage signal from the transceiver and translates it into a readout on the nice Panaplex digital display.

Rather than gutting the thing and just driving the display directly, [porkfreezer] decided to build a circuit to generate the proper signals for the DME. The board uses a PIC16 and an MCP47C dual 10-bit digital-to-analog converter to generate the voltages needed, while a USB-powered DC-DC converter provides the ±15 volt supply the DME display expects.

Everything lives on a PCB that fits right on the back of the instrument. Sadly, the connector needed to mate up to the one on the instrument was outlandishly expensive — again, avionics — so [porkfreezer] had to solder the board directly to the DME’s pins. Otherwise, this would have been a completely reversible hack.

Still, it’s an interesting reuse of an unusual piece of gear, and one that respects the original design as much as possible. That counts as a win in our book.

Guitar Distortion With Diodes In Code, Not Hardware

Guitarists will do just about anything to get just the right sound out of their setup, including purposely introducing all manner of distortion into the signal. It seems counter-intuitive, but it works, at least when it’s done right. But what exactly is going on with the signal? And is there a way to simulate it? Of course there is, and all it takes is a little math and some Arduino code.

Now, there are a lot of different techniques for modifying the signal from an electric guitar, but perhaps the simplest is the humble diode clipping circuit. It just uses an op-amp with antiparallel diodes either in series in the feedback loop or shunting the output to ground. The diodes clip the tops and bottoms off of the sine waves, turning them into something closer to a square wave, adding those extra harmonics that really fatten the sound. It’s a simple hack that’s easy to implement in hardware, enough so that distortion pedals galore are commercially available.

In the video below, [Sebastian] explains that this distortion is also pretty easy to reproduce algorithmically. He breaks down the math behind this, which is actually pretty approachable — a step function with a linear part, a quadratic section, and a hard-clipping function. He also derives a second, natural exponent step function from the Schockley diode equation that is less computationally demanding. To implement these models, [Sebastian] chose an Arduino GIGA R1 WiFi, using an ADC to digitize the guitar signal and devoting a DAC to each of the two algorithms. Each distortion effect has its own charms; we prefer the harsher step function over the exponential algorithm, but different strokes.

Kudos to [Sebastian] for this easy-to-understand treatment of what could otherwise be a difficult subject to digest. We didn’t really expect that a guitar distortion pedal would lead down the rabbit hole to diode theory and digital signal processing, but we’re glad it did.

Continue reading “Guitar Distortion With Diodes In Code, Not Hardware”

Bust Out That Old Analog Scope For Some Velociraster Fun!

[Oli Wright] is back again with another installation of CRT shenanigans. This time, the target is the humble analog oscilloscope, specifically a Farnell DTV12-14 12 MHz dual-channel unit, which features a handy X-Y mode. The result is the Velociraster, a simple (in hardware terms) Raspberry Pi Pico based display driver.

Using a Pico to drive a pair of AD767 12-bit DACs, the outputs of which drive the two ‘scope input channels directly, this breadboard and pile-of-wires hack can produce some seriously impressive results. On the software side of things, the design is a now a familiar show, with core0 running the application’s high-level processing, and core1 acting in parallel as the rendering engine, determining static DAC codes to be pushed out to the DACs using the DMA and the PIO.

Continue reading “Bust Out That Old Analog Scope For Some Velociraster Fun!”

Audio Playback Toy For DSP Adventures

The declining costs of single-board computers has made serious computing power available for even the most trivial of tasks. It’s easy enough to slap a Raspberry Pi onto almost anything for nearly the same cost as a powerful 32-bit microcontroller platform, but this takes some of the fun out of projects for a few of us. Looking to get into the weeds can be a challenge as well, as [Michal Zalewski] demonstrates in this audio playback device he built from a simple 8-bit microcontroller.

The small toy takes audio input from a microphone through an op-amp and feeds this signal to an ADC within the AVR128DA28 microcontroller. The data is then stored on a separate memory chip ready to be played back through another op-amp paired with a speaker. This is where being familiar with the inner workings of the microcontroller comes in handy. By manipulating the interrupt routines in specific ways, the audio stored in memory can be played back at various speeds.

[Michal] intended this build to be a toy for one of his younger relatives, and for the price of a few ICs and buttons it does a pretty good job of turning a regular voice into a chipmunk voice like some commercial children’s toys some of us might remember. If the design aesthetics of this gadget look familiar, you may be thinking of his minimalist gaming device which we recently featured.

A Straightforward Old-Fashioned DAC

With modern microcontrollers, the process of interfacing with the analogue world is easy. Simply enable the on-board DAC or ADC, and talk to the world. If you’ve ever done this with a slightly older microprocessor, you might have encountered the DAC and ADC as chips in their own right, but how about the earliest generation of microprocessors? In those days, if an analogue component was needed, the circuit which would later be integrated on chip would have to be made from scratch. So it is that [Florian Wilhelm Dirnberger] has built a very old-style 6-bit DAC, using a circuit that would have been familiar back in the early 1970s.

At its heart are a pair of 4007 triple CMOS inverters, which form the six bits driving a resistor ladder DAC. This is simply a chair of R… 2R resistors, relying on Ohm’s law for its operation. Each successive bit contributes twice the current to the output of its predecessor, and the 4007 simply provides a buffered supply for the bits.

It’s the simplest of DACs, if not the most capable. Back in the day a typical ADC might also use this circuit, feeding a comparator alongside the input voltage. The microprocessor would count through the digital values until the comparator output bit flipped, at which point it would take the counter value as the analogue measure. You may never need to build one when your microcontroller has one built in, but it’s useful to know how simple DACs and ADCs work.

If the subject interests you, we’ve had a look at DACs including resistor ladders used in audio.

Our Favorite Things: Binary Search

You might not think that it would be possible to have a favorite optimization algorithm, but I do. And if you’re well-versed in the mathematical art of hill climbing, you might be surprised that my choice doesn’t even involve taking any derivatives. That’s not to say that I don’t love Newton’s method, because I do, but it’s just not as widely applicable as the good old binary search. And this is definitely a tool you should have in your toolbox, too.

Those of you out there who slept through calculus class probably already have drooping eyelids, so I’ll give you a real-world binary search example. Suppose you’re cropping an image for publication on Hackaday. To find the best width for the particular image, you start off with a crop that’s too thin and one that’s too wide. Start with an initial guess that’s halfway between the edges. If this first guess is too wide, you split the difference again between the current guess and the thinnest width. Updated to this new guess, you split the differences again.

But let’s make this even more concrete: an image that’s 1200 pixels wide. It can’t get wider than 1200 or thinner than 0. So our first guess is 600. That’s too thin, so we guess 900 — halfway between 600 and the upper limit of 1200. That ends up too wide, so we next guess 750, halfway between 600 and 900. A couple more iterations get us to 675, then 638, and then finally 619. In this case, we got down to the pixel level pretty darn fast, and we’re done. In general, you can stop when you’re happy, or have reached any precision goal.

[Ed note: I messed up the math when writing this, which is silly. But also brought out the point that I usually round the 50% mark when doing the math in my head, and as long as you’re close, it’s good enough.]

What’s fantastic about binary search is how little it demands of you. Unlike fancier optimization methods, you don’t need any derivatives. Heck, you don’t even really need to evaluate the function any more precisely than “too little, too much”, and that’s really helpful for the kind of Goldilocks-y photograph cropping example above, but it’s also extremely useful in the digital world as well. Comparators make exactly these kinds of decisions in the analog voltage world, and you’ve probably noticed the word “binary” in binary search. But binary search isn’t just useful inside silicon. Continue reading “Our Favorite Things: Binary Search”