PDA

View Full Version : PICAXE servo command



Macgman2000
- 21st November 2011, 18:42
Hello,

I do a lot of work with servo's and I am coming up against a wall with synchronizing them. I usually do the following:

portb.0 = 1
pauseus (servo1 * 4) + 960 ; scaling factor to give me 2.0ms full scale.
portb.0 = 0

If I repeat the above 4 or more times I am going to see the signals staggered in time. 1ms at the least and 2ms at the most between each routine. The picaxe seems to be able to start all servo's at once and update on the fly each servo (8 servos). Has anyone tried to do this?

I am thinking about using a 20ms interrupt to seed ADC values, synchronously start low to high output on 8 pins and decrement variables in main. Like the following:


intMe: ; interrupt every 20ms
asm
portb = 1
load ADC0 into counter 1
load ADC1 into counter 2
etc
etc

return from interrupt

end asm




Main:

if servo1 > 0 then
servo1 = servo1 - 1
else
portb.0 = 0
endif

if servo2 > 0 then
servo2 = servo2 - 1
else
portb.1 = 0
endif

etc
servo3 ~ servo8

pauseus 100
goto main

Is there a better way of doing the above mentioned? I can't shake the feeling that it seems too brute force and there should be a more elegant way of doing this.

Nick

Charles Linquis
- 22nd November 2011, 02:47
I'm certainly no expert with servos, but can't Darrel's SSPWM do this?

Acetronics2
- 22nd November 2011, 10:35
Hi,

The common trick is to use a free running timer and the " interrupt on match " feature of a CCP module ...

you "launch" all the servos signals together and reset relative output when CCP detects their duration reached ...

Much Better done in assembly than Basic , for the interrupt stubb ... :surprise:

Alain

BTW : Picaxe ??? Does that thing really exist ??? :chargrined:

rmteo
- 22nd November 2011, 15:08
Hi,

BTW : Picaxe ??? Does that thing really exist ??? :chargrined:

Not only do they exist but doing well with worldwide distribution http://www.picaxe.com/Distributors