wireman22
- 7th June 2007, 04:45
Hello,
I am trying to control a servo using 3 buttons (1 for moving it left, one for centering it, and one for moving it right).
Im following the example from the index help file where it talks about servos, but the buttons do not seem to make the servo respond at all. I know I am able to communicate with the servo by using this code to center it:
DEVICE=16f818
xtal=20
DELAYMS 100
DIM Pos as WORD
SYMBOL PinA = PORTA.3
PORTA=0
TRISA = %00000001
Again:
SERVO PinA , 1500
DELAYMS 20
GOTO Again
Im using a 16f818 with 20mhz crystal. The code below is from the help index and is supposed to move the servo like previously stated:
DEVICE 16F628
DIM Pos as WORD
SYMBOL Pin = PORTA.3
Pos = 1500
PORTA = 0
TRISA = %00000111
' ** Check any button pressed to move servo **
Main:
IF PORTA.0 = 0 Then IF Pos < 3000 Then Pos = Pos + 1 ' Move servo left
IF PORTA.1 = 0 Then Pos = 1500 ' Centre servo
IF PORTA.2 = 0 Then IF Pos > 0 Then Pos = Pos - 1 ' Move servo right
SERVO Pin , Pos
DELAYMS 5 'Servo update rate
GOTO Main
I was pretter sure this meant to connect one end of the buttons to gound and the other end to the corresponding pin on porta. The buttons don't seem to do anything at all, if in fact, interfere with the original code to center the servo. Im just learning pbp so any help would be great, thanks!
I am trying to control a servo using 3 buttons (1 for moving it left, one for centering it, and one for moving it right).
Im following the example from the index help file where it talks about servos, but the buttons do not seem to make the servo respond at all. I know I am able to communicate with the servo by using this code to center it:
DEVICE=16f818
xtal=20
DELAYMS 100
DIM Pos as WORD
SYMBOL PinA = PORTA.3
PORTA=0
TRISA = %00000001
Again:
SERVO PinA , 1500
DELAYMS 20
GOTO Again
Im using a 16f818 with 20mhz crystal. The code below is from the help index and is supposed to move the servo like previously stated:
DEVICE 16F628
DIM Pos as WORD
SYMBOL Pin = PORTA.3
Pos = 1500
PORTA = 0
TRISA = %00000111
' ** Check any button pressed to move servo **
Main:
IF PORTA.0 = 0 Then IF Pos < 3000 Then Pos = Pos + 1 ' Move servo left
IF PORTA.1 = 0 Then Pos = 1500 ' Centre servo
IF PORTA.2 = 0 Then IF Pos > 0 Then Pos = Pos - 1 ' Move servo right
SERVO Pin , Pos
DELAYMS 5 'Servo update rate
GOTO Main
I was pretter sure this meant to connect one end of the buttons to gound and the other end to the corresponding pin on porta. The buttons don't seem to do anything at all, if in fact, interfere with the original code to center the servo. Im just learning pbp so any help would be great, thanks!