First of all, excuse me for my bad english.
I was trying to do a program to control a servo with buttons and this is the result, it seem good to me, the buttons does not work!. need a little help from you.
this is my program:
#chip 12F675, 4 ' Control de 1 servo con botones, Pablo Curvelo S.
#config BODEN_OFF, MCLRE_OFF, INTRC_OSC_NOCLKOUT
'SERVO TIMING (MIN: 1 ms - CEN: 1.5 ms - MAX: 2 ms)
'TIEMPO TOTAL, INCLUYENDO TIEMPO ANTERIOR: 20 ms
'TIEMPO DE REPETICION: +-50 CICLOS POR SEGUNDO
'arriba1 = gpio.0 - centro1 = gpio.1 - abajo1 = gpio.2 - servo1 = gpio.4
dir gpio b'11101111'
set gpio.4 off
#define izq gpio.0
#define cen gpio.1
#define der gpio.2
dim tk as word
dim al as word
tk = 150 ' arrancar en posicion central
do
if izq=low and tk>100 then
tk=tk-1
wait 50 ms
end if
if cen=low then
tk=150 ' centrar servo
wait 50 ms
end if
if der=low and tk<200 then
tk=tk+1
wait 50 ms
end if
al = 20 - (tk/100)
pulseout gpio.4, tk/100 ms
wait al ms
loop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
First of all, excuse me for my bad english.
I was trying to do a program to control a servo with buttons and this is the result, it seem good to me, the buttons does not work!. need a little help from you.
this is my program:
#chip 12F675, 4 ' Control de 1 servo con botones, Pablo Curvelo S.
#config BODEN_OFF, MCLRE_OFF, INTRC_OSC_NOCLKOUT
'SERVO TIMING (MIN: 1 ms - CEN: 1.5 ms - MAX: 2 ms)
'TIEMPO TOTAL, INCLUYENDO TIEMPO ANTERIOR: 20 ms
'TIEMPO DE REPETICION: +-50 CICLOS POR SEGUNDO
'arriba1 = gpio.0 - centro1 = gpio.1 - abajo1 = gpio.2 - servo1 = gpio.4
dir gpio b'11101111'
set gpio.4 off
#define izq gpio.0
#define cen gpio.1
#define der gpio.2
dim tk as word
dim al as word
tk = 150 ' arrancar en posicion central
do
if izq=low and tk>100 then
tk=tk-1
wait 50 ms
end if
if cen=low then
tk=150 ' centrar servo
wait 50 ms
end if
if der=low and tk<200 then
tk=tk+1
wait 50 ms
end if
al = 20 - (tk/100)
pulseout gpio.4, tk/100 ms
wait al ms
loop
A few things to get you going:
The TRIS bits were backwards, use dir gpio b'110000'.
Think integer math on the Pulseout function, 150/100=?? Use 10us increments on servos commands so tk = 1500 and:
pulseout gpio.4, tk/100 10us
Debounce input buttons with a return to Main.
Main:
do
if izq=low and tk>100 then
tk=tk-1
wait 20 ms
if izq=high then goto Main
end if
...
...
Loop
goto Main