Browsed by
Author: john

Electronics technician
This one’s kinda random

This one’s kinda random

What I’m doing — and pics will follow — is building 1R/2R DACs for the arduino mega board, because it has two ports that have all 8 pins available. As a result I can rapidly write to PORTA and PORTC and get a nice fast output, like a really nice quality pair of sinewaves that are 0-5V, quadrature offset, with down to a 200 microsecond period.

That’s pretty cool.

One of the things I noticed is a weird 40uS blip in the otherwise lovely sinewave, and I tracked it down to how I had the program set up.

So quickly:

loop() {
int a; int sinedata[] = {numbers for one quarter of a sinewave};
for (a=0; a<(length of the sine array); a++)
{ PORTA = 128 + sinedata[a]; //128 offsets it as the output is only 0-5V }
(same thing three more times, to reverse-traverse, invert, and rev-invert the sine series)
}

This results in a beautiful sinewave with a 40uS blip.

However:

loop() {
int a; int sinedata[] = {numbers for one quarter of a sinewave};
while(1)
{
for (a=0; a<(length of the sine array); a++)
{ PORTA = 128 + sinedata[a]; //128 offsets it as the output is only 0-5V }
(same thing three more times, to reverse-traverse, invert, and rev-invert the sine series)
}
}

Does NOT have that little blip. What’s the difference? Just that it no longer runs the initialization step. Well, that’s weird. The Mad Scientist Hut.

So then I did what I should have done in the first place and declared sinedata[] as a static int, and that worked great as well. No blips!

What’s the difference? What’s GCC doing differently between the two? Is it reallocating that array assignment every time? Probably yes, but why?

Well, it’s time to go look.

So you go to (in linux) /tmp/arduino[version] and you’ll find a directory that has the hex file. (It has two, one that includes the bootloader and one that’s raw, in case you’re uploading via a hardware programmer. You want the one without the bootloader.)

You can decompile on linux using objdump. However, the objdump that ships with GCC will shrug at you and say it doesn’t recognize the architecture, even though objdump is supposed to do that. Well, now what. I downloaded binutils-avr to get avr-objdump but it still didn’t know the architecture automatically. Apparently Atmel stuff is fussy.

As a result you have to specify to avr-objdump what AVR family you’re trying to decompile.
Wikipedia has a nice list of the ATTiny devices here:
https://en.wikipedia.org/wiki/ATtiny_microcontroller_comparison_chart
But I haven’t yet found a similar list for ATMega cores, which is really irritating.
https://linux.die.net/man/1/avr-gcc
Seems to indicate that any chip of this general architecture with over 64K of flashmem is of the avr5 dataset.

This works, FINALLY.
avr-objdump -d -j .sec1 -m avr5 [hexfilename].hex gets me a disassembled chunk of code and I can go see what the goofball Arduino IDE is telling gcc to do.

Scratch building a replacement LED microscope light

Scratch building a replacement LED microscope light

I got a nifty stereo boom microscope off eBay years ago, and it is revolutionary for doing small work. It shipped with 5x and 10x lenses, and that’s more than enough to clearly see rework on 0201 components, or find and remove tiny glass fiber splinters from my hand.
My only complaint is that a couple months after I got it, the incandescent lightbulb that lights up the object I’m looking at failed, and quite shortly thereafter so did the replacement they sent along with it.
It’s a little weird: an odd sized edison-style screw base, with a roughly 17 volt AC supply. (I think the bulbs are 12V bulbs and that’s why they’re dying fast.)

So I went for a couple of years using a gooseneck lamp as illumination, and that worked fine, but then I need to have that plugged in and cart it around along with the scope if I’m working somewhere else, and bleah.

I decided, well, since my job is testing LED driver chips, I might as well make an LED driver.
In part, I decided this because I found a cut-off snippet of a reel of LED’s, that had two lonesome LED’s in it. These are square, 1.6mm on a side, which, curiously, is the thickness of a standard PCB.
So I can put one on the _edge_ of a bit of copper clad FR4 and if I twist it a little bit with respect to the PCB, I can solder one lead to each face of the FR4. As a result, I use both sides of the PCB as both conductors and heatsinks. For tiny high power LED’s like this, getting the heat out of the LED body is the major determinant of how long they’re going to last.

micro led carrier board with 1.6mm led edge-mounted
micro led carrier board with 1.6mm led edge-mounted

I have a LPKF circuit board plotter at home. It’s glitchy and doesn’t always work well because one of the stepper motors is damaged. But when it does work, it does a lovely job of cutting PCB’s in copper.
I did an initial layout in KiCAD, to provide a bridge rectifier, some ripple caps, and a little constant current asynchronous buck regulator. The regulator I chose, the LM3414, is a bit old, but it handles an amp and is very simple. In addition to needing the typical inductor and diode of a buck regulator, it needs a capacitor for the boost voltage to drive the internal FET, a resistor to set the switch frequency, and a resistor to set the current it’s providing. The only annoying bit is it also needs to have its enable pin tied high, but the enable pin has a max voltage of 5.5V, so I have to derive 5.5V from the 20-ish volts of the rectified transformer voltage.

Here are two layouts, illustrating one of the reasons milling pcb’s can be useful: on one side, exactly what KiCAD says, on the other, redesigned with copper floods around the footprints for the FWBR and inductor. This lets me use the (salvaged from a failed LED bulb) bridge rectifier I have, which is a weird package, and the only 1000uH inductor I could find, neither of which was even close to any of the KiCAD footprints. But with big fat copper pours, I could stick on anything.

raw pcb's, two kinds
raw pcb’s, two kinds

So I populated the FWBR and the caps and figured before I did anything more I’d test it to make sure there was enough cap to handle the ripple. There’s a formula for this, although it’s dependent on the load, and I didn’t know the load precisely.
I also learned that KiCAD 5.0 or newer has ngspice integrated right into it, so I can draw a schematic (if I choose parts from the spice library) and simulate it and see the result, and ensure that the ripple never drops below the amount the chip needs. Which, again, is dependent on load, so I provided enough cap to ensure a less than 200mV ripple into a 1 amp load, because nothing succeeds like excess.

Here’s a screenshot of a FWBR and what ngspice has to say about the ripple voltage. You can see the red trace showing the rectified signal. In the schematic, you can see the spice directives showing the voltage source characteristics, and in blue below that a graphics-text directive to set the transient parameters. Things I learned: you have to know where to put the spice reference ground. If it’s over on vin- you get nonsense results, with no warning, but if it’s on the ground of the load you get the output you wanted. (This may be why vin shows as all positive numbers rather than an ac signal centered at 0V.)

ngspice simulation of full wave bridge rectifier
ngspice simulation of full wave bridge rectifier

And then I tried measuring it at the Mad Scientist Hut and my cheap harbor freight multimeter gave me nonsense numbers, so I put an oscilloscope on it, which is hilarious overkill.

scope_probing
scope_probing

And that showed me that the FWBR output was identical to its input because I’d only soldered down the positive rail on all the capacitors and they were ungrounded. Sooooo I soldered down the ground pads and got a fantastic output with no ripple… into an empty load.

Then I put on the rest of the parts and powered it up and nothing happened, so I measured the output of the 5v linear regulator, and it showed 0V, and I remembered that I got a weird reel of 5v regulators that has an inverted pinout so I was shoving 18VDC into the regulator’s output. Well, phoo. But luckily the logic level input is extremely low current so I flipped the regulator over and stood it up on end, leaving the tab of the SOT223 leaning against the adjacent inductor, and then it worked just fine.

lm3414 buck regulator pcb
lm3414 buck regulator pcb

I trial-wired it to the LED.

testing out wired up pcb
testing out wired up pcb

and turned it on

too bright

and that is waaaaaaaay too much light, and that’s running at like 150mA, which is like a quarter of what the regulator and the LED are rated for.

But that’s okay. It’ll do just fine.

I let it run for a while with a cheap harbor freight non-contact thermometer measuring the led pcb temperature. Those rotten little things aren’t accurate, but I don’t need accuracy: all I need is to make sure it’s not heating up near 125C. It isn’t. Whatever it is doing, the cold-hot temperature rise was less than 5F.

checking the temperature with a cheap noncontact thermometer
checking the temperature with a cheap noncontact thermometer

I 3d printed a neato little adapter to hold the LED pcb colinear in the optics tube. The cylinder is 2 nozzle widths wide, and the fingers that hold the board are 3NW. They’re canted inwards: at the outside edges of the board the gap between them is 1.8mm, but at the center it’s 1.4mm. That way when I press the board in, they spring outwards 0.1mm each way, holding the board very securely.

3d printed colinear pcb mount
3d printed colinear pcb mount

Here’s a closeup of the sketch with the bowtie nature somewhat exaggerated to show what it’s doing. Flexures dramatically simplify 3d fixtures.

flexure based adapter solid model
flexure based adapter solid model

I’ve gotten much more confident about designing items that have flexures built-in so they hold things. PLA creeps over time so this isn’t a great idea if you really need something important to be held solidly. But for little who-cares items like this, it’s a great design technique.

Then I wired the regulator into the transformer (making sure to check continuity to the LED’s cathode through the wiring) and printed a little 2NW slide-on enclosure for the PCB to prevent it shorting against something.

wired in with 3d printed shroud
wired in with 3d printed shroud

So now the board’s soldered into the transformer, driving the original wiring up to the head, and the LED carrier’s soldered into the wiring up there and sitting in its little adapter in the optics mount, and I have a usable microscope again.

Back in service
Back in service
Halloween mask

Halloween mask

This year, kids being eternal little disease carriers, I thought it would be interesting to make a remote candy dispenser. I thought about making it fully automated, but it’s surprisingly difficult to single-select candy, and very easy to make something that jams and ends up dispensing smooshed candy.
So I went with an easier plan: a long PVC tube the right diameter for Snickers bars to slide down. (Not the Snickers Peanut Butter ones. They’re chunkier and didn’t fit. I had to eat those. Aw, phoo.)

The pipe was a piece of 8′ long PVC 1 1/2″ inner diameter tubing that I got from a home improvement store. It worked just fine. Well, more on that later. In testing, it worked just fine.

My intent was a SCARY FACE, so I went to Thingiverse and found one. It’s a Weeping Angel mask, printed in two pieces, which each barely fit on my Prusa Mk3S. They each took about 14 hours to print in PLA, partly because they had so much support structure.

I tried to use meshlab to cut the mouth out before printing, but my old laptop didn’t deal well with a shape that had like 687880435 faces. Soooo I gave up and printed it out as the stock Thingiverse design.

Once that was done, I drilled a hole through the mouth and used a Delta scrollsaw to cut the mouth out.
Here’s something interesting about scrollsaws. If you move really fast, aggressively cutting, they work well. The moment you slow down, the blade heats up, and then you’re still moving the blade through the material but you’re no longer meaningfully cutting. You’re just melting a hole that refills on the back side, so you can go any direction you want regardless of the blade tooth orientation.

What this meant was I’d cut a section of the mouth out, then it’d start melting, and I’d back out a different direction into the central area I’d already cut out, wait a moment for everything to cool, and take another run at it.
This did work eventually. It was a dumb way to do things.

The handrail from the house down to the steps is maybe a 20 degree angle, so I used FreeCAD and modeled an adapter that on one side was a nice cylinder that pressed onto the PVC, and on the other was a square opening just a bit larger than a Snickers bar, and used FreeCAD’s sweep feature to smoothly transition from one shape (round) to the other (square) along a curved path. The result came out really nicely.

Here are two different sizes, when I was briefly trying slightly narrower tubing (in which the Snickers totally jammed.)


(plumeria flower for scale.)

Then I had two halves of the mask and the elbow to attach to each other, and the back side of the mouth was quite uneven, and I needed to attach an electronics package to the back of the mask.

It turns out that you can use a soldering iron and a roll of filament just like a tig welder on PLA. I used my Metcal with a STTC126 tip, a slightly curved tip running at 775F that I strongly prefer for SMT soldering.
I sanded the joint surfaces on the two halves of the mask, put the two halves of the mask together, and quickly ran the soldering iron along the joint on the front. It left a visible line, but not much of one. If I’d spent some time with filler putty, I could have made this go away. On the back I progressed more slowly, while adding in filament, and made quite a thick weld. I attached the adapter the same way: butted it against the back of the mask, made a few spotwelds, then started adding filament.
Like gas and tig welding, you get the material hot and semi-molten, then add the filler, and move along. (I didn’t get a stack-of-dimes weld, though.)

Here’s a picture of the back, with the halves welded together, the adapter welded on, and some LED’s on thermal carriers, which I attached to the mask by simply welding a couple of pieces of filament to the mask back, putting the PCB holes over the filament, then bending the filament over and sticking it to the mask again. It’s a loose fitting, but it’s quite robust, and it’d be easy to tighten up if needed.

For more fun, I stuck a photodiode onto a breakout board we used to sell for AS5040 chips. It soldered in where I used to have an LED for the magnetic alignment indicator, and with some luck, a bias resistor across where the VCC cap used to go gave me a resistive divider using the photodiode, where Vcc, Vss, and the middle node, all were attached to separate but adjacent holes that served for the magnetic indicator interface, so I could solder wires in and have a nice solid proto board.
On the other side I used a spectacularly bright 20mA white LED, forming a nice optical tripwire circuit.
I drilled holes in opposite sides of the PVC just above the adapter and taped them both in, and then when a snickers bar broke the beam, the Arduino received an interrupt and went on to do something.

In this video it drives an LED with a 4% pwm cycle, and when triggered, it ramps up to 100%, then back to 4%, then flashes a couple of times. Here’s a video. I hope it works.

I freely admit I was inspired by a mechatronic display, Enma-Do The Hell God, in the town of Noboribetsu, Hokkaido. It’s super cheesy.

So I also wanted it to go RAAAAAR. And while I did get that to happen, it required a 12V supply to drive the H-bridge that drove the speaker. (I did this by setting up two PWM pins attached to the same Timer, one in inverting mode, so when I set up TCCR3A/B and rapidly shift values to them from a stored array, it drives the speaker quite well.) But that’s an aside, because I didn’t deploy that for lack of having a 12V supply I wanted to leave outside.

One of the above pictures shows the LED’s being triggered by a couple of TIP120 darlington transistors. They worked okay. I ended up using a dedicated two-channel constant current LED driver that could put about 400mA through each LED.

Here it is rigged up with one eye not yet functioning because my wiring was rubbish, but this got me convinced that the project was viable.

Then I did a better wiring job, got both eyes working, and ziptied it to the handrail, and was in business. Candy went in the top, dropped out the mouth, the eyes flashed, kids screamed, it was great.

Except sometimes the candy got stuck halfway down and I don’t actually know why. I ended up putting a ziptie around the bottom of the tube just above the adapter, a second around the railing, and a third connecting them, so it could move but wouldn’t fall down, and then I’d tip candy in the top and if it slid, great, and if it didn’t, I’d lift it up until it did. Sometimes that was a greater than 45 degree angle. I have no idea why they jammed so badly. It wasn’t a result of the holes I drilled for the opto, either: they were jamming about halfway down.

The other problem, as you can see from the picture, is that the LED’s were vastly, vastly too bright. You could hardly see the mask. Kids didn’t see where the mouth was.
These are old Cree XPEW LED’s and even at the minimum PWM (like 0.3% duty cycle) they were still too bright.
I needed some regular indicator LED’s sold as ultrabright, 40mA LED’s, not these giant monsters.

If I do this again, I’ll put in a boost circuit so I can drive the 12V sound system from a USB-type battery, and maybe figure out if it’s possible to add a vacuum assist to accelerate the candy down (without shooting it out the end like a full vacuum cannon), plus less aggro LED’s.

But it did look pretty great from the side with some auxiliary lighting to pick out the face details.

sheet metal pressing with 3d printed dies

sheet metal pressing with 3d printed dies

When I was taking metalsmithing classes, one of the forming techniques we learned for forming sheet was clamped sinking: you bolt just inside the edges of a metal sheet and hold it in a clamped plywood form with a recess in the middle that has the outline you want. I think the critical part of this lesson was that you then form the metal by hammering it down into the void in a spiral pattern, going around the outside, then working your way inwards. This way you distribute the stretch over the whole area.
A friend is trying to press-form battery springs in very thin aluminum flashing with 3d printed dies, and his dies kept punching through the aluminum. I was thinking about how deeply we could sink metals by careful stretching, so I thought I’d try it in a progressive set of printed dies.
I made five dies, printed in PLA with 70% infill. Each die has a base that is 25x25mm, 6mm thick. The female die has a conic recess with a 30 degree slope, 10mm in diameter. The male dies have a series of frustra of increasing height, terminating in a conic section. The male dies have a base diameter of 7.8mm, because the difference between that and the female die is the thickness of the metal I’m trying to dimple.

Blacksmiths use a tool called a spring fuller. It has two arms that join with a sprung pivot on one end, and in the other end, hold whatever it is you’re hammering into your work: cold chisel or fuller grooving die. Similarly, aircraft mechanics use the same general setup if they need to single-handedly put rivets in really difficult to reach places, where they need a massy anvil held in the right place behind the finished head but can’t see where they’re working, or they need to match-drill a hole to a hole beneath the top layer.
I designed my first 3d printed fuller anvil tool to peen the heads of copper rivets going through a carbon fiber structure, where I didn’t dare crush the carbon fiber, and it worked so well it seemed like the right tool for the job here.
So I printed a spring fuller 30mm wide, that the anvil dies press into, female on one side, male on the other, and then I can stick them in the vise and smoosh them closed and know they’ll start off aligned. (They do self-align as they’re tapered, but when you’re sinking the second and third you really want them correctly aligned to start or they’ll stretch the metal unevenly before aligning.)

Each frustrum is 1mm higher than the previous ones.
Start with #1.

Then punch in #2

and #3

and finally the pointy #4

For pressing, I cut some steel pieces that sit on the vise jaws to distribute the pressure evenly across the back of the dies.

Here are a couple of pictures of all the dies and the resulting workpiece after punching.

The metal is 3003 aluminum 1.3mm thick. That’s 16 gauge. 3003 is quite soft (which is why I chose it.) My intent for this is forming small replacement patch panels for old race car bodies, and 1.3mm is significantly thicker than common aluminum body panels.
I punched about 10 of these, and only the final, sharp-tipped, die showed any measurable damage. The others looked like they were right off the 3d printer plate, and measured the same dimension to within 0.05mm around their circumference.

The Mad Scientist Hut finished product has some lines on the sides of the cone from the previous draw cycles. Probably the best plan for making this specific shape would be to do the first three punches slightly undersize and the last punch would have a slightly larger female and male die to stretch the whole surface just a tiny bit.
But it looks to me like small batch production of stamped aluminum using 3d printed dies is entirely feasible.

Next day, adding in: 20mm hemispheres pressed in 4 steps. This did require annealing after the first two punches; otherwise, the leading edge of the punch would stretch the aluminum enough to make it fail in tension. This says to me that I need to learn more about punch design: I think right now I’m stretching the metal in five shallow bands separated by thicker sections. These dies were made with a rounded lip to distribute the stretch more evenly, and maybe that needs to have a larger radius.

I’m ridiculously pleased with this. This is a good start on pressing a small fuel tank or a brooch from thin gold.
Next up: form a thin shell structure, then stamp between two complex dies to get re-entrant complex curvature.

Next update: I didn’t get to making the re-entrant shape yet. Instead I moved to steel.
Here are two shots of a 12mm deep stamping in un-annealed, right off the Lowe’s rack, galvanized steel sheet.

From the top you can see there are no folds or wrinkles going up into the stamped part. I think it’s interesting that the Z layers print all the way through the steel, showing up on both sides, so using PrusaSlicer’s variable layer height option is probably a good idea for the top of the final die.
Here it is, cut out.

The female die for this has now gone through more than 40 stamp cycles and is still in fine shape. All the dies now have marks on their flat outer surfaces from the metal folding and concentrating stress, but the action parts of the dies are still in great shape.

What I need to do is figure out a way to clamp the outside flat first, then press the stamp die through: make the male die a two-part with an outer and inner sections. The drawback to this is it’s no longer an easy stamp in the vise setup, so I’m still thinking about this.