ayman12204143
Newbie level 1
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: