Scrap A Hard Drive, Build A Rotary Encoder

There’s something to be said for the feel of controls. Whether it’s the satisfying snap of a high-quality switch or the buttery touch of the pots on an expensive amplifier, the tactile experience of the controls you interact with says a lot about a device.

[GreatScott!] knows this, and rather than put up with the bump and grind of a cheap rotary encoder, he decided to find an alternative. He ended up exploring hard drive motors as encoders, and while the results aren’t exactly high resolution, he may be onto something. Starting with a teardown of some old HDDs — save those magnets! — [Scott!] found that the motors fell into either the four-lead or three-lead categories. Knowing that HDD motors are brushless DC motors, he reasoned that the four-lead motors had their three windings in Wye configuration with the neutral point brought out to an external connection. A little oscilloscope work showed the expected three-phase output when the motor hub was turned, with the leading and lagging phases changing as the direction of rotation was switched. Hooked to an Arduino, the motor made a workable encoder, later improved by sending each phase through a comparator and using digital inputs rather than using the Nano’s ADCs.

It looks like [GreatScott!]’s current setup only responds to a full rotation of the makeshift encoder, but we’d bet resolution could be improved. Perhaps this previous post on turning BLDC motors into encoders will help.

26 thoughts on “Scrap A Hard Drive, Build A Rotary Encoder

    1. Well… If you feed that 100V into the MCP6002 opamp, it’ll come right out the VCC pin that’s connected to the nano anyway…. But with a current limit resistor that can be mitigated.

      Anyway, you can use the input circuit of the AVR as the comparator. Just tie the star-point to VCC/2.

  1. GreatScott!’s setup has a few flaws, though – the opamps he is using are low voltage one and he has no clamping on the input signals – spin the motor fast enough and the generated EMF voltage will likely blow them.

    The second problem is that this setup will actually respond only if you turn the motor fast enough – the voltage generated depends on how fast the rotor turns. So probably not that great for precise control without some modification.

  2. I wonder if it would be possible to make it spin by itself (it’s still motor after all) at low-torque while still remaining the ability to work as encoder? That would make nice DJ controller, since most controllers do not spin by themselves as vinyl deck does.

    That would need to make some hybrid BLDC motor driver that would be able to detect EMF spikes without interferring with them.

      1. Or get one from an inkjet printer, although those have often ridiculously high resolutions ie. 1000 lines per rotation = 4000 counts, needing a fast ISR or dedicated counter chip.

        1. Or a dedicated encoder counting timer. The STM32 has a couple of timers that have this mode. So with 4000 counts per revolution, as long as you’re not exceeding 1000 rotations per second (60k RPM!) that should continue to work…..

          Doesn’t the AVR have one too?

  3. There appears to be a single hall effect sensor on the back. Not enough for quadrature direction detection from just one. The HD controller already knows which direction it’s spinning. I’m sure it just uses it for RPM and maybe relative phase. However, you could improve the experience by using the hall sensor for counts and the motor induction for direction.

  4. Maybe you can energize one leg and compare amplitude and phase of the other two like a Selsyn. You can get very high resolution by correlation – multiplying the samples from one cycle by the samples from a reference and adding them up. It is called an “optimal filter” in some places.

    1. I was thinking along the same lines. The only motors that I have are 3 wire motors, so I drove a 2KHz sine wave across two of the wires. Watching the amplitude from one of the driven wires to the undriven wire, you get kind of a double hump sinusoidal amplitude variation as you turn from pole position to pole position. There may be a pole position between those two humps, but it is pretty soft if there is. This makes sense if you are driving two of the phases, 120 degrees (electrically) apart and sensing on the third. It would work better with a 4 wire motor because you would have two phases to watch to recover position information from, and you would not be measuring across one of the phases that you are driving across. I was kind of expecting to see a phase change between the driving waveform and the sensed waveform as the motor was turned, but the output signal stayed in the same phase relationship with the input signal through out the motion.

  5. So I built/use something like this as a USB scroll wheel that uses a 5″ platter stack. I did a lot more work on the analog front end — with decoupling caps and an adjustable voltage threshold for eath of the three channels. I also updated in software on every pole’s zero crossing. I think I get a lot more steps per revolution than are apparent in the video.

    If I were doing the project again, I would bias the whole motor around mid-rail so that it’s not running the comparator below it’s ground rail. I.e. using VCC/2 instead of GND at the common point in the wye. Done right, I can imagine this getting rid of the need for comparators entirely.

    As someone said in the comments, though, using the motor as a generator _does_ require you to spin it at a minimum speed before it generates enough voltage to trip a comparator. I can spin my platter slowly enough that it doesn’t scroll. That said, it’s entirely useable, and very pleasant for reading long PDFs.

    1. A long time ago, I did something similar with a really old laptop HDD, except I used the PCB and encoder out of an old mouse and actually coupled it to the platters. Needless to say, figuring out the mechanical part wasn’t quite trivial…

  6. Why not simply write out a “servo track” (“encoder track”) onto the platter and read that? Then you could have a pretty high-density encoder pretty cheap. You would have to watch out for crashing the heads, though there’s no reason why you couldn’t alter the spacing a bit to make that less problematic. There’s no rule that says you would have to write / read at the same original distance / density, or even with the same electronics…

  7. Its the budding start to a resolver almost; might be more possible to utilize something from that train of thought versus encoders// with the motor windings its vaguely already there. I think someone mentioned injecting sine-waves into one or more windings, I would look at something like inducto-syn technology in that case

  8. When you take those HDDs apart, don’t forget to keep the bearing on which the head arm pivots. Those are just about the highest precision bearings you can get and they can be useful in all sorts of small projects. I have used them in the Z=0 switch in my 3D printer, a printable Van DeGraaff generator, and in a tangle-free filament spool holder for the 3D printer. The bearing usually press-fits into the arm and can be pushed out pretty easily without damaging the bearing.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.