#include <12F683.h>
#device adc=10
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOCPD //No EE protection
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES PUT //Power Up Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#use delay(clock=8000000)
#define set_temp_max 50.0 // temperatura efriamiento.
#define set_temp_min 30 //
int16 d;
int16 digital_reading; // ADC resolution is 10Bit, an 8Bit integer is not enough to hold the reading
float temp;
void main()
{
/* ADC Initialization */
setup_oscillator(OSC_8MHZ); // reloj interno micro
setup_adc(ADC_CLOCK_INTERNAL); //
setup_adc_ports(sAN3); // Establecer PIN_A3 como canal de entrada analógica
set_adc_channel(3); // canal 3 para la lectura del ADC
setup_ccp1(CCP_PWM); // Configure CCP1 as a PWM
setup_timer_2(T2_DIV_BY_1, 79, 1); // frecuenca 25Khz cooler
delay_ms(1); // ADC module is slow, needs some time to adjust.
while(true) // infinite loop
{
digital_reading = read_adc(); // capture current temperature reading
delay_us(100); // 0.1ms delay for ADC stabilization
temp = digital_reading * 0.4883; // convert reading to Celsius
//lcd_gotoxy(1,2); // point LCD cursor to col1 row2
//printf(lcd_putc,"%2.1f C",temp); // print value on LCD
//---- Arranca el cooler al 50% de su velocidad --\\
if(temp <= set_temp_min) // si temp es - que set_temp_min (29°)
{//output_high(LOAD); // Control Load
//else output_low(LOAD);
d=160; //al 50%
set_pwm1_duty(d);
delay_ms(1000); // 1 second delay between readings
}
else if(temp>=set_temp_max) // si temp es + que set_temp (50°) cooler al 100%
{//output_high(LOAD); // Control Load
//else output_low(LOAD);
d=320; //al 100%
set_pwm1_duty(d);
delay_ms(1000); // 1 second delay between readings
}
}
}
PWM = 8*Temp - 80;set_temp_min = 15
set_temp_max = 50