Floppy-disk controller
A floppy-disk controller (FDC) is a special-purpose integrated circuit (IC or "chip") and associated disk controller circuitry that directs and controls reading from and writing to a computer's floppy disk drive (FDD). The FDC is responsible for reading data presented from the host computer and converting it to the drive's on-disk format using one of a number of encoding schemes, like FM encoding (single density) or MFM encoding (double density), and reading those formats and returning it to its original binary values.

Depending on the platform, data transfers between the controller and host computer would be controlled by the computer's own microprocessor, or an inexpensive dedicated microprocessor like the MOS 6507 or Zilog Z80. Early controllers required additional circuitry to perform specific tasks like providing clock signals and setting various options. Later designs included more of this functionality on the controller and reduced the complexity of the external circuitry; single-chip solutions were common by the later 1980s.

By the 1990s, the floppy disk was increasingly giving way to hard drives, which required similar controllers. In these systems, the controller also often combined a microcontroller to handle data transfer over standardized connectors like SCSI and IDE that could be used with any computer. In more modern systems, the FDC, if present at all, is typically part of the many functions provided by a single super I/O chip.



Overview 
A floppy disk stores binary data not as a series of values, but a series of changes in value. Each of these changes, recorded in the polarity of the magnetic recording media, causes a voltage to be induced in the drive head as the disk surface rotates past it. It is the timing of these polarization changes and the resulting spikes of voltage that encode the ones and zeros of the original data. One of the functions of the controller is to turn the original data into the proper pattern of polarizations during writing, and then recreate it during reads.

As the storage is based on timing, and that timing is easily affected by mechanical and electrical disturbances, accurately reading the data requires some sort of reference signal, the clock. As the on-disk timing is constantly changing, the clock signal has to be provided by the disk itself. To do this, the original data is modified with extra transitions to allow the clock signal to be encoded in the data and then use clock recovery during reads to recreate the original signal. Some controllers require this encoding to be performed externally, but most designs provide standard encodings like FM and MFM.

The controller also provides a number of other services to control the drive mechanism itself. These typically include the movement of the drive head to center over the separate tracks on the disk, determining the speed of rotation and attempting to keep it relatively steady, racking the location of the head and returning it to zero, and sometimes functionally to format a disk based on simple inputs like the number of tracks, sectors per track and number of bytes per sector.

To produce a complete system, the controller has to be combined with additional circuitry or software that acts as a bridge between the controller and the host system. In some systems, like the Apple II and IBM PC, this is controlled by software running on the computer's host microprocessor and the drive interface is connected directly to the processor using an expansion card. On other systems, like the Commodore 64 and Atari 8-bit family, there is no direct path from the controller to the host CPU and a second processor like the MOS 6507 or Zilog Z80 is used inside the drive for this purpose.

The original Apple II controller was in the form of a plug-in card on the host computer. It could support two drives, and the drives eliminated most of the normal onboard circuitry. This allowed Apple to arrange a deal with Shugart Associates for a simplified drive that lacked most of its normal circuitry. This meant that the combined cost of a single drive and controller card was roughly the same as on other systems, but a second drive could be connected for a smaller additional cost. 

The IBM PC took a more conventional approach, their adaptor card could support up to four drives; on the PC direct memory access (DMA) to the drives was performed using  IRQ 6. The diagram below shows a conventional floppy disk controller which communicates with the CPU via an Industry Standard Architecture (ISA) bus or similar bus and communicates with the floppy disk drive with a 34 pin ribbon cable. An alternative arrangement that is more usual in recent designs has the FDC included in a super I/O chip which communicates via a Low Pin Count (LPC) bus. 

Most of the floppy disk controller (FDC) functions are performed by the integrated circuit but some are performed by external hardware circuits. The list of functions performed by each is given below.

Floppy disk controller functions (FDC) 
 Translate data bits into FM, MFM, M²FM, or GCR format to be able to record them
 Interpret and execute commands such as seek, read, write, format, etc.
 Error detection with checksums generation and verification, like CRC
 Synchronize data with phase-locked loop (PLL)

External hardware functions 
 Selection of which floppy disk drive (FDD) to address
 Switching-on the floppy drive motor
 Reset signal for the floppy controller IC
 Enable/disable interrupt and DMA signals in the floppy disk controller (FDC)
 Data separation logic
 Write pre-compensation logic
 Line drivers for signals to the controller
 Line receivers for signals from the controller

Input/output ports for common x86-PC controller 
The FDC has three I/O ports. These are:
 Data port
 Main status register (MSR)
 Digital control port

The first two reside inside the FDC IC while the Control port is in the external hardware. The addresses of these three ports are as follows.

Data port 
This port is used by the software for three different purposes:
 While issuing a command to the FDC IC, command and command parameter bytes are issued to the FDC IC through this port. The FDC IC stores the different parameters and the command in its internal registers.
 After a command is executed, the FDC IC stores a set of status parameters in the internal registers. These are read by the CPU through this port. The different status bytes are presented by the FDC IC in a specific sequence.
 In the programmed and interrupt mode of data transfer, the data port is used for transferring data between the FDC IC and the CPU IN or OUT instruction.

Main status register (MSR) 
This port is used by the software to read the overall status information regarding the FDC IC and the FDD's. Before initiating a floppy disk operation the software reads this port to confirm the readiness condition of the FDC and the disk drives to verify the status of the previously initiated command. The different bits of this register represent :

Digital control port 
This port is used by the software to control certain FDD and FDC IC functions. The bit assignments of this port are:

Interface to the floppy disk drive
The controller connects to the drive using a flat ribbon cable with 34 connectors split between the host, the 3.5" drive, and the 5.25" drive. This type of cable is called a universal connector. In the IBM PC family and compatibles, a twist in the cable is used to distinguish disk drives by the socket to which they are connected. All drives are installed with the same drive select address set, and the twist in the cable interchange the drive select line at the socket. The drive that is at furthest end of the cable additionally would have a terminating resistor installed to maintain signal quality.

More detailed descriptions of the interface signals including alternative meanings are contained in manufacturer's specifications for drives.

Format data 

Many mutually incompatible floppy disk formats are possible; aside from the physical format on the disk, incompatible file systems are also possible.

Sides:
 SS (or 1S) – Single sided
 DS (or 2S) – Double sided

Density:
 SD (or 1D) – Single density (FM)
 DD (or 2D) – Double density (most often MFM)
 QD (or 4D) – Quad density
 HD – High density
 ED – Extra-high density
 TD – Triple density

"3mode" floppy drive 

Primarily in Japan there are 3.5" high-density floppy drives that support three modes of disk formats instead of the normal two – 1440 KB (2 MB unformatted), 1.2 MB (1.6 MB unformatted) and 720 KB (1 MB unformatted). Originally, the high-density mode for 3.5" floppy drives in Japan only supported a capacity of 1.2 MB instead of the 1440 KB capacity that was used elsewhere. While the more common 1440 KB format spun at 300 rpm, the 1.2 MB format instead spun at 360 rpm, thereby closely resembling the 1.2 MB format with 15 sectors per track previously found on 5.25" high-density floppy drives. Later Japanese floppy drives incorporated support for both high-density formats (as well as the double-density format), hence the name 3mode. Some BIOSes have a configuration setting to enable this mode for floppy drives supporting it.

See also 
 Western Digital FD1771
 Integrated Woz Machine (IWM)
 Paula (Amiga controller)
 Floppy disk drive interface
 List of floppy disk formats

References 

 
 ISO/IEC 8860-1:1987 Double-Density (DD)
 ISO/IEC 9529-1:1989 High-Density (HD)
 ISO 10994-1:1992 Extra-high-density (ED)
 ECMA-147

Further reading

External links 
 viralpatel.net  A Tutorial on Programming Floppy Disk Controller
 isdaman.com Programming Floppy Disk Controllers

Computer storage devices
Floppy disk computer storage
Integrated circuits