Saturday, 12 November 2011

Arduinos Floppy Drives, and Maples..

Time for some serious geekery documenting =)

This tale starts with my other half getting intrigued by an arduino.. and picking up an Uno, with a whole exploratory box full of parts, and little projects to build. Then shortly after that, getting an arduino nano, and an ethernet module, with the aim of solving our garage door opening problems..

This led to me to start looking at arduinos & MIDI, and lcd's, and thus I ended up with an arduino Mega. Then I got a little sidetracked, and started looking at how to read floppy disks, and things just kinda spiralled from there..

So, I should probably wind back a bit here.. Garage Door Opening problems? MIDI? Nano?

Our garage door has an electric opener, which frankly, is a good thing, as it's largish door & pretty heavy, and this way we don't get wet opening the door in the rain. But, the controllers use radio, and just occasionally it would appear something interferes with the signal, leaving the door pretty firmly shut..

The opener also has a switch to press to open the door, but oddly enough putting a switch on the wall outside the garage would be a bit insecure.. and with the garage being detached from the house, a new solution was needed.. Enter the arduino, a pair of ethernet-over-mains adapters, an ethernet module, some code, and a relay.. and bam.. pull up outside the house, sign into the house wifi from a smartphone, and click 'door open'.. or at least that's the theory.. the small pile of parts on the floor hint that this project may take a while =)

Can see a preview of it all here.. the top is a switching regulator dropping the 9v to 5v, then hiding up top right is a 3.3v LDO regulator dropping the 5v further to 3.3v. The Ether Module is running off the 3.3v, the arduino nano off the 5v, and the phone showing the webpage coming from it =) Yes, that tiny blob with the green & red LED's showing is the entire 'computer'.. scary tiny =)

Ok, MIDI? .. totally ancient connector/protocol for hooking together synths, computers, etc.. but oddly still relevant even today.. great thing about MIDI is it's only serial data at 31250bps, with a pretty simple protocol, and, yes, entirely within the capability of an arduino.. hook the TX & RX up to a set of MIDI jacks, and soon, you end up doing oddball things like..

Which wasn't really intended as a psychedelic light show, so much as a way to debug the data flowing without having any real display.. course, now, I have a pile of 16x2 character LCD displays.. which makes using a row of LEDs seem a little .. quaint..

Right.. onto the floppy disks.. I've got quite the pile of Amiga Floppy Disks, and some time ago started building a floppy disk autochanger (with mindstorms!).. but I got wondering.. could an arduino pretend to be a floppy drive? I mean I know of floppy emulators, like the HxC, and the 3.5" form factor ones that take a usb stick / sd card.. and I know of other projects where it's been done.. so the problem should be pretty well understood..

After a bit of reading around.. I got about this far..

Which is to say, able to time the Index pulse, and move the head, and be able to understand where Track 0 is.. and even see some RDATA transitions..

Course, that isn't an arduino there either.. I sort of upgraded along the way, partially because the Maple is a 72mhz board with 20k of ram, vs the Arduino Uno's 16mhz, and 2k, which makes holding a tracks worth of data pretty feasible. the other reason, would be accidentally putting 12v down the arduino Mega's 5v pin.. which didnt just kill it, it _Really_ killed it.. we're talking glowing ball of light carving a burnt canyon through the CPU and vaporising the 5v pin. No, I don't have a video of that..

Getting this far required a bit of help, so thanks go to the few people left at work who understand things like floating outputs, and pullup resistors, for taking the time to explain that to a software engineer =)

That gets me pretty much back to 'now', where the Maple is able to see the RDATA transitions, but I'm a long way off seeing them clearly enough to decode the data.. I've had some great email exchanges with the author of who's been patient enough to explain a few of the steps I'd become blind to, about how to decode MFM when capturing pulse widths.

I've just got a cheap 8 channel usb logic analyser (up to 24mhz, samples stored at the host, so can hold an entire track worth of data.. ).. and now I need to spend some time creating some tools to do comparisons of what I grab with the maple, vs what the logic analyser sees.. maybe then I'll be able to debug where it's going odd... (plus I've got a 16 channel 'open logic sniffer' ( on its way from china.. that'll help too =)

Until then.. I've spent some time reading the datasheets for the Maple, and although the nice friendly library that comes with the Maple doesn't support it yet, I've got Timer Input Capture via DMA up & running.. essentially this means the hardware will monitor a signal line, and every time it goes from high to low, it will copy the value from a hardware timer directly into my array.. all without me getting involved.. all rather freaky if you're used to Java ;p

Sadly this won't solve the problem by itself, as with 20k of ram, even storing 8bit timer values, I'll only be able to hold around 16000 of them.. and I need to hold more like 56000 of them.. but still.. mebbe if the cpu isn't busy doing the grabs.. I can use it to do something with the data.. possibly push it down to an sdcard, or into a FRAM chip via SPI with DMA.. just not sure of the timings.. the floppy data is pretty unrelenting coming in every 4, 6 or 8us, not leaving much time to do stuff in between..

1 comment :

  1. Yup. There's fun in optimizations+ nice tight code. Also, there's fun in these: