Category Archives: electronics

“MOAR POWER!” … Wait… I mean, “LESS POWER!”

My electronics experimentation has brought a couple of comments from people I’ve met who have much greater experience and knowledge than I. For instance, in response to my posting of a schematic for flashing a rather large, powerful LED yesterday, I drew the attention of Mike Colishaw on Twitter:

https://twitter.com/#!/MikeCowlishaw/status/129464059937554432

And of course, Mike is absolutely 100% correct. The circuit that I posted is inexcusably inefficient. But of course, I have an excuse (a couple in fact).

First of all, there is the relatively lame “everybody does it.” If you go to section 7.3 of the Arduino Cookbook, you’ll see this exact circuit, with nary a mention of the relatively silly amounts of power wasted. I’d submit that in many battery powered applications, the power wasted by driving even ordinary LEDs this way can be quite large, and techniques to drive them more efficiently should be better known. Mike’s circuit is for a spelunker’s light, so battery life is obviously very, very important, and yet the overall circuit is pretty simple. Worthy of your (and my) study. When I get back to working on my light based communication experiments, I’ll want to make sure I’m driving these powerful LEDs efficiently, so I’ll be studying this stuff a lot harder.

My second excuse is one of simple expediency: Halloween is just a few days away, and I wanted to get this working. Doing a better job would require more parts, and probably parts I don’t have in my junk bin.

I’ll unveil the (very simple) project that this tinkering is a part of shortly. Stay tuned.

Addendum: I just learned about the Twitter Blackbird Pie plugin which allows you to embed tweets into WordPress plugins.   Very nice little gadget, and I’ll be using it more in the future.

I make things too hard… Thanks Lee…

Nothing is quite so humbling as someone coming in and showing you that you are making your problem way more complicated than it really is. Lee pointed out that I was overthinking it: that a simple 2N2222 would work just fine, and indeed, I went back over it, and realized he was right. I entered in the schematic shown below into LTSpice….

And it looks like it will work fine. I had thought that the 2N2222 would have to dissipate too much power, but I made mistakes based upon two problems: I had placed the current limiting resistor on the emitter side of the circuit, which meant that the base of the transistor was improperly biased, and I had originally used a 12v supply. In the configuration above, less than 50mw gets dissipated by 2n2222, and just about 1/2w by each of the current limiting resistor and the LED. Cool.

And thanks Lee, for taking the time out of your day to lend advice to such an introductory topic.

On using an IRF510 as a switch…

This posting begins with a caveat: while I’m pretty experienced as a programmer and software engineer, I’m actually a bit of newbie when it comes to electronics. I’m entirely self-taught, and because of my inherent laziness, I find it hard to learn anything before I actually need to know it. This means that I often get in a bit over my head, and only then start to figure things out and find out where my preconceptions and misunderstandings have lead me astray.

This happened with a project I was working on last night.

The basic idea is that I wanted to use PWM to control a high power (1W) Cree LED. I had the program running nicely on my little ATtiny13, and if I hooked an ordinary (20ma) LED to the pin through a current limiting resistor, all was well. But I knew that the Arduino couldn’t supply the current necessary to light the Cree, so I needed a switch.

And so, I’m off into territory I hadn’t been in before.

In my junk box, I have a bunch of IRF510s. I think to myself, they can handle high power, I could use them to switch the LED. So, I hooked it up. I put the LED in series with a 100 ohm resistor for safety, and wired that through the source/drain of the MOSFET to a 9v supply. I sent the voltage from the PWM on the microcontroller to the gate, and added a 10K resistor from the gate to the ground. I powered it up, and… well… it worked!

I then decided to drop the current limiting resistor’s value. The easiest way on the breadboard was to parallel another 100 ohm resistor in place. Sure enough, when I switched in that resistor, the LED got visibly brighter. Good deal, think I.

But then I moved on. I had been powering the ATtiny13 from the 5v supply on my USB port. I didn’t really want to do that in the final configuration. I didn’t have a spare 5v regulated supply, but I know that the ATtiny can operate down to 2.8v. I had a pair of fresh AA batteries, so I plugged those in, and sure enough, the processor booted and ran just fine.

But then I noticed that the overall brightness of the LED display seemed pretty weak. And when I paralleled in the extra resistance to drop the current limit, the LEDs got no brighter.

It only took me a few minutes to figure out what the deal was: the voltage driving the gate of the MOSFET wasn’t strong enough to open the MOSFET entirely. The MOSFET itself must be limiting the current.

That sent me back to the web to look at datasheets (which mostly confused me) but one thing became clear: the IRF510 wasn’t meant to be driven from logic levels. The important figure would seem to be specified as the Drain to Source Resistance (rDS(ON)). For a gate to source voltage of 10V, and a drain current of 3.4A, the resistance is typically about 0.4 ohms. But if the gate to source voltage is only 5v, what happens? What if the gate to source voltage is only 3v?

I stared at the Fairchild datasheet some more. Figure 6 was telling: it showed the graph of the saturation characteristics of the IRF510 at a variety of gate/source voltage levels, ranging from 4V to 10V. For each VGS value, the graph shows the relationship between the VDS and ID, the current through the drain. For a VGS of 5V, the curve is remarkably flat right around 1 amp. But if you look at the curve around 4V, it’s flat right at zero. In other words, the MOSFET doesn’t switch any current at all. And who knows what happens below that.

When I am running my circuit at 3V, I’m barely tickling the output. In fact, the specifications say that it shouldn’t work at all at 3V. My hypothesis is that it’s just a fluke: my transistor is actually just conductive down at that voltage level. (The appropriate specification would appear to be VGS(TH), the gate to source threshold value, which is specified to be between 2.0 and 4.0 V)

Interesting.

By the time I got all this figured out, I started tinkering with LTSpice. I learned a bit, but it really would be helpful if I had a model for the LED that I am using. But I did discover that by mucking around with the LED supply voltage and the gate/source voltage, I could emulate some of the features I saw in my actual circuit. It does seem possible to limit the LED current to 200ma or so with a 5V VGS, but it won’t reach anything close to that level of current with only a 3V VGS.

Thus, what seems like a very simple electronics project turns into a lesson. I can proceed along a number of possible avenues to make it work:

  • I could try to make it work with a 5V logic level, still using the IRF510. I suspect that since I don’t need a full ampere of current through the drain, that is at least possible. I plan on using a 6V lantern battery for the LED supply. I could inject 5v onto the gate, and empirically test the current through the LED by just measuring it with my multimeter, and adjusting the current limiting resistor until I get the current I desire.
  • I could ship to using a common Darlington (maybe a TIP120 or similar, which you can even get at Radio Shack). That will let me run the processor from just two batteries, but a lot more power will go into driving the Darlington than is consumed by the entire rest of the chip. I could of course use a Darlington at 5V as well just fine.
  • Did I mention overall power? It would be great if this thing could be powered by a 6v lantern battery, but if I want to drive the chip at 5V, any of the common 7805s I have in the box won’t work (drop out voltage would be too high). Maybe just a Zener diode supply?

I have to remind myself: projects like this are like musical scales to a budding pianist.

I2C Pull Up Resistors Needed?

The great thing about doing a real project like my satellite tracker is that it makes you learn a lot, in a whole lot of different areas. In other words, it’s good exercise! And thus, it is good when you discover something doesn’t quite work right: you have another opportunity to learn.

Well, today, something wasn’t working right.

Every three minutes, the “active satellite” dot would pass one of the balls on the track. The “track dot” would then get recalculated to the time 2 hours in the future. But I noticed that occasionally, that dot would appear somewhere wrong: a point clearly off the track. It’s of course possible that I had a bug. But I also remembered that this didn’t happen before I placed an LED on the square wave output of the DS1307 real time clock chip I have wired in.

That got me thinking: could some kind of power glitch be occurring that’s causing an error when the program reads the time from the I2C bus? So, I pulled the LED out, and left it running. It’s an hour and a half later, and the glitch has not reoccurred. Interesting.

So, I got to thinking. I didn’t bother putting in any pull up resistors on the I2C bus (laziness, and lack of understanding about how important they are). I realize that the I2C bus is open drain: either the master or the slaves can pull the line down, but perhaps the LED adds enough capacitance to keep the signals from returning to high quickly, which causes a communication error? I suspect it might be informative to check out the signals on my oscilloscope. Stay tuned, but any gurus can go ahead and tell me what’s going on in greater detail, or pointing me to materials that will spoon feed me the necessary knowledge.

Addendum: Stuck in a pair of 10K pullups, my glitch did not reoccur. I should hook it up to a scope and see the difference it makes, but for now, I’ll just consider the problem fixed.

Sprites mods – CP/M on an AVR

I’ve always been fascinated by emulation and virtual machines, as well as retro-computing: resurrecting the old machines of my past. I never owned an old CP/M machine, but there are still some neat projects where people construct there own, and simulators like SIMH and YAZE-AG are good software simulators. But what I always wondered was whether a small microcontroller like an Atmel AVR could simulate an 8080 or Z80 fast enough to simulate these older machines.

And of course, today I found a link to someone who did just that. With a remarkably simple chunk of hardware. One AVR, a dynamic RAM, and an SD card to serve as a mass storage device. The combination is good enough to run Zork. I’m suitably impressed. The design and code are all GPL.

Sprites mods – CP/M on an AVR – Intro.

How-To: Coffee Can Radar

This is awesome! MIT has created an interesting course as part of the their Open Course Ware project: it describes how radar can work, and as a final project, students were expected to build an test a simple radar system. Their description:

Are you interested in building and testing your own imaging radar system? MIT Lincoln Laboratory offers this 3-week course in the design, fabrication, and test of a laptop-based radar sensor capable of measuring Doppler, range, and forming synthetic aperture radar (SAR) images. You do not have to be a radar engineer but it helps if you are interested in any of the following; electronics, amateur radio, physics, or electromagnetics. It is recommended that you have some familiarity with MATLAB®. Teams of three students will receive a radar kit and will attend a total of 5 sessions spanning topics from the fundamentals of radar to SAR imaging.

I haven’t read a lot of this, but I’m bookmarking it for future perusal.

MAKE | How-To: Coffee Can Radar.

Real Sound Cookery – Make a contact mic with baking soda and cream of tartar. | leafcutterjohn.com

A couple of months ago, Collin’s Lab featured a story about making your own piezoelectric crystals from Rochelle salt. Collin stopped short of making an actual microphone though: he just demonstrated that the salt crystal would generate a series of voltage spikes when whacked with the handle of a screwdriver. Leafcutter John followed pretty much the same recipe to make crystals of his own, and then clamped the crystal between the jaws of a little panvise, and hooked it to an audio amplifier. When a small music box was held near the crystal, a surprisingly high fidelity recording resulted. Check it out!

Real Sound Cookery – Make a contact mic with baking soda and cream of tartar. | leafcutterjohn.com.

Arduino PWM Laser Transmitter

A couple of weeks ago, I programmed an Arduino to take digitized sound stored in its rom, and send it out via PWM of an LED. A couple days after that, I used the same code to send voice using a small 5mw laser module. Ever since then, I thought it would be good to use the Arduino’s analog to digital converters to sample the sound from a small microphone, and then use that as the signal to send over PWM. Here’s my first test:



There is lots of noise remaining in the signal. Some further experimentation showed that the voltage regulation wasn’t very good: I did tap 5v from the Arduino, but the load must have been near its limit, because the overall voltage levels were varying by nearly 100 millivolts, which is only slightly less than the signal amplitude. I also have many leads which are too long, poor layout, and unoptimized values for AC blocking caps. But it does seem to work. I’ll be revising this over the next couple of weeks.

Addendum: I did measure the current through the op amp preamp, and the laser diode module. The op amp circuit only needs to drive the Arduino input, which is very high impedance, so it draws less than four milliamps. The laser diode averages 20ma, but has a peak power of twice that.

I before E except after Hellschreiber « SWHarden.com

Scott Harden had a very cool idea: sending Hellschreiber, an old fax-like teleprinter code invented by Rudolf Hell, using just an Atmel ATMega48 and a canned oscillator. The idea is pretty simple: the canned oscillator will produce a square wave with the same amplitude as the input voltage. So, you simply power the oscillator with the PWM output (presumably with some low pass filtering) of the AVR, and you can produce a simple AM modulated signal. There are some issues with this, but the basic idea is pretty cool, and I have most of the parts I need to make this happen at home. I’ll try it out and let you know how it works out.

>>> I before E except after Hellschreiber « SWHarden.com.

Addendum: I experimented with this basic idea using my LED/Laser PWM code/circuit that I built on my Arduino. I’m uploading the youtube video now, but I realize that now that I didn’t do what Scott did, and what he did was somewhat more likely to work better. If you watch my latest YouTube video (uploading now) you can anticipate that I’ll be apologizing for my stupidity. My experiment did work, after a fashion, but his idea is somewhat better. Stay tuned.

Addendum2: Here’s the video that I shot tonight. It’s still horribly wrong, but in the interest of full disclosure, I thought I’d toss it out there. I need to work at understanding the filters and the like, maybe add a buffer, and consider the biasing. What can I say, my eyes were dialated, my brain foggy. The aliased copies I hear at the end are probably not going to be present if I actually did what Scott did. Stay tuned, I’ll redo this after some thought.


More on Dino’s simple common emitter amplifier…

I hadn’t worked through the biasing calculations for collector feedback common emitter amplifiers before, so I thought I’d do that for the simple one transistor NPN preamp that Dino built as his weeklyhack. But even before I got to it, I was confused by something. Check out the schematic (cribbed from Dino’s post):

I was confused by R1. It’s only purpose seemed to be to provide a DC offset, which was immediately removed by the action of C1. So, since I had built the circuit in LTSpice, I tried varying its value from 1 ohm to 100MEG ohms, and indeed, it had no effect on the overall gain of the amplifier. So, I removed it entirely. And the circuit continued to work just fine.

So, what’s the deal? I suspect that R1 was part of a circuit that powered an electret microphone: if the Input on his schematic were an electret microphone, you’d need to provide some voltage into it to power the built in FET preamp (like you see in the diagrams on the Wikipedia page for electrets). If that power is not needed, then all that happens is the current is dissipated by the input as heat. If you cascade two of these in the naive way, you end up a resistor feeding between voltage between two DC blocking transistors, which doesn’t waste a lot of power (no current flows at DC), but you end up with an extra cap and resistor.

Preamps and Microphones…

A few weeks ago I did an experiment that stored an 8 bit PCM file in the flash memory of an Arduino, and then used PWM to flash a laser at a high rate so I could transmit that audio over a long distance to a solar cell based receiver. A few days ago, I assembled a nifty little gadget called the bliplace, which interfaced a small electret microphone to an AVR ATtiny processor. For the last couple of days, I considered merging the two: the idea was to build a small interface circuit to condition the signal from an electret microphone to feed into the A/D converter of an Arduino. Then, it would be simple enough to use the Arduino to modulate the PWM output.

I’m a bit confused about the bliplace, it doesn’t seem to employ any kind of preamp to increase the output. My understanding is that the output from these kind of microphones is typically quite low, so a preamp would seem to be necessary to boost the overall voltage swing to something that the Arduino can measure with some precision.

My idea was to use a simple op amp circuit to boost the voltage from the microphone, and center it around 2.5v. It’s not hard. You create a resistor divider to halve a 5v supply, and put it into the non-inverting input of the op amp. You then feed the input signal through a blocking cap (I used 0.1uF) and a 1K resistor into the inverting input. Then, feedback from the output of the amp is fed through a 100K resistor back into the inverting input. Here’s the schematic in LTSpice:

I put it together today on a breadboard, and it seems to work. I couldn’t dig up a suitable microphone (I know I have some somewhere), but I’ll get to it in the next day or two and get it all soldered up so I can hook it to my Arduino. Since the LM324s are a quad operational amplifier, I could even use the spare op amps to do some additional filtering. I’m still working on that part.

Through some strange coincidence, a couple of other people I know have been playing with amplifiers too. Whisker over at tymkrs has been working on a preamp for a microphone, and MakerDino’s weekly hack at HackAWeek was to build a single transistor preamp. It’s a simple little class A amplifier, and he did a great video:

I played around with the circuit in LTSpice a bit, and it seems to work pretty well. It provides about 36db of gain, and seems reasonably linear. You can get distortion of the input signal is too high, but other than that, it looks pretty good. The gain is enough to convert a 10mV signal to a 600mA signal. Current draw is about 700 microamps with a 3v supply. Not bad! I could use similar circuit for electret preamp. I’ll play with both circuits some more. Thanks Dino!

Schematic for tanjent’s “bliplace”

Yesterday, I wrote about soldering together my bliplace kit. Today, I thought I’d have a peek at the code and the schematic. Here’s the schematic:

Not much there, but a couple of interesting things. The microphone is an electret, which needs some power to be functional (supplied through the 10K RU resistor). To me, the capacitor CC and the RD resistor look like a high pass filter, with the supplied values the cutoff frequency is nominally about 160Hz. Not 100% sure I understand how the capacitor CN or what the overall input impedance is for the ADC input pins on the Atmel chip, so I am not 100% sure I understand the subtlety.

I also thought that current limiting resistors were interesting. The center LED always seems to glow brighter, and this seems to be because R2 is only 100 ohms, compared to the 1000 ohms that were used for the other two. I also wondered about the LEDs: this gadget is powered by a single 3V cell. The ATTiny25/V can run down to 1.8 volts, but I thought that white LEDs had fairly high forward voltage requirements. For instance, this page on Wikipedia says that the typical voltage drop for white LEDs is around 3.5 volts. I don’t have a lot of white LEDs lying around, but it does suggest some experimentation.