Problems controlling an ESC from picaxe

Pauly1980

New Member
So I wrote a little bit of code with the intent of controlling the speed of a brushless motor using an ESC via the picaxe. Initially I tested it with a servo attached to check the output of the code worked. I am using a picaxe 28x1 and using the servo motor I had no problem
Using the programmed picaxe the esc will initialize correctly but after that I cant get the motor to run. If I reset the picaxe whilst the power is still on to the controller then at the servo 4,225 the motor will run up for the 4 second wait period at full speed. I then went and commented out the program and just added a servopos command operating in a loop to see if the motor would run but with no luck. I will attach the code below but would appreciate it if anyone could suggest something stupid I'm doing.

Code

init:
servo 4,225
wait 4
servo 4,75
;main:
;readadc A.0,w1 ;reads the hall effect adc
;readadc A.1,w2 ;reads the pot adc, was only for initial testing
;debug
;let w3=w1-130 ;takes the min input of hall effect switch and zeroes it
;let w4=w3*2 ;doubles the value returned due to low sensitivity
;let w5=w4+75 min 75 max 225 ;sets a min value of 75 for servo pos and limits the max value returned to 225
;servopos 4,w5
;goto main
main:
servopos 4,100
goto main

Thanks,
Paul
 

abenn

Senior Member
Some ESCs need to be "taught" the full range of the throttle signal, which I presume is the purpose of your three lines in the init: routine. In my experience, after doing that I always de-power the ESC to "save" the settings -- maybe it's not necessary with some brands, but I do it anyway. So I'm wondering if a servo 4,OFF command at the end of the init: routine would do the same job.

Alternatively, having run the program once, to teach the ESC the full range, try powering everything down, then comment out the init: code lines and see if it will then run as intended with just the simple main: loop using servo instead of servopos.
 

Pauly1980

New Member
Well with a load of fiddling and trying your suggestion it turns out I needed to add a pause into the loop. Not 100% sure but I think it was trying to send a new servopos command each loop before the first command had finished executing. Adding a pause 50 has got it up and running as per my original program. Thanks for your suggestion abenn
init:
servo 4,75
main:

pause 50
readadc A.0,w1 ;reads the hall effect adc
readadc A.1,w2 ;reads the pot adc, was only for initial testing
debug
let w3=w1-130 ;takes the min input of hall effect switch and zeroes it
let w4=w3*2 ;doubles the value returned due to low sensitivity
let w5=w4+75 min 75 max 225 ;sets a min value of 75 for servo pos and limits the max value returned to 225
servopos 4,w5
goto main
 

eggdweather

Senior Member
ESC have to be armed. Do that by applying zero throw (let's call it power) for 1-sec, then full power/throw for 1-sec, then back to zero. Your nearly doing that, but it seems more logical to not rely on the PICAXE to make the output zero at start-up and programme a low output at start-up. Then before you can issue a new power command you have to wait for a standard frame rate to elapse before the next servo command, typical frame rates vary between 50 to 333 Hertz or 20mS to 3mS, you would need to check the ESC specification to know how fast yours can go.
init:
servo 4,75
wait 1
servo 4,225
wait 2
servo 4,75 ; Arming completed, ESC should bleep, it uses the windings of the motor / load as its speaker!
main:
pause 20 ; 20mS is a typical frame rate
readadc A.0,w1 ;reads the hall effect adc
readadc A.1,w2 ;reads the pot adc, was only for initial testing
debug
let w3=w1-130 ;takes the min input of hall effect switch and zeroes it
let w4=w3*2 ;doubles the value returned due to low sensitivity
let w5=w4+75 min 75 max 225 ;sets a min value of 75 for servo pos and limits the max value returned to 225
servopos 4,w5
goto main

Your ESC has to be learnt what is zero (as already mentioned), so 75 may be low enough or not. ESC instructions usually have a sequence to follow to get them to calibration mode and require you to apply minimum and maximum throws at the Tx / Joystick, then it confirms calibration complete with a beep. Most ESC do not have instructions in my experience and come pre-programmed to 1000uS for zero 1500uS for neutral and 2000uS for maximum.
 

Pauly1980

New Member
I know about the initialisation of the ESC, that was never an issue and the init routine I used in the first program is what the esc manual says is required to program the esc for the first time, it needs to start at full throttle not zero. After that the throttle only needs to be at zero(75 value) on powerup to allow the motor to start. Thanks for the suggestions though

ESC have to be armed. Do that by applying zero throw (let's call it power) for 1-sec, then full power/throw for 1-sec, then back to zero. Your nearly doing that, but it seems more logical to not rely on the PICAXE to make the output zero at start-up and programme a low output at start-up. Then before you can issue a new power command you have to wait for a standard frame rate to elapse before the next servo command, typical frame rates vary between 50 to 333 Hertz or 20mS to 3mS, you would need to check the ESC specification to know how fast yours can go.
init:
servo 4,75
wait 1
servo 4,225
wait 2
servo 4,75 ; Arming completed, ESC should bleep, it uses the windings of the motor / load as its speaker!
main:
pause 20 ; 20mS is a typical frame rate
readadc A.0,w1 ;reads the hall effect adc
readadc A.1,w2 ;reads the pot adc, was only for initial testing
debug
let w3=w1-130 ;takes the min input of hall effect switch and zeroes it
let w4=w3*2 ;doubles the value returned due to low sensitivity
let w5=w4+75 min 75 max 225 ;sets a min value of 75 for servo pos and limits the max value returned to 225
servopos 4,w5
goto main

Your ESC has to be learnt what is zero (as already mentioned), so 75 may be low enough or not. ESC instructions usually have a sequence to follow to get them to calibration mode and require you to apply minimum and maximum throws at the Tx / Joystick, then it confirms calibration complete with a beep. Most ESC do not have instructions in my experience and come pre-programmed to 1000uS for zero 1500uS for neutral and 2000uS for maximum.
 

eggdweather

Senior Member
OK, well you have it running now, good to hear, but I'd say the frame rate is too slow, 50Hz is the usual minimum, otherwise the ESC is working out of specification, you may know that a lost of signal (simulated by slow frame rates) results in the ESC switching the output off, as it helps in a model crash or out-of-range situation.

Interesting that the ESC should be initialised at full power, I think you mean 'armed', a common problem with RC models is the Tx throttle being knocked to full power when the model is switched on, (used to be) resulting in dangerous surprises and cut arms and legs, so AFAIK none on the market will arm at full power, they must be at zero first to prevent this and they sit unarmed until that sequence is completed.
 

Pauly1980

New Member
Sorry, I meant that it learns the throttle range by first powering up at full throttle and a few seconds later going to zero throttle. You are right in that it won't run until a zero throttle has been applied which is what you refer to as arming.
I'm not sure I understand what you mean by framerate though. I was under the belief that the servopos command continued to operate once issued, so I could just issue a servopos 4,150 command and that would keep re issuing itself automatically whereas my program is merely updating the value 20 times a second.
 

eggdweather

Senior Member
The servo command repeats the command pulse every 20mS, the Servopulse gives it s apposition to repeat. The frame rate is the time between command pulses. In some really new ESC designed for digital RC systems they expect a much higher frame rate of 200Hz plus, which the PICAXE can't deal with.
 
Top