The Smell of Molten Projects in the Morning

Ed Nisley's Blog: Shop notes, electronics, firmware, machinery, 3D printing, laser cuttery, and curiosities. Contents: 100% human thinking, 0% AI slop.

Category: Electronics Workbench

Electrical & Electronic gadgets

  • Defective PCB-mount Switches

    Defective PCB Option Switches
    Defective PCB Option Switches

    This type of switch is a nice alternative to the ordinary pin-header option jumpers: pull the white plunger up to open the switch, push it down to close. Nothing to lose or (worse) drop into the machinery.

    Being that sort of bear, I test most components, particularly surface-mount parts, before soldering them onto the board. Switches, however… well, what could go wrong?

    Unfortunately, both of these switches were defective.

    The gutted switch at the top of the pictures stuck open after I soldered it in place: pushing the plunger down didn’t do anything at all. Leaning rather hard on it didn’t get its attention, so I unsoldered and tore it apart. The parts looked OK: no obvious corrosion or deformity.

    I tested the second switch, found it worked perfectly, and soldered it in place, whereupon it failed just like the first: stuck open.

    Perhaps the soldering iron’s heat (immeasurably) reshaped the plastic or (invisibly) oxidized the contact point? Maybe the design is close enough to not working that installing it pushes the tolerances over the edge? I’ll never know.

    These were surplus parts, so there’s no recourse, but I’m pretty sure they’d misbehave the same way if I’d paid full retail for them. If you see any inside your widgets, this may be why you can’t select an option… or why the widget suddenly enters a mysterious new mode.

    I tossed the rest of my supply in the trash.

  • Diode Parameter Extraction & Plotting

    After blowing up a MAX4372 high-side current amp, I thought a Schottky diode would do the trick as a voltage limiter for the delicate current-sensing inputs. The comments to that posting showed I might be close, but that I hadn’t figured it right.

    The first step is finding out how the diode behaves.

    Clip a multimeter (set to the 2 V range) across the diode, clip another multimeter (set to maybe 200 mA in series with the diode, then connect a bench power supply through a 100 kΩ (more or less) resistor to limit the diode current across everything.

    Twiddle the power supply knob, record voltage and current pairs, type them into a spreadsheet (say, OpenOffice, but Excel is probably similar). That gives you a table & plot that looks like this:

    1N5819 Schottky diode current vs. forward bias
    1N5819 Schottky diode – current vs. forward bias
    mV uA
    20.1 0.4
    40.1 1.4
    60.0 3.5
    80.6 8.2
    100.2 18.0
    125.4 48.9
    150.5 131.3
    175.0 343.0
    183.8 481.0

    Nothing surprising there: the current has an exponential relation to the forward voltage.

    An exponential relation cries out for a semilog plot, so add a third column figuring the natural log (a.ka. ln or log-to-the-base-e) of the current values in the second column. The equation is just

    =LN(B3)

    copied down the column as needed.

    1N5819 Schottky diode - ln(current) vs fwd bias
    1N5819 Schottky diode – ln(current) vs forward bias

    That gives you another table & plot, thusly:

    mV uA ln(current)
    20.1 0.4 -0.92
    40.1 1.4 0.34
    60.0 3.5 1.25
    80.6 8.2 2.10
    100.2 18.0 2.89
    125.4 48.9 3.89
    150.5 131.3 4.88
    175.0 343.0 5.84
    183.8 481.0 6.18

    The trick is to add a regression line to the data, which you do by selecting the data series, other-clicking, selecting “Add Regression Line”, selecting the regression line, other-clicking, selecting “Show Equation”, then futzing around until the equation shows enough decimal places. Also extend the X & Y axes so you can see the Y-axis intercept on the left and the current at the MAX4273’s Absolute Max rating of 300 mV on the right.

    I threw out the first measurement point, as it didn’t quite fit the rest of the data. My measurement accuracy isn’t all that great below a microamp, sooo that seemed justified. Check the raw data and see for yourself.

    The regression equation is, comfortingly, ln(current) = 0.040 * voltage – 1.187.

    The slope of 0.040 = kT/q, which says the temperature of my basement laboratory is 464 K, a tad warmer than the actual 286 K. Feeding the actual temperature in, the slope should be 0.046.

    What that really means is that the ideality factor n = 1.62. We usually forget about that little Fudge Factor, but here it is in action: 0.040 = nkT/q.

    The Y-axis intercept is -1.187, which means:

    saturation current = exp(-1.187) = 0.3 uA = 300 nA.

    Not a number you’ll get from the datasheet, of course.

    For more on all that, consult the Wikipedia diode entry.

    It’s worth mentioning that the slope depends linearly on the temperature. The exponent causes the far end of that nice line to whip the current around something nasty.

    Anyhow, with numbers in hand, it’s back to the schematic… and a bit of SPICE simulation that uses a canned diode model.

  • MAX4372 Sense Input Protection

    My initial thought was to stick a Schottky diode across the sense terminal inputs, but John Kasunich suggested that requires a much heftier diode and might not work anyway. He suggested sampling the current-sense voltage through high-value resistors, which will certainly affect the linearity & calibration of the sense voltage.

    My sissy circuit has a peak fault current of maybe a few amps, which the diode should shrug off if I’m not stupid about it. But I like the resistor notion, as it dramatically reduces the diode current.

    MAX4372 Sense Input Protection
    MAX4372 Sense Input Protection

    Maxim has a useful Application Note (AN-3888) describing the effect of common-mode filters on the amp’s calibration. A key suggestion: the two resistors should differ by a factor of two to match the input bias currents.

    So here’s one approach that might work.

    The schematic is a screen snapshot from Linear Technology’s LTSpice IV. The two current sources on the left model the MAX4372 sense amp inputs, with their max bias current values. R1 is the current-sense resistor: a whopping 0.5 ohm for my low-current application.

    R2 and R3 isolate the diode from the sense resistor. High values introduce more error due to diode current, while also helping to protect the sense inputs from excessive voltage. Low values reduce those errors, while bypassing more load current through the diode. Ya can’t win.

    Running the simulated load current up to 5 A shows that the diode clamps the input voltage to about 330 mV, which is likely good enough. Higher values for R2 and R3 reduce that; 10 and 5 ohms might suffice. The factor-of-two difference is really only important at very low currents for these very low resistors; at higher currents, the diode is all that matters.

    MAX4372 Simulation Results
    MAX4372 Simulation Results

    What’s of more interest is the error induced by those resistors in normal operation. Here’s a screen snapshot of simulation up to a load current of 500 mA, well above my expected max of 300 mA. Pay attention to the middle trace in each group of three, which shows the results at 30 °C (the others are 20 and 40 °C).

    The red traces angling down from the upper left represent the ratio of the diode voltage to the sense resistor voltage It starts a bit over 0.99 and gets down to 0.92 by 300 mA. So, basically this protection network introduces less than 10% error if you ignore temperature effects.

    The board I’m building has a calibrated current sink, so (if I were doing this for a real project), I’d be sorely tempted to just build a lookup table on the fly. Then I could work backwards from the desired current setpoints to the PWM voltage outputs required to generate those values. But that’s a simple matter of software, right?

    If you care a lot about accuracy, you’ll obviously want to measure the board temperature and tweak the table accordingly.

    If you want to see how an actual diode behaves, you can measure it.

  • Arduino Command Line Programming: Avrdude Puzzlement

    For all the usual reasons, I’d like to compile & download Arduino programs from the command line, rather than through the (excellent!) IDE. That is supposed to work and, for most folks, apparently it does.

    Not here, alas.

    I’ve installed the 0012 Arduino Java IDE (x86 or x86_64 as appropriate) from http://code.google.com/p/arduino/ on three different systems, all with Kubuntu 8.04:

    • Dell Dimension 9150 – x86_64, which seemed like a good idea at the time
    • Dell Inspiron E1405
    • Dell Inspiron 8100

    In all cases the IDE works perfectly, compiles & downloads programs just fine, and behaves exactly as you’d expect. I had a few minor quibbles with sorting out various paths & suchlike, but, on the whole, it has no troubles at all with either a Diecimila or a Sparkfun Arduino Pro (with a Sparkfun FTDI Basic USB gizmo).

    I tweaked ~/.arduino/preferences.txt to include:

    console.auto_clear=false
    build.verbose=true
    upload.verbose=true

    Here’s the final step in the IDE compile-and-download dance. Backslashes indicate continuations of the same line; the original is all on single line:

    hardware/tools/avrdude -Chardware/tools/avrdude.conf -v -v -v -v -pm168
    -cstk500v1 -P/dev/ttyUSB0 -b19200 -D
    -Uflash:w:/mnt/bulkdata/Above the Ground Plane/
    2009-06 Solar Data Logger/Firmware/Logger/applet/Logger.hex:i 
    
    avrdude: Version 5.4-arduino, compiled on Oct 22 2007 at 13:15:12
             Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
    
             System wide configuration file is "hardware/tools/avrdude.conf"
             User configuration file is "/home/ed/.avrduderc"
             User configuration file does not exist or is not a regular file, skipping
    
             Using Port            : /dev/ttyUSB0
             Using Programmer      : stk500v1
             Overriding Baud Rate  : 19200
    avrdude: Send: 0 [30]   [20]
    avrdude: Send: 0 [30]   [20]
    avrdude: Send: 0 [30]   [20]
    avrdude: Recv: . [14]
    avrdude: Recv: . [10]
             AVR Part              : ATMEGA168

    The IDE evidently does the reset-from-USB trick through the standard USB hardware.

    I set up the command-line Makefile from http://www.arduino.cc/en/Hacking/CommandLine, although that’s for the 0011 IDE, then made the recommended tweaks. The make section does exactly what you’d expect: compiles the source program.

    Running make upload fails every time, on every PC, with both boards. Indeed, in all cases, running avrdude on the command line produces the dreaded “not in sync” errors, showing that it’s unable to communicate with the Arduino board. Blipping the reset button on the Arduino board generally makes the USB transfer work fine, with the failures most likely due to my lack of dexterity & timing precision.

    The usual debugging suggestions aren’t relevant, as they all assume there’s a basic communication failure caused by anything from a completely dead board to mysterious library incompatibilities. In this case, however, I have an existence theorem: the IDE works perfectly before and after the command-line failure.

    It turns out that the IDE includes a specially patched avrdude, so I tried running that version from the directory where the IDE lives, using exactly the same command-line flags as the IDE does. Surprisingly, that doesn’t work. Again, backslashes indicate continuations of the same line and I added quotes to the file name to protect the blanks…

    hardware/tools/avrdude -Chardware/tools/avrdude.conf -v -v -v -v -pm168
    -cstk500v1 -P/dev/ttyUSB0 -b19200 -D
    -Uflash:w:"/mnt/bulkdata/Above the Ground Plane/
    2009-06 Solar Data Logger/Firmware/Logger/applet/Logger.hex":i
    
    avrdude: Version 5.4-arduino, compiled on Oct 22 2007 at 13:15:12
             Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
    
             System wide configuration file is "hardware/tools/avrdude.conf"
             User configuration file is "/home/ed/.avrduderc"
             User configuration file does not exist or is not a regular file, skipping
    
             Using Port            : /dev/ttyUSB0
             Using Programmer      : stk500v1
             Overriding Baud Rate  : 19200
    avrdude: Send: 0 [30]   [20]
    avrdude: Send: 0 [30]   [20]
    avrdude: Send: 0 [30]   [20]
    avrdude: Recv: . [1e]
    avrdude: stk500_getsync(): not in sync: resp=0x1e
    avrdude: Send: Q [51]   [20]
    avrdude: Recv: . [0f]
    avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x0f

    There’s no difference between the /opt/arduino/lib/librxtxSerial.so and /usr/lib/librxtxSerial.so libraries, which normally causes some confusion on x86_64 systems. I think that means the x86_64 version of the IDE has the correct library.

    I’ve also tried the stock Kubuntu avrdude, which is at V 5.5, to no avail.

    Given that the IDE works, that I’m running the same avrdude executable, and that the libraries match, I’m not sure where to go from here.

    While I’m generally dexterous enough to run make upload and blip the Arduino board’s reset button with my other hand, I’m bringing up a shield-like board that plugs atop the Arduino and, alas, lacks both a reset button and a hole over the Arduino’s button.

    The board is, of course, that one.

    Update: As a reasonable workaround, I’ve set the IDE up to use an external editor. Then I can tweak the programming, flip to the IDE, click the Download button, and away it goes. Not quite as easy as a full command-line solution, but close enough.

  • MAX4372 High-side Current Amp Gotcha

    MAX4372 output and boost transistor base drive
    MAX4372 output and boost transistor base drive

    Maxim’s MAX4372 is a high-side current sense amp that simplifies DC-DC converters, battery chargers / monitors, and stuff like that. It’s a nice gadget because it has a 28-V common-mode voltage rating that’s independent of the supply voltage. That means you can monitor the current from a relatively high voltage source with a low-resistance in series with the supply’s positive lead.

    I’m using it as part of a solar panel characterization circuit for a Circuit Cellar column, where it’s a key part of a simple DC-DC boost converter that will illustrate how maximum power point tracking works.

    The current sense resistor is a 0.5 Ω (that’s a capital Omega, if your browser just burped) resistor that produces 150 mV from the maximum 300 mA I’ll be drawing from the small panels in my collection. That’s the maximum rated full-scale sense voltage in the datasheet.

    The scope shot shows that it works like a champ, with the DC-DC converter’s transistor base drive toggling at the 100 and 200 mA setpoints. There’s a touch of deliberate hysteresis in the comparators, hence the overshoot.

    The datasheet has one Absolute Maximum Rating value that I’d managed to overlook:

    Differential Input Voltage (VRS+ - VRS-) ... ±0.3V

    What that means is that you must not, under any circumstances, apply more than 300 mV across the sense resistor. That translates into 600 mA for my circuit, which seems unlikely.

    I was bringing the board up with a bench power supply set to 4 V and connected through an 8-Ω resistor to simulate a solar panel’s declining voltage-vs-current characteristic, with the supply set to a 300 mA current limit. Worked fine until I managed to connect the power supply without the resistor, at which point the MAX4372 stopped working.

    What most likely happened was that the booster drive transistor stayed on a mite too long while the microcontroller was rebooting, which drove the inductor into saturation and put the supply directly across the sense resistor: 4 V / 0.5 Ω = 8 A, if the supply was up to it (which it isn’t). Not for very long, mind you, just long enough to kill the MAX4372 stone cold dead.

    The best solution, which doesn’t appear anywhere in the datasheet or the app notes, seems to be a Schottky diode across the sense resistor. When the sense voltage exceeds the more-or-less 300 mV diode forward threshold, it’s clamped to a (presumably) safe value.

    I haven’t tested this yet, but I don’t see any other way to prevent toasting the MAX4372 during the inevitable brief circuit glitches and faults. Even in an operational circuit, you might well see a brief short-to-ground that would apply the full supply voltage across the sense resistor: poof!

    Oh, yeah, if you’ve just blown your two samples, Maxim nails you with a $15 shipping charge (!) to order more. I picked up ten through DigiKey for 60% more per piece, but just $4 in USPS postage.

    I wanted to get some MAX4322 high-current op amps, but they’re non-stock items. Fooey!

    Memo to self: Use the diode, Ed!

    Update: see the comments for a better idea. More details later.

  • Circuit Board Grounding Point

    Instrument grounding point
    Instrument grounding point

    When you’re bringing up a new circuit board, you need a place to attach test equipment ground clips.

    Take a resistor lead from that pile you’ve been collecting (you do save snipped-off through-hole component leads, don’t you?), bend it into a sort of flattened horseshoe with the ends pointing out, and firmly solder the ends to a convenient point on the board’s ground plane, ideally near the power entry point.

    It helps if you leave a nice spot for the thing; tiny boards with all surface-mount parts pose a problem.

    Long dangly ground leads clipped to a distant part of the board are definitely not adequate for low-level or high-frequency analog probing, but when you’re just trying to figure out if the mumble thing is alive, this hack will do the trick.

    Oscilloscope probe tip ground
    Oscilloscope probe tip ground

    For detailed stuff, get up close & personal with that odd little scope probe nosepiece you’ve been keeping in a bag for some reason.

    The top board is, of course, the one you’ve seen earlier.

  • Making PCBs: Etching and Plating

    PCB Etched and Plated - Front
    PCB Etched and Plated – Front

    Continuing the saga from there, this is the etched and plated board.

    I mask around the edges with ordinary masking tape and cover the back surface with duct tape. Basically, the less copper you remove, the better and faster the job.

    I use ferric chloride etchant, formerly available in nearby Radio Shack stores. These days it’s getting harder to find, so I picked up a few kilos of dry powder on eBay. Most likely that supply will vanish, too.

    The usual directions call for heating the etchant, submerging the board, bubbling or agitating, and so forth and so on. The folks at Pulsar suggest simply rubbing the etchant on the board with a sponge and, perhaps not surprisingly, that works perfectly with boards sealed using their green film.

    I hold the board horizontally in my left hand, pour a dollop of etchant on it, then rub it with a small sponge in my right hand. The etchant gradually turns into a gel as it removes copper from the board; when the gel becomes too stiff, I just wipe it off with the sponge.

    I do this over a small glass tray and scrape the accumulated gunk off the sponge into the tray. Pulsar recommends diluting the residue in a gallon of water, but I’d just as soon not have that much spent solution sitting around.

    PCB Etched and Plated - Rear
    PCB Etched and Plated – Rear

    Wear latex gloves, an apron, and eye protection. Expect that everything within a radius of two meters will accrue small spots of ferric chloride that will instantly produce a vivid, permanent yellow stain. Repeat: everything within two meters will sprout yellow spots.

    You have been warned!

    Even if you pay attention to the board’s edges and corners, those will still be the last areas to finish etching. You’ll also learn to not run fine lines parallel to the edges right next to the masking tape, as the tape protects adjacent areas from the sponge: no contact, no etching!

    Spent ferric chloride (most likely, it’s now copper chloride or some such) disposal occurs on our town’s Household Hazmat collection days, but direct etching leaves very little bulk waste. Although it’s not particularly hazardous, the rituals should be observed.

    After eching, rinse the board, remove all the tape, and rinse the board again.

    Acetone and paper towels remove the green sealant film and the laser toner from the board, an operation best done outdoors. I have yet to find protective gloves that don’t disintegrate in acetone, so I simply try to not soak my hands in the stuff. Remember: leave the mask on the back side of the board to help protect it from the etchant when you do the front side.

    Then I silver-plate the copper with Cool-Amp Silver Plating Powder, which makes the board look and solder better. Looks are important, as the boards sometimes wind up in my Circuit Cellar columns.

    That hasn’t stopped me from hand-soldering SMD parts: the bigger the blob, the better the job.