maandag 2 december 2013

Microstepping with Arduino

I bought these stepper motors online for a project I'm working on. I'm trying to build a small CNC machine to cut and drill in light materials such as plastic housings or PCBs. The main issue for this purpose will be accuracy in the stepper motors that drive the X- and Y-axis. Torque is not a big deal, since I won't be cutting hard materials.

These motors were cheap for a reason: the step angle is 3.75°, making 96 steps in one revolution. That's not very accurate as steppers go, so for my purpose they may not be suitable. That's te reason why I tried to write some new Arduino code to make them more accurate using microstepping.

As you can see on the picture, the motor comes with six wires, so I could choose to drive it like a unipolar or a bipolar stepper motor. I chose the latter method, since my L293D driver chips support 0.5 Amps current per winding, which is exactly what the supplier claims to be the working current of the motor.

The Arduino code I wrote can now drive the stepper motor in full stepping, half stepping and microstepping. Full stepping would be the best choice if you want maximum torque, half stepping and microstepping are more useful if you need accuracy.

I hooked it up to an oscilloscope to see what waves come out in the different methods. Note that this is only half of the story, meaning the pictures only show one winding (A,B). I use a very old machine as you can see, hooking up two channels to the four wires of the motor would shortwire the driver chip because the scope uses a common ground between the channels. Actually, I had to make the mistake first to find out that the motor stopped and things got hot very fast when connecting channel two ;-)

Now, just imagine channel two (C,D) showing the exact same picture, only with a 90° phase shift. This is what it looks like:



ABCD
1+-+-
2+--+
3-+-+
4-++-
ABCD
1+-+-
2+---
3+--+
4---+
5-+-+
6-+--
7-++-
8--+-
ABCD
1+-+-
2+-½-
3+---
4+--½
5+--+
6½--+
7---+
8-½-+
9-+-+
10-+-½
11-+--
12-+½-
13-++-
14-½+-
15--+-
16½-+-

Full stepping is pretty straight-forward. Just switch polarity on channels (A,B) and (C,D).

Half stepping introduces four extra steps (2,4,6,8) where only one of the four wires is connected to Vcc (the plus side of the power source of the motor), the other three are connected to ground. This means that only one winding is activated in these steps.

In microstepping, eight new steps are introduced which have columns marked '½' for convenience. What it actually means is that my Arduino code switches at a high frequency between two half stepping steps, creating these thick vertical lines on the scope. Step 6 is actually a fast alternation between step 5 and 7.

This is one of these steps in detail. Note that other options are possible with this approach, because when I use these waveforms, the duty cycle can be altered.

This example has a duty cycle of 25%, so it's 25% high and 75% low.




This is what happens when we would create even more steps with different duty cycles.

Instead of inserting one '½' step (or '50% step' like step 6 above), we could insert three new steps 25%, 50%, 75%.




The only difference between the previous microstepping and this one is the vertical thick lines being a bit thicker. But this is what really happens in the code: the duty cycle is incremented from 25 to 50 and then 75%. This creates a 32 steps microstepping model.




Check out this video where I tried to check how far I could go with this motor. I used a mirror on the motor and a powerful LED flashlight to see the refection on the wall. That's the only way to notice these small changes.



I boosted it up to 64 steps, but that's not really useful. In fact, I'm now assuming that a 25% duty cycle in the waveform correponds to a 25% movement between the steps and that's just not true. In fact, in the video I already adjusted some values to correspond to actual movement of the light. So a 25% duty cycle corresponds to a movement of 40 or 50%. It's a bit trial and error and only meaningful up to 32 steps in my setup.

Still, I'm pretty happy with my results! It means I can use my motors at least in 16 steps microstepping, maybe 24 or 32. It means my motors will be at least four times more accurate !

UPDATE
After more testing, I found that boosting the voltage near to the maximum allowed for my motor (so it gets its 500mAmps per winding), results were much more accurate. Even 96 microsteps were possibible resulting in a perfect lineair movement of the motor, much better than the 64 steps in the video.

The source code can be found here:
HTML readable
ZIP source file --> zipped .ino file (Arduino)

6 opmerkingen:

  1. Super! Merci beaucoup pour mon Rail Photo!!!

    BeantwoordenVerwijderen
  2. Fantastic work, thanks for sharing this information

    BeantwoordenVerwijderen
  3. Hi, very nice work
    can you please provide schematic for testing the code
    thanks

    BeantwoordenVerwijderen