servo32v3 object
seadog13
Posts: 9
hey all, have a question for ya.
I am using the servo32v3 object and trying to get multiple servo's to work. I saw in the object file that that a max of 8 servos would receive a pulse at a time.
Only using two servo's attached different pins, I can only get one to move at a time. Is there a way to get two of them working at the same time? If so, can they go in opposite directions?
sample code that i'm using:
pub main
···· repeat
···· servo1
···· waitcnt(clkfreq + cnt)
···· servo 2
pub servo1
··· servo.set(servo1,1200)
··· waitcnt(clkfreq+cnt)
··· servo.set(servo1,1500)
··· waitcnt(clkfreq+cnt)
··· servo.set(servo1,1800)
··· waitcnt(clkfreq+cnt)
pub servo2
··· servo.set(servo2,1800)
··· waitcnt(clkfreq+cnt)
··· servo.set(servo2,1500)
··· waitcnt(clkfreq+cnt)
··· servo.set(servo2,1200)
··· waitcnt(clkfreq+cnt)
I am using the servo32v3 object and trying to get multiple servo's to work. I saw in the object file that that a max of 8 servos would receive a pulse at a time.
Only using two servo's attached different pins, I can only get one to move at a time. Is there a way to get two of them working at the same time? If so, can they go in opposite directions?
sample code that i'm using:
pub main
···· repeat
···· servo1
···· waitcnt(clkfreq + cnt)
···· servo 2
pub servo1
··· servo.set(servo1,1200)
··· waitcnt(clkfreq+cnt)
··· servo.set(servo1,1500)
··· waitcnt(clkfreq+cnt)
··· servo.set(servo1,1800)
··· waitcnt(clkfreq+cnt)
pub servo2
··· servo.set(servo2,1800)
··· waitcnt(clkfreq+cnt)
··· servo.set(servo2,1500)
··· waitcnt(clkfreq+cnt)
··· servo.set(servo2,1200)
··· waitcnt(clkfreq+cnt)
Comments
Notice that you need to do an initial set call for each servo you intend to use, then call the start routine to initialize the object, then you can call the set routine whenever you want to change the servo position (or speed/direction).
set both servos to an initial postition and then started the object all before the repeat. Sorry for not mentioning that. I plan on taking another look tonight. Will post what i find out.
So two options, update both between each waitcnt, or start a second cog to handle the other one.
Also not sure if this is an effect of the forum, but make sure your function calls under Pub Main Repeat are indented in, or it will never loop correctly.