Single direction servo maths help.

Status
Not open for further replies.

dr pepper

Well-Known Member
Most Helpful Member
I'm building a positioner servo with a microcontroller and a stepper motor, I need to position the motor in one of 16 positions, the motor needs to turn clockwise only, no reverse.

Any ideas on an efficient way in to C to calculate the number of positions to move forwards, ie if the motor in on position 8 and the next position command is 4, then the motor needs to move 12 positions forwards.
 
Last edited:
16 is an awful number if the positions need to be symmetrical!!! 1.8 or 3.6 degree steps both don't divide down!!

You will be half a step out with at least 8 of the positions..
 
I'm using a 7.5 degree stepper, divides no problem, and a step out on some would be ok anyway.

Thought you liked JD.
 
I'm actually back on the JD... I may change the bottle to Singletons..... I keep looking at it!!! It's a Christmas pressy!!
 
Assuming I have understood the question being asked. Subtract current position from desired position. If the answer is positive move that number of steps. if the answer is negative then subtract the magnitude of the difference from 16. In the mid 1970s I had a similar problem with an antenna tracking system (For the antenna to track radio amateur satellites.) I wanted it to take the shorted direction to move the antenna. For example if the antenne was pointing 350 degrees and the next position was 20 degrees I wanted it to move 30 degrees to the new position. Not 330 degrees.

Les.
 
Top mon Les, that sussed it.

Turned out I'd nearly understood it, I was adding 15 if <0, I wasnt taking zero into account 16 is the correct number.

I packed in booze years ago, but having a bit of scot im me I liked Mc Callan, esp the 12 year old stuff.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…