Sunday, August 9, 2015

Raygun XIV.IV

Programming is done and wiring harness completed. I'll add a pic once the paint on that side of the clamshell dries.

And here's the pic. I decided against adding a connector to allow detaching the grip; it is hard-wired now (the LiPo, of course, pops out on a spring catch.) That's another "gotcha" that will catch you up some times; the sheer volume of the wiring can make the difference between everything fitting in a tight prop, and not being able to screw down the lid.

(And this also illustrates why I didn't use a sound board, even though Adafruit has several wonderful ones. There's no space!)



On the downside, the volume was lower than I'd been hoping on 5v -- it is even lower running on the LiPo. But on the upside -- it runs, everything works, and the sounds are basically the same. Also on the downside, the silver paint takes fingerprints a bit. I noticed that when testing to see if the clamshell would close properly on the completed wiring harness.

I'm pretty much over the delights of synthesis on the AVR. It is so sensitive to program flow, even when you have access to multiple timers, that even RTOS programming doesn't quite help you. The last trick I did before I closed it up was program the all-the-way-over knob position. Which plays a clave rhythm (I wanted to program a bar of "Garota de Ipanema" but with the cobbled-up synthesis framework I'm using it would have been a huge pain.)

Some of the sounds were fairly nice. One of the few small advantages to getting old. I've spent time in the trenches doing synthesis, all the way back to programming on FM (hardware!) synthesizers. Never worked with any of the really old-school stuff but read enough about the theory so I grok ADSR envelopes, VCOs, and all that. Which is to say; I have some sense (between that and a lot of sound design doing manipulation of samples with other tools) of how to achieve certain effects.

So I was able to get an okay clave sound.

The effect I'm most pleased with, oddly, is the knob. The "Set Atomic Ray to Stun!" knob is a simple linear-taper potentiometer with a hardware switch that breaks the main power lead. Something I learned from on the Morrow Project CBR!

The code does an anti-jitter routine by not reacting unless the current analog read off the knob is 2% or more off the stored value. When this increment is detected, it goes to the PWM timer that is outputting to the speaker and commands a single square wave. This makes a "tick" sound. So as you turn the knob, it clicks softly as it turns.

As certain preset bracketed values are entered it does a similar routine to see if it is already in that state, if not, it sets a new state (playing State Machine here) and plays a short beep using both timers (the PWM out giving the voltage and the second timer setting the frequency via an ISR -- Interrupt Service Routine.)

The continuous beam settings are all warbling tones anyhow, so the functions are written open-ended so at each pass through the tone and light generating function, the program flow goes back to check the knobs-and-switches status again.

The "zap" settings are handled differently; each enters a function with a single timed loop in it, and a toggle is set that requires the trigger be released before the function can be triggered again.




And, yeah, based on this, I'm definitely going to fork the DuckNode project. One fork will be a simple 3-channel (or perhaps four) Cree driver with minimal hardware connections for simple adjustments (aka tuning in a color on the fly). And that means I can do it with an ATtiny45.

The other I'll jump up to the more popular ATtiny2313. Or something. Eventually I'm going to have to learn to solder larger SMD chips. And learn how to manipulate the USB stack properly. And find a cheaper radio solution than the XBee.



So tomorrow, or Monday, I'll lathe up the nozzle. And start on the holster (I'm waiting on client approval for the design of that item). Dunno if I'll have time for the Disintegrating Pistol, though.

(I'm also wondering if it is worth making a quick "buck" to form the clear parts of the holster around. One of these days I want to fire up the CNC wood router, but -- as in so many other things -- I need to find time to create the computer files as well.)

Lathe reserved. In the meanwhile, got a start at making the holster. First stage; working up the shape in successive mock-ups:


Saturday, August 8, 2015

Raygun XIV.III

In any project, one of the nicest places to arrive is where a cut-out is possible; where you can go to a simpler plan, finish it up and put it in the box.

I took one of these a while back when I dropped the machining to have most of the gun printed. But I'm choosing not to take two others; to go with "good enough" on the programming, and to accept the results of the Rub 'n Buff experiment.

The latter first. I did several pieces in Rub n' Buff before discovering that although it generally wears well, it was coming off the sharp edges. Such as on the grips, with the decorative grooves. So I've gone back to Krylon Premium Original Chrome. Over the black epoxy enamel I'd sprayed earlier (for strength, mostly.)


Paint on the left, Rub 'n Buff in the middle. The trigger guard is real metal; CNC'd aluminium with my M40 Grenade-tested treatment of 220 then 400 grit wet-dry paper, a buff with 0000 steel wool, then a protective film of sewing machine oil.

The picture is a little misleading. The Rub 'n Buff looks better at a distance, and the aluminium piece is at the wrong angle to the light to catch highlights here. And I can see some typical orange-peel in the paint (like a lot of metallics, it doesn't achieve the really good shine unless you put it on heavy enough for it to self-level).

But it works. And, yes; this is another huge advantage to all-metal construction; you can ding that stuff up pretty badly without scratching the "paint." (Would have also helped in some of my mechanical connections -- the e-cell catch, for instance, was really designed around metal-on-metal contact, and it also suffers from the larger footprint required of brass thread inserts over the original plan to tap the aluminium.)



The final details are coming together. I spent another day at the 3d printer. TechShop finally got a second printer working -- which they gave to the classes, but at least that gets those out of the way of making a reservation. And they have at least four of the Zim machines being prepped now. So in the long term printing there will be less of a chore.

Speaking of which. Someone had run nickel-powder PET through the machine I logged into, and perhaps because of that or perhaps because the bed is increasing warped (Type A Machines really need to look into a better print bed) I could not get my prints to adhere. Spent a good hour messing around with the settings (and adding more and more glue to the print bed) until I finally started getting clean prints.

Also oddly -- I set up the first print using the Cura v.15.06 they had loaded on the machines at Techshop, but the subsequent prints I sliced with my own copy of Cura v14.12. And whether it was the software itself, or the possibility that my own tweaked settings had been saved to my copy, but I got nicer prints and a better printing experience with those.

My original idea was a Starburst; a typical Googie design element I really wanted to incorporate (just as the design consciously includes boomerang shapes, jet nacelles, tail fins, etc.) But a last-minute suggest from a friend was another famous bit of Atomic Age design; the atom.



The top is the Starburst idea, but that side is actually where the power setting knob will be. The Atom will be on the other side. And, yes...it should have had three orbits for a proper Bohr atom (which would be Lithium, right?) but I was modeling at warp speed while sitting at the printer with the minutes on my reservation running low.

While I was trying to figure out how many electrons I wanted I had the inspiration to make this the element Tikium, atomic number 12:8 -- with a tiki head for a nucleus. Which is a little easier to see in the Cura display (where I tried and tried to put the quick Carrara model into the quick Fusion model, and after crashing Fusion multiple times finally gave up and did with two prints and some superglue).






Besides re-painting -- and painting up the fresh elements -- the only physical task left on the gun is to lathe out the emitter. Which with luck I'll get to on Sunday.

And finish the wiring harness. All the electronics are mounted now, but it is a good thing I left some of the wiring loose because I had to make several adjustments in how things were wired. I've really fallen out of love with the ATtiny84. I picked that chip for the DuckNode as a compromise between the tiny footprint of the ATtiny45 and the greater number of I/O ports. But there really aren't a lot of ports anyhow. I'm sharing ones I'd rather not share, and at some point I'll be in that ugly little round of having to disconnect the ISP in order to test a pin function properly.

It also only has two hardware timers (not including the watchdog timer, which I'm not about to get into. So my program has ended up taking on certain aspects of RTOS programming again. I have to really watch the operations I perform (modulus is an ugly one on the smaller AVR's -- even though they have a math co-processor it takes them 15x longer to run a modulus calculation than it does to run an "if" statement.)

So within the loops I have to program exceptionally lean. Because the program has to step through everything fast enough to be able to run a software PWM of the light (in order that I can fade it smoothly), and fast enough to not put too much jitter into the audio. And the timing is hyper-critical to where the sound only sounds right with the right number of delaying elements in the loop; meaning there's at least one spot where I have to use modulus just to get the timing to come out right!

Yes, more discoveries. The Arduino "delaymicroseconds" function leverages a timer. So I can't call it without messing up my own timers. And for some reason changing the system clock prescaler on either of the timers makes the "delay" function either run slow or not at all. Don't understand what's going on there.

More so, it appears my stick of ATtiny84's shipped with, instead of the 8 mHz internal oscillator ATmel promises they are supposed to default to, but the 128 kHz low-power oscillator selected! Fortunately, "burn bootloader" from the latest Arduino IDE -- patched with various third-party AVR-duino packages -- reset the fuses. Because I'm not up for trying to remember how to use the avrdude chain right now. (No doubt discovering a broken instal somewhere along the way!)

Thing is, in this kind of micro-computing one doesn't write a program. One writes a "sketch." The idea is you aren't trying to make something bulletproof, and test it before uploading to production. You just throw together whatever pile of code gets the project of the moment working. If Larry Niven's Pak Protectors programmed, this is how they'd do it.

Hence my current code-in-development, a horrible hybrid of Arduino macros and register directives written down so close to the metal they might as well be in Assembly. And of course lots of lines commented out, magic numbers everywhere, a few scrawled notes here and there, function calls done entirely so I can see where I am in the program flow, etc. Sure, your code might look like this when you are coming up with ideas, but I'm quite literally testing this in production; uploading it in real time to the hardware to see what happens.


But with any luck, I won't need to make any more hardware layer alterations, and I can finish the wiring harness and close it up. Today, I'm hoping. I just need to finish writing the Power Selector Knob routines, a nice Continuous Wave setting, and if I get ambitious a Power On hum for when the system boots and a "Phaser on Overload" for when you twist the control knob all the way over.


That is, assuming all the paint has dried by then. I may have to wait until Monday to bolt everything back together (it was all bolted together for the test assembly so I know that part is all good). And switch to working on the holster instead. Picked up a couple yards of white pleather and clear vinyl to play with...


Thursday, August 6, 2015

Wavetable Synthesis on the ATtiny84

Yes, it is actually possible. I wouldn't recommend it; the built-in 8 mHz oscillator is slow enough that even Interrupt calls take enough clock cycles to be heard as "grit" or "chatter" in the sound.

But I've got a code hacked to the point where I can control frequency, volume, and get an audible difference between sawtooth and square wave. (Haven't plugged in the wavetable for a sine wave yet...but hopefully that will sound a little purer).

I figured it out from Jon Thompson's excellent article over at Make. Although it took quite a lot of mental struggle before it all became clear! Thus this post; I'm going to attempt to explain what it is I figured out in the almost certainly quixotic hope that someone else will find my fumbling explanation easier.


Wednesday, August 5, 2015

Hardware/Software

That's the lovely thing about embedded computing; the software and hardware layers are so intimately entwined.

On the one side, since the software is controlling physical processes (like servo motors, ultra-bright LEDs, etc.) a software error can "crash" the hardware. I've bent a servo shaft more than once due to getting a line wrong in the code I was testing.

And on the other side, the hardware can make for a less than pristine software environment. I was struggling this whole evening to get tone generation via timers to work sensibly. And as it turns out -- even though the amp I'm using was designed to be attached to Arduino clones, when I sent a full-strength pin signal to it, it crashed the chip and caused it to reset.

The reset is FAST on AVRs. Fast enough that the result was actually in the audible domain; the chip would crash and reset as fast as 400 times a second.

I finally clued in to what was happening when I realized I couldn't write a time out function that worked. And a single slim resistor before the amp seems to have solved that issue.

So good thing I got into this now. Would have been even more of a pain to debug when I had trigger switch and LED and so forth connected as well.

And now I'm comfortable enough again with the hardware timers on the AVR to make another shot at software synthesis. I found a cute little article on waveform lookup tables on the AVR and although I don't really need the waveform per se, I do want the ability to make complex tones that would be difficult to achieve with the Arduino tone() library.




So the raygun is more or less on schedule. I didn't finish the electronics assembly (preferring to leave parts out until I'd figured out which pins were best to drive the speaker with). But that's solved, and finishing the harness is maybe another hour. The biggest chunk of time left on this project is the programming, and all in all I made a good start at it today.

Oh, yeah. And now one of the companies I called asking for work calls back to see if I can drop in for a week or two to cover a guy who is on vacation. And it's a company I do not want to turn down...

Tuesday, August 4, 2015

Raygun XIV.II

Took longer than I wanted, but all the assembly work is done. Everything fits (except the nozzle -- I'll be lathing that this week). Made several hardware store runs to get the appropriate bolts and so forth. Still shy the 4-40 setscrew to hold the barrel assembly (but it is a tight fit anyhow).


So now all the pieces are cycling through the paint stages. They've all been wiped with superglue and sanded with 220. I'm progressively priming, wet sanding with 400 grit, then spraying on the epoxy black. Which takes 24 hours to cure completely, so only the back of the dish (my test piece) is actually finished.

Mildly annoying, because I kinda need the right side housing to complete the electronics work:


Trigger and switch is working great. Setting knob works. And the e-cell seats nicely and with the new spring, is a lot easier to extract from the handle. The picture below is from before it was modified to plug directly into the gun:


Tonight's task (assuming I have any energy left) is to solder up the CPU and constant-current PWM driver for the LED, using one of that first run of "Ducknode" boards I got made at Osh Park.


And I've been reading about wavetable synthesis. It's a bit much -- but I can probably handle creating a white noise burst. Not sure how to combine it with the tone generation, though. One handy thing; I don't have to do any clever things with interrupts. The way the functionality of this gun works, it runs through a complete "pew!" sequence before it bothers to poll inputs for control changes.



The last main task will be to create the holster. I've pretty much narrowed down the design in my head to a wide belt worn snug at the natural waist, holster depending from it for ease in draw, decorative buckle. The holster itself stiff, shaped, and clear but edged with the same white vinyl as the belt.

And I hope there's enough time left for the Disintegrating Pistol. There certainly isn't time for jetpack or bubble helmet!

Monday, August 3, 2015

Raygun XIV.I

TechShop is sort of bugging me. One lathe is still busted. Still only one printer, and not only is that reserved most of the time, it keeps getting dragged off to be used in some sort of afterschool outreach they are running. And today...the bandsaw was busted (and like the lathe, the parts may take weeks to arrive, if ever... apparently Jet Tools is not the best at support).

With no bandsaw, I made do with file, hacksaw...and mill. Was actually able to use the mill to cut the pieces I wanted to width and length, then used grinder and file to do the final shaping.

My CNC parts went okay. I seem to have forgotten which corner needs to be set to properly zero the various steps; my G-code had the cuts way off in space. So I eyeball zeroed the CNC mill to where the cuts would land on my stock -- lots of air passes to make sure I was getting it right.

After I broke my old end mill that other day, I've been a lot more conservative in my G-code. So much so I was able to dial up to 100% machine speed over-ride (aka, running the G-code as written) and the mill sounded just fine. 8 ips, by the by, step-over of 30%, and a plunge depth of .04" on a .25" end mill.

V-Carve Pro is not the most complicated software out there, and I didn't want to play with trying to face my stock. So I faced on the manual mill, and exported only the contour cut-off path from V-Carve. That worked fine...but facing with a 1/4" end mill takes a while! If I had really gone through with making the raygun all metal, I would have had to break down and purchase a face mill (well..you can get one for under a hundred bucks on eBay).

Clean-up was the other reason I chickened out on all-metal. There were several notches in the parts I ran off today that the end mill couldn't reach, and I spent a good hour with a file working on that. And these were simple outlines; the main parts with all their compound curves are giving me a hard time just with sandpaper and the soft plastic I got back from Shapeways!

(And, yes, there are several errors in the CAD. I've been having to cut into the plastic in various places, as well as add more material with scrap plastic and superglue. The revised e-cell connector took even more than that; I assembled that with Apoxie Sculpt.)

Well, the metal parts fit. The sound board is a lot smaller than I thought, but jammed up against the housing and fed a strong audio signal from my computer, it seems sufficiently loud anyhow. But that means that, more and more, assembly is bleeding into electronics assembly/final assembly. And that means I have to finish most of the painting.

And painting is currently waiting for the trial piece in epoxy enamel to finish curing so I can evaluate if all the pieces are going to get that treatment. At this point, it looks like the combination of superglue seal on the plastic and epoxy enamel as final coat will give the tough shell I need, and Rub 'n Buff will give a metallic sheen that will look appropriate and last a while.

And oops. Before I put on the final coats of paint I really need to print off the "swooshes" for the side. If and when that last ailing 3d printer at TechShop even becomes available again!


Sunday, August 2, 2015

Raygun XIV

My short bit of summer stock -- painting sets in the hot sun -- is done for now and it is back to the Raygun with a week and a half remaining before the deadline.


The Shapeways parts arrived earlier in the week and I'd started sanding them down. This weekend, I moved to the next step on that; painting them with Superglue to seal them, then spraying them with primer.

Experimented with a couple different paint treatments on the mockup.


The leading contenders now are rattle-can chrome (Krylon Premium Original) or Rub 'n Buff. The former is shinier but I'm not sure I want that, and the latter may have better wear characteristics (but also might stain). I also didn't like the OSH-brand black gloss, and am experimenting with an epoxy enamel now (for greater strength).


The other big task was making sure everything fit together correctly. The original design was for tapped holes, but the plastic print didn't stand up to that well. Some of the parts will be held in with sheet metal screws into the plastic, but both for ease in multiple assembly/disassembly, and for the look of the original bolts, I added threaded inserts.



And it turns out getting inside the grip to unhook the battery cable just wasn't working. So I spent a big chunk of today coming up with a revised approach. Because, after all, I'd gone through all the effort to make the e-cell removable, and it seemed a shame to lose that.

Tomorrow is the first machine reservation I've been able to make since I started summer stock. With luck I'll be able to CNC the guard, trigger, the strap that holds the potentiometer, and the sounding board the transducer presses against to make sound.

All the pieces are basically sanded and primed, and I'm already moving into electronics and functional parts. So I have pretty good hopes of finishing up this week. And I can start on the holster over the weekend.