Amith Jose
Newbie level 4
- Joined
- Aug 12, 2013
- Messages
- 5
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 50
hey am a newbie , trying to make a temp controlled fan using a pic16f877a.
i hope to vary the rpm using PWM .
i made a design and code but unfortunately smething's wrong with it..
i have like zero experience when it comes to PWM, so i doubt the problem is with my code.
I used an 'lm35' to sense the temp and a 'l293d' as the driver circuit to run the fan ..
please help me out .
//code
#include <16F877A.h>
#device adc=8
#FUSES NOWDT,HS
#use delay(clock=20000000)
#include <lcd.c>
void main()
{
int x;
lcd_init();
setup_adc(ADC_CLOCK_DIV_32);
setup_adc_ports(ALL_ANALOG);
setup_timer_2(T2_DIV_BY_4,255,1);
setup_ccp1(CCP_PWM);
delay_ms(500);
while(1)
{
set_adc_channel(0);
x=read_adc();
delay_ms(5);
lcd_putc('\f');
lcd_gotoxy(1,1);
lcd_putc("Temp");
printf(lcd_putc,"%u\n",2*x);
delay_ms(20);
if(x<40)
{ set_pwm1_duty(3*x);
OUTPUT_HIGH(PIN_C6);
OUTPUT_LOW(PIN_C7);
}
else if(x>40)
{set_pwm1_duty(255);
OUTPUT_HIGH(PIN_C6);
OUTPUT_LOW(PIN_c7);
}
else
{OUTPUT_LOW(PIN_C6);
OUTPUT_LOW(PIN_C7);
set_pwm1_duty(0);
}
}
}
i hope to vary the rpm using PWM .
i made a design and code but unfortunately smething's wrong with it..
i have like zero experience when it comes to PWM, so i doubt the problem is with my code.
I used an 'lm35' to sense the temp and a 'l293d' as the driver circuit to run the fan ..
please help me out .
//code
#include <16F877A.h>
#device adc=8
#FUSES NOWDT,HS
#use delay(clock=20000000)
#include <lcd.c>
void main()
{
int x;
lcd_init();
setup_adc(ADC_CLOCK_DIV_32);
setup_adc_ports(ALL_ANALOG);
setup_timer_2(T2_DIV_BY_4,255,1);
setup_ccp1(CCP_PWM);
delay_ms(500);
while(1)
{
set_adc_channel(0);
x=read_adc();
delay_ms(5);
lcd_putc('\f');
lcd_gotoxy(1,1);
lcd_putc("Temp");
printf(lcd_putc,"%u\n",2*x);
delay_ms(20);
if(x<40)
{ set_pwm1_duty(3*x);
OUTPUT_HIGH(PIN_C6);
OUTPUT_LOW(PIN_C7);
}
else if(x>40)
{set_pwm1_duty(255);
OUTPUT_HIGH(PIN_C6);
OUTPUT_LOW(PIN_c7);
}
else
{OUTPUT_LOW(PIN_C6);
OUTPUT_LOW(PIN_C7);
set_pwm1_duty(0);
}
}
}
Last edited: