Controlling servo speed with 18X / SD21

Spuddly

New Member
Hi there,

I'm trying to control the speed of a servo connected to the SD21 21 channel servo controller module (containing the PICAXE 18X) using Basic. The documentation that comes with the SD21 (http://www.robot-electronics.co.uk/htm/sd21tech.htm) says it is possible to control the speed, but doesn't say how. I've looked everywhere for code or hints about how to do this, but can't find anything. Is there anyone out there who could give me a few lines of code demonstrating this (or change the example code below?):

Servo1 = 63 ' servo 1 base register
Servo1p = 84 ' servo 1 positive offset register
Servo1n = 105 ' servo 1 negative offset register
Base = 128 ' centre position
Offset = 50 ' +/- 50 from centre position
ProgStart:
i2cslave $c2, i2cslow, i2cbyte ' setup i2c port for servo controller
writei2c Servo1, (Base)
Loop:
writei2c Servo1p, (Offset)
pause 300
writei2c Servo1n, (Offset)
pause 300
goto Loop


Any help would be much appreciated! Thanks in advance!
 

hippy

Technical Support
Staff member
Servo control is about positioning a servo and it will jump to where it is instructed to point to at the fastest rate it can go. To control the speed of movement it therefore means not jumping from one point to another, but stepping through all teh intervening points at a selected rate.

Thus instead of jumping from A to B ...

- Send command to go to position A
- Pause a while
- Send command to go to position B

You would glide from start to finish using something like ...

- For P = A to B
- Send command to go to position P
- Pause a short while
- Next
 

Mycroft2152

Senior Member
It looks like the SD21 has a built in speed ramping function. According to the datasheet it is a matter of putting values in spcific registers.
 

hippy

Technical Support
Staff member
It looks like the SD21 has a built in speed ramping function. According to the datasheet it is a matter of putting values in spcific registers.
I've since looked at the data sheet and agree. To alter speed it's just a matter of setting the speed register for the appropriate servo -

- I2cWrite 0,(speed) ' Set servo 1 speed

The bigger the number, the faster it moves.

Use of the "More Registers!" registers took a couple of readings to fully understand what was going on there. It would have been better IMHO to have duplicated the BS2 version of code for the PICAXE ...

- SYMBOL Speed = 0 ' maximum speed <-- Adjust this 0..255
- SYMBOL Servo1p = 1800 ' Right position
- SYMBOL Servo1n = 1200 ' Left position
-
- SYMBOL Servo = w0
- SYMBOL ServoLOWBYTE = b0
- SYMBOL ServoHIGHBYTE = b1
-
- Loop:
- Servo = Servo1p
- I2CWRITE Servo1, (Speed, ServoLOWBYTE, ServoHIGHBYTE)
- PAUSE 300
- Servo = Servo1n
- I2WRITE Servo1, (Speed, ServoLOWBYTE, ServoHIGHBYTE)
- PAUSE 300
- GOTO Loop
 
Top