PDA

View Full Version : Help with Servo Control Please!



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!

Doormatt
- 7th June 2007, 04:51
Hate to tell you, but you've got the wrong forum. Pic Basic Pro has no Servo command :(

Proton Basic perhaps? (They're not the same)

wireman22
- 7th June 2007, 05:00
Thanks, wow, I never even thought to look at that.

wireman22
- 7th June 2007, 05:02
So proton uses pic basic then and not pic basic pro? I just got it today so am a little confused, thanks.

skimask
- 7th June 2007, 06:00
So proton uses pic basic then and not pic basic pro? I just got it today so am a little confused, thanks.

Proton Basic <> PicBasicPro
Different companies, different continents...

Acetronics2
- 7th June 2007, 07:34
Hi,

No need to be a Proton expert to see the example is ... not so good !

a closer look to your "Help file" example will show you there's some inconsistance ...

1) Buttons are connected between inputs and ground, good ... BUT you must add 10k resistors between V+ and inputs to give some "pullup" ...

2)

Replace

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

by

IF PORTA.0 = 0 Then IF Pos < 2200 Then Pos = Pos + 1 ' Move servo right
IF PORTA.1 = 0 Then Pos = 1500 ' Centre servo
IF PORTA.2 = 0 Then IF Pos > 800 Then Pos = Pos - 1 ' Move servo left

This will prevent damaging your servo or having strange behaviour ... by overtravel !!!

Alain

wireman22
- 7th June 2007, 16:39
Thanks for all the help! even though i'm in the wrong forum :0. So any thoughts on which is better? Is proton a good software package. I got it without really knowing what else is out there? Thanks!

malc-c
- 7th June 2007, 18:15
Thanks for all the help! even though i'm in the wrong forum :0. So any thoughts on which is better? Is proton a good software package. I got it without really knowing what else is out there? Thanks!

Asking that in a Picbasic pro forum... you're probably going to get a slightly bias answer :)

There are several languages that allow you to program PIC's, and then several variants with in those. Most will allow you to get started, some will allow you to progress better than others, most have excellent support, either direct or via forums like this one.

Some, like MicroBASIC are free up to a limit of 2K of code, others can cost upwards of £200 (like PicBasic Pro) but then you are using a "professional" application which is very strong.

I'm sure if you lurk over on the correct forum and post your questions there you will get as much support as you need.