omega6
Member level 3
- Joined
- Oct 14, 2008
- Messages
- 55
- Helped
- 8
- Reputation
- 16
- Reaction score
- 8
- Trophy points
- 1,288
- Location
- Sri Lanka
- Activity points
- 1,652
Hi Guys,
I'm attempting to build a temperature controlled DC fan based on a PIC12F683 micro controller. Currently my circuit is not working and i need some help to find out the problem. So far this is what i have.
This is the schematic
Appreciate any help and suggestions provided in this matter.
Thank You.
I'm attempting to build a temperature controlled DC fan based on a PIC12F683 micro controller. Currently my circuit is not working and i need some help to find out the problem. So far this is what i have.
Code:
unsigned long int Temp;
unsigned int adc_sample_1, adc_sample_2;
unsigned int adc_sample_3, adc_sample;
int scale_coeff = 2932;
void main() {
WDTCON = 0x0018; //Enable Watchdog timer
PWM1_Init(19530); //Initialize PWM at 19.53KHz (per pic spec-sheet allows 10bit resolution)
ADC_Init(); //Initialize ADC
ADCON0 = 0x1F; //Set VDD as Vref, ANO as analog read
TRISIO.B2 = 0; //Set pin 5 (CCP1) as output, used for PWM
TRISIO.B0 = 1; //Set pin 7 (ANO) as input, used for ADC read
while(1){
//ADC Read at ANO
adc_sample_1 = ADC_Read(0);
Delay_ms(1000);
adc_sample_2 = ADC_Read(0);
Delay_ms(1000);
adc_sample_3 = ADC_Read(0);
Delay_ms(1000);
adc_sample = (adc_sample_1 + adc_sample_2 + adc_sample_3)/3; //Take 3 sample from ADC and take the average
//Read ADC Channel 1
Temp = (adc_sample*scale_coeff)/10000; //Using Integer calculation
//PWM formular for 10 bit resolution: (Percent*1023)/100
if(Temp > 30 && Temp < 40)
{
PWM1_Set_Duty(307); //Set PWM to 30%
PWM1_Start();
}
else if(Temp > 40 && Temp < 50)
{
PWM1_Set_Duty(512); //Set PWM to 50%
PWM1_Start();
}
else if(Temp <= 30)
{
PWM1_Set_Duty(0); //Trun off PWM
PWM1_Stop();
break; //Breaks program out of the while loop and causes it to re-initialize all the registers/start over the process.
}
}
}
This is the schematic
Appreciate any help and suggestions provided in this matter.
Thank You.