john120
Banned
- Joined
- Aug 13, 2011
- Messages
- 257
- Helped
- 11
- Reputation
- 22
- Reaction score
- 10
- Trophy points
- 1,298
- Activity points
- 0
Hello,there can you please help me to generate a pwm signal for controlling a TRIAC which deals with bulb light control and use its duty cycle as the value of Potentiometer connected to the analog input .
please help see the codes and poteus circuits.
,the circuit is here
Please help.
please help see the codes and poteus circuits.
PHP:
#include<16f877a.h>
#device ADC = 10 // Need to tell compiler ADC is configured for 10-bit reading
#fuses HS,NOWDT
#use delay(clock=12000000)
#include<stdio.h>
#include<STDLIB.H>
#use standard_io(A)
#use standard_io(B)
#use standard_io(D)
#define PORTB
#DEFINE PORTC
#define PORTA
//byte const digit[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
//char display[3];
int value;
//unsigned long volt;
//unsigned int value2;
void main(){
set_tris_A(0xFF);
set_tris_B(0X00);
set_tris_D(0x00);
output_b(0);
output_d(0);
setup_comparator(NC_NC_NC_NC);
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(AN0);
set_adc_channel(0);
setup_vref(FALSE);
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_1, 25, 1);
set_pwm1_duty(volt);
while(TRUE)
{
delay_us(100);
//value=read_adc(); //Not required
read_adc(ADC_START_ONLY);
delay_us(100);
value=read_adc(ADC_READ_ONLY);
volt=(value*5)/1023;
}
}
Please help.