Monthly Archives: October 2011

A Constant Current LED Driver…

While tinkering with my ATtiny13 Pumpkin Project, I ended up using a fairly inefficient circuit: the same amount of power is dissipated in the current limiting resistor as in the LED itself, which mean that at best, the efficiency would turn out to be around 50%. In reality, some power is consumed by the switching transistor, so it’s more like 35% or so, and when driven at the maximum power level of the resistor, the 2N2222 got uncomfortably warm.

In staring at some “constant current” sources, I began to understand what was going on. I put this circuit into LTSpice to help me understand:

The key to understanding how this circuit works is what happens at the base of Q1. It be around 0.65v higher than ground. That means the current through R1 is essentially constant (that’s good, from my LED’s view). 0.65 volts divided by two ohms means about 330 ma (which is pretty close to 100% of the limit of the LED current). The forward voltage drop for these LEDs is around 3.2V, so we are right around 1 watt of power per LED. The MOSFET is forced to absorb some current, because there is still some remaining voltage drop, if you do the math, that works out to about 1.75 volts, which multiplied by the current turns out to be 575mw. The overall efficiency works out to be around 75% or so. Not too bad. The 2N2222 transistors consume very little current.

If we actually had an 11v supply instead of a 12v supply, the efficiency would be a bit better: the current through the LEDs would remain unchanged, but the power consumption would drop by more than half. At 10v, the voltage supplying the gate of the MOSFET begins to swing to Vcc, and the MOSFET power consumption drops to around 40mw or so, but at 10V, the voltage drop through the LEDs is too much to maintain the 0.65V needed at the base of Q1, and the current drops. We can compensate a bit by changing R1 to a 1Ohm resistor, and when we do, we see that the circuit becomes very efficient (about 1W per LED, with overall circuit consuming about 3.2W).

I’ll try to get a circuit like this on a breadboard for some practical experimentation soon…

CQWW SSB Contest This Weekend!

I’m not much of a contester (not any kind, in fact) but this weekend is one of the biggest: the CQWW SSB Contest. Expect the bands to be completely awash with chatter from 0:00 UTC October 29th through 23:59UTC October 30th. I doubt I’ll do much, other than maybe hookup my SDR-IQ to scan around some of the higher bands like 17, 15 and 10m to see what’s up.

If you’d like more information, check out their official website at cqww.com.

Baseball and Pascal’s Triangle

I was standing in Tom’s office, and asked him a simple probability question (and a timely one, given the World Series):

If the odds of a particular team winning against their opponent is some probability p, what are the odds that they will win a 7 game series?

If you had any probability at all, you probably have solved this problem before. I know I have: I blogged about it before.. But I was trying to remember the equations: I knew they had something to do with the binomial coefficients, but their exact form seemed problematic.

Tom pointed out that you could just write it down by making a table. We are looking for the best 4 out of 7, so let’s make a 5×5 array. For each cellij, we are going to compute the odds that the series will reach team A having I wins and team B having wins. Let’s begin by writing down the table:

1        
         
         
         
         

Let’s say that team A wins with probability p, and team B wins with probaility q (note that q = 1 – p). Each time team A wins, let’s move one step to the right… Let’s imagine that team A wins in a clean sweep, we can fill in those numbers quite easily:

1 p p2 p3 p4
         
         
         
         

Similarly, we can compute the odds that team B has a clean sweep by marching down the first column, multiplying each previous entry by q.

1 p p2 p3 p4
q        
q2        
q3        
q4        

But now, what are the odds that we reach (say) a 1-1 even series. Well, there are two ways of reaching 1-1, either team A wins then team B, or team B wins then team A. If the games are independent, then the odds are the same regardless of the path taken, and there are two paths. So, we can fill 1-1 in as 2 p q …

1 p p2 p3 p4
q 2 p q      
q2        
q3        
q4        

We can continue this, being careful to keep track of the number of paths, and it will begin to look like Pascal’s triangle…

1 p p2 p3 p4
q 2 p q 3 p2 q 4 p3 q  
q2 3 p q2 6 p2 q2    
q3 4 p q3      
q4        

If you are familiar with Pascal’s triangle, or with binomial coefficients, those numbers are beginning to look pretty familiar to you. But you have to be a little careful in filling in the remaining squares: for instance, it’s perfectly possible for the series to end 4-1, but there are no paths that end up there that pass through 4-0 (when the first team wins 4 games, the series is over). So you don’t continue to add in the same way. for these remaining squares. And, of course the series won’t end 4-4, so the final square will remain unfilled.

1 p p2 p3 p4
q 2 p q 3 p2 q 4 p3 q 4 p4q
q2 3 p q2 6 p2 q2 10 p3 q2 10 p4 q2
q3 4 p q3 10 p2 q3 20 p3 q3 20 p4 q3
q4 4 p q4 10 p2 q4 20 p3 q4  

So, what are the odds that team A wins? We can just sum up the probabilities in the final column. That team B wins? We can sum up the final row (and the combination better add up to one).

Let’s say that p = 0.5. That means p = q, and we’d expect the odds to be the same. Just staring at the equations, substituting p for q should convince you that the probabilities are the same. If we’ve filled in our formulas correctly, we’d expect the overall probability to be 0.5 as well. It’s far from obvious to me, staring at those equations that it’s true, but if you go ahead and plug in the numbers, you’ll find that it does indeed work out.

So, let’s say that in a (for examples) Rangers vs. St. Louis matchup, the Rangers would win 60% of their games. What are the odds that the Red Birds win the Series? About 26.4% of the time. But if the Series is all tied up 3-3, then of course their probability is 40%.

Of course all this doesn’t take into account the difference in home field advantage, or pitching matchups, or any of a million other factors, so it’s relation to any games being played tonight is strictly theoretical.

Electromagnetic Propulsion of Ships and Submarines

The other day, I was watching The Hunt For Red October on TV. Through some odd coincidence, today I found a link to an article that was published in Popular Science back in 1966 on a silent electromagnetic drive for submarines, just like the “caterpillar drive” of the Red October. I didn’t realize that this was a real thing! It seems like it would be a fun experiment to build an demonstration showing this effect, and indeed, this page links to some articles that would seem to be helpful.

Electromagnetic Propulsion Ships, Submarines: patents & articles

Bookmarked for later perusal.

“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.

Approaching 100K views this year… Thanks!

This morning, I consulted the little revolving map over there in the left column, and found that I had passed 99,000 views. I reset that counter back in February, and since then nearly 100K people (or more realistically, 99K robots and maybe 1K people) have viewed a page here on brainwagon. I’d like to thank all of the people who take time to read my chaotic jumble, and would especially like to thank those who take the time to comment. While this blog is mostly a sort of personal journal, your participation makes the time I spend here seem more valuable.

I hope in the next year to continue to improve and expand the kind of materials that I post here, documenting more of my own projects, and linking with more people who share a common philosophy. I hope you will stay tuned and participate going forward.

And thanks again to you all!

Nifty paper on Batting Average…

For some reason, I never do much reading about baseball during the season itself. But as the World Series approaches its end (still hoping for a game seven) I have started to dust off some of my reading materials. A couple years ago, I mentioned this work by Lawrence Brown on this blog, but the paper that he was writing was still a work-in-progress. But it’s available now:

IN-SEASON PREDICTION OF BATTING AVERAGES: A FIELD TEST OF EMPIRICAL BAYES AND BAYES METHODOLOGIES
By Lawrence D. Brown, University of Pennsylvania
.

Batting average is one of the principle performance measures for an individual baseball player. It is natural to statistically model this as a binomial-variable proportion, with a given (observed) number
of qualifying attempts (called “at-bats”), an observed number of successes (“hits”) distributed according to the binomial distribution, and with a true (but unknown) value of pi that represents the player’s latent ability. This is a common data structure in many statistical applications; and so the methodological study here has implications for such a range of applications.

There is a lot of meat to chew in it, but some easy take aways are that simply imagining that the batting average of a player in the first half of the season is indicative of their performance in the last half is just not true: it turns out to be a relatively poor measure. A better measure is simply to average that performance with the mean batting average of all players (best predictor is that the player will regress towards the mean). I’ve been aware of this principle for quite some time, but Brown goes on to derive some more interesting statistical techniques, well outside my normal comfort zone. If math/statistics is your thing, check it out.

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.

Using an Arduino as a programmer for the ATtiny13

I’m pretty much near the end of where I wanted to be for the Arduino/Gameduino project: all the major functions that I originally wanted to include are in and working. I’ll be doing a video about it shortly, so I’ve begun to think about what my next project could be. While doing this project, I found an older Arduino NG, and thought it was a shame that I wasn’t using it for something. I also found some old ATtiny13 Atmel chips, and thought those might be pressed into service. Perhaps there was some project I could do that would use both?

Indeed there is.

If you look under the “Examples” menu on your Arduino software, you can find an entry for ArduinoISP. With this, you can turn your Arduino into a programmer that can program other Atmel chips, including really tiny members of the AVR family like the ATtiny13. Why would you want to do that? Well, cost for a start. Arduino clones are cheap, but they aren’t that cheap: you can get the cheapest clones for about $15 or so. But if all you are going to do is flash an LED, or monitor a couple of switches, or read a temperature sensor, that seems like a lot. You can get ATtiny13Vs (nice, they can be powered down to 1.8v) for about $1.91 from digikey in quantity one, and about $1.20 if you buy 25 of them. Cheap! Not quite 555 timer cheap, but pretty close. Anyway…

I thought it might be nice to try to do this. I had some ATtiny13s that I bought a while ago and never did anything with, and an old Arduino NG (previous generation, uses the 168 chips with only 16K of memory). I found this great set of instructions:

Great instructions from Nickolaus, at http://www.local-guru.net

And a few minutes later, had programmed his example “blink” program into my own ATtiny13. Check it out!

So, what can I do with such a thing? I think I am going to try to make a “flickering LED candle” for a halloween pumpkin. I have some of those powerful Cree LEDs, and a little PWM flicker program on one of these chips will make a nice effect. Stay tuned!

Addendum:

Make magazine had a project earlier that showed how you could program slightly more powerful chips (the ATtiny45 and ATtiny85) using the Arduino environment. That’s possible because they have enough space to run shrunk versions of the Arduino libraries.

For the ATtiny13, you need to be even more cagey: you compile with either avr-gcc directly (bypassing the Arduino libraries) or use an assembler like avra.

My IC-735 makes it’s first contact: T32C on 17m…

A few months ago I acquired a used IC-735 from my boss, and other than getting it hooked up and using it for the occasional bit of RX, I haven’t actually powered it up and done any QSOs with it. Part of the reason is my inherent “mic-fright”, but I also know that my impossibly low and decrepit 40m dipole is simply the wrong thing to use. I’ve been thinking of making a better antenna for the higher bands (20m, 17m, 15m, and 10m) but I haven’t gotten around to it.

But today, I was spinning around on 15m, and heard the T32C station calling. I’ve been reading a lot about how easy they were to work, so I thought I’d give it a try. I summoned up some courage and responded to the call for CQ. “Kilo Six Hotel X-Ray”. No dice. I gave it a couple of more tries. It was obvious he wasn’t hearing me.

After 10 minutes, I spun the dial down to 17m and hunted to see if I could find him there. I heard him calling on 18.145, operating split and listening 5khz up. A few minutes of fumbling made me figure out how to operate split on the IC-735, and I called him.

Bam. Immediate success. We exchanged 5-9 signal reports, and he goes in the log book.

This was also my first contact logged on 17m.

When the QSO was done, I tried to remember exactly where Christmas Island was. I was initially confused, because it turns out there are two islands known as Christmas Island. The first (and the one where T32C is operating from) is Kiritimati, in the mid-Pacific. The other Christmas Island is an Australian territory, and lies north west of Australia in the Indian Ocean.

I should really pay more attention to geography.

Here’s a picture Kiritimati, taken from the ISS:

Altimeter Module MS5607

Once I get my current project off my table, I’m going to start working more on the payload for a high altitude balloon launch. Today, I noticed that Paralllax added a nice little atmospheric pressure sensor. It claims to have a range of about 10 mbar to 1200 mbar, which covers pretty nicely the range expected from a balloon launch (wolframalpha claims the atmospheric pressure at 100K feet is around 11mbar). It includes both SPI and I2C interfaces, which make it easy to pair with any microcontroller, and also has a built in thermometer. Very cool.

Altimeter Module MS5607

They have a bunch of other cool sensors too. Bookmarked for later consumption.