|
» About me
» Bristol VA/TN
» E-Mail
» Hobby Electronics
Connecting a Servo to a PICAXEby Lewis Loflin The three simple routines below go further than the PICAXE manual. The programs are self explanatory.
Program 1
#rem
Page references pertain to PICAXE Manual 2 Basic Commands
#endrem
; uses command 'servo'
symbol pulse_pin = B.0
symbol val = b0
init: servo pulse_pin,75 ;initialize servo
main:
readadc control, val ;read ADC1 8-bit mode into variable b0 p. 170
val = val * 1 MIN 75 MAX 225 ; set limit on val
servo pulse_pin, val
pause 20
goto main ;loop back to start
Program 2 Position with PotentiometerRelated: also see Potentiometers and Analog-to-Digital Conversion with the PICAXE
; uses pulsout command (p. 161), uses no servo commands
; uses a potentiometer to position a servo
symbol pulse_pin = B.0
symbol control = C.1 ; position control wiper
symbol val = b0
LOW pulse_pin
main:
readadc control, val ;read ADC1 into variable b0 p. 170
val = val * 1 MIN 75 MAX 225 ; set limits on val
pause 19
pulsout pulse_pin, val ; val * 10uS at 4mHz
goto main ;loop back to start
Program 3 Sweep Back and Forth
; Operate a servo sweep back and forth.
symbol pulse_pin = B.5
symbol val = b1
init: servo pulse_pin,75 ;initialize servo
main:
for val = 75 to 224
servo pulse_pin, val
pause 20
next val
for val = 224 to 75 step -1
servo pulse_pin, val
pause 20
next val
goto main ;loop back to start
Picaxe Micro-controller Projects!The PICAXE series of micro-controllers rank as the easiest and most cost effective way to use Microchip processors. I wanted an easier and less expensive way to introduce my students to the "PIC" micro-controller. Here I hope to get those starting out past poorly written literature and lack of simple working code examples.
Other Main Sections of this Website
General Electronics
If using this material on another site, please provide a link back to my site. |