Solid-State Tilt Sensor with a PLL?

January 12th, 2006 by Keith Neufeld

In order to show off the ADXL202 tilt sensor, I want to hook up two LEDs that brighten and dim in response to the tilt. Because the sensor is +/- 2g, my PWM duty cycle is only varying from 25% to 75%, which isn’t enough to see the variation in brightness of my LEDs. Somehow, I have to translate that into a range that varies down to near 0%.

My ultimate plan for the tilt sensor involves controlling a motor (duh), and I expect to experiment with several different drive logic configurations. Regardless of how I end up driving the motor, though, it’d be nice to have indicator LEDs to demonstrate what decisions are being made and fed to the motor–so even if I don’t need any additional circuitry for the motor drive, I’d like to get the LEDs working.

I had previously considered, and am now looking carefully, at using a phase-locked loop (PLL) to help decode the PWM signal. A PLL locks onto the input frequency and provides an output signal of the same frequency–but with 50% duty cycle. A Type II PLL is edge-triggered, so it provides an in-phase output. (A Type I PLL’s output is nominally 90 degrees out of phase for a 50% duty cycle input.)

So if I can manage to get a PLL to work, I can use it to lock onto the fixed frequency of the tilt sensor’s output, and give me a reference signal that goes high at the same time as each pulse of the sensor, but goes low at exactly half of the signal period, while the sensor’s signal is going lower earlier or later depending on its tilt. Then instead of looking at the raw sensor data with a duty cycle range of 25% to 75%, I can compare the sensor to the reference and get “left” and “right” signals with duty cycles each varying from 0% to 25%.

ADXL202 and PLL

That means the LEDs would both be dark when the device is level, instead of each varying from dark to bright over the whole range–but I can live with that. It also means the LEDs will give a very direct representation of what I need the motor to do.

So I picked up a couple of 4046 PLL chips, and I’ve been reading the datasheets. Many, many times. After three or four readings, I understood that they were really going to do what I want with their Type II phase detectors. After another three or four readings, I think I have a pretty good idea how to select external components to set the frequency capture range I need. I don’t think I’m stupid–I’ve just never worked with these before.

I’m itching to try it out.

Solid-State Tilt Sensor, Unplugged

January 12th, 2006 by Keith Neufeld

Having got the ADXL202 working, I wanted to show it off, and then get it installed in a little project that I’ve had waiting in the wings. Showing it off has the side benefit of demonstrating the accuracy of my assumptions about how it works and how it interfaces, above and beyond being able to view its signal on my scope.

So this weekend, I breadboarded some LED drivers onto the sensor. I didn’t remember how much current the ADXL202 would source or sink; plus I wanted one LED to get brighter when it tilted left and another to get brighter when it tilted right. So I plucked a 7404 hex inverter out of my parts bin and wired one of the ADXL202′s outputs to a couple of inverters, then the output of one of them into a third inverter. This gave me two buffered outputs, one inverted and one non-inverted, which I wired through resistors into a couple of LEDs.

And because I wanted it to be portable so I could show it off, I left the benchtop power supply behind and strapped on a 9V battery and a 7805 voltage regulator. I cleverly soldered the black and red leads onto the wrong terminals on the battery connector, which I didn’t discover until I had covered the solder joints with nail polish (pink coral, if you’re curious) and cleverly smeared it around the breadboard when I accidentally touched the connector before it was dry.

Since the sensor’s PWM output is dramatically visible on the scope, I figured it’d be dramatically visible on the LEDs. Wrong-uh. Even knowing what was supposed to be happening, and with the LEDs’ domes carefully aligned in the same direction, in a dark room, I could just barely tell that one brightened and one dimmed as I rotated the assembly back and forth.

Feh.

Well, the ADXL202 is a +/- 2g sensor, and tilted vertically, it’s only experiencing 1g. That means my PWM duty cycle isn’t changing from 0% to 100%; it’s changing from 25% to 75%. I would still think that’d be enough to see a difference in brightness of my LEDs!, but apparently not. So I have to get smarter.

Blue LEDs

January 12th, 2006 by Keith Neufeld

In December, I was inspired by a post on the Makezine blog to search for retail LED Christmas lights, as a source of cheap LEDs. I couldn’t find any at Wal-Mart, but my wife found the Phillips LED Christmas lights at Target.

I wasn’t particularly impressed with the white ones–they looked very blue to me. But the blue ones were pretty, and bright!, so I bought a string. 60 LEDs for $12 is $.20 each, which is a pretty respectable price for blue LEDs (although you can do somewhat better on eBay buying from Hong Kong). And the review linked above doesn’t recommend these as a home lighting product (as packaged, they flicker just at the edge of perception), but they work great for cannibalizing. :-)

The LEDs have their leads stuck through little plastic bases, so they clip into and out of the plastic sockets much like other miniature Christmas lights. Happily, they also slip right out of the sockets, so they’re very easy to use.

I had an old stereo receiver with a burned out backlight on the mechanical tuner, and I’ve already soldered in a blue LED (with current-limiting resistor) to replace the original incandescent. It actually looks almost violet now, and I’ll probably replace it with a green LED the next time I have an excuse to open it–but it’s cool to have it working again.

Solid-State Tilt Sensor

January 12th, 2006 by Keith Neufeld

Years ago–probably about 2000, shortly after I got my first Handspring PDA–I saw an article on adding a solid-state tilt sensor to your Palm computer. I was enchanted by the idea of playing games by tilting the PDA from side to side, but even more excited about the possibilities for walking, balancing robots.

After reading about Analog Devices’ ADXL202, a micro-machined +/- 2g accelerometer with pulse-width modulated (PWM) digital output, I filled out their sample request form and received two chips in the mail. Unfortunately, I ordered the LCC (brick with leads painted onto the surface) instead of the small-form-factor surface-mount chip, thinking I’d find an LCC socket for it. Alas, I never did locate one.

I had long thought I should make some kind of daughterboard for the chip, with DIP pins on the underside to make it easier to use for prototyping. Fast-forward to 2005. After I was no longer commuting to Pittsburg, I had much greater continuity of free time between weekday evenings and weekends. I also had all my spare junk in one place. :-) I desoldered a larger LCC socket from a scrap board and cut opposing corners out of it with a razor saw, thinking I might be able to glom something together that would work, but to no avail.

Finally, late last fall, I did what any self-respecting (or was that desperate?) tinkerer would do: I soldered leads to the chip and stuck them into the top side of a machined DIP socket. It’s gross. It’s tacky. It’s done and it works.

ADXL202 carrier

The machined pins on the DIP socket fit very nicely into another DIP socket, and it works perfectly on my solderless breadboard. After assembling the carrier, I added the supporting components and a power supply, and was at last able to confirm that the device worked! I hooked it up to my scope and tilted it back and forth, enthralled by the tidy constant-period waveform with the high region changing width as I moved the board. W00T!