N20 miniature geared motor with AS5600 encoder

In this video, I show a different approach to accurately position things with the N20 miniature geared motor. Originally, these geared motors come with a magnetic encoder installed on the motor’s shaft, but based on my experience so far, they are not too accurate for positioning. This is mainly due to the fact that there is a wonky gearbox between the actual driven shaft and the motor. This gearbox suffers from backlash which messes up the positioning. It is not super noticeable when the motor drives a lead screw, but it becomes very bad when circular motion is needed, for example when the shaft of the gearbox should position a wheel on a 0-360° coordinate system. In this article, I propose a possible solution for this issue.

Technical information

So, the issue is the following. I want to rotate something on a scale of 0-360°. For example, I want the motor to the 175° position, then back to 0° and then I want to repeat this 100 times. I noticed after a while that the shaft was drifting, despite the fact that based on the encoder, the positioning was always within a few encoder pulses of the target position. Since the gearbox has many gears in it and they are probably far from perfect, there is a noticeable backlash. Also, there is an uncertainty in the position of the gearbox shaft as well. The shaft can be rotated a few degrees plus or minus without moving the rest of the gearbox.

So basically the main issue here is that the motor thinks that it arrived at the target position because according to the encoder on its shaft, it suggests so, but in reality, there are a lot of things going on in the gearbox. So even though the encoder registered the number of pulses which correspond to the target position, the main shaft on the encoder is not at the actual target position. But of course, this makes sense, because the encoder is far from where the driving occurs (main shaft of the gearbox), so it cannot account for the issues within the gearbox.

The solution for this issue is to add an encoder to the main shaft. With this approach, the encoder would actually see what happens on the load side instead of looking at the motor. There are a few things that might discourage people from using this approach:

  • A 3d-printed bracket is needed for mounting the encoder

  • A tiny (d = 1 mm) diametrically magnetized (a.k.a. radial) magnet is needed

  • An additional encoder (AS5600) is needed

However, the encoder is extremely cheap, the magnet is also easy to source and I provide some design files for the bracket.

Just to understand how the positioning works when the default encoder is used for positioning, let' me show you an example.

Typically, the motors are equipped with a 3 PPR (pulses per revolution) or a 7 PPR encoder. Let’s use the 7 PPR encoder in this example. The gearboxes can differ, but let’s take a 1:50 gearbox in this example. So, when the motor completes a full turn, the encoder should register 7 encoder pulses. Also, the main shaft of the gearbox should have rotated 1/50th of a full turn, so about 7.2 degrees. To do a full turn on the shaft of the gearbox, the motor’s shaft has to rotate 50 times because of the gear ratio of the gearbox. That is also 50x7 = 350 pulses. So, if the microcontroller registers 350 pulses, it is safe to assume that the main shaft was rotated by 360°.

Based on the encoder and the gearbox, we can estimate the angular resolution of the main shaft. Since we know that a full turn on the shaft of the motor rotates the main shaft by 7.2°, and we also know that the encoder can generate 7 pulses per revolution, then one pulse-to-pulse rotation is about 1.03 degrees. But this is a “theoretically optimal value”, plus it is a very bold assumption that we can make the motor move only between 2 pulses. Nevertheless, based on these back-of-the-envelope calculations, the resolution is about 1 degree. This can be improved with a better encoder (difficult) or a gearbox with a higher gear ratio. However, a higher gear ratio means slower speed, even though the torque is higher.

So the solution is to monitor the main shaft with an AS5600 magnetic encoder. By using this encoder, the angular resolution on the main shaft becomes 0.088° which is quite high. And since this shaft, due to the large gear ratio, typically rotates slowly, we don’t need to worry that we overwhelm the encoder with a too-quickly rotating shaft.

Then finally, the only thing that is needed is to set up a PID algorithm that drives the motor until the target position is reached. Since the AS5600 reads angle, the easiest to do is to define the target position in degrees. However, if you know the characteristics of the mechanism that you drive (for example, a lead screw with a known pitch), then you can convert the target position to another unit.


Additional resources

 
 

Previous
Previous

How I Automated My Metallurgical Microscope

Next
Next

RP2040-ADS1256 DAQ module with GPIOs