Interactive Disk Spin
The Interactive Disk Spin was born one fateful night when Paul took the cover off an old hard drive, started compulsively spinning the shiny platters with his finger, and then wondered "how fast am I really making it go?" Two late-night sessions later, this whimsical gadget was completed. It could be claimed to impart an appreciation for just how fast hard drives really spin, or embody some unique geeky artistic insight, but it's really just fun to see how fast you can make it go!
How It Senses Speed
The spindle motor acts as a generator when you turn the disk with your finger. Only a tiny amount of power is generated at low speeds, but that really does not matter. It is the timing of the generated waveform that is important.
The motor produces a sine wave output, with 6 cycles per revolution of the disk as the magnets on the rotor pass over the coils. More current is generated at higher speeds, which translates into higher voltage. All the generated power is fed into a resistor, so a nice low-noise waveform is made.
An amplifier converts the sine wave, which can be only a few millivolts at slow speeds, into a 5 volt square wave. The amplifier is just a simple LM393 voltage comparator, with bias resistors and a tiny amount of hysteresis (about 3 millivolts) so that the Interactive Disk Spin isn't sensitive to noise.
Measuring Sine Wave Half-Cycle Times
An AVR ATMEGA16 microcontroller measures the period of the waveform. The input capture feature of its 16 bit timer allows a timer which increments at 7.37 MHz to be captured at the precise moment the amplifier outputs a transition from high to low, or low to high. This allows 12 highly accurate measurements during each revolution.
With 135.6 ns precision, square waves as fast as 368.64 Hz can be measured before the timer resolution is 0.1% error (off by 1 in the lowest digit on the display), but that corresponds to 22118 RPM! In other words, Interactive Disk Spin can easily measure all the way up to 9999 RPM with minimal error.
The 16 bit timer in the AVR chip quickly overflows. An interrupt routine is used to extend the counter to 32 bits, which allows a half cycle up to 582 seconds! Of course, the motor doesn't produce a strong enough signal for reliable measurement (using the simple LM393 voltage comparator as the amplifier) below about 50 RPM.
Every time the interrupt routines measure a new 32 bit half-cycle timing measurement, the main program simply converts the measured time into RPM and displays it on the four 7-segment displays. Of course, there are a couple complications.
Standing Still, Zero Is Special
Using only the waveform timing measurements, it is impossible to measure zero speed. Because zero is so important, another timer is used. Every time a new measurement is completed (the amplifier gave a transition), the timer is reset. If the timer period elapses, it is assumed the disk as stopped and the display is set to zero. Despite many attempts to tweak this timing, the delay is always somewhat noticeable when playing with the disk and suddenly stopping it, where the last measurement remains on the display until the timer expires.
The Code Is Too Fast
The timer also is used to limit the update speed to the display. The code can do the conversion to RPM and update the display very quickly, in much less time than the disk can physically spin to make the next interrupt, even at 20000 RPM (early testing was done with a signal generator to simulate these speeds).
Updating the display too quickly causes all the lower digits to flicker so rapidly they appear to the human eye as the number 8, perhaps not fully illuminated, though the eye is very forgiving and basically sees the number 8. So the timer is also checked every time a new measurement is available and the display...Read more »