skip navigational linksPJRC
Shopping Cart Checkout Shipping Cost Download Website
Home MP3 Player 8051 Tools All Projects PJRC Store Site Map

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!

The Interactive Disk Spin lives at Freegeek, and was also partly inspired by a made-from-recycled-parts art show hosted by Freegeek and Scrap.

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 is only changed at a reasonable rate that "feels" fast, but is actually very slow. The vast majority of all the measurements are simply discarded, which makes the display respond in a way that looks very natural.

Cheating, Abuse & Countermeasures

When the Interactive Disk Spin was installed at Freegeek, several people quickly learned they could trick it into displaying a very high speed, if only briefly, by tapping the disk rather than spinning it. While the event seemed random, in fact this would occur when the magnets in the motor were position almost exactly between adjacent coils and the tap would quickly alter the position between one coil and then back again. The amplifier would detect the tiny voltage change and produce a very narrow pulse, which the AVR microcontroller could easily measure and turn into a "high score".

Of course, very few taps would result in a narrow enough pulse to make a 4-digit number, and many would not cause any change at all. The natural human tendency is to believe that striking it harder must be more effective than only tapping lightly, and indeed that became the norm. After many months, the motor bearing started to wear and the disk didn't spin as freely. The Interactive Disk Spin received a major upgrade, a motor replacement and metal cut away from the back side of the drive to make repairs and motor replacement easy, and also a software change to address "cheating".

A simple solution to the single narrow pulse problem would be to simply average the last few measurements, and avoid displaying anything until the buffer is full. Unfortunately, at slow speeds each individual half-cycle can be a considerable length of time. If many are averaged, the result could be a "slow" response time. Any human perceivable slowness would diminish the fun factor, so instead a more complex scheme was devised.

A buffer holds the last 16 measurements. The raw elapsed times from the half-cycles are stored in the buffer. In the first step, the stored times are added, until a total of 0.333 seconds is accumulated, or all 16 are summed, and of course the sum is divided by the number that were averaged. This guarantees the display will never show information older than 1/3rd of a second, unless of course the speed is under 15 RPM where the half-cycle is longer than 0.333 seconds (and the motor output is barely detectable by the amplifier), in which case the display shows the best that can be done with so little information.

The anti-cheat check is accomplished by inspecting the number of buffered readings that were used. If 16 measurements were in the buffer (the zero timer always clears the buffer), then there is very high confidence in the result and it is always "safe" to display it. If there are 15 or fewer, the total accumulated time is compared against a sanity check (15 different, depending on the number of readings). If the total time is less, the display is not updated. If the disk really did suddenly start spinning that fast, the buffer will quickly fill to 16 measurements in very rapidly, far faster than a human could perceive any delay. Of course, as the disk accelerates, the display can update. But when someone taps slightly, or hits the disk very hard, they will never be rewarded with anything more than a 2-digit number!

It's All About Fun

Many people have enjoyed the Interactive Disk Spin at Freegeek, and it never gets old watching people frantically trying to make it go faster, especially to see who can get the highest score.

Paul usually manages to get about 800 RPM. Several people have managed to spin into the low thousand RPM speed, which isn't as easy it might seem. Early on, Paul "tested" using a dremel tool with soft buffing pad attached, which was able to get the disk spinning over 9999 RPM, which Robin found very amusing!

Open Source Code

Download tach_1.03.tar.gz.

Or View just the main code. Search for t1_capture_isr for the part that captures the waveform timing, and main_loop for the code that receives those measurements and makes everything else happen.

Interactive Disk Spin
Paul Stoffregen