Cheap USBASP knockoff programmer

MyGoodCable1394I’ve been using the Arduino ISP programmer sketch, an Arduino, and one of my mini shield cables as my AVR programmer for a couple of years now, and that’s been pretty satisfactory.  There’s always an Arduino around, it works, and it’s essentially free.  I felt no need for a dedicated programmer.

But when I ran across a USBASP knockoff on Ebay for $2.29 (and of course free shipping) I couldn’t resist.  Unfortunately, it had the ‘other’ Atmel standard programming cable – the 10 pin version.  Everything I have – including Tiny85 boards – is 6 pin.  Fine – the cable shouldn’t be hard.

Pinouts6+10HackedCableThe pinouts of the two connectors are readily available.  But it turns out there’s a really nice Inventable on making such a cable, complete with an excellent picture that tells just about everything you need to know.  The author suggested using little scraps of wire to fill in the unused positions in the 10 pin header, which seems to work well.


My programmer came with a 10 pin cable, and I think I cut one end off and reused the connector for the 10-to-6 pin adapter cable that lives in the programmer now.  That’s not a great idea, since the insulation displacement clips in those connectors are really designed for one-time use.  But it was in keeping with the cheap programmer.  And it works :)  The 6-pin end is marked with whiteout on pin 1 as is my custom.

But avrdude didn’t like it

Unfortunately, the first time I tried to use it with avrdude, I got this error:

avrdude: warning: cannot set sck period. please check
for usbasp firmware update

Fortunately, that’s an eminently googleable string, and Google did not disappoint.  Many thanks to this nice article by Roger Clark that told me everything I needed to know.  The latest code comes directly from USBASP originator  Thomas Fischl’s site (thanks for the great work, Thomas!).  I’m running usbasp.2011-05-28.tar.gz.  The critical not-so-obvious tidbit is that there’s a jumper (JP2 on mine) that must be populated to reflash the ATMega8A.  Interestingly, you program it over the same connection that it uses to program its target chips.

ReprogrammingTheProgrammer2079Of course you have to have an AVR programmer to program it.  And I do :)   My old standby did a fine job of (re)training its replacement.

Once that was done (and the J2 jumper cut) avrdude stopped complaining, and the programmer seemed to work just fine.  I reburned a bootloader on an Arduino, and verified that I could check the signature on a Tiny85.  Great!

Not so great

While I was working on a hacked version of grbl for the W88 Shapeoko 2, I threw the new programmer in my bag since I knew I’d need it to burn grbl on the SO2’s Uno.  (Grbl overwrites the bootloader, so every time you want to install a new version, you have to have a programmer.  The grbl code is available as a hex file – which you need a programmer to install.  It’s also available as a library that can be compiled and downloaded with the Arduino IDE.  But that requires a bootloader, and you have to have a programmer to burn the bootloader.  So you need a programmer no matter what.)

I pulled out my new toy, plugged it onto the ICSP header on the Uno and tried to burn a bootloader.  Fail.  Couldn’t even read the signature on the ATMega328P.  WTH!?  Fortunately I had another Arduino, and scrounged a programming cable from the first Thotcon badge stuff.  That worked fine, so I was able to do the night’s grbl work.  But what was wrong with the programmer?

When I got home, I tried the USBASP clone on a couple of AVRs.  It worked fine.  Back to Google.

It’s a matter of speed

That ‘sck’ referred to in the original error message is the SPI clock rate the programmer uses to clock data into its target.  And if the speed is too high, some chips won’t program (as was apparently the case with the Uno).  It turns out there are two ways to change that speed with USBASP.

The first way is with yet another jumper on the programmer.  On mine, it’s marked JP3.  When that jumper is in place, the programmer runs with a much lower clock rate.  It takes noticeably longer to program with it that way.  But at least it works!

The other way is from the avrdude command line.  The -B bitclock option (you know – the one it thinks you meant when you screw up trying to set the -b baudrate) lets you specify it directly in μsec.  Sorry, I don’t know actual appropriate numbers.

Anyway, after I put in a push-pull switch for JP3 (you can see it in the picture above) and connected the pins, the programmer talked to the SO2’s Uno fine.  That was very reassuring.

I’m sufficiently sold that I bought a second one (cost me $2.59 this time!) so I can keep one in my box at W88.  Now that I know about JP2 and JP3, have the latest firmware and know how to make the cable, it won’t be hard to set it up as a reliable tool.

Posted in Miscellaneous | Tagged , , | Leave a comment

CNC machine emulator for grbl

I don’t have a CNC machine at home, but several times I’ve wanted to do some kind of testing that sort of needed a machine to see what was happening.  Not particularly to print or cut – just to watch the movement.  I considered making a very bare bones machine – some cheapie 5V steppers and string and pulleys, or maybe CD drive hardware.  But they quickly grew more complex than I wanted.

Emulator2205+redSo I built a simple CNC controller/machine emulator with LEDs to indicate gantry movement and buttons for limit switches etc.  It’s an Arduino shield that expects grbl running on its host.

Pairs of LEDs (red ovals) show X, Y, Z motion by decoding the step and direction pins from grbl.  Cranking the step pulse width up from 10 to 50 μsec improves the brightness.  Just as with the W88 Shapeokos, there are limit switches for X, Y, and Z – implemented as small button switches at the ends of their axes.  There’s also a button on the A5 line grbl0.9 uses for the G38.2 probe command, plus one for Arduino reset, since the one on the board is covered up.  Two more LEDs – for Stepper Disable and Spindle complete the hardware.  Since grbl0.9 supports spindle speed control via PWM – at the expense of pin compatibility with 0.8 – there’s what amounts to a DPDT switch of header pins to support either pin configuration.  There are traces hard wiring it for the 0.8 assignments that would need to be cut if I ever populate the jumpers.

SchematicIt was an interesting challenge to figure a simple way to decode step/direction for the LEDs, but I think the 3 transistors are about as simple as it gets.  Yeah, if I’d used MOSFETs I could have saved 3 resistors, but I didn’t have any on hand.

The first application of the emulator was to hack grbl to add the very slick “smart clamp” Z auto-touchoff like Carvey uses.  It performed admirably for that task.  (The implementation was a surprise:  I expected to implement it in code in grbl, maybe triggered by a private M code.  But it ended up just being some gcode in the $N ‘startup blocks’ grbl supports.  The hack was just to support more blocks (I needed 5 instead of grbl’s normal 2) and ensure that they were not executed after a reset.)  I even put the code in the W88 github repo, thanks to gentle browbeating from a couple MVI_2213of other members.

Here’s a quick and dirty clip of it in action.

Overall, it’s a real success.  But if I ever make another (unlikely), here’s what I’d add:

  • 100K resistors from all 3 step lines, run to a common post for audio output.
  • Easy access pins for both sides of the serial comms.  I needed to sniff them a couple of times to see what was going on.
  • Lay out / cut the board so the ICSP header is exposed.  Since grbl overwrites the bootloader, I had to pull the shield off so I could burn a bootloader each time I wanted to load a new round of code.
Posted in Shapeoko | Tagged , , , , , , , , , | Leave a comment

Printing transparencies for PCBs with Epson NX300

I need to print PCB artwork on transparencies for my preferred PCB making approach using presensitized board material.  My printer is an inexpensive Epson Stylus NX300.  That printer does not support printing on transparency.

The problem is that the printer uses an optical paper sensor to which the transparency film is, well, transparent.  It picks up the film fine, but then just keeps feeding, usually declaring a paper jam.

OldStyle2039For years, my workaround has been sticking an 11″ long piece of 1″ white PostIt correction tape exactly along one edge of the film.  I put it on the non-print side of the film, allowing me to print all the way to the edge of the film if needed.  Here’s a piece on which  lots of small PCBs have been printed and cut out.  (I can probably only get 1 or 2 more from it.)  And yes, those words were written on the adhesive side of the tape.

The box of 60 sheets I had lasted me for many years.  It was an Office Max house brand, and I figured I’d just get some more.  Nope – they haven’t had that for years.  I ended up with a box of Apollo Quick-Dry Ink Jet Printer Transparency Film VCG7033S.  It was ridiculously expensive – over $1/sheet, but it said it had a “removable sensing stripe for smooth feeding”.  OK – the price doesn’t hurt quite so much if it saves me having to carefully stick tape on each sheet before I use it.

NewOutOfBoxBut when I opened it up – the stripe was the dumb way!  OK, I suppose that works for some printers, but not mine.  It would see the film, but thought it was ~1/4″ tall!  OK, at least they give me some tape with each sheet.  Not long enough, but it’s a start.  I removed it and stuck it along the edge as I’d always done.  But the printer never even saw that skinny strip.  So exactly where do I have to put it?

The second printer

When I bought the printer several years ago, it was $50 new.  (They make it up on the ink!)  But to get a spare full set of 4 ink cartridges was maybe $38.  For a couple bucks more, I could buy a whole nother printer – with ink cartridges!  I could throw the printer away and keep the ink and just about break even.  So I bought 2 printers.  (OK, not quite as good a deal as I thought: the “starter” cartridges it comes with don’t have nearly a full dose of ink.)

I opened the second printer and stole and used the ink, just as planned.  The new carcass sat around for a couple of years.  But one day the print heads on the live printer clogged so badly I couldn’t get them going, despite alcohol and windex soaks and lots of other home remedies.  (I now keep a humidifier inside the printer and set a calendar reminder to print a little color test pattern once/week.  That’s worked so far.)  So I pulled out the spare, swapped it in, and was back in business.  All my printer settings (including carefully tuned ones for PCB printing) still worked perfectly.  I put the bad one in the pile waiting for the next electronics recycle event.

BigPicture1999Fortunately I missed a couple of recycle events, and the dead printer was still here when I wanted to know exactly where that paper sensor was.  It was junk anyway, so I didn’t even have to be very careful as Sensor1997I took it apart.  (The back of the printer is at the bottom of both pictures.)  I had to strip it pretty far down to find the sensor.  It looks like the active part is maybe 1/4″ wide, near the open end of the sensor package.  Unfortunately, the paper path was substantially compromised by that time, but by sliding a card through against what I think was a paper guide, I concluded that the center of that 1/4″ wide sensitive place was just about 7/16″ from the (left) edge of the paper.

NewStripeRelocated2035StripLocatedCorrectly2036I moved the strip so it was centered 7/16″ from the (long) edge and printed a couple of characters in the top left corner.  It worked!  Of course the strip was too short, so the printer stopped feeding before the film was all the way out and I had to gently pull it out the last couple of inches.  In practice, when I prep a new sheet I can scavenge some tape from the previous sheet and patch it so it goes the whole 11″.

The old stuff had a nice rounded corner that helped identify which way to put it in the printer so it would print on the correct side.  The new film doesn’t have that, but since the scrawny little strip is on the non-print side, as I prep a new sheet, all I have to do is lay it down non-print/strip side up, peel off and re-stick the strip (along either long edge!), add some old strip so it feeds all the way, and I’m done.  (Writing “print this side” on the sticky side of the tape couldn’t hurt.)  I know it goes in the printer with the strip on the non-print side, and it’s burned into my fingers that the white strip goes on the right side as I face the printer.  (That’s what lets me put it on either edge.)

PackageWithOffsetInstruction2043So the new stuff produces fully acceptable prints, it provides material for the strip for free, and I’ve figured out where the dumb strip has to go.  And I even marked it on the package so I won’t even have to refer back to this Project Note.  I have 40-several sheets, so I’m set for making PCBs for a bunch of years to come.

Posted in PCB Etching | Tagged , , , , | Leave a comment

Cheap USB LiPo charger notes

Front2009I got a couple of cheap ($1.29) 1A USB LiPo chargers since I’m doing more and more LiPo/LiIon powered stuff.  I mostly discharged a recycled 18650 cell for a test load and it looks like it does charge at nearly 1A.  Two LEDs – red charging, green (mine is blue) fully charged.  Seems like a pretty ideal cheap device.

Since I use a variety of cells, I wanted to be able to charge at Chip2014under 1A.  Most such charge controllers have a single resistor that programs the bulk charge current, so I looked for the datasheet to find what values I’d need for the charge currents I wanted.  The chip is marked 4056ES, and there are charge controllers with that number – but they don’t match this package layout.  The Ebay ad was titled “5V Mini USB 1A Lithium Battery Charging Lipo Charger Module for Arduino A866″, but I couldn’t find anything under A866, either.  It says RD084DY002 on the back, but that’s not helpful either.  Rats.  (But see update!)

I replaced the likely candidate programming resistor – 1.2K stock – with some leads so I could determine values experimentally.  Here’s what I found:

  1 A   1.2K (stock)
~480mA  2.1K
 400mA  2.6K
 200mA  4.9K
 100mA  9.3K
  50mA 18.5K

Now I’m all set for when I need to deploy one.

ProgrammingResistorUpdate 10/8/14:  Thanks to Vitor, we now know the chip is a NanJing Top Power  TP4056.  I did a comparison of the programming resistor vs charge current info from the datasheet, and my empirical data seems reasonable.  Thanks, Vitor!

Update 12/1/14: Looks like it’s actually a knockoff of the TP chip, and a possibly dangerous one at that.  Thanks, Halo!

Posted in LiPo stuff | Tagged , , , , | 4 Comments

Shapeoko 2 cutting tests

S2WithDremel0693Now that the W88 Shapeoko 2 (graciously donated by Inventables) is mostly working, we tried some test cuts in various materials.  All were done with my old Dremel and a 1/8″ upcut end mill (WRONG: downcut; see update at end).  We ran a nightly build of Universal Gcode Sender 1.0.8 (to avoid the Reset Home bug in 1.0.7) with grbl0.9g on the Shapeoko2’s Uno.  Thanks to Scott for his help and consultation!

We had a lot of trouble with unexpected hard limit alarms until I disabled the limit switches in grbl.  Looks like picking up noise on the limit switch wires is a common problem.  We suspected electrical noise and tried plugging the Dremel into a UPS, but that didn’t help much.  Next steps I’d suggest are 330Ω pullups (instead of depending on the ~20K internal pullups) and maybe 0.1μF caps to ground on each limit input, along with running shielded wires.  Not sure whether to use shielded 2 conductor or just thin coax.

All the cuts were with hand edited Gcode tracing out a 1″x1″ square, with various directions, depths, passes, and feed rates.  There’s lots of lessons in these cuts; I’ve only picked some highlights here.


GreenFoamAll1875A dense flexible craft foam I seem to know as “foamie” cut pretty well.  This piece was 5mm thick.  One of the things we learned early on was that the wall of the cut where the cutter was going in the feed direction (maybe conventional cutting vs “climb cutting”) was much smoother than the other.  GreenFoam+RevPath1877You can see that effect in the far right vertical cut here.  The far left cut shows that by having the cutter retrace the path in the opposite direction, the sloppy wall was considerably cleaned up.  The rounded outside corners reflect the radius of the cutter.


Foamboard+BlueTape1895I had high hopes for foamboard, but although it cut easily, the top surface tore out badly.  We tried 2 approaches to reducing the tearout – both pretty unsuccessful.  Here’s the result of covering the surface with blue painter’s tape and cutting through that.  Bits of tape are obvious in the bottom of the cut.  But the real problem was that the tape stuck so aggressively to the nice outside finished surface of the foamboard that despite careful removal, it destroyed the surface.  There’s evidence that the cut edges were protected and cleaner, but tearing off the good surface is a show stopper.  It could be that other flavors of tape and foam board might play more nicely together.

FoamBoard+AlumCan1887This was a failed attempt to protect the edges by taping a thin sheet of aluminum (pop can) over the surface.  The aluminum didn’t stay in intimate contact with the surface, and so protected it little, if any.  PepsiOverlay1896The results were about the same as with no protection – unacceptable.  This is probably what chipboard would look like with this cutter.  I think the blue here is from the paint on the can, and you can see little bits of aluminum that didn’t get cleaned out.  On the plus side, the aluminum cut beautifully.

Foam insulation board

PinkFoamCcw1Pass1884This is a classic material for hacker CNC machines.  It cuts easily and is cheap.  (A 4’x8′ sheet of 1″ thick board is maybe $15 at Home Depot; pink and blue are just different brands.)  I think I ended up with good results at 1500 mm/min (1″/sec).  This was an early cut when we were working through the “smooth side/ rough side” behavior.  The cutter spins CW (looking down) and this cut started in the upper left and went across the top, down the right side etc, so the outside wall was cut the good way, with the fuzzies on the inside wall.

PinkFoamCcw+halfRev1885To verify the dependency on feed direction, we tried going the other direction.  This one started lower right, went up then across the top to the left.  Sure enough, the fuzzy side is now on the outside.  This one was also testing whether reversing the path would clean up the bad wall.  After it got back to the lower right, it went the other way (left across bottom) half way.  The cleanup pass is quite effective.

Plastic badge material

BadgeMaterialLowAngle1901One of the obvious target materials is the stuff name badges are often made from.  A thin layer of one color is laminated over a substrate of another; cutting through the top layer exposes the lower color.  The clunker 1/8″ mill we had isn’t useful for reasonable size badges/signs, but here’s the result of a quick test on an old badge.  Only after cutting did I realize that the original badge – with white substrate – had been engraved and then the (white) groove filled with yellow paint!  That (well dried) paint tainted the cut.  The bottom surface was much rougher than I’d like, though that probably won’t matter with a much smaller cutter.  I suspect the roughness was due to melting from too high spindle speed.  You can also (barely) see that the cut was deeper on the left than the right.  Just a reminder that when you make cuts this shallow having the spoilboard dead level is critical!


Acrylic1897I really hoped to be able to do better than this with plexiglass.  The spindle’s pitch change told us it needed a pretty slow feed speed.  But with the Dremel at maybe 10K RPM, melting was a real problem.  The circled path is way larger than the diameter of the cutter.  It was essentially being milled out by the big blob of melted plastic on the end of the cutter!  This makes me even more critically interested in seeing how a much lower spindle speed – with closed loop speed control able to crank more power in at that low speed – would do with plastic.


I brought several samples of chipboard, but after the nasty rough edges on the foamboard, I didn’t even bother cutting any.  I’m almost certain the results would have very similarly disappointing torn out edges.

That said, I suspect strongly that the problem was in using an upcut spiral end mill.  I wondered initially why anybody would want a downcut – since it would force the cuttings into the cut rather than lifting them out as the very reasonable upcut mill would do.  But now I see:  With soft material like this, dealing with the chip load in the cut would probably be worth it to get a nice clean cut at the top surface.  The idea that a downcut was suitable here was reinforced when as I looked on Ebay for downcut mills I came across a set of “Luthier’s” mills for doing inlays.  They would obviously care about clean edges – and those mills were downcut.  Guess we need some of those, too!

Update 9/23/14 (from 9/12/14):  Rats.  The endmill used for all the cutting above was in fact a downcut mill.  I was just being dumb when I first looked at it.

The very sad consequence of that is that my hope for better surface edge cuts with another mill were unfounded.  I got those bad edges with the mill I thought was what I needed.  Bummer.

Someone suggested that there’s another kind of downcut mill, with additional relief that would work better.  Could be.  The range of choices in cutting tool design, geometry, and material along with the real fundamentals of tool speed, feed rate and depth of cut multiplied by the variety of materials to be cut and results desired produces a mind boggling array of choices, with only a few being near optimal.  It looks like a year and thousands of dollars in education to run a milling machine sensibly as a beginner.  There must be an easier way.  I guess the hope is that someone with the necessary education and years of real world experience will write a Dummies book for the rest of us.

Posted in Workshop 88 Stuff | Tagged , , , | Leave a comment

Current sink and starter’s gun boost converter test

Background failures

I’ve had some problems getting DC power for the audio amp for the starter’s gun project.  I needed maybe 15V to get the output I needed, but didn’t want a battery voltage that high, so looked at boost converters.  I found some little (Chinese) boards for $2.50 on Ebay that took in 1.2V or more and put out what ever you wanted up to 30V or so, and said 4A max.  Should be fine, and I can’t even source the parts for that money.  I ordered some.

Running off one 3.7V 18650 Li-ion cell they put out 15V no problem.  The first surprise was that when I put it all together, the whole thing didn’t work.  Funny noises from the speaker, and the Tiny4313 wouldn’t even boot reliably.  It took a while to figure out I was running afoul of the current limit of the protection PCB in the cell.  (Worked fine with the unprotected 2P bench battery!)

While the design had been for one 18650, in desperation to get a prototype working, I put in 2 cells in series.  Sure enough, now the Tiny booted, no funny noises, and it played sounds, though not quite as loud as I expected.  I looked at the voltage out of the converter with a scope, and during loud sounds it dropped from 15V to ~8V!  WTH?!?  Going thru the doc more carefully, that was 4A max input current, and there are limitations of max output current at various output and input voltages.  Rats.

Very grudgingly, I decided to try a small 12V sealed lead acid battery.  Surely the boost converter will do what I need with that much voltage in.  But this time I’ll actually measure and qualify the boost converter at 12V in / 15V out.  Let’s see – I may need 2A (or a little more?) at 15V, so I need a resistor to provide that load.  Whoa – that’s 30 or 40 watts.  Using a 2W 10Ω resistor – and just at 1.5A – the resistor got really hot before I could even comfortably make measurements.  Sure would be nice if I had that high power adjustable current sink I’ve thought about making from time to time.  And that need brings us up to this yak-shaving project.

The current sink


A current sink is basically a big honking transistor with a big honking heat sink, plus some electronics to let you control how much current it will sink.  I should be able to come up CurrentSinkSchematicwith that out of the junk box.  A little googling scored ideas that led to this as the final design:  (Bonus:  I figured out how to add an image to a custom library schematic symbol in Eagle!)

I found an N-channel MOSFET good for max 55V and 29A – sounds fine.  A 0.1Ω current sense resistor under it provides feedback thru an op amp listening to a pot for a reference voltage (and thus current).  I went with using the bench 2S Li-ion battery for the occasional use this device will get, as the spec sheet indicated the MOSFET wouldn’t turn on for many amps without > 3.7V on the gate.  A voltage regulator feeds the reference pot for stability.  The heat sink has a 12V fan, which runs fine (and quietly) on 8V.  A switch, an LED and a couple of resistors (for LED and pot range set) plus some connectors and it should work!

BoardFront1798It looked simple enough that I could get away with perfboard instead of making a PCB.  It took longer than I hoped, but it came out OK.  The lampcord is for the current to be sunk.  There’s a 2-pin 0.1″ male for power in and a 2-pin female for power to the fan.  The 0.1Ω resistor is across the bottom.  Its long left lead HoldingNut1803is to clip a voltmeter to for setting the current (0.1V/A).

The only mildly clever bit was using some gaffer’s tape to hold the nut in place while assembling it to the heat sink.  Worked well and pulled out easily.  I had to grind one side of the nut down so the hole would line up.

Heat sink

I’ve never really done any proper thermal management design, so the heat sink was new territory.  Fortunately, Dave has a simple intro to heat sink basics on EEVblog that got me started.  Thermal resistance of a heat sink in °C/watt makes perfectly good sense.  But who knows what the TR is of all the random stuff in the junk heat sink box?

I looked around in Digikey to get some ballpark numbers.  The heat sinks there ranged over 3 orders of magnitude – from 0.1 to 100°C/W.  Reasonably enough, the 100°C/W jobs were tiny fins you could glue to a DIP, and the ones at the other end were massive CPU coolers with fans and heat pipes.  The one Dave used was ~5°C/W with no fan.  If I could get to maybe 2°C/W with a fan, the 60C increase at 30W would hit ~85C – well within the operating temp of the transistor.  Might work!

FirstHeatSink1821To be conservative, I grabbed the biggest sink I could find, and peeled the old Pentium off the bottom.  Unfortunately, since it was designed for the large flat top of the processor, there were no holes in it to mount the TO-220 MOSFET.  Drilling thru the fins for the nut or screw head would be a pretty ugly task.  Maybe if I had a 1/2″ end mill – but I don’t.  I suppose there might be one at the space, but that has problems of its own.  Bummer.

WholeThing1808The next biggest was much smaller, but had fins that allowed drilling a mounting hole – sold!  Here it is attached to the finished device.  (The MOSFET is on the underside of the perfboard.)

On the to-do list is putting a temperature probe on the transistor and characterizing time/temperature/power curves with and without the fan.  Sure would be nice if I had that datalogger I’ve been thinking about making…

“Opportunities for improvement”

While the current sink was a junk box special, I did try to think it through.  For example, I wanted to be able to run with or without the fan.  But did I really need another switch?  Naw – the 2 pin connector would be fine.  Did it really need an LED?  Yeah, I could imagine accidentally leaving it on.  And I dry fitted the parts to make sure it would all go together.  But I still had 2 surprises – one electrical and one mechanical.

The main consideration in something like this is handling the power – and getting rid of the attendant heat.  I put some moderate effort into the heat sink to do that.  If it can dump 30 W or more without the transistor going above maybe 85C, it should be fine.  The MOSFET is good for 29A, so current isn’t a problem.

Well, not for the transistor.  But what about that 0.1Ω current feedback resistor?  I’d like to be able to do 10 or 20 A.  But wait – at 10A that resistor will dissipate 10W!  With the 2W resistor I used, it’s only good for ~1.5A.  Boo.  I ordered some 20W 0.1Ω resistors to upgrade it some day.  0.1Ω resistors don’t usually manage to get very hot, but I guess this isn’t a usual application!

The mechanical issue was pretty bad, and I really should have seen it coming.  The only mechanical connection between the heat sink and the perf board is the MOSFET – or more accurately the 3 legs of the MOSFET’s TO-220 case.  To allow for some air flow past the transistor, it’s 1/4″ off the board – with only those spindly legs in between.  The pot – which is manipulated a lot – is screwed to the heat sink – so that’s not a problem.  But the power switch and the connector for the battery are on the perfboard.  And every time I touch either one, the board woggles around dangerously.

There’s a nice chunk of aluminum very near by, and I could drill and tap a hole for a screw.  But I don’t have much real estate left on the board, and if I used a plastic spacer I’m not sure how it would do with a hot heat sink.  I’m sure I’ll come up with something, but MechanicalSupport1824Bcatching it earlier would have been good.

Update (next day):  OK, this is crude, but it keeps the board a lot more stable, particularly when I operate the switch.  Good enough.

Back to the task at hand

BoostConverter1817Now to take a closer look at the little boost converter.  I don’t know how it works, but I wonder if a larger cap on the output would help keep the voltage from drooping?  Hmm – looking at the board, the larger cap in on the input.  Is that just another student error?  These things are usually exactly from the example schematic in the datasheet.  Let’s see…BoostDiag

Gee – it shows a 220μF on the output – and the board has a 220 on the input.  Pretty suspicious.

Ooh – a shiny thing to distract me!

Looking at the schematic, I realized I had no idea how this thing  worked.  OK – output cap, voltage divider on the output for feedback, some kind of enable, yeah, yeah.  And all the current that goes to the output goes thru the inductor.  Oh – except for what comes from that “SW” pin.  What does that do?  <checks block diagram in datasheet>

BoostSwPinHmm  – nuthin’ comes out of that pin.  All it has is a MOSFET to ground.  So all it does is … SHORT OUT THE INPUT AND OUTPUT TO GROUND!  WTH?!?  Oh, that’s what the diode is for:  it doesn’t short out the output.  But it still shorts the input to ground!  OK – thru the inductor, but still…

<light slowly comes on>  OK, as soon as the switch comes on (connects to ground), the whole input voltage is impressed across the inductor.  There’s no current spike – since the inductor “doesn’t want the current to change”.  But as the current slowly builds, it’s storing energy in the inductor.  When the switch opens, the current thru the inductor would drop, but there’s a big inductive spike as the inductor keeps the current flowing.  Where does it go?  (Thru the diode and) into the output cap!  Aha!

So what does that inductor-driven ripple look like?  And is it better/smaller with more capacitance across the output?  <hooks output to the new current sink and puts scope across the boost converter output>

BoostOutputCapsHere’s the output voltage (AC coupled, 20mV/div, 1μs/div) at 0.5A stock (left) and with another 100μF across the output.  <scratches head>  So maybe with more C there’s lower impedance to the high frequency component of the inductive spike, and we see it as a leading spike on output voltage?  I’m really not sure how it’s all supposed to work, but there’s a gut reaction that says those near-square waves from the stock config indicate that the inductor and stock cap are about ideally matched, despite the 220μF value in the datasheet example.

I suspect the tilt in the stock picture is the cap being discharged at constant current.  Let’s see:  Stackexchange says discharging a cap at constant current gives a rate of voltage change of I/C v/sec.  That’s 0.5A/100μF=5V/ms, or 5mV/μs.  Eyeballing the 2 slopes of the waveform (bottom is steeper), it’s maybe 0.25div vertical per div horizontal.  At 20mV/div, that’s 5mV; horiz is 1μs/div; so that’s about 5mV/μs!

SlopesHmm – so if I change the current load, the slope should change.  <goes back to bench>  Well that was interesting.  Here’s the output ripple at 100mA and 800mA.  Starts with the bottom flat and the top tilted, ends the other way (plus greater overall amplitude).  Slopes were the same around 300mA.  I have no idea what’s happening.

And then there’s the question of why the datasheet shows a 33μH inductor and the one on the board is marked 330…  Update:  Duh.  33*10^0.  Thanks, Michael!

Back to work

So why were we here again?  Oh yeah – does additional output cap make less droop?  And the original question:  how much current can the booster put out at 12V in/15V out?  Looking at the output voltage on the scope (DC coupled) when it’s dropped down to maybe 12V, touching an extra 100μF across the output does bump the output up by maybe 0.1V – not enough to do any good.

The output voltage really hits a wall as current increases above about 1A.  There are significant thermal effects in the booster, so it’s hard to get good measurements.  Output is still 15V at 1A, but by 1.2 or 1.3A output is down to ~13V.  By 1.5A it’s below 11V.  That’s not great news.  One amp is 15W DC in to my audio amp, and the amp isn’t 100% efficient.  I’m afraid that makes a max output of 10 or 12W – less than I’d hoped for.  But now I know.  Let’s see if it’s loud enough.

So the actual testing that started the current sink project was almost trivial once I had the tool.  But making the tool was fun.

Posted in Miscellaneous, Rf starter's gun | Tagged , , , | 4 Comments

Tiny85 dev/target boards

NewBoards1750Just a quickie, but it seems to delight me.  I finally got around to making up a little bunch of generic Tiny85 boards so I can knock out some simple projects.  They’re a lot like the I2C slave boards for the dollhouse, but have all the pins brought out and have a 6-pin ICSP header so programming is easy.  I laid out the board several months ago, but hadn’t gotten around to making any.

Of course, the first one didn’t work.  I’m pretty good about putting a mark on the PCB for Pin 1 on ICs and connectors, but I missed it for the Tiny on this board.  (It’s fixed now :)  No problem – the board is so simple I can reverse engineer it visually.  Let’s see – I always put a pullup on the RESET pin, and there are only two 1206 pad pairs, and that one is a jumper, so the pullup must be here – and that goes to the Vcc pin, which is pin 8, so the chip must go this way.  Done!  I put all the SMT parts down and reflowed it – and it looked about perfect.  A couple of minutes to hand solder the header, and it was time to test.

But it didn’t even get as far as running avrdude for a signature check.  As soon as I plugged it into the Arduino ISP, all the lights on the Arduino went out.  I held it to my lip, and the Tiny was fairly warm.  Not good.  Then I proceeded to make myself crazy trying to more carefully reverse engineer it visually.  Was the header layout backwards so the pins came out the back of the board?  Did I actually lay out that nice big ground pad wrong?

When I finally looked up the original Eagle layout files (like I should have in the first place!) it became frustratingly clear:  I didn’t put a pullup on RESET (it’s not really needed) – and those pads are for a cap across +5/Gnd, not a resistor!  And sure enough, my reverse engineering based on the non-existent pullup led me to put the Tiny in backwards!  Rats.

I made up another board (correctly, this time), and it worked first try.  Same for the next one, and the same for another set of 3 I reflowed all together.  So I had 5 working boards plus the bad one (now with an X on the back, since they all look very similar) as a continuous reminder of my sloppiness.  Guess I better fix it.  (The picture was taken before the fix.  Can you find the one with the Pin 1 dimple opposite all the others?)

Hmm – it really should just be a 5 minute job with the hot air station.  But did I fry the chip?  (Fires up the hot air.)  Eight minutes later, reusing the original Tiny, I had another working board!  To reward the board for surviving being powered up with the chip in backwards, I even replaced the wimpy green LED with a nice bright red one.  Now I not only have 6 boards at the ready, but no longer have the reminder dud staring at me.  (And I got to wipe that big X off the back!)


What will they be used for?  One of the first applications will be a beeper to remind me the hot melt glue gun is plugged in.  When I need it I plug it in and, having better things to do than watch the glue melt, walk away.  I usually come back a few minutes later to use it.  But sometimes it’s an hour.  And once it a while it’s many hours.  Ouch.  So one of the Tinys will wait until the gun is hot (open loop timing), and sound a piezo buzzer once.  A minute later, 2 beeps, then 3, etc.  That should work well.  (When I get around to making it.)

Another application will be making the house stereo amp more robust.  The dumb Sherwood RX-4109 that lives in the basement (always on) and drives speakers in the kitchen, living room and bedroom has a ‘soft’ power switch that defaults to OFF after a power cycle.  Since the music it provides is also my alarm clock, the priority of a fix jumped much higher on the list after I overslept the morning after a brief power outage shut it off.

I’ll decode the Power ON sequence from the Sherwood’s IR remote, program a Tiny to reproduce that signal to drive an IR LED taped to the front of the amp, and have the music startup script tell the Tiny to send Power On to the amplifier every time some music starts.  Overkill, but at least it should always come back after a power failure.  Since the music script is on the main PC, I’ll have to invent a channel to send a message to the home automation system which can in turn actually operate the IR sender Tiny.  Several steps, but it will be nice to not have the (upstairs) music fail after a power failure.

RcvrUPS2007Update 10/3/14: Not related to Tiny85s, but just to the dumb Sherwood receiver:  I won’t need this Tiny app, as the problem has been resolved.  Someone donated several dead UPS units to W88.  I brought an APC BackUPS 350 ES home and (as expected) the only problem was a dead battery.  In an interesting lesson about industry standard battery sizes, I was able to remove the stock 3 A-hr 2.6″x5.25″x2.7″ 12V SLA battery, and by breaking out a bunch of support webs, drop in an old, much larger 7.2 A-hr battery that fit perfectly!  It had been removed (I think) from a B&D string trimmer and found to only have 2.4 A-hr capacity.  That’s plenty for this app, and the battery worked, fit, and was free.  The receiver is now on its own UPS, and should survive at least short outages without turning off.  A perfect, free solution!

Another possible application will be at least doing initial datalogging to see how much power I can get from a small solar panel in a tree where I really want to put a camera looking at the house.  Solar (or possibly wind?) is the only way I can power it to take a picture every few minutes and radio it back to the house.  Doing this initial energy monitoring/logging has been on the list for oh, maybe 5 years.  Maybe these Tinys will let me make it happen.

But just having that little stash of Tinys there – each one eagerly awaiting its chance to serve – gives me a little delight each time I see it.

Posted in Tiny 85 stuff | Tagged | 2 Comments

Quickie 1-cell discharger

Wow – I wasn’t planning to make this.  But as I fantasized about just building a simple discharger while struggling with 1-cell problem on the big 18 cell discharge tester, it sounded too simple to resist.  I could get to a couple of analog inputs and ground with a mini-shield just on one side of an InUse1681Arduino.  (And I seem to like mini-shields.)  And a MOSFET instead of a relay would make it simpler and more robust.  It sounded so simple I just made it up on perfboard rather than laying out a PCB.

The extra juicy bit of simple was realizing that the Drain-Source resistance Rds was pretty constant, and for this MOSFET was in the neighborhood of what I needed for a current sense resistor.  If I put the MOSFET at ground and measured the voltage on the Drain, I’d have the current reading – for free!  And it doesn’t take a fancy 1% 0.1Ω resistor – as long as it’s a fairly constant value, a calibration constant in the code will deal with it.

LittleDischargerIt uses screw terminals to connect an external load resistor like the big discharger, but stayed very simple with just a single pair of clip leads for the single cell.  An LED on the Gate (really on the Arduino pin driving the Gate) to show when it’s discharging is nice.  The 1.1V internal reference on an Arduino (328P) is fine for the current sense, and just took tweaking a voltage divider to make a good fit for the voltage sensor.  Setting up for ~5V full scale gives me very good resolution for either 1.2 or 3.6V cells fresh off the charger.  By putting in an extra pin, it’s pretty unambiguous how it aligns with the Arduino header pins.  (OK, unambiguous on a Duemilanove, though not on a Mega.)

The code was pretty simple, and as it matured, I was able to steal some bits from the other discharger code.  The one open issue at the moment is to verify whether Rds is constant enough to treat as a constant for the current sense.  I guess worst case I can code up a piecewise fit for it.  (Done – see update.)  But the device is booked solid for a while testing some AA NiMH cells, so I can’t even get it to the bench for the calibration/linearity test.

Ever infected with the “Ooh – and with just a little change I could make it do something even cooler…!” bug, I thought about making up a PCB and having it as a giveaway tool for a class on battery tools and technology.  Like I need one more prep-for-a-class project on the list.  But if I were to do that, the choice of MOSFET becomes important.  I even ordered some nice ones with Rds of 20 milliohms or some such, but they’re not ideal for the Rds-as-a-current-sense-resistor bit.  It’s kind of interesting to need to select a part with resistance not too high but not too low, either!

PerfboardJoy1677Anyway, I’m surprised with how pleased I am with this little guy.  The fact that I can just throw it on an Arduino, and that I didn’t even have to make up a PCB means I’m not even sad it’s not Tiny85-based.  The fact that it’s completely junk box parts makes me smile, too.  This little bit of perfboard’s a winner!

Update 6/2/14: Here are the results of a current calibration on the bench (all in mA):

Actual    20   50  100  200  300  400  500  600  750  1000  2000
Reported  14   45   96  197  308  420  545  675  840  1200   1700
Corrected      55  100  189  288  387  498  612  739  1015

Between those observations and the datasheet, it looks like at Vgs of say 4.8V we’re at the edge of linearity of Rds at an amp.  The transistor got quite hot at 2A, so it looks like the practical upper limit is 1A.  The current calibration constant is 1.67mV/count, so we’re at the ragged edge of digitization problems at say 20 mA.  Let’s say a practical lower limit is 50 mA (and rocky at that).

CurrentCalibrationTaking the A/D count as Reported/1.67 and doing en embarrassing amount of manual cut and try in Excel, a final formula with corrections (A/D count=A):  (A+10)*1.48-(IF(A>400)then((A-400)*0.2); else 0)) gives a pretty good fit over the range of interest.  (Apologies for the Excel expression.)  Red is ideal, green is corrected.  Guess I better code that in (and test it again :( ).  Done.

Selection of a new MOSFET for building multiple units would like:

  • Max continuous Ids > 2A, Vds > 5V (trivial)
  • Rds(on) ~0.5 ohms  (requires finding suitable part)
  • Vgs of 4.5V fully saturates at 2A  (requires finding suitable part)

OK, now I’m pretty comfortable with the current calibration, know the device limits and what next steps might be.  I’m still really pleased with this little guy.  And it’s done!

Posted in Little Discharger | Tagged , , , , | Leave a comment

Battery discharger problem with 1 cell

UnderTest2The big battery discharger works well (or so I thought) except for the case of testing single 1.xV cells.  It just doesn’t work – reporting 0V often.  There’s even a comment in the code dated 2/15/11 (right under the V1.3 update comments) that it doesn’t work with 1.5V cells.  The comment was that the A/D returned 0 counts, and that it worked with 2 or more cells, and that I hadn’t looked for the threshold.

I had a bunch of NiMH cells I wanted to test and had forgotten about this problem.  After going thru 3 battery holders, I started to make better observations, and rediscovered this problem.  There are various debug prints commented out in the code, so it looked like it wouldn’t be too hard to figure out what was going on.  (Wrong.)

Setup1664To get a handle on what voltage the problem happened at, I hooked a 2.5K pot across my good bench Li-ion battery for a stable adjustable voltage source.  I put a good DVM across the main discharge leads (clear zipcord, R/B clips).  The discharger code displays the voltage across the main leads while waiting for a CR to start the test.  That should be a good test setup.

With the pot in the middle, the voltage on the DVM bounced all over the place – by several tenths of of volt.  After a bunch of head scratching and other test configurations – including using the (AC) bench scope while powering the Arduino with the 1xAA 5V supply, I’m fairly confident in the following observations:

  • There is a substantial – tenths of a volt or maybe much more – noise signal on the main discharge leads.  I think I saw it as a more or less a symmetrical sawtooth.
  • As I watched the “waiting” output voltage indication and played with the pot, there seemed to be a threshold around 2.1V.  I’d occasionally see values in the range 0<V<2.1, but never stable.  But that 2.1V indication was NOT at a pot slider value of 2.1V!  There’s something VERY wonky about the voltage indications at low values.  A few points: (Actual=pot set with leads disconnected, Reported = leads connected)
Actual V    0.06  0.11  0.65  1.0   1.4   1.5   4.0
Reported V  2.1   2.5   3.5   3.6   3.75  3.75  3.98
  • With the pot set for 1.40V (measured with the discharger leads disconnected), with leads connected, the DVM bounced between 1.41 and 1.82 (watching for a minute or so).
  • Hmm – that’s not consistent with the misbehavior:  With a AA NiMH cell fairly fresh off the charger and measuring 1.38V, when I connected the main leads to it, the reported voltage dropped instantly and consistently to 0.  With the leads floating, they showed ~4.1V.  The source impedance of whatever’s on those main leads is very unclear.
  • Scary question:  Does this mean all the tests I’ve done for the past few years (on higher voltage batteries) have produced inaccurate results?
  • HackedBoard1673For reference, here’s the board as it has been in service for the past couple of years.  From what I can see/reverse engineer, the voltage out of the mux (from whichever input lead) goes thru a 12K/1K voltage divider (0.077 of orig) to Arduino A/D input A0 which is referenced to an external (on the discharger shield) 1.88V zener (sourced from 5V in from the USB/serial connection).  That would give a theoretical max voltage of 24.4V for 1024 A/D counts.  (Reasonable for nominal 18V Nicads, which were the original max target.)
  • Continuing the theory, that would give a formula of (A/D counts) * (24.4/1024=.024) to get actual voltage.  The code has a comment with that as the “expected” value and a #define of 0.0263 as the working calibration constant.  For a 1 V input that would give around 38 counts on the A/D.  Not a lot, but unless the A/D isn’t working well, it shouldn’t give any weird threshold effects.

I’ve spent way more time than I should on what I thought would be a fairly quick fix, and am grudgingly pulling the plug for now.

Next steps

  • NextTest3Put a bench supply on the 1K/12K junction and watch the indicated “waiting” voltage compared to actual.  Yeah, I’m driving one side of the mux with that, but it’s thru 12K.  Hmm – seems to me the specs of the mux chip say no inputs > some V+ voltage.  I think that means I need to put at least as high voltage on the main discharge pins (which go to that V+ on the mux) as I’ll put on the mentioned test point.  (That jives with a vague recollection of strong requirement that the outer ends of a battery MUST be connected before any of the per-cell leads.)  Maybe a red LED to make that V+ about 1.7V higher than the test point?  That ought to do it.  Heck, even a Schottky should do it.  Next step after that depends on what we see with this (if I ever get time to do it).  But at least these notes will help me remember what I saw today.

There was a lot of daydream level consideration given to making up an even more “appliance” discharger, maybe for just one cell, probably with a Tiny85.  By using a 1:1 voltage divider with 1% resistors (maybe 4.7K?) and the internal 2.56V band gap voltage reference and 5V power from the fake FTDI cable, it should handle a fresh 4.2V lithium cell and give good resolution.  I even ordered some IRLB8721 MOSFETs with ~20milliohm RDS(on) for the discharge switch.  (Thanks to Adafruit for choosing that part!)  They’ll handle several amps, so keeping the external load resistor approach, it would handle most everything I’d be likely to throw at it.  If I just had time to build it…

A little later:  Oops – on 328P it’s a 1.1V reference.  Rats.

Posted in Discharge tester - PCB build | Tagged | Leave a comment