For various reasons, I am trying to emulate the function of a servo control board, insofar as the application will be only for motor speed and direction control via one pin and a pwm input- essentially, I'm trying to make a tiny motor driver compatible with inputs via a picaxe servopos command.
(I think there's lot of other potential applications here, but this is where I'm at for now).
For my test setup,I have the servopos commands (after a "servo" init) issued by a separate picaxe 18X. The servo command is input into a picaxe 08M which reads the pulse via a pulsin command.
The code for the 18X is straightforward:
;------------------18X CONTROL
servo 0,75
main:
servopos 0,254
pause 1000
goto main
The code for the 08M is also basic:
;------------------08M CONTROL
symbol pwmval = w0
checkservo:
input sigpin
pulsin sigpin,1,pwmval
;debug pwmval
goto checkservo
My understanding of the servopos command: e.g. servopos,0,150 is that a pulse of 1.500 ms width is sent to pin 0, and repeated every 20ms.
my understanding of the pulsin command: e.g. pulsin 3,1,w0 is that a pulse is measured, triggered by the rising (or falling) edge, and the duration is returned in w0, in 10us units.
This means that if I read a servpos,0,150 output with a pulsin 3,1,w0 (connecting output 0 on the output picaxe, to input 3 on the input picaxe), then w0 should contain the value 150.
Great. except it doesn't. Hence the forum.
Here's a list of the issued pwm command and the resulting (reproducable) read, w0 value with a 08M reading the servpos command from a 18X:
servopos (18X) w0(08M)
260 9
255 5
254 283
250 279
247 275
245 273
240 267
200 223
150 169
120 136
100 114
90 103
85 97
80 92
70 81
60 70
50 59
30 37
10 15
Now, I can understand why the w0 goes lower for servopos>255, no problem. These data are just included for interest.
What I can't understand is why the W0 values are always higher than the servopos command AND seems to be a function of the servopos value (if it's useful, the fractional discrepancy seems to be asymptotic towards 10-11% for high servopos values). If there were strangenesses with the shape of the pulse, and the point at which the trigger started, then that also would result in a constant offset, not one dependent on the servopos value, all the other processes I can guess at would seem to me to produce a constant offset, or at least, a factor - but not a variable one.
Does anyone have any thoughts?