Tom2
Full Member level 5
i use an analog input to pic and i generate a pwm.When i change the amplitute of the input i want to change the duty cycle of the pwm.This is not happen.Is anyone know why.I use Pic16F777 and pcm ccs compiler. My code is :
#include <16F777.h>
#device ADC=16
#fuses XT,NOWDT,NOPROTECT
#use delay(clock=4000000)
//long duty_cycle,period;
void main()
{
long adc_result;
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_16);
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_1, 255, 1);
WHILE (1)
{
set_adc_channel(0);
delay_ms(1);
adc_result=read_adc();
adc_result>>=6;
set_pwm1_duty(adc_result);
}
}
#include <16F777.h>
#device ADC=16
#fuses XT,NOWDT,NOPROTECT
#use delay(clock=4000000)
//long duty_cycle,period;
void main()
{
long adc_result;
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_16);
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_1, 255, 1);
WHILE (1)
{
set_adc_channel(0);
delay_ms(1);
adc_result=read_adc();
adc_result>>=6;
set_pwm1_duty(adc_result);
}
}