I find servo signals from M2 chips pins B.3 and B.4 are jerky...?!

Morganl

Senior Member
EDIT: workaround below in #8 /EDIT

This is true even for very simple programs, even when this is the whole program:
Code:
servo B.0, 150
servo B.1, 150
servo B.2, 150
servo B.3, 150 ; This one and
servo B.4, 150 ; this one.
servo B.5, 150
servo B.6, 150
servo B.7, 150
do
loop
Swapping a 20M2 to 20X2 solved my problem.

Anyone else seen this?

I am going to hook it to a logic analyzer, update here later.
 
Last edited:

Technical

Technical Support
Staff member
Try adding a 'disabletime' command to reduce the internal timer workload/number of internal interrupts.
 

Morganl

Senior Member
Thanks for the quick reply.
I had that idea too but i got

"Error: disabletime and servo not allowed together in program"

However the error is much worse; i can understand timing would shift a few machine cycles depending on concurrent interrupts, but this error actually consists of double pulsing, so here seem to be a real firmware bug.
 

Morganl

Senior Member
Did you know when you sold them that i was going to start using them 1:st of april, so you hid an animatronics program in it? ;)
Hah! You really need to try this:

Take a 14M2, connect a servo to each pin on port B (six)
(of course powered from a separate supply, but common GND with picaxe.)
Program it using this: (disconnect servo on B.0 (serial out) during programming)
Code:
#picaxe 14M2 ;v 6.A, PE6.0.6.4
#no_data
dirsC = %00000001
setfreq m16
servo B.0, 150
servo B.1, 150
servo B.2, 150
servo B.3, 150
servo B.4, 150
servo B.5, 150
do
loop
And you see servo on B.0 jerk cyclically, and a fraction of a second later, both servos on B.4 and B.5 jerk syncronously.

With the dirsC line commented out, servo only B.3 and B.4 jerk syncronously at 80 times per minute.

Maybe you can find out other interesting combinations...
seem to also work on other M2.

If I use setfreq m4 or dirsC = %11111111 i see no problem, however i do not want to do either.
 
Last edited:

Morganl

Senior Member
Logic analyser screenshots channel number = portB bit number.
servojerk5-14M2-B3B4.pngservojerk5-14M2-B3B4-zoom.png

This is from scenario of dirsC line commented out.

At a fixed frequency of about 80 times per minute the signal B.3 finished the pulse in right time, but microseconds later it give an extra pulse for a short time. Concurrently, B4 starts its pulse at correct time, but microseconds later go low again for the duration of the false extra pulse on B.3, then when B.3 go low B.4 go high to finish on originally correct time.
Result: B.3 send a correct, then incorrect pulse, and B.4 sends two consecutive incorrect pulses.
Total timing of B.3+B.4 together seem to be correct.
 
Last edited:

Morganl

Senior Member
Thanks for the reply and head up :)
I first found the problem first on 20M2 actually, and forgot about adding disconnect command when moving to 14M2 for further testing
( 14M2 have serial programming out common with servo 0, on 20M2 they are separate. )
I do not know wether PICAXE should stop using serial out pin for serial automatically or not(?) because servo use it...?
Adding disconnect however seem to be part of workaround on 14M2, the other part is to configure portc pins, but why?

This program jerks only the servo on B.5:
Code:
#picaxe 14M2 ;v 6.A, PE6.0.6.4
#no_data
disconnect
;dirsC = %00000001
setfreq m16
servo B.0, 150
servo B.1, 150
servo B.2, 150
servo B.3, 150
servo B.4, 150
servo B.5, 150
do
loop
Uncommenting the dirsC line this time makes it calm.

So yes disconnect helps, so do configuration of another port than servos use, but really, none of that should really influence servo operation on i.e B.0 ...

Going back to test 20M2,this program jerk servo on B.4
Jerk frequency is somewhat higher (double?) here than on earlier examples.
Code:
#picaxe 20M2 ;v 8.A, PE6.0.6.4
#no_data
;disconnect
;dirsC = %00000001
setfreq m16
servo B.0, 150
servo B.1, 150
servo B.2, 150
servo B.3, 150
servo B.4, 150
servo B.5, 150
servo B.6, 150
servo B.7, 150
do
loop
At 16MHz, uncommenting either the disconnect or the dirsC line and all servos are calm.
Changing frequency to m4 halves jerk frequency, no lines commented out, now both B.3 and B.4 jerks.
At 4MHz uncommenting only dirsC make B.0 jerk instead..., uncommenting disconnect with or without dirsC all servos are calm.

But really, neither disconnect nor dirsC nor 16 or 4MHz really should affect Portb and servo operation... here we see they all do.
 
Last edited:

Morganl

Senior Member
Screenshot of double pulse on B.4 on 20M2 using last program aboveservojerk5-20M2-B4.png.


This problem is far from critical as it can be workaround easily in most cases, apparently.
(and in most practical uses do not shop up)
But it is "interesting" :) Basically:

WORKAROUND: if you find servos jerk regularly on M2 series, try the disconnect command and/or add or change your dirsC line. It may help to change between 16 and 4 MHz. If nothing of that work or it does not suit your situation: If the problem is on smaller chip than 20M2, try moving to 20M2; if problem on 20M2, move to 20X2.

UPDATE: adcconfig apparently have positive effect. Even when value is 0 there is a change to the better, value $FFFF fixes it on 18M2, se below, but that is not a good value for other reasons always... i guess using the adc also counts. Possibly seting up other functions have effect too.)
 
Last edited:

Morganl

Senior Member
Finishing the tests while i am at it...
Code:
;How to make 18M2 animate 6 servos B.1 through B.6
#picaxe 18M2 ;18M2+ vD.A
#no_data
disconnect
;dirsC = %00000001 ; uncomment for a slightly different behaviour
;dirsC = $FF, less servos jerk
setfreq m4
servo B.0, 150
servo B.1, 150
servo B.2, 150
servo B.3, 150
servo B.4, 150
servo B.5, 150
servo B.6, 150
servo B.7, 150
do
loop
Apply some black magic
Code:
;How to make 18M2 drive 8 servos stable
#picaxe 18M2 ;18M2+ vD.A
#no_data
adcsetup = $FFFF ;this fixes it <<<<<<
setfreq m16
servo B.0, 150
servo B.1, 150
servo B.2, 150
servo B.3, 150
servo B.4, 150
servo B.5, 150
servo B.6, 150
servo B.7, 150
do
loop
Code:
;How to make 08M2+ animate servos B.1 and B.2
#picaxe 08M2 ;marked "08M2+" reports as 08M2 v4.A,  NOTE: servos on C.0,1,2,4
#no_data
setfreq m16
servo C.1, 150
servo C.2, 150
servo C.4, 150
do
loop
Code:
;How to make 18M2+ drive 4 servos stable
#picaxe 08M2 ;marked "08M2+" reports as 08M2 v4.A,  NOTE: servos on C.0,1,2,4
#no_data
setfreq m16
disconnect
servo C.0, 150
servo C.1, 150
servo C.2, 150
servo C.4, 150
do
loop
 

radiogareth

Senior Member
Fascinating, I have been wondering why my servos sometimes 'twitch'. It would be good to have a definitive fix. I use mainly 08M2 (up to 3 servos) or 14M2/20M2.

Technical?? (OK, not on a Sunday!!)
 

Technical

Technical Support
Staff member
These posts jump around a lot so are quite hard to follow, but we'll do some tests of our own and look into it.

The main issues reported seem to be at 16MHz when using all available servo outputs, whereas most people use 4MHz for servos and don't generally use them all, and also most people having servo twitches will actually be for totally different reasons such as:

1) using commands that suspend pulses (e.g. debug or sertxd)
2) using servo within loops instead of servopos and hence resetting timers
3) not enough supply capacitance, servos are very noisy

Normally when people report twitches the above actions to get reported back as resolving the issue.

Some of the comments here also doesn't make much sense at first read, for instance 'adcsetup' command simply disables the input buffer within the silicon on that pin. This makes no difference at all to the PICAXE firmware/BASIC program running, in fact it should be directly considered an 'electronic circuit' change completely unrelated to what code the chip is processing - and hence implies an electrical noise type issue in the circuit.

Similarly all 'disconnect' does is skip over the line of code that checks the input state of the RXD pin. This should make no difference to servos and would be effectively the same as physically removing the download cable. So both of these 'workarounds' actually imply to us an electrical issue.

However we will look into it all. But not on a Sunday!
 

Morganl

Senior Member
I am impressed you even post friday and sunday evenings, great support! :)

The program listings are the complete programs - no offending commands.
Problem occours also when only connected to logic analyser - no noise from servos.

Yes the tests "jump around" as i just tested "this and that". To do systematical tests would take more time than i have, and to be intelligent i would have needed details of inner workings, so I leave that up to you - have fun ;)

Yes, i pulled my hair a bit, now I wonder what really happens when using adcsetup and disconnect....

OH, BTW update documentation at
http://www.picaxe.com/BASIC-Commands/Digital-InputOutput/servo/
at bottom it say
"Applies To: All (except 08, 18)" but apparently 08M2 and 18M2 also works.
 

Circuit

Senior Member
OH, BTW update documentation at
http://www.picaxe.com/BASIC-Commands/Digital-InputOutput/servo/
at bottom it say
"Applies To: All (except 08, 18)" but apparently 08M2 and 18M2 also works.
The 08 and 18 are obsolete chips; see Manual 1 page 16 for details of the full listing. They did not support this command. Nevertheless some, probably most, of these are still around and therefore it is important that this is reflected in the documentation. You are misreading the nomenclature.
 
Top