Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

controling multiple servos by each flex sensor MikroC easypic v7

Status
Not open for further replies.

moad

Newbie level 5
Joined
Jan 30, 2015
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
113
Hi all,

I am trying to control 5 servos using 5 flex sensors. I have succesffuly controlled one servo using 1 flex now when i try to control two m finding it very difficult. can any one suggest any ideas as to why im getting this problem. code runs fine without any errors and the sensors work perfectly (checked the ADC on LCD).

here is my code!


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
unsigned int Adcval;
 unsigned int Adcval2;
 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);
  for(i=0;i<Adcval;i++)
  {
    Delay_us(1);
  }
  PORTB.F0 = 0;
   Delay_us(19500);
 }
void servoRotate1() //0 Degree
{
PORTB.F1 = 1;
  Delay_us(500);
  for(a=0;a<Adcval2;a++)
  {
    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
  ADC_init();
  do
  {
  
    Adcval = ADC_Read(2);
    Adcval = map(Adcval, 455, 588, 0, 255);
    test1 =Adcval;
 
    
    Adcval2 = ADC_Read(3);
    Adcval2 = map(Adcval2, 455, 588, 0, 255);
    test2 = Adcval2;
 
    if (test1!= Adcval) {
       servoRotate0();
    } else if(test2!= Adcval2){
       servoRotate1();
    }
 
 
 
  }while(1);
}

 
Last edited by a moderator:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top