# Controlling multiple servos using multiple sensors MikroC on easypic v7

#### rocker123uk

Joined Dec 6, 2015
33
Hello all,

I am now trying to control multiple servos each by a flex sensor. i have successfully got the first flex with one servo working, however, i cant seem to get it working when i try it with two servos. any idea or suggestion as to how i could achieve this? im trying to control 5 servos using 5 flex sensor. also i dont believe there is anything wrong with the circuit or hardware as it all worked fine. im assuming its a firmware/software problem.

here is my code:

C:
unsigned int Adcval;
unsigned int i,a;

long map(long x, long in_min, long in_max, long out_min, long out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

void servoRotate0() //0 Degree
{
//unsigned int i;
PORTB.F0 = 1;
Delay_us(500);
{
Delay_us(1);
}
PORTB.F0 = 0;
Delay_us(19500);
}
void servoRotate1() //0 Degree
{
PORTB.F1 = 1;
Delay_us(500);
{
Delay_us(1);
}
PORTB.F1 = 0;
Delay_us(19500);
}

void main()
{
int test1, test2;
TRISA.F2 = 1; //analogue IP servo1
TRISA.F3 = 1; //analogue IP  servo2
TRISB = 0; // PORTB as Ouput Port
do
{
servoRotate0();

servoRotate1();

}while(1);
}]\code] Mod edit: code tags

Last edited by a moderator:

#### jjw

Joined Dec 24, 2013
594
The period between pulses is now ~ 40ms,
should be 20ms ?

#### rocker123uk

Joined Dec 6, 2015
33
i dont think thats the problem because i have it set at different funtctions and it happens after the ports are set

#### jjw

Joined Dec 24, 2013
594
What is the power supply for the servos?
What will be the minimum value from the map function?
You could make a test by halving the 19.5 ms delays.

Last edited:

#### rocker123uk

Joined Dec 6, 2015
33
i have checked all of that. im pretty sure the circuit is fine. i think i need to do a interrupt but i dont know how to implement it

#### djsfantasi

Joined Apr 11, 2010
7,552
What C compiler you are using?

#### rocker123uk

Joined Dec 6, 2015
33
mikroc

#### djsfantasi

Joined Apr 11, 2010
7,552