Archive for Projects

I don’t lamp well

 

That was a long “next month”. A recap is in order. This post chronicles the long descent into complete and utter apathy.

 

In September 2014, I made some sketches for a lamp I wanted to build. The intent was to use the glass plate from a desktop scanner as the light diffuser, and laser etch a fractal pattern onto it to create a frosted effect, instead of being optically clear.

Here is a test piece I did, with a laser cutter and an image found off the internet.

 

 

The results were pretty fantastic. Fine details get lost, because it looks like the mode of operation is the laser heating up enough of the glass to chip off a small chunk before moving on. And so on, for the entire image. It creates great looking, even optical diffusion, though.

 

For another test, I decided to design and build a similar, but smaller lamp. Glass scanner beds are a limited supply. Using a glass tile I found at a craft store, I designed an arm to hold it onto a wall, a few centimetres away from a PCB containing some high power LEDs.

 

 

The initial model and 3D print is shown on my previous post.

Here is the final version, with some corrected measurements and better mounting point.

Lamp print

 

And the PCB arrived shortly after the last post.

 

Lamp PCB

Oops!

That’s mistake number one. Everything was intended to be clean and white, but I guess I forgot to change the soldermask from the default DirtyPCBs red. It’s not the end of the world. This is a prototype of a prototype, after all.

 

The first board was populated, and then the lamp languished for a year and a half.

 

 

Recently, I found it buried in a locker and tried plugging it in for the first time. With no prior consultation to documentation, I tried it on a bench power supply, starting at 5v. Nothing happened, so I turned it up to 10. At 15v, the semiconductor on the board released some smoke and glowed red for a few minutes.

Nope!

 

Back to the docs, I read that I had used an adjustable 5v boost converter, so that solved that.

I soldered up another board (I had two spares of the IC), including the DC barrel jack this time, and plugged it in again. Turns out I had the wrong polarity!

No smoke, but some troubleshooting proved that I had definitely fried the chip.

 

This was pretty much the limit of how much I cared, so I did what anyone would do:

I jumped over the active parts of the circuit with a power resistor, and ran the LEDs directly from a 19v laptop power supply.

 

 

Job done!

Next time I’ll build in some more safety factor.

Additionally, looking at the lamp from the side is really really bright because of the bare 1W LEDs. I kinda planned for this and put some slots in the side of the base for some acrylic sheets, but I’m quite done with this design.

Snap-on Desktop Widgets

And now, for my next trick, I’m going to manufacture a million tiny monitor widgets to snap onto your big monitors to monitor your widgets.

 

Still with me?

 

This is a project with many parts, but I will only get in to one phase on this log.

 

I’m hooking up an ESP8266 WiFi module to an inexpensive TFT LCD. The idea is to have an internet-connected, smaller-than-credit-card sized screen that displays one thing, and one thing only.

Some use-cases could be the two-day weather forecast, a slideshow picture-frame, or a graph of the current price of Bitcoin. Things that don’t require more than a couple changes per second, and don’t warrant using up real estate on a main monitor when work needs to get done.

The system design is actually really simple. A mini-USB connector is feeding power to a 3.3v linear regulator, and data to a USB-UART bridge. The bridge is able to program the ESP8266 via USB to a host computer, but that is not required for general operation. A standard cellphone charger plugged into the USB connector for power is fine. The WiFi module connects to an Access Point periodically and grabs a static image from a website.

This image is then fed to the LCD. That’s it. That’s all it does. I’ve gotten the BoM cost down to around $8 each, so it’s reasonable to have a lot of them on a desk, displaying various bits of data.

 

The hardware files, including Gerbers, of revision 1 are here. There are also folders for the firmware, software, and test rig, but as of the time of writing, that is all very much a work in progress.

That link will soon be outdated, but I’ll tag the first revision as a “Release” in GitHub when I’ve got the different parts working.

As for next steps:

The LCD I’ve chosen is one of the cheapest ones I’ve found. It has a parallel data bus for communication, and I’ve used a 74HC595 serial-parallel chip to make it work with the ESP8266 module’s limited IO. I’m using an ESP-12E for reference, but trying to make it work with the original ESP-12 as a bonus.

Schematic

I think I can do some interesting things by replacing both the SIPO and the USB-UART bridge with a microcontroller. Things involving bootloaders, and things involving cross-monitor communication. Cool stuff.

Hysterical

After building my Piccolo and playing around, I really don’t like the software. It’s certainly simple and hackable and does a lot of what I need to do, but something about the Arduino/Processing pair don’t quite work for me.

Fortunately it’s just a bunch of servo motors, and I already have the PIC code in my toolbox.

Using my Arduino-form-factor PIC dev board and my Bus Pirate as a computer-UART bridge, I wrote in a simple protocol to communicate.

The “communication enable” pin will go high, and then two (might change to three) bytes get sent. The first is an “address” or command, and the second (or second two) bytes are a value/argument.

The 0 address is X axis, 1 is Y, and 2 is Z. The Z only uses binary 1 and 0 for arguments.

The z axi has two states: active and inactive. Inactive/up is the parked position, obviously. The active mode has a hysteresis loop attempting to control the position. The feedback is wired up to a window comparator, like so:

On the computer side, I’m controlling the Bus Pirate with a Python script that feeds it one scalar for a given axis at a time.

The speed at which the PIC executes the movement is controlled in the processor, to be tweaked. I will probably add that command in, when it becomes cumbersome.

As more commands become necessary, I’ll be adding more to the processor, I guess. Maybe eventually I’ll implement a rudimentary G-Code.

 

Now for the fun part:

 

Part of my original design goal was to have a 10ns response time. That’s very fast. Most of the old monolithic MOSFETs I’m using (because they’re cheap) have turn-on times in the tens of microseconds.

That totally blows my requirements out of the window, but there are still some optimizations to be made. By using analog circuitry, I can directly control certain parameters and speed them up, compared to hitting a microcontroller and being a slave to a clock source and interrupts getting in the way.

I’ve designed a window comparator. It looks like this:

Window Comparator

If the input goes above the “HIGH” voltage, then the top output turns on. If it goes below the “LOW” level, then the bottom output turns on. There will be two of these circuits. Feeding these outputs to some discrete logic, or something clever that I haven’t thought of yet, I can turn on or off transistors to the different power stages.

EDM Schematic V2

There are three power stages: Stage 1 (rectified input), stage 2(charge), and stage 3 (output).

 

The S2 MOSFETS can be ignored, just treat them as one. I should be able to parallel as many as I need, within reason, it doesn’t change (most of) the math.

 

The input of one window comparator is from VOUT, and the outputs are hooked up to the micro. If the HIGH output is on, then that means the MOSFET Q2 is on, but the EDM electrode has not made contact with the workpiece. Start (or continue) jogging the Z axis down.

If the LOW output is active, then we’ve gone down too low, start jogging up.

The other comparator’s input is at S2VCC. That controls the turn-on and turn-offs of the MOSFETS. If C3 is too low, then Q2 must be shut off and Q1 turned on to charge it up. When it is high, flip that. The idea is that Q1 and Q2 should never be on at the same time, providing a direct path to ground. The logic here will also involve halting the Z jogging, or making it jog up.

 

So there you go. With two different kinds of hysteresis going on at once, there will be some experimentation going on with how they work together. That leads me to one last trick:

You see the HIGH and LOW inputs on the comparator circuit? Those must be an analog voltage. That I’m going to set with a PWM out on the micro and the caps smoothing it out to an analog value. Varying the duty cycle of the PWM will allow me to vary the analog voltage.

 

Counting up my PWM outputs:

Two for each window comparator (4 total)

One for each axis (7 total)

One for the oil pump (8 total)

 

I haven’t discussed that last one yet, but stay tuned!

 

CNC Day

Aw yeah, CNC day.

CNCed Tank

Pretty simple parts, I guess it wasn’t strictly necessary to use a CNC, but hey, it was there.

 

Here it is coming together.

Tank Test Fit

 

A spaceship!

CNC Spaceship

 

~~~~

Brief interlude

~~~~~~

 

 

Laser cut Piccolo parts.

 

Piccolo Assembly

 

And the rest of it.

Piccolo Assembled

Rough-ish final box.

Small EDM Tank

And it flips up!

EDM Tank Up

 

So the next step is to figure out a way to mount the Piccolo on top of the box as shown. There’s a little bit of MDF I need to cut away to make it fit better, too.

 

After that, I need to modify the Arduino sketch (ugh) to jog the Z-axis up and down to keep the electrode in the conductive region.

WPA2 HMAC SHA1 PMK FPGA VHDL

Hell yeah, acronyms.

Restartin’ dis.

I’ve got the old working SHA1 encryption algorithm going. It’s up on GitHub, here. I was waffling between parallel and serial loads and outputs. SHA1 takes a 512 bit input and outputs 160 bits, and no FPGA that I have access to will have that many pins.

Here’s a fallacy I got stuck on for a while:

If I use completely parallel I/O, it’s faster. Therefore, I should try to use as much parallel communication as possible to maximise speeds.

 

The truth is, though, that most modern high-speed circuits use serial data. When you’re clocking at very high frequencies, propagation errors become very difficult to mitigate. With many data lines, you have no way of knowing when exactly data arrives at the lines. It’s better, easier, more reliable to just send one bit at a time and pump them through really fast. That’s a core principle of pipelining; you don’t even need to wait for a signal to reach its destination before you’re sending the next one.

 

With this project, I don’t think I can go faster than 100MHz with the FPGAs I have. That’s right on the edge of where efficient pipelining starts to matter, so I’ll be experimenting with a mix of serial and parallel interfaces to see how far I can stretch it.

 

Right now at this moment, though, I want to get the computationally-intensive parts of the WPA2 protocol offloaded to the FPGA. I won’t worry about speed juuust yet.

 

 

Here’s how WPA2 works, from a security analysis perspective:

 

 

Some definitions

 

  • Access Point (AP) – Usually the router, in these systems
  • SSID – AP name. This is the router name that you connect to
  • Master Key (MK) – AP password. This is the key we ultimately want to find
  • Pairwise Master Key (PMK) – This is the cryptographically hard part of the whole transaction. It’s derived from the MK and SSID
  • Pairwise Transient Key (PTK) – The cleartext portion of the authentication to verify the correct PMK
  • PBKDF2 (wiki, RFC) – Password-Based Key Derivation Function 2 – A cryptographic function, used like PBKDF2(PRF, Password, Salt, c, dkLen) where PRF is any given hash function, c is the quantity of iterations, and dkLen is the output length
  • HMAC (RFC) – Hash-based message authentication code – Intermediate function applied to the SHA1 hash
  • SHA1 (RFC) – Standard hashing function. Uses a one-way algorithm to generate non-reversible output

 

The AP has the password, from which it can derive the Pairwise Master Key (PMK). To verify that both sides of the transaction have this, a PTK is generated using the PMK and nonces (randomly generated, one-time-use numbers).

This PTK is transmitted over cleartext, and is part of the 4-way handshake.

 

So, in short, if you combine the proper PMK with the proper PTK, the whole conversation breaks wide open and you can associate with the AP.

If you’re watching the WPA traffic, then you can easily capture the 4-way handshake and therefore the PTK.

 

That means that, for my purposes anyway, the PMK is the important unknown variable, and the computationally hard part. Here‘s how you calculate it, from top to bottom:

PBKDF2:

x1 = HMAC_SHA1(MK, SSID + "1");
x2 = HMAC_SHA1(MK, SSID + "2");
f1 = x1
f2 = x2
for(i = 1; i < 4096; i++) {
    x1 = HMAC_SHA1(MK, x1);
    x2 = HMAC_SHA1(MK, x2);
    f1 ^= x1
    f2 ^= x2
}
return f1 + f2;

 

HMAC:

This is more complicated. Given HMAC(secret, value)

  •  Initialise two 64-byte variables, Bi and Bo with secret, padded with zeros on the end
  • XOR each of byte of Bi with 0x36, and XOR each of byte of Bo with 0x5C
  • Append value to Bi
  • Append SHA1(Bi) (in Ascii!) to Bo
  • Return SHA1(Bo)

In short:

HMAC_SHA1(s, v) = SHA1((s ⊕ 0x5c)||SHA1((s ⊕ 0x36)||v))

 

And finally, with the SHA1 function, I have covered it in previous posts. This portion is already done.

Imbles of Gimbals

I got handed a box of old gimbals from a movie set! I love gimbals!

 

Most of them are very slightly broken in very repairable ways.

 

I left, like, 5 for other people to fight over, and grabbed two for myself. One of them was in great shape, the other had some loose set screws and was missing an encoder. Fortunately the bin had some spare encoders!

 

Anyway. I stashed the good one, and focused on the brokenish one. Fixed it up, and started wiring up some drivers.

 

Here’s what the gimbals are like:

On the horizontal axis, there’s a DC motor with a gear meshing with the base. On the other side of the base gear, there’s another one connected to an optical encoder. There is also a photo-interrupter at one point along the rotation for calibration, I guess.

So the base can rotate freely in either direction indefinitely.

 

There is a slip ring that passes some wiring up to the vertical assembly. A similar system is in place for that motor, with an encoder tracking absolute position, but this one only has about 45 degrees of travel. There is a limit switch at either end, and a bunch of spare lines to be used for a camera or whatever.

 

This system is extremely easy to reverse engineer. All of the cables are out in the open, only disappearing into a slipring, where the maintain colour code.

 

 

So I starting breadboarding a motor driver. The brain is an old PIC that was in a bin somewhere, and I tried to find some driving transistors that would work. I burned a couple, and then took stock of what components I had on hand.
There was really no transistors around that fit the bill. I measured these DC motors to run at a good speed at about 8.5v and 500mA,so the power requirements are not low, when you’re trying to use 3906 BJTs or whatever.

Breadboard H-Bridge

 

 

That day ended there. I thought about the problem for a few days, then I came back and grabbed a 200w amplifier from the recycling bin and pulled it apart.

 

300W Amp Outside300W Amp Inside

 

 

Inside it were 4 sets of 2SA1908 and 2SC5100 complementary BJTs. Perfect. Wired them up like so, and I have a gimbal driver.

Gimbal breadboard schematic

Now I need to incorporate all of the sensors.

First Burn

During my research on how others have handled the sparking circuit in an EDM, I’ve been fairly unimpressed. Off the top of my head, there was one 555-based pulsing EDM circuit, one purely analog circuit that was never built, and one hand modulated system attached to a drill press.

It’s hard to tell exactly what will make a winning design, so I’d rather not hamstring myself with fixed logic that may or may not be ideal. And for the first few iterations will almost certainly fall on the “not” side of that line.

 

What I’ve settled on (and indeed, what my education is in) is computer control. Small microcontrollers have gotten fast and cheap enough that there is very rarely a reason not to use them, other than bragging rights or very high volume manufacturing.

 

That’s a little bit unfortunate in some cases, but it’s great for this one.

 

Here’s a first third draft of the circuit I’ll be using. I had a few false starts, but this one is the first one I actually (mostly) drew out, and it seems to work. I used two power supplies in series to get 60V and breadboarded it up. Not the final 80V supply, but close enough.

EDM SPICE

I only simulated the first stage (and with the wrong optocoupler!) but it proved the concept.

 

So I got my first burn last week to prove the concept! I tried to get a picture of the sparks, but it was tricky with my crappy phone camera. I was totally welding wires together, though, it was awesome. In theory, that shouldn’t even cause excess wear on my components or power supply. Everything is well within spec.

First Burn

 

I’m a little but worried about the speed of my components. I’d like to be able to get this pulsing in the 20ns range, but I’m pretty far away from that, I believe.

The two important components in this are the H11D3 optocouple and the IRF9540 P-Channel MOSFET.

 

According to the datasheet, the transistor has a rise time of 73ns, which right there blows my timing requirements. It has a turn-on delay of 16ns which also isn’t fantastic. That’s 100ns just for the transistor.

 

The optocoupler is worse, however. About 5 us. I’m not familiar enough with them to know if that’s a good value or not, but I’ll look at my options for rev 2.

Worth noting that this has a base connection, which doesn’t seem to make sense, given that the optical input is basically the base.

From here, though:

Click to access an3011.pdf

It looks like it’s to my advantage to use the base! It’s floating for now, but I’ll tweak the values to get to the most out of it when I have a scope on it.

Start small.

Other than wanting to spend very little money on this project, the scope of it is huge enough that I’ve been trying to use as many prebuilt components as possible.

If I have the majority of the project build with discrete, modular components, then I can start drilling down and replace the weakest links, one at a time.

Because the CNC portion is horribly complicated, and itself comprised of several parts (drive electronics, mechanical movements, control software, firmware), several weeks ago I made the decision to use a low-cost CNC platform. I mean “platform” in the sense that it’s designed as a starting point to hack, redesign, and improve.

It’s called the Piccolo:

piccolo stock

It uses three (TINY!) servo motors, a bunch of laser cut gears and mounting plates, and some Processing-based software. Everything is open-source, and I don’t think they even sell any of the components themselves. They provide all of the files and expect people to make it on their own, which is kinda cool.

One thing I couldn’t find on their site anywhere was the work area. I needed dimensions of all of the parts to mount and design around this anyway, so a couple hours with their laser cutter files produced this:

piccolo model

Turns out all axis have a range of about 2.5 inches. That’s really tiny for a CNC platform, but definitely usable for making PCBs. At first, anyway. That double-ensures that this portion will eventually be replaced, probably with a CNC system of my own design. That will be fun, I am looking forward to it.

One note for future-self:

There is a decent chance that the sparking from my electrodes will cause enough interference to mess with my servos. If they get really jittery during a burn, I know exactly what is happening, and a redesign will happen sooner rather than later.

Working with the above files, I gathered together some more materials:

EDM Tank Supplies

A 12V oil pump($12) for the EDM fluid (more on this in a future post), a standard heavy duty door hinge($3), and a small plastic tank($0.89). The tank is a lot smaller in person than it looks.

Putting it all together:

edm tank model 1

That’s a reasonably accurate mode of the tank on the left.

There’s also models of the Piccolo and the fuel pump that you can see there.

The rest of the frame is designed out of 1/2 inch MDF. The tank fits in the box, which can flip up like so:

edm tank model 2

And BAM. Hinges. The idea is that the whole mess can flip up for servicing, changing out the PCB, etc.

The PCB holders at the bottom might be changed a little before I build this, but the idea will stay the same. They’ll be submerged in the EDM fluid in the tank during operation. Afterwards, the top flips up, and those PCB holders are angled so that the oil drips back into the tank.

That should mitigate oil going everywhere somewhat. I still expect this to get messy.

EDM Prime

One of my theories for rapid PCB prototyping is EDM, or electro-discharge machining. The idea behind EDM is that you have an electrode hooked up to negative voltage, dunk the system in a high impedance fluid, and then put a potential on the metal workpiece. When that electrode is close to the metal and the potential is high enough to ionise a path through the dielectric fluid, an electric arc gets created between them, taking out a chunk of your workpiece.
Basically a spark welder to remove material.
This is often used for removing broken taps from holes or machining very deep, narrows holes with high precision.

I think I can use this to directly erode paths between traces on a sheet of copper-clad.

EDM is one of those strange niche tools that only machinists are really into. The hardcore kind of machinists that don’t really internet well. There seem to be about three resources on the internet for details on the inner workings of these machines: one CNC forum, one thread of a 3D printing forum, and one Yahoo group. None of these are particularly fantastic.
Fortunately, machinists are a lot more into books. Robert Langlois put out a couple how-to manuals in the early 2000s, and Ben Fleming has some much more recently.
Someone got in contact with Langlois recently, and relayed that he lost interest in the project, would definitely like to see Raspberry Pi control of an EDM, and is open sourcing his books. So, naturally, I’ve read those books. I’ve also found some academic papers and expired patents that go over some design constraints.

There really are three major building blocks in building one of these: a CNC platform, the dielectric fluid immersion tank, and the electronics. The mechanical guys have got the first two figured and polished to a degree that I’m not capable of. The circuitry, though, is all extremely simplistic. I think I can add some microcontroller controls and improve hugely on the designs.
Most of the EDM schematics out there are just rectifiers and 555 timer-based pulse circuits.
One of the more sophisticated designs out there, The Garden of EDM by C. Scott Ananian provides an excellent rundown of design decisions, and has some similar ideas to what I’ve come up with independently. His version seems a unnecessarily complicated, though. Especially considering he never actually built his circuit. I’ll start with a much simpler design, offload more to a microcontroller, and end up with more control out of the deal.

Here are some parameters I’m trying to hit:
20-100kHz pulses
20ns rise times or better
Adjustable voltage up to 80VDC
4 amp current max

That’s enough substanceless discussion for now. Starting with sink-EDM, the circuitry and mechanical Z-axis go hand-in-hand. I sat down for a few hours and built something in Solidworks:

After another few hours, I’ve got it laser cut to get this:

Man, clear acrylic is really hard to photograph properly. Everything was cut on a single try and slotted perfectly into itself on the first try. I’m really quite pleased. The rails are scavenged from an old scanner.

And then alongside that, this is the very first draft of “maybe what I’ll build, unless I have some better ideas”:

EDM Schematic V1

This is a test

Quite a while ago, I did some experimenting with laser etching on glass. The intention was to backlight it and make a large lamp with some LEDs behind a large sheet of laser patterned and frosted glass.
Material costs pushed me towards scaling it way down and designing around a small glass tile that I picked up for a few cents. Just for an initial test, anyway.

The tile I chose is about 96mm², and just a hair under 7.3mm thick at the edges.

For the material acquisition side of things, I hunted for high power LEDs from Dealextreme, one of my favourite sites. They carried some 3W LEDs for a couple bucks, not bad. Then I checked Aliexpress. 1W LEDs were substantially cheaper, but I could only get them in quantities of 100. For $12. So I have some extras.

They measured out at around forward 3.2V. Current is about 120mA when the LEDs appear to be at max brightness. Theoretically they should go up to around 300mA, but this is good enough! I can’t see out of the centre of my vision!

I’m not really a huge fan of 3D printers, but I really wanted to crank this thing out quickly and using one freed up any design limitations for this janky part I needed.

After six quick iterations, I came up with this:

Printed Object

The angles turned out to be tricky to get right, but it worked out. Printed with support material on a Rostock MAX delta printer. The tile is held very securely with no fasteners, perfectly parallel to the base.

Balanced

It even stands up!

 

Bonus SolidWorks model view:

SW Lamp

For the actual circuit design, I went with all surface mount for easier custom boards, and some free sample chips from TI. See! That program totally works for them, I’m locked into this design now. Actually, it was the best part for the job that I could find. The LM3410, which is a constant current, analog dimming, PWM output boost converter. Yeah, pretty cool.

 

I found an Eagle library part that had the same footprint as the LM3410, and then I used my standard “print footprints at 1:1” method to find suitable library parts for my Chinese LEDs and salvage-bin inductor with no datasheets.

Parts list:

  • Inductor L1 – CDRH6D28-3R0NC – 3.0uH, 3.0A
    • The datasheet reference designs used anywhere from 4-20uH inductors. Less inductance just means a little more ripple current, which should be okay.
  • Schottkey Diode D1 – B260A-13, rated for 60V reverse voltage, 2A forward current.
  • Zener Diode D2 – I don’t have this yet! Reverse voltage drop between 21-24V. Might have to stack a bunch in series.
  • 1Ω R1, R3 – Two resistors, 1% tolerance, 1206, in parallel to make 0.5Ω
  • 100Ω R2 – 5%, 0805 for voltage overload.

Here are the results of my circuit building:

Lamp Schematic

The schematic is mostly a reference from the datasheet. Max current and voltage limits are a dependent on switching speed, the inductor I used, and the heatsinking of parts, so no hard-and-fast rules. I stretched it to the most high-power LEDs I thought I could get away with. That’s 6. Six LEDs. Worst case scenario, I have to jump one or two of them if everything starts to burn. Best case scenario, I’ve got ten of these boards coming, a dozen inductors, a hundred LEDs, but only three LM3410s.

For this build, I’m trying out the new Dirt Cheap Dirty Board service run by Dangerous Prototypes. I’ve used OSH Park and iTead Studios before, so this will be a fun experiment.

 

Originally, I was going to etch my own board using a laser cutter and the spraypaint etch resist method. Unfortunately, I have (temporarily, I hope) lost access to the laser cutter. For $14, this seems like a reasonable alternative.

 

I will update in a month or so, when the PCBs get here.