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.

[PIC] servo control pic 18f4550

Status
Not open for further replies.

ayman12204143

Newbie level 1
Newbie level 1
Joined
Apr 28, 2016
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
13

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
void main() {
 unsigned int i;
 float j;
 float adc1,adc2;
 adc1=0;
PORTA=1;
TRISA=0xff;
ADC_Init;
PORTC=0;
TRISC=0;
TRISB=0;
   PR2 =  0xFA;                 //oxFA for 250  (used to set time period)
   PWM1_Init(5000);
   PWM1_Start();                       // start PWM1
   CCP2CON |= (1<<2)|(1<<3);            //  select for PWM mode
   T2CON |= (1<<2)|(1<<1);              // enabling timer 2, prescalar 16
 
 
do{
   adc1=ADC_Read(2);
   adc2=ADC_Read(1);
   for(i=0;i<50;i++)
    {
     PWM1_Set_Duty(adc2);
     CCPR2L=adc1;
     PORTB.F3=PORTC.F1;
     delay_us(10);
    }
  }
while(1);
}




i wrote this code to control a servo using a potentiometer the problem is when i simulate this on proteus the potentiometer sends signal from 5% to 14% is there any thing wrong with te code?
 
Last edited by a moderator:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top