# Servo motor control with POT

#### Cagatay_AKSOY

Nov 5, 2017
3
Hi friends, I can not speak English well. Sorry. I'm doing a project. My goal; Using 2 potentiometers to control 2 servo motors separately. Now I can control 1 servo motor with 1 potentiometer. 2. I can not add potentiometer and servo motor. I'm coding and uploading the proteus file. Thank you very much for your help. I use Mplab XC8 and pic 16f877a.

#### Harald Kapp

##### Moderator
Moderator
Nov 17, 2011
12,715
2. I can not add potentiometer and servo motor.
You connect a second pot in the same way as the first, e.g. on AN1.
You connect a second servo in the same way as motor 1, e.g. on RB1.

I cannot help much with the coding of a PIC. However, You probably need to change the program structure. Currently you sare generating the PWM waveform in a subroutine using delay statements. This kind of delay is created by having the CPU running in a loop for a defined number of iterations to "burn" time. The CPU is not able to do usefil work during this time.
It is preferable to haev the PIC hardware generate the PWM signals autonomously as described e.g. here. You'll have to connect the servos to PC.1 and PC.2 for this to work.
The idea is that you set up the registers of the hardware PWM channels such that these hardware module generate the signals without further intervention. You'll have to change only the register settings for changing the ducty cycle.

As for the analog input you'll have to read both input channels to get the settings of the two potentiometers.

A rather general code could look like this (you'll have to work out the detailed code as I'm not familiar with PICs):
Code:
setup ();

while (1)
{
}

Alternatively, using parameterized routines for reading the ADC and setting the PWM:
Code:
setup ();

while (1)
{
}

#### BobK

Jan 5, 2010
7,682
If you insist on doing it with a program loop, you would turn both pins on, then, loop until the lower time is reached, turn it off, continue loop until the higher one is reached, turn it off.

Bob

#### Cagatay_AKSOY

Nov 5, 2017
3
First of all thank you for everything. I solved the problem by changing channels. Forced the Proteus simulation because I use PWM 2 also MAINE. @Harald Kapp and @BobK thank you. I am removing pictures because there is an error in the code. You can email to [email address removed for privacy] for information about this project.

Last edited by a moderator:

#### Minder

Apr 24, 2015
3,318
I presume these are RC servo's and not industrial versions?
M.

#### Cagatay_AKSOY

Nov 5, 2017
3
Yeah, not industrial engines. I will use the SG90 servo motor.

Replies
6
Views
1K
N
Replies
1
Views
1K
Sonali
S
J
Replies
0
Views
935
J
G
Replies
1
Views
1K
Charles Schuler
C
B
Replies
0
Views
2K
Bernard Michael Tyers
B