Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

unsigned short current_duty1,current_duty2;

unsigned int out;


void InitMain()
{
TRISA = 0xff;
// configure PORTA pins as input
PORTB = 0;
// set PORTB to 0
TRISB = 0;
// designate PORTB pins as output
PORTC = 0;
// set PORTC to 0
TRISD = 0xff;
TRISC = 0;
// designate PORTC pins as output
PWM1_Init(35000);
// Initialize PWM1 module at 35KHz
PWM2_Init(35000);
// Initialize PWM1 module at 35KHz
}
void main()
{
InitMain();
current_duty2 = 128;
// initial value for current_duty
current_duty1 = 100;
// initial value for current_duty
PWM1_Start();
// start PWM1
PWM1_Set_Duty(current_duty1);
// Set current duty for PWM1
//current_duty = 5;
// initial value for current_duty
PWM2_Start();
// start PWM1
PWM2_Set_Duty(current_duty2);
// Set current duty for PWM1
while (1)
{
out=ADC_Read(0);out=out/20;
PWM1_Set_Duty(current_duty1);
// Set current duty for PWM1
PWM2_Set_Duty(current_duty2);
// Set current duty for PWM1
if(out>=19)
{
/*current_duty1++;
// increment current_duty
if(current_duty1>=210)
{current_duty1=210;}*/
current_duty2++;
if(current_duty2>=210)
{current_duty2=210;}
//PWM1_Set_Duty(current_duty1);
PWM2_Set_Duty(current_duty2);
// Set current duty for PWM1
Delay_ms(100);
out=ADC_Read(0);out=out/20;
}
if(out<=22)
{
// button on RA1 pressed
/*current_duty2++;
// increment current_duty
if(current_duty2>=210)
{current_duty2=210;}*/
current_duty2--;
if(current_duty2<=30)
{current_duty2=30;}
PWM2_Set_Duty(current_duty2);
//PWM1_Set_Duty(current_duty1);
// Set current duty for PWM1
Delay_ms(100);
out=ADC_Read(0);out=out/20;}
}
}

You might also like