|
DumHed
Experienced Roboteer
Joined: 29 Jun 2004
Posts: 1219
Location: Sydney
|
DumHed's PICaxe stuff
OK, I thought I'd jump on the PICaxe bandwagon since I wouldn't mind some custom control stuff for future bots
My first program is a PWM speed controller driven from a normal RC servo channel which I'll probably use in the boat, and maybe in the ram bot.
It provides a PWM output and a reverse pin, and seems to work pretty well.
It has a basic noise gate sort of setup to reduce interference problems, but with my ultra dodgy receiver in a very noisy environment it gets the occasional glitch through. edit: with the pause between the two pulsin commands it seems to not get the glitches. Further testing will really tell
I'll think more about that, but in general it failsafes in that if the transmitter is turned off or the signal goes out of bounds the motor output is turned off.
One of my aims with this was to make configuration easy, so there are no variables hidden in the code. Everything can be adjusted in the setup section and it should all work.
The values in there now are what works best with my radio gear in the small amount of testing I've done.
Anywho, here's the code:
code:
;-------------------------------------------------------------;
;DumHed
;PicAxe 08M PWM Speed Controller
;Updated: 02-02-2006
;(c) Andrew Handmer 2006
;-------------------------------------------------------------;
; RC input setup
symbol neutral = 155 ; pulse length at mid point (ms/100)
symbol range = 45 ; range above and below neutral (ms/100)
symbol dead_zone = 5 ; dead zone (+- ms/100)
symbol full_on = 85 ; Full on output band (%)
; PWM rate
symbol period = 249 ; 249 = 4Khz
; PicAxe Pin Definitions
symbol receiver = 3 ; Servo signal from Receiver
symbol motor = 2 ; PWM Output to Motor
symbol dir = 1 ; direction output pin
; PicAxe Register Definitions
symbol signal = b0
symbol duty = b1
symbol dead_high = b2
symbol dead_low = b3
symbol fail_high = b4
symbol fail_low = b5
symbol sigcomp = b6
symbol PWMduty = w6
;-------------------------------------------------------------;
OUTPUT 1 ; set IO pins
OUTPUT 2
INPUT 3
LET dead_high = neutral + dead_zone ; sets dead zone points
LET dead_low = neutral - dead_zone
LET fail_high = neutral + range ; sets fail safe out of bounds points
LET fail_low = neutral - range
main:
PULSIN receiver,1,signal ; receiver pulse input
pause 20
PULSIN receiver,1,sigcomp ; pulse comparison input
LET sigcomp = sigcomp - signal
IF sigcomp > 10 AND sigcomp < 245 THEN GOTO main ; noise gate
IF signal > fail_high OR signal < fail_low THEN motor_off ; turns motor off if outside signal range
IF signal > dead_low AND signal < dead_high THEN motor_off ; turns motor off inside dead zone
IF signal >= dead_high AND signal < fail_high THEN fwd ; drives motor forwards
IF signal <= dead_low AND signal > fail_low THEN rev ; drives motor backwards
motor_out:
IF duty > full_on THEN duty100 ; set duty to 100% if over full_on value
doit:
LET PWMduty = duty * period / 25 ; calculates PWMduty depending on duty cycle % and period
PWMOUT motor, period, PWMduty
GOTO main
fwd:
LOW dir ; turn off reverse pin
LET duty = signal - neutral ; gets pulse width above neutral
LET duty = duty * 100 / range ; converts pulse to duty cycle percentage
GOTO motor_out
rev:
HIGH dir ; turn on reverse pin
LET duty = neutral - signal ; gets pulse width below neutral
LET duty = duty * 100 / range ; converts pulse to duty cycle percentage
GOTO motor_out
duty100:
LET duty = 100 ; sets duty cycle to 100%
GOTO doit
motor_off:
LET duty = 0 ; sets motor PWM to zero for shutdown
GOTO doit
bah it's a bit hard to read with the word wrapping of comments..
If anyone wants it I'll email _________________
The Engine Whisperer
- fixer of things
|
Thu Feb 02, 2006 10:31 am |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|