Saturday, June 30, 2012

Modifying servo for continuous rotation and adding digital encoder - part 2

Now we'll add encoding capabilities to the servo so it can report it's incremental or/and absolute position. I'll be using AS5040 - 10-bit Absolute Programmable Magnetic Rotary Encoder with Incremental, SSI, and PWM Output from ams (ex- austriamicrosystems and TAOS) with incremental mode on, but if you care to re-program the device, it can feed you step/dir data. And if you modify PCB you can also use absolute position (that can be read through SPI as well as PWM/analog output).

What you'll need:

  • the pot that you salvaged from the servo
  • AS5040 magnetic encoder with a magnet* (read below about the magnet!)
  • a few SMD resistors and caps
  • everything that it takes to make a PCB
  • glue (I used superglue, but I actually think this is the worst idea I could come up with)
  • IDE cable (5 wires)
  • 5-pin connector (that fits into your project)
  • Soldering iron
  • Side cutters
  • File
  • Magnifier
  • Patience
*You will need a special magnet for this. Read more in datasheet. Be warned that most of neodymium magnets will not work as they are magnetized axially, and we'll need diametrically magnetized ones.

Modifying pot

The pot that sits inside of 1501MG is perfect in all the ways - it's got its metal shaft that fits into the output gear of the servo, it's got thick enough for magnet case with three holders. All of these will help us make a great magnetic encoder.

1501MG servo pot modification
  1. Carefully streighten the holders that hold the resistive material and pins to the body of the pot. Don't break them or cut them - this will make your life harder.
  2. Take that resistive thing with pins off and throw it away
  3. Carefully remove the slider from the pot rotor and throw it away
  4. With cutters take off the positioning pin from the outsite of the pot's body and use file to remove any remaining material
  5. Use a small screwdriver and a hummer to remove the limiting pin inside of pot's body. Be very careful not to deform the body itself. The shaft must rotate full 360 degree circly ubsolutely freely.
  6. Attach magnet to the shaft and center it. Don't glue it yet.

Making the PCB

With PCB you may get really inventive. I didn't. I just measured insides of the servo, put in all the necessary holes to let magnet through the PCB and to attach the pot's body. Very little space remained to lay out ground and VDD paths as well as A, B and Index pins out through 220 Ohm resistors. I made 3,3V version as I'm going to use it with STM32. Making 5,5V will take an extra cap.
If done laying out, just make your PCB (if don't know how, ask Google. There's a method which we call here in Russia "Laser Iron" - works perfectly if you care to master it). I recommend using two-sided PCB (you'll see later why).
PCB etched and cut. Time to drill.
Drill one big hole for magnet (I used 7mm drill) and three small ones for pot holders (1,6mm). 

Assembling the PCB

Install the pot on the PCB, put your magnet into the hole, center it and check that when you rotate the pot shaft, PCB does not touch the magnet. If all's OK, take the magnet away and apply a drop of superglue to the center of the shaft. Put the magnet on the shaft and again, center it and check it rotates well. Wait till the glue cures.
Note that magnet and PCB are on the same level. Also, use holes on pot body as keys
to account for imperfections. Once you centered the magnet, it's not a great idea to turn the pot around.
Now carefully remove the pot with the magnet from the PCB and use "proper" glue to glue the magnet. First time I used just superglue, but I hate the idea - I got used from my childhood that superglue wears off with time (maybe todays superglues are different). Also we'll need to remove flux using a removal liquid and I don't know how superglue will withstand that. My first servo works with it however... Second attempt was to use glue gun - which is even more stupid idea when you think of it. You can't get the gun to the place you need to apply the glue to, it cures very fast and you need to use soldering iron to fix it, you have almost zero control over the glue drop and may easily glue shaft to body, and to crown it, you can't really apply heat to neodymium magnets! It's not good for magnetization and it is particularly bad for your health as when you heat such a magnet it starts producing very unhealthy products. Don't do that, really. Use more appropreate glue, ask someone more wize than myself.
Ok, now that the magnet is glued, stick the pot into the PCB and check again if everything works well. If yes, solder the body holders to the PCB from the bottom side.
The pot is soldered to PCB
Populate PCB, wash out flux and check that the thing works.
Remove flux and apply some glue to hold wire in place, so
it's rigit and doesn't look like on this picture :-)

Testing and assembling

You'll need to apply 3,3V and check with the scope that you've got your signal on the output. You should see something like this:

Depending which way you rotate the shaft of the ex-pot, either yellow or blue waveform will be leading.
So, if everything works, just a few little steps left. Stick your PCB with your pot into the servo so pot shaft gets out of the hole in the gears pit. Glue the PCB inside the servo (this time glue gun will work perfectly).
If you can't see the PCB glued inside of the servo,
you'll just have to believe me it's in there
 Now assemble the servo and test how it works. Next post will be about how to control it, but you'll well get away with knowing the rest position is at pulse length of 1515us and with google.
It's got feedback!

Post a Comment