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.