View Full Version : Best way to control rotation of motor?

04-12-2007, 05:18 AM
I am using an electric motor for a school project and am tyring to figure out how to control the rotation of a motor. I want it to rotate half a rotation. I have an encoder already wired into the basic stamp, and have a program that reads the position of the motor. I have a couple of h-bridges available that have brake, dir, pwm commands on them. Anyone have any ideas to help me out?

Mike Green
04-12-2007, 05:31 AM
You mention that you have been able to read the position of the motor already using the encoder. What have you been able to do with controlling the movement of the motor (irrespective of the position of the motor)? Once you can get the motor to go in different directions and stop, you can combine the two sets of routines. You need to make the motor rotate in the direction you want, slow it down as it approaches the position you want it to end up at, then stop the motor as it reaches that position. If this seems a little obvious, it should be a simple solution once you know how to control motor motion and determine actual position.

04-12-2007, 05:31 AM
Sounds like you have everything you need.· A very low duty cycle PWM setting on your hBridge will move the motor slowly.· The direction it rotates depends on which transistor pairs are enabled in the h-Bridge.· One pair gives forward and the other gives reverse.· Using to I/O pins on the stamp wil let you enable forward or reverse based on code.

forward pin 5

reverse pin 6


low pin6 'disables reverse pair

high pin 5 'enables forward pair



low pin5 'disables forward· pair

high pin·6 'enables reverse pair


Make sure to buffer the stamp pins to the hbridge I use 2N3904

after the motor starts moving read the encoder until 1/2 rotations. you have to know where the motor is starting from.

04-12-2007, 05:42 AM
So if I find out how many position steps there are from the encoder, use a low PWM duty cycle from h-bridge, and set the h-bridge to brake when it hits the position I want, it should work?