Ask Hackaday: Computing Square Roots On FPGA?

Hackaday reader [nats.fr] wrote in with some code from a project that resizes a video stream on the fly using an FPGA. Doing this right means undoing whatever gamma correction has been applied to the original stream, resizing, and then re-applying the gamma. Making life simpler, [nats.fr] settled on a gamma of two, which means taking a bunch of square roots, which isn’t fast on an FPGA.

[nats]’s algorithm is pretty neat: it uses a first-stage lookup to figure out in which broad range the value lies, and then one step of Hero’s algorithm to refine from there. (We think this is equivalent to saying he does a piecewise linear interpolation, but we’re not 100% sure.) Anyway, it works decently.

Of course, when you start looking into the abyss that is special function calculation, you risk falling in. Wikipedia lists more methods of calculating square roots than we have fingers. One of them, CORDIC, avoids even using multiplication by resorting to clever bitshifts and a lookup table. Our go-to in these type of situations, Chebyshev polynomial approximation, didn’t even make the cut. (Although we suspect it would be a contender in the gamma=1.8 or gamma=2.2 cases, especially if combined with range-reduction in a first stage like [nats.fr] does.)

So what’s the best/fastest approximation for sqrt(x) for 16-bit integers on an FPGA? [nats.fr] is using a Spartan 6, so you can use a multiplier, but division is probably best avoided. What about arbitrary, possibly fractional, roots?

Millennium Tower Is Sinking; And Waiting Is The Hardest Part

San Francisco’s Millennium Tower is sinking. Since its completion in 2009, the 58-story, 645-foot tall residential building has settled 16 inches and tilted perhaps 2 inches to the northwest. Since the foundation issues came to light in August 2016, the vertiginous ultra-luxury highrise has become the subject of outrage, ridicule, and at least two pieces of pending litigation.

Nothing that we build is static. Our office towers, apartment complexes, and single family homes move in response to loads applied by the environment. Buildings sway in the wind, expand and contract in response to temperature changes, and shift with the land upon which they rest. In most scenarios, these deflections are so minuscule that the occupants never even notice. Millennium Tower happens to be a large enough project with a severe enough problem that the whole world can’t help but gawk.

Millenium Tower located in San Francisco's SOMA, near the Financial District
Millenium Tower located in San Francisco’s SOMA, near the Financial District.

In foundation design, not all terra is firma. While a one or two story wood-framed building can be built safely with a shallow foundation on crummy soil, a major skyscraper requires a foundation that can transfer extremely high loads into the earth. But the strata below our city streets can consist of anything from sand to clay to solid rock, and many cities, including San Francisco, have infilled former marshes and bays with soil in order to expand their coastlines and generate valuable real estate. Millennium Tower was built in South of Market, a neighborhood that mostly used to belong to San Francisco Bay.

Continue reading “Millennium Tower Is Sinking; And Waiting Is The Hardest Part”

Off-Grid Travel — Setting Up A Solar System

When you’re living out of a vehicle, or even just traveling out of one, power quickly becomes a big concern. You need it for lights, to charge your various devices, to run your coffee maker and other appliances, and possibly even to store your food if you’ve got an electric refrigerator. You could do what many RV owners do: rely on campgrounds with electrical hookups plus a couple of car batteries to get you from one campground to the next. But, those campgrounds are pricey and often amount to glorified parking lots. Wouldn’t it be better if you had the freedom to camp anywhere, without having to worry about finding somewhere to plug in?

That’s exactly what we’re going to be covering in this article: off-grid power on the road. There are two major methods for doing this: with a portable gas generator, or with solar. Gas generators have long been the preferred method, as they provide a large amount of power reliably. However, they’re also fairly expensive, cumbersome, noisy, and obviously require that you bring along fuel. Luckily, major advances in solar technology over the past decade have made it very practical to use solar energy as your sole source of electricity on the road.

Continue reading “Off-Grid Travel — Setting Up A Solar System”

The Many Faces Of JTAG

Wouldn’t it be great if there were just one standard for attaching to, programming, and debugging hardware?  If you could just plug in and everything would just work? Dream on, dreamer! But of course we hobbyists aren’t the only people to suffer from multiple standards. Industry has the same problems, writ large. In response to the proliferation of smart devices — microcontrollers, sensors, and their friends — on any given PCB makes it difficult to test them all, much less their function as a system.

The Joint Test Action Group (JTAG) got together in the mid-80s to make automated testing of circuit boards a standardized process. A JTAG port can be found on almost any piece of consumer electronics with enough brains to warrant it, and it’s also a tremendously useful entry point for debugging your own work and hacking into other’s. You’re going to need to use JTAG someday.

Implemented right, it’s a very cool system that lets you test any compliant IC on the board all from a single connector. It’s mostly used by hackers for its ability to run and halt individual processors, and put them in debugging modes, inspecting their memory states, etc. Essentially every microcontroller responds to JTAG commands, and it’s an incredibly widespread and powerful standard. A victory for rationality and standardization!

The connector pinout was, of course, left up to the manufacturer. The horror!

Five Signals

In principle, JTAG uses five signal lines. They form a chain starting at the debugger, where one device’s output is the next device’s input, until the result is returned back to the debugger.

654px-jtag_chain
JTAG, as imagined by Vindicator CC BY 2.5
  • Test Data In (TDI) is the input from the debugger
  • Test Data Out (TDO) is the return end of the chain
  • Test Clock (TCK) clocks this data along synchronously, similarly to SPI
  • Test Mode Select (TMS) lets the devices know that they’re being debugged — it’s a global chip select
  • Test Reset (TRST) is an optional signal that resets all devices in the chain

Continue reading “The Many Faces Of JTAG”

A How-To In Homebrew Design, Fab, And Assembly With Structural Framing Systems

At this point, the internet is crawling with butt-kicking homebrew 3D printers made with extruded profiles, but it’s easy to underestimate the difficulty in getting there. Sure, most vendors sell a suite of interlocking connectors, but how well do these structural framing systems actually fare when put to the task of handling a build with sub-millimeter tolerances?

I’ve been playing around with these parts for about two years. What I’ve found is that, yes, precise and accurate results are possible. Nevertheless, those results came to me after I failed and–dry, rinse, repeat–failed again! Only after I understood the limits of both the materials and assembly processes was I able to deliver square, dimensionally accurate gantries that could carry a laser beam around a half-square-meter workbed. That said, I wrote a quick guide to taming these beasts. Who are they? What flavors do they come in? How do we achieve those precision results? Dear reader, read on.

Continue reading “A How-To In Homebrew Design, Fab, And Assembly With Structural Framing Systems”

Ask Hackaday: Dude, Where’s My MOSFET?

(Bipolar Junction) Transistors versus MOSFETs: both have their obvious niches. FETs are great for relatively high power applications because they have such a low on-resistance, but transistors are often easier to drive from low voltage microcontrollers because all they require is a current. It’s uncanny, though, how often we find ourselves in the middle between these extremes. What we’d really love is a part that has the virtues of both.

The ask in today’s Ask Hackaday is for your favorite part that fills a particular gap: a MOSFET device that’s able to move a handful of amps of low-voltage current without losing too much to heat, that is still drivable from a 3.3 V microcontroller, with bonus points for PWM ability at a frequency above human hearing. Imagine driving a moderately robust small DC robot motor forwards with a microcontroller, all running on a LiPo — a simple application that doesn’t need a full motor driver IC, but requires a high-efficiency, moderate current, and low-voltage-logic compatible transistor. If you’ve been here and done that, what did you use?

Continue reading “Ask Hackaday: Dude, Where’s My MOSFET?”

The Many Uses Of The Neon Lamp

Neon lights are that kind of nostalgic item that everybody seems to love. The neon lamp is a type of gas discharge lamp, they generate light when an electrical discharge travels through an ionized gas, or plasma. When the voltage between the electrodes exceeds certain threshold, the gas ionizes and begins conducting electricity. The basic process that generates light is the return of the ions to the ground energy state, with the emission of a photon of light. The light color depends on the emission spectra of the atoms in the gas, and also  on the gas pressure, among other variables.  Gas discharge lamps can be classified by the pressure of the gas:

  • Low pressure: includes the neon lamp, fluorescent lamps and low pressure sodium lamps.
  • High pressure: such as the metal halide, high pressure sodium and mercury vapor lamps.

Another classification comes from the heating method of the cathode:

  • Hot cathode lamps: the electric arc between the electrodes is created via thermionic emission, where electrons are expelled from the electrodes because of the high temperature.
  • Cold cathode lamps: In these, the electric arc results from the high voltage applied between the electrons, that ionizes the gas and conduction can take place.

High intensity lamps are another type of gas discharge lamp where a high power arc is formed between tungsten electrodes. Power levels of several kilowatts can be easily produced this type of lamp. Of course we can’t forget to mention nixie tubes, which are a type of cold cathode neon lamp, popular for building retro clocks. Fortunately, they are now in production again.

Continue reading “The Many Uses Of The Neon Lamp”