How to manage pic 18f4550 pwm motor controller?

0 votes
asked by about mikroC PRO for PIC
edited by

hello I am traying to built pwm motor controller using pic18f4550 and I need help to CHECK and improved my code AND add watchdog timer because my project will run for long time , I will attach my code .

unsigned int adcrd1 ;
long current
duty1;
unsigned int adcrd2;
long current
duty2;

void main() {
TRISA.RA2= 1 ;
TRISA.RA3= 1 ;

TRISC = 0 ;
TRISB = 0 ;

PWM1Init (6000);
PWM1
Start();

PWM2Init (6000);
PWM2
Start();

ADC_Init();
PORTB.F0 = 1;

while (1) {
adcrd1 = ADCRead (2);
adcrd2 = ADCRead (3);

currentduty1 = (long) adcrd1 * 240;
currentduty1 = currentduty1/1023;

currentduty2 = (long) adcrd2 * 240;
currentduty2 = currentduty2/1023;

if( adcrd1 > adcrd2){
Delayus(50);
pwm1
setDuty(currentduty1);
pwm2setDuty(0); }

else if ( adcrd2> adcrd1){
Delayus(50);
pwm2
setDuty(currentduty2);
pwm1setDuty(0);
}

else {
Delayus(100);
pwm1
setDuty(0);
pwm2
set_Duty(0);
}
}
}

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register
...