servos modified for continuous rotation

ams

Member
Using the servo (Futaba S3003) modified for continuous rotation and the PICAXE 20X2 and 18m2 with the following codes:

#picaxe 20X2
do
servo B.0,50
servopos B.0,50 'maximum speed
wait 2
high B.0 'stop
wait 2
loop

#picaxe 18M2
do
servo B.0,50
servopos B.0,50 'maximum speed
wait 2
servopos B.0,135 'not always stop
wait 2
loop

With the command "high B.0" the servo stops in 20X2. However, this command does not work in 18m2. Why?

Stopping the servo, in 18m2, with the command "servopos B.0, 135," (midpoint of the servo) sometimes the servo continues to spin slowly. I need to stop even with 18m2. How?

best regards
ams
 

hippy

Ex-Staff (retired)
With the command "high B.0" the servo stops in 20X2. However, this command does not work in 18m2. Why?
Good question. It appears that setting B.0 high or low ( and disabling the servo pulsing on B.0 ) does not work for the 18M2. This appears to be one which slipped through the testing process. We will investigate.

Using "dirB.0=0" may however achieve the effect you desire ( does on a logic analyser watching the pin ). As that makes the pin an input, floats the servo control line you may need a pull-up or pull-down resistor. I'd suggest starting with 10K.
 

ams

Member
Grateful for the quick response Hippy.

For 18X2 or 20X2 works:

do
servo B.0,50
servopos B.0,50 'maximum speed
wait 2
dirB.0=0 'stop
wait 2
loop

Best regards and continuation of a happy birthday.
ams
 

ams

Member
After the error continues to 18m2:

do
servo B.0,50
servopos B.0,50 'wheel forward
wait 6
dirB.0=0 'stop
wait 6
servopos B.0,200 'wheel forward, it must rotate back
wait 6
dirB.0=0 'stop
wait 6
loop

Also experienced resistance to the + and - does not seem to solve the problem.
(135 - midpoint of the servo)

Best regards
ams
 

hippy

Ex-Staff (retired)
Servo operation has to start with a SERVO command and subsequent SERVOPOS simply set the position ( or direction / speed for a continuous servo as here ), so you don't need a SERVOPOS immediately following the SERVO.

However, having disconnected the servo pulse using "dirB.0=0" it may be necessary to re-issue a SERVO command to restart the pulsing. It's late to test it but that's the scenario I tested earlier. In which case this may achieve what you need -

do
servo B.0,50
wait 6
dirB.0=0 'stop
wait 6
servo B.0,200
wait 6
dirB.0=0 'stop
wait 6
loop
 

Technical

Technical Support
Staff member
servopos B.0,135 'not always stop
Remember not all servos are the same. You may need to use, for instance, 137 to stop one servo and 134 on another servo. The only way to find out is by experimentation.
 

ams

Member
Ok Hippy, with the tests I conducted now works correctly.
The servos are intended to move the wheels of small robots that follow a black line. The robots are built by students from schools (in Portugal) so require precise control to the wheels.

The X2 command “servo” needs to be improved because it has several problems
(I use software Programming Editor 5.3.1).

Once again grateful for the help,
Yours Sincerely,
ams
 

westaust55

Moderator
Although not stated here, from past ams posts a year ago, I suspect that the claimed servo “problems” relate to the fact that PWM and SERVO commands use a common timer (timer2) resulting in conflict between these functions.

This is not something that Revolution Education have control over.

The PIC chips is designed by Microchip dictates which timer is used for which function (eg PWM uses timer2) Additionally Microchip only have generally at most 3 timers within the PIC chips as used for PICAXE purposes.
As the internal silicon structure and organisation of the PIC chips is by Microchip it cannot be deemed something for Rev Ed to fix when such conflicts arise. Rev Ed cannot miraculously define a new timer for say the PWM command to avoid the conflict.
 

MartinM57

Moderator
...agreed, but there are standard techniques in low level microcontroller programming to have "fast tick" timers where tick counting is used to invoke processes that run on multiples of the "fast tick" time

e.g. a 1ms timer where process A (e.g. fast reacting output port changes) is invoked each time the timer expires;process B (switch de-bouncing) is invoked every 10th time the timer expires;process C (servo command output) is invoked every 20th time the timer expires - we now have three timed processes, but only one underlying timer
 

hippy

Ex-Staff (retired)
Don't forget that the servo signals don't run and change at a standard 'tick rates'; only the 20ms frame does. There will then be up to eight servo channels ticked along on approximately 2ms sub-frames, but each of the eight servo pulse can be anything from 0ms to 2.55ms ( 1ms to 2ms in practice ) with 0.01ms resoluton.

A base tick rate suitable for all that would have to be 10us, and with 1us per PICmicro instruction at 4MHz if we did that the PICAXE would be spending almost all its time inside servo handling and execution of the user program would drop to a crawl.

Therefore the ticking has to be far more complicated; on tick expiry determine what to do now and determine how long the next tick will be, set that up, return to main firmware loop.

There's also the problem of main firmware loop and software servo loop being like two entirely independent people, both updating the outputs of the chip; at some point one person ( main firmware, handling High/Low etc ) will want to put something out to the outputs, but between deciding what and doing it, the other ( servo handler ) can change what should be output, and wants to output that. It's a very complicated process to get that to work.

Also for timing critical commands, serial, pulse in or out, counting etc with servo both want absolutely perfect timing but that's impossible, getting perfect timing for one will force non-perfect timing for the other.

Handling all that is what makes servos so difficult. Collisions and collision resolution may only occur once every many millions of internal instructions but that can sometimes be noticeable as jitter.

The only perfect solution would be a multi-core processor and separate ports for digital outputs and servo outputs, a separate servo controller, or taking servo pulse generation and timing into your own hands using PULSIN and PULSOUT etc, but that gets complicated if wanting to control more than one servo channel.

Perhaps the ease of using servos, and how well it works when there are no collisions has led to over-estimations of servo capabilities, expectations of perfection where ( as noted above ) that never can be, with it seemingly perfect at times only by good fortune. One cannot outright say "servo on PICAXE doesn't work" with any fairness because it's entirely satisfactory for many who use it but it does have its limitations. How those limitations will affect things will depend on application, coding and use of servo commands and even hardware chosen.
 

Technical

Technical Support
Staff member
Although not stated here, from past ams posts a year ago, I suspect that the claimed servo “problems” relate to the fact that PWM and SERVO commands use a common timer (timer2) resulting in conflict between these functions.

This is not something that Revolution Education have control over.

The PIC chips is designed by Microchip dictates which timer is used for which function (eg PWM uses timer2) Additionally Microchip only have generally at most 3 timers within the PIC chips as used for PICAXE purposes.
As the internal silicon structure and organisation of the PIC chips is by Microchip it cannot be deemed something for Rev Ed to fix when such conflicts arise. Rev Ed cannot miraculously define a new timer for say the PWM command to avoid the conflict.
It's also worth noting that on the new 28X2, the two new pwmout channels (B.1, B.5) do have their own timer, so could be used with servo at the same time.

This is exactly because, as WA55 points out , these new generation 25K22 chips now have extra internal timers to do make this possible in their silicon. Without those new extra timers it is not possible.
 

westaust55

Moderator
Thanks for that info Technical.

For those who do read the manuals and X2 briefing/addenda sheets the new Dec 2010 X2 sheet does state:
- Two additional PWM channels with separate timers (so now 4 PWM channels available on 28pin parts)
 

BeanieBots

Moderator
Using PWM and servo has been an age-old problem which was particularly unfortunate because many RC'ers require PWM for speed control and servo for direction. There is/was the solution of using pulsout for servo control but it's not for the faint hearted trying to maintain a constant frame rate whilst doing everything else at the same time:eek:

I think it would be worth a specific mention in the manual that these commands can be used together on the newer devices as this will make my life and I'm sure many other's much easier:)
 

Technical

Technical Support
Staff member
Will do. On new 18M2 the pwmout on B.3 and B.6 are also separate from servo (and each other).

On 28X2 there are now three different pwmout timers C.1 & C.2, B.1, B.5

So now, for instance, an RGB LED on C.2, B.1, B.5 can be fully controlled.
 
Top