Communications is I2C
For each servo there are only two parameters to deal with, Speed and Position
To control servo1 I need to write the speed into register 0 (speed is a byte-range0-255)
Then I need to write position which is a word (range 1900-2300) into registers 2 & 3, low byte first followed by hi byte.
I haven't used I2C before so I started out reading everything I could find about it. Seemed to me that using the I2C Library would make it quite simple to do this. Next I started with David's I2C EEPROM example and adapted it (I thought) ...to talk to the Servo controller - after many attempts so far no success.
Here's a link to the short "Manual" for the Devantech SD21 Servo Controller if that helps
ttp://www.robotstorehk.com/sd21tech.pdf
I sure appreciate any time you spend helping me out with this
Thank you
Bryan
Here's my last attempt at coding this:
Code: Select all
Device = 18F458
Clock = 10
// import libraries...
Include "I2C.bas"
'include "usart.bas"
// target SD21 Servo Controller device...
Const Servo_Controller = $C2
// local variables...
Dim
Address As byte, 'only need to access registers 0-65
Speed As Byte, ' 0 is Full speed, range0-255
Position As Word, '800 to 2200 (translates to uSec of pulse width, 1500=centered
Public Sub WritePosition(pAddress As Byte,pPosition As Word) 'SF doesn' like this !!
WriteByte(pAddress,pPosition.byte0) 'thought it might work
WriteByte(pAddress+1,pPosition.byte1)
End Sub
// program start...
Address = 0 'point address to first register
Speed=0 'full speed for now
Position=1500 'center position for initial test
I2C.Initialize
I2C.Start 'begin I2C comm
I2C.WriteByte(Servo_Controller) 'wake up the controller
WriteByte(Address) 'write speed to first reg
WriteByte(Speed)
Address=Address+1 'point at next register
WritePosition 'call Sub above to get position data written
'Problem here as I don't know how to convert
'Position word into LSB and MSB and then get
'them into the next two regs (2 & 3) LSB first.
I2C.Stop
DelayMS(10) 'allows Servo Controller to write data
DelayMS(1000) 'hold position for 1 second then move
end