Read servo pulses

D396

Senior Member
I am trying to build something like an ESC for RC cars. What I want a picaxe to do (18X) is to read Servo pulses And to propotianly control the speed of the motor. I have a single N channel Mosfet circuit built so the picaxe can control the motor but I only know how to do on and off how could I read a servo pulse say something like servo pin1,90 and have the motor go at 90% speed. Could you please post example code. Thanks.
P.S sorry spell check is broken
 

hippy

Ex-Staff (retired)
The best way is to read the servo pulse length using PULSIN, convert that to a PWM duty and output it with PWMOUT. Basically -

duty = ( ( pulse - min pulse ) / ( max pulse - min pulse ) ) * pwm freq * 4

A forum search should find lots of other discussion on using PICAXE with RC servo inputs.
 

D396

Senior Member
I realized I didnt need speed control for this project so I just have my picaxe sending on and off signals. Thanks anyway though.
 

D396

Senior Member
Got it. Here is the code to take a SERVO pulse from 1 to 100 on and arduino and 75 to 175 on a picaxe(untested) and throttle a motor proprtianlly to the servo pulse.
Code:
symbol in = w1
symbol throttle = w2
symbol duty = w3
main:
pulsin 1,1,in 
throttle = in  - 56
duty =  throttle * 8
pwmout 3,199,duty
debug
goto main
 

hippy

Ex-Staff (retired)
I think you'll have to explain how you mean by 'outtputing a percent'.

There's the DACLEVEL command which can set one of 32 analogue levels ( 0 to 31 ) and a 75% level would be value 23.

You can also set PWM duty to 75%, so the signal is on for 75% of the time and off for 25% of the time. That can be converted into a proportional voltage using an RC circuit.
 
Top