Count Leading Zeros For Efficient Logarithms

[Ihsan Kehribar] points out a clever trick you can use to quickly and efficiently compute the logarithm of a 32-bit integer. The technique relies on the CLZ instruction which counts the number of leading zeros in a machine word and is available in many modern processors. Typical algorithms used to compute logarithms are not quick and have a variable execution time depending on the input value. The technique [Ihsan] is using is both fast and has a constant run time.

The above equation summarized the math behind the algorithm. We get the first term easily using the CLZ instruction. Using the remainder and a pre-computed lookup table, it is possible to get the second term to various degrees of accuracy, depending on how big you make the table and whether or not you take the performance hit of interpolation or not — those of a certain age will no likely groan at the memory of doing interpolation by hand from logarithm tables in high school math class. [Ihsan] has posted an MIT-licensed implementation of this technique in his GitHub repository, which includes both the C-language algorithm and Python tools to generate the lookup table and evaluate the errors.

Why would you do this? Our first thought was real-time streaming DSP operations, where you want fast and deterministic calculations, and [Ihsan]’s specifically calls out embedded audio processing as one class of such applications. And he should know, after all, since he developed a MIDI capable polyphonic FM synthesizer on a Cortex M0 that we covered way back in 2015.

All About USB-C: Manufacturer Sins

People experience a variety of problems with USB-C. I’ve asked people online about their negative experiences with USB-C, and got a wide variety of responses, both on Twitter and on Mastodon. In addition to that, communities like r/UsbCHardware keep a lore of things that make some people’s experience with USB-C subpar.

In engineering and hacking, there’s unspoken things we used to quietly consider as unviable. Having bidirectional power and high-speed data on a single port with thousands of peripherals, using nothing but a single data pin – if you’ve ever looked at a schematic for a proprietary docking connector attempting such a feat, you know that you’d find horrors beyond comprehension. For instance, MicroUSB’s ID pin quickly grew into a trove of incompatible resistor values for anything beyond “power or be powered”. Laptop makers had to routinely resort to resistor and one-wire schemes to make sure their chargers aren’t overloaded by a laptop assuming more juice than the charger can give, which introduced a ton of failure modes on its own.

When USB-C was being designed, the group looked through chargers, OTG adapters, display outputs, docking stations, docking stations with charging functions, and display outputs, and united them into a specification that can account for basically everything – over a single cable. What could go wrong?

Of course, device manufacturers found a number of ways to take everything that USB-C provides, and wipe the floor with it. Some of the USB-C sins are noticeable trends. Most of them, I’ve found, are manufacturers’ faults, whether by inattention or by malice; things like cable labelling are squarely in the USB-C standard domain, and there’s plenty of random wear and tear failures.

I don’t know if the USB-C standard could’ve been simpler. I can tell for sure that plenty of mistakes are due to device and cable manufacturers not paying attention. Let’s go through the notorious sins of USB-C, and see what we can learn. Continue reading “All About USB-C: Manufacturer Sins”

MicroPython ESP32 IDE Makes Life Simpler

In theory, using MicroPython on the ESP32 is easy —  just flash an image and connect using a serial port. But that leaves a lot of things you still have to do. You need to move files between the two platforms. You’ll want to manage network configurations. You might want better editing and assistance, too. So there are a number of IDEs made to help you and one we recently noticed was MPY-Jama.

The IDE provides source code editing, of course. But it also allows you to do things like pull information about the network using a dashboard or connect to a WiFi network easily. You can even create your own AP with a simple interface.

Although the front part of the README mentions it is for Windows or Mac, if you scroll down you’ll find instructions for installing under Linux. The IDE is extensible using “Jama Funcs” and can handle the flashing operation from inside the IDE.

Of course, there is an IDE from Arduino (but not the Arduino IDE) that handles MicroPython. You can also find a rundown of several similar alternatives online.  If you need some inspiration for a MicroPython project, perhaps you’d like to play a game?

OG DOOM Shows Off The Origins Of Multi-Monitor

We have a thing for DOOM, and we admit it. The source was released, and clever hackers have ported the engine to every system imaginable. It’s a right of passage, when hacking a machine, to run DOOM on it — be it a VoIP phone, or tractor. But the original 1993 release does have a few notable tricks, and there’s something to be said for recreating that experience on period hardware. And that’s what we’re covering today: [Tech Tangents] discovered DOOM’s multi-monitor support, and built a 4-computer cluster to show it off.

There is a catch, of course. DOOM 1.1 has the multi-monitor support, and under-the-hood, it works by running a copy of the game on individual computers, and controlling the drones over the network. As the game’s network code was updated for version 1.2, the multi-monitor feature was axed to make the network code easier to maintain. So, find a 1.1 shareware release, install it on a DOS machine with IPX drivers, and start each iteration with a -net flag. Use -left and -right to set the drones to the appropriate view. And that view is ninety degrees left and right.

Maybe not ideal, but at the time it was one of the first games to have any sort of multi-monitor support at all. Likely inspired by a commercial flight simulator setup. Either way, it’s a neat feature, and kudos to [Tech Tangents] for showing off this obscure feature of a beloved classic!

Continue reading “OG DOOM Shows Off The Origins Of Multi-Monitor”

Spy Drone Propeller Makes For A Quiet PC

MIT recently announced its research on toroidal propellers to create quieter drones. That got [Major Hardware] thinking about noisy PC fans. The obvious solution was to adapt the toroidal shape for a PC fan. He was familiar with the idea from similar screws on boats that are commercially available. You can see his tests in the video below.

The shape of the blades on the MIT drones is visible in video and pictures, but there were no available 3D models. [Major] did a design and 3D printed the blades. Watching the comparison with a conventional fan using smoke was pretty impressive.

Continue reading “Spy Drone Propeller Makes For A Quiet PC”

Researchers Find “Inert” Components In Batteries Lead To Cell Self-Discharge

When it comes to portable power, lithium-ion batteries are where it’s at. Unsurprisingly, there’s a lot of work being done to better understand how to maximize battery life and usable capacity.

Red electrolytic solution, which should normally be clear.

While engaged in such work, [Dr. Michael Metzger] and his colleagues at Dalhousie University opened up a number of lithium-ion cells that had been subjected to a variety of temperatures and found something surprising: the electrolytic solution within was a bright red when it was expected to be clear.

It turns out that PET — commonly used as an inert polymer in cell assembly — releases a molecule that leads to self-discharge of the cells when it breaks down, and this molecule was responsible for the color change. The molecule is called a redox shuttle, because it travels back and forth between the cathode and the anode. This is how an electrochemical cell works, but the problem is this happens all the time, even when the battery isn’t connected to anything, causing self-discharge.

Continue reading “Researchers Find “Inert” Components In Batteries Lead To Cell Self-Discharge”

Custom Enclosure For 3D Printer

Having an enclosure around an FDM 3D printer is generally a good idea, even when printing only with PLA, as it keeps the noise in, and the heat (and smell, with ABS) inside. With all the available options for enclosures out there, however, [David McDaid] figured that it should be possible to make an enclosure that does not look like a grow tent and is not overly expensive. He also shared the design files on GitHub.

The essential idea is very simple and straightforward: the structural part is cut out of pine beams that are cut to size and joined into a cube by (3D-printed) corner brackets, with acrylic (Perspex) sheets filling in the space between the wooden beams. A door is formed using (also 3D-printed) hinges and door handles. The whole enclosure is rounded off with a lick of paint on the wooden elements, and a diffused set of LED lights for internal illumination.

It definitely has to be admitted that it makes for a very stylish enclosure, with a lot of modding potential. It can also easily be adapted to differently sized printers and filament material demands.