Hello,
I am new to PIC Microcontrollers, but have gone through all the tutorials. I can write codes on my own for PWM and ADC seperately. But when I try to use both at the same time I don’t get any output signal at CCP1 *checked with Proteus also*
I am trying to use 2 buttons RC4 and RC5 to increase and decrease the PWM duty cycle. And use ADC for lighting up LEDs , but I can get any signal out of CCP1.
Here is the code I tried:
unsigned int ADC;
void main()
{
short duty1 = 16;
CMCON = 0x07;
ADCON1 = 0x80;
TRISA = 0xFF; //input analog signal
TRISC = 0x30; //RC4 RC5 input button, RC2 output PWM
TRISB = 0x00; //output MSB's of ADC
TRISD = 0x00; //output LSB's of ADC
//ADC Function
do
{
ADC = ADC_Read(1);
PORTB = ADC;
PORTD = ADC>>2;
}
while(1);
////////////////////////////////////////////////
//PWM Function
PWM1_Init(5000);
PWM1_Start();
PWM1_set_duty(duty1);
while(1)
{
if (PORTC.F4 == 0)
{
Delay_ms(1);
duty1++;
PWM1_set_duty(duty1);
}
if (PORTC.F5 == 0)
{
delay_ms(1);
duty1--;
PWM1_set_duty(duty1);
}
delay_ms(100);
}
}