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 currentduty1;
unsigned int adcrd2;
long currentduty2;
void main() {
TRISA.RA2= 1 ;
TRISA.RA3= 1 ;
TRISC = 0 ;
TRISB = 0 ;
PWM1Init (6000);
PWM1Start();
PWM2Init (6000);
PWM2Start();
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);
pwm1setDuty(currentduty1);
pwm2setDuty(0); }
else if ( adcrd2> adcrd1){
Delayus(50);
pwm2setDuty(currentduty2);
pwm1setDuty(0);
}
else {
Delayus(100);
pwm1setDuty(0);
pwm2set_Duty(0);
}
}
}