Stepper motor position control using pololu driver

29 Apr 2011

Hi, I'm kinda new in electronics and aslo in C programming .any advise on how to control the position of a stepper using pololu stepper driver. I want to move the stepper to three position. position 1 - 45 degree, position 2- 90 degree and position 3- 135 degree and my stepper has a 7.5 degree step angle .

please give me some advise.

Thank you.

29 Apr 2011

Hey Rigonto,

Since the number of steps that you have to make (6 steps for 45deg) an acceleration ramp isn't really helpful I think, unless you want ridiculous speeds.

I assume you want them to move to the positions on command (button pressed, code received in a message etc.)? I think you should make a counter for the actual position it's in. (0 on reset) This counter represents the position it's in. 6=45deg, 12=90 etc. Next to that you'll need a target position, which has the same values.

If target > actual then it has to move in one direction. If target < actual then it has to move in the other direction (change Direction..) The amount of steps that have to be taken are target-actual (or actual-target, to give a positive number in both cases..). You can make the steps with a little for or whatever.

Remember to change your output to 1 and back to 0 for every step ;) as the polulu wants rising edges.

See how far this gets you, depending on how demanding your application is it might be enough.

Cheers,

Melchior

29 Apr 2011

I also assume you have a driver like this one? http://www.pololu.com/catalog/product/1201

You can use the minimal wiring diagram, plus I think you need to connect the !enable pin to either ground or to a pin on your mbed and make the pin low to enable the drive.

There's a little pot on the board which you can change to limit the motor current. My power supply is a bit weak so I can't run the motor at "full power". When looking at the minimal wiring diagram on the pololu site, turning the potmeter counter clockwise sets the current limit lower.

The 5V power you can make using a simple 7805 supply if you don't have a power supply yet. Vmot goes in, 5V comes out. Add some capacitors from 5V to ground and from Vmot to ground to make the voltage smoother.

I have written a little program that turns the stepper for a given index, speed and acceleration. It's probably not much good for your application, but you can have a look at it to get an idea. You'll just have to change the values so it fits with your motor. Speed would be 48 * 16thmicro for 1 rotation per second.

Import programlazysteppercontrol

Simple pulse direction program for testing stepper motors.

I should change the name huh..

Also make sure you connect your stepper motor to the pololu drive correctly :)

Good luck!

Melchior

01 May 2011

Hi Melchior,

Thanks for you advise,helped me a lot to start.Thank you

02 May 2011

hi Melchior, I'm struggling to control the stepper in between 0-180. I'm thinking to keep the stepper at 90 (home position) so that I can go to either 45 degree or 135 by simply deifinig one step index for 96 micro steps (step angle 7.5) and changing the direction. And i'm thinking to put two machanical stop at 0 and 180 degree. Please advise.

Thank you

03 May 2011

How exactly are you controlling the motion? Does the mbed loop between the three positions in a pattern? Or do you send it commands via USB or something, to make it go to one of the three positions?

What sort of problems are you having? Can't figure out how to code it? Or the motor doesn't keep up?

With 96 microsteps you can use my sample code to make a smooth movement. But I need more specific info to help you further.

Melchior

03 May 2011

mbed will control stepper according to PIR sensor modules movement detection. I'm using three pir sensor module which are placed in three different positions to cover 180.If PIR detects any motion , say PIR1 at 30 degree detect motion and send active low output to mbed and mbed rotate the stepper to 30 degree position. and for PIR2 will be 90 degree position ,(since PIR has 60 degree detection angle) For PIR3 150 degree position.I haven't figured it out yet how to write code.

I have replaced the stepper .new one has 1.8 degree per step.Thank you.

Digonto

04 May 2011

Okay, there's a few things to think about. You definitly need a variable for the absolute position.

To keep things simple, I would say that the stepper finnishes it's motion every time a sensor detects something. In other words, if sensor1 detected something and starts movement to 30 degrees, interrupts from the other sensors are ignored untill the stepper is at 30 degrees.

There is some info at the InterruptIn "Working with Interrupts" in the handbook on how to dissable interrupts temporarily I believe. (I think you'll want your sensor connections to be of the kind interruptIn)

You basically have three target positions. And you have to calculate howmany steps have to be moved from the absolute position.

If your sensor3 detects something and the stepper motor is at absolute position 0, the stepper has to move for 83 steps (1333 at 16th microstep). You basicly do target-absolute every time.

So now your motor moved to the absolute position of 1333. And sensor 1 fires. The target position is now 17 steps (267 at 16th). 267-1333 = -1067. Result<0? change direction and do 1333-267 instead.

This should be relatively easy to implement on top of my example code or on your own code.

Hope it helps.

Melchior

04 May 2011

Oh right and the other thing to think about is how to initialize your motor. If you reset the mbed while your motor is at 90 degrees, the absolute position will be reset to 0. Causing your motor to be off by 90 degrees :p

You may have to add an encoder wich can find a 0 position if this is a problem. Otherwise you have to check your motor before you turn on the power every time and move it to roughly the right position manualy...