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 adc_rd1 ; long current_duty1; unsigned int adc_rd2; long current_duty2;

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

TRISC = 0 ; TRISB = 0 ;

PWM1_Init (6000); PWM1_Start();

PWM2_Init (6000); PWM2_Start();

ADC_Init(); PORTB.F0 = 1;

while (1) { adc_rd1 = ADC_Read (2); adc_rd2 = ADC_Read (3);

current_duty1 = (long) adc_rd1 * 240; current_duty1 = current_duty1/1023;

current_duty2 = (long) adc_rd2 * 240; current_duty2 = current_duty2/1023;

if( adc_rd1 > adc_rd2){ Delay_us(50); pwm1_set_Duty(current_duty1); pwm2_set_Duty(0); }

else if ( adc_rd2> adc_rd1){ Delay_us(50); pwm2_set_Duty(current_duty2); pwm1_set_Duty(0); }

else { Delay_us(100); pwm1_set_Duty(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
...