Controlling Floppy Disk Drive with Arduino
According to this (dead link):
http://bitsavers.trailing-edge.com/pdf/nec/FD1035_Product_Description_Jul84.pdf
This is an archived copy of the FD1035 3.5" Floppy disk drive: Product Description July 1984 - PDF:
https://archive.org/details/bitsavers_necFD1035Pl84_876629
The outputs are open-collector, so a pull-up resistor is required. You can instead enable the Arduino internal pull-ups on those pins by
pinMode(indexPin, INPUT_PULLUP);
pinMode(track0Pin, INPUT_PULLUP);
You should replace int
with unsigned long
in all locations where you deal with time in milliseconds.
The point is that millis()
returns an unsigned long
, thus using int
to store millis()
value, you have a loss of information due to automatic cast performed by the compiler.
The changes you have to perform are:
unsigned long motorSpinTime = 1000UL; //in ms
and:
//spins the disk motor for a number of ms and prints the state
void spinMotorForThisManyMs(unsigned long msToSpin) {
//start spinning
digitalWrite(motorEnableBPin,LOW);
//delay.. keep printing the state
unsigned long maxTimeMs = millis() + msToSpin;
while(millis() < maxTimeMs ) {
printState("Spinning");
}
//stop spinning
digitalWrite(motorEnableBPin,HIGH);
}
Note that I have also performed some optimization in the waiting loop by calculating the maximum time once and then compare millis()
directly to that value. This is not mandatory but I just find it a bit more clean.