Controlling a Floppy Drive with a BeagleBone Black

BeagleBone Black Floppy InterfaceInspired by David Gesswein’s MFM Hard Disk Reader/Emulator I added a pair of voltage translator chips to a BeagleBone Black to control a floppy disk drive.

The software makes use of the BeagleBone Black’s programmable real-time unit subsystem (PRUSS) to control the head stepper and drive motor.  The PRUSS contains a capture unit running at 200Mhz, which is used to record the time of each pulse from the drive as the flux transitions pass under the head.  Using a 200Mhz clock results in a resolution of 5ns, which is easily able to capture the  4 microsecond cells used by the Apple Drive II controller.  The index signal is routed to one of the PRUSS controlled input pins for recording along with the timing data.

The software records 512000 samplings per track, with each sample consuming 4 bytes.  An additional 4k of space is allocated for the storage of the index pulse timings.  This results in 2052096 bytes per track, or 160320kbytes of data per disk.

The process of reading an entire 80 track disk takes about 8 minutes.

Reading floppy disks formatted for use on an Apple II results in a record of at least 10 rotations per track.  As many of the disks that I have in my possession are over 30 years old, multiple reads are useful in assisting with the recovery of data that may be barely readable.  I have found that using alternate floppy drives has occasionally produced tracks that are read correctly where another drive has had issues.

Once the timings are available, I can turn them into a stream of zero and one bits by performing an appropriate sampling function on the data.  The simple method for Apple II disks is to simply divide the time by 5microseconds.  The integer portion of the result is used as the number of zeros to shift before a single one is added.  This captures normal disks where the times are roughly 4, 8, and 12 microseconds.

As the processing is all handled in software, more complex algorithms can be designed.  Of particular use is one that follows the state machine as described in “Understanding the Apple II” by James Sather.

Once the general bit stream is formed it can be saved, similar to an EDD format.  If  the synchronization bits are stripped, then it can be saved as a nibble (.nib) file.  Lastly, if the bit stream is further processed, emulating the DISK II and DOS RWTS routines, a final disk image can be generated.  This last step is useful in validating the original disk image of normal DOS disks without copy protection as each sector has a checksum.  With multiple copies of each track available, it is possible to select a good copy of each sector and save it individually, creating one good image out of multiple passes.