Thursday 4 January 2018

Hooking up the 3.5" internal floppy drive

Today I finally got around to testing the floppy drive interface, that is, the interface for the internal 3.5" floppy drive.  Making it read and write 1581 disks will take some time, as we have to write the floppy controller from scratch. Rather, my goal was to make sure that the hardware interface we have built works correctly.

For simplicity and cost effectiveness, we are using standard PC floppy drives, as these are  the most likely to be available for the longest time into the future, and are indeed already about the only drives that are easily available now.  This isn't a problem for compatibility, precisely because we are building the floppy controller in the FPGA, and so can avoid the compatibility problems that have arisen in the past between different types of drives.

The floppy interface uses a 34 pin cable which is capable of talking to two floppy drives.  All the odd numbered pins are ground, and two of the odd ones are reserved, reducing the number of important signals to 15, which are enough to do all sorts of things.  However, for those of us who are more interested in reading and writing data, rather than playing classical music, then this is what matters:

2 - Density select (720K / 1.44MB -- this means we will be able to read HD disks eventually)
8 - Index hole sense
10 - Motor enable, drive A
12 - Drive select, drive B
14 - Drive select, drive A
16 - Motor enable, drive B
18 - Step direction
20 - Step track
22 - Write data
24 - Write gate (write enable)
26 - Track 0 sense
28 - Write protect sense
30 - Read data
32 - Head select
34 - Disk change sense flag

The principle of operation for reading is surprisingly simple:

1. All signals are active low, i.e., ground them to activate them.
2. To talk to a drive, pull the appropriate drive select low.  Turn the motor on, pull the motor enable line for the matching drive low, then start reading data from the read data line.
3. To step between tracks, use the step direction and step track lines, noting that you have to step twice to move a whole track. Many modern drives move in whole tracks, while older drives would step a half-track at a time (this is why you have to step twice per track, even on newer drives).
4. You can tell when you are on track 0, by waiting for pin 26 to go low.
5. You can tell when the index hole has passed, by watching for pin 8 to pulse low.

For writing, it is much the same, you just pull pin 24 low when you actually want the write head to do its work.  To write good data there are some tricks, such as write precompensation, to work around the fact that magnetic domains tend to move after you write them, but the general theory is the same.

Finally, PCs support two drives on the one cable, without having to change the jumpers on the drives. This works by twisting the section of cable that connects pins 10 to 16 -- this is why those pins are laid out in a palandromic order.

This means that for each floppy drive there are 8 signals that the computer has to provide, 6 of which are common between the two drives, so a total of 10 output signals.  In addition, there are the five shared input signals.

I modified my VHDL test harness to allow me to control the floppy interface using my VGA + joystick interface.  This is a nice way to test this on the actual MEGA65 PCB, without spending lots of time resynthesising VHDL designs all the time.

The first steps were remarkably easy: Pulling the motor or drive select lines low caused the LED to turn on on the drive.  Stepping in and out tracks was also very straight forward.  Where I got stuck for a bit, however, was reading the inputs.  This was partly just from some clumsy typing and thinking in my VHDL harness writing.  However, once that was sorted out, I noticed two problems:

1. The drive didn't like doing much when the drive select for the other drive was active.  This probably varies among drives, but it was nice to discover it early rather than in production.  This was easily solved by pulling up the drive B drive select.

2. The inputs all need pull-ups on them, which we didn't have. Again, I added some temporary ones (well, actually a single temporary one jammed into the drive B connector on the floppy cable, which I moved around as I tested things).  This worked just fine, and I was able to observe the track 0, index and write-protect sense lines.  Read data I wasn't able to see doing anything, as I was only game to put a blank disk in a floppy drive that I was controlling completely using only a joystick, and that was very easy to accidentally turn on the write head without realising it.



The last line to test was the disk change sense line.  My make-shift pull-up arrangement and just the comedy of errors that often happens when testing made this process a little more drawn out than intended.  However, in the end, I was able to confirm that this line goes low when a disk is ejected, and remains low until such time as the drive head is stepped in any direction.

What is not quite visible in this image is that the floppy drive is being powered from a joystick port, because the floppy cable has no 5V line, and the revision 1 PCBs don't have a power connector header for the floppy. Older 3.5" drives also needed 12V, but not this one. We will likely provide a connector with both voltages in the production boards, just in case someone needs to use an ancient drive.

So, the current state of play is that, with the exception of the read and write lines, the floppy interface is known to be fully functional. As the read and write lines are connected in the same manner as the other lines, we have no reason to doubt that they will also work.  We do need to add pull-ups on the input lines, and should also connect the two drive B signals, both to avoid problems, and also to allow people to add a second internal floppy drive if they wish.

7 comments:

  1. Isn't the write signal gated by the write protect line inside the floppy drive?

    ReplyDelete
    Replies
    1. I think this is very likely the case, assuming the drive is sanely designed. In the middle of the night when working on these things, these thoughts don't always occur to one, though ;) Once I have my 1581 working again, I'll format up a disk and test with that, in complete safety.

      Delete
  2. This is wonderful and all, and I know you are trying to replicate the C65 pretty much, but I have to express my opinion you are barking up the wrong tree. Yes we want 8 bit computers. Does that mean we have to be saddled with outdated and very soon to be completely obsolete data storage? These disks are getting more expensive and harder to find by the day. And in the interest of being retro, lets face it, it's just a storage medium. It does not affect how the computer will operate. I would simply drop the floppy and go with an SD card implementation or something similar that supports .d81 or some custom HD format or whatever you would like to create. This in my opinion would be the better way forward. I mean, you are using a modern FPGA for the CPU? Why not modern storage too? It will still be retro and everyone will still want it and it will be better all the way round. Just my 2 cents.

    ReplyDelete
    Replies
    1. Nothing stopping you putting a hxc in there in place if that’s your wish.

      Delete
    2. Or just run disk images from the SD card!!

      Delete
    3. Also, there is the SD-card there already, as a modern storage. Nothing says you must use floppy drive if you don't want, but you *can*, that's all. That is my opinion.

      Delete
    4. We agree completely. It is there, because we think something would be missing if it were not there, but nothing makes you actually use it.

      An HxC floppy-replacer would also work, but with the on-board SD card which already emulates the floppy drive, the value in this would likely be limited.

      Paul.

      Delete