I recently did a project with a PIC12F675 in order to control the temperature of some internet equipment. It has the PIC, an LM35 sensor, one NPN BJT, one fan and 3 3mm led's.
I think you might be seeing what all this does... it just switches the fan ON and OFF to control the temperature sensed by the LM35.
The 3 led's just give me some information of what's happening, like a thermometer...
The code is working great, I had some problems with MCLRE but I put it as internal and was solved. The thing is, the middle led somehow doesn´t stay as bright as the other two and I don't have any idea why.
The resistors are all the same (1K), the led is also OK (I tested it separate) and the other two have a nice bright light. The middle one I hardly can tell when it's ON.
If someone has the solution for this problem I would be very thankful!
This is my code:
Code: Select all
//Input of calibration values:
// Temp(0~255) = Temp(ºC) x 255
const min_temp = 168; //min_temp ~= 33ºC | --------------
const max_temp = 219; //max_temp ~= 43ºC | 50
unsigned short zone_1 = (0.2 * (max_temp - min_temp)) + min_temp;
unsigned short zone_2 = (0.4 * (max_temp - min_temp)) + min_temp;
unsigned short zone_3 = (0.6 * (max_temp - min_temp)) + min_temp;
unsigned short zone_4 = (0.8 * (max_temp - min_temp)) + min_temp;
unsigned short temperature;
#define red GPIO.F5
#define yellow GPIO.F4
#define fan GPIO.F2
#define green GPIO.F1
//------------------------------------------------------------------------------
void InitMain()
{
OPTION_REG = 3;
GPIO = 0;
TRISIO = 4;
ANSEL = 1;
ADCON0.VCFG = 0;
}
//------------------------------------------------------------------------------
void Thermo_LED()
{
temperature = Adc_Read(ANS0) >> 2;
if(temperature < zone_1)
{
yellow = 1;
green = 0;
red = 0;
}
if((temperature < zone_2) && (temperature >= zone_1))
{
yellow = 1;
green = 1;
red = 0;
}
if((temperature <= zone_3) && (temperature >= zone_2))
{
yellow = 0;
green = 1;
red = 0;
}
if((temperature <= zone_4) && (temperature > zone_3))
{
yellow = 0;
green = 1;
red = 1;
}
if(temperature > zone_4)
{
yellow = 0;
green = 0;
red = 1;
}
asm {CLRWDT}
}
//------------------------------------------------------------------------------
void main()
{
InitMain();
delay_ms(25);
Fan_OFF: fan = 0;
while(1)
{
temperature = Adc_Read(ANS0) >> 2;
if(temperature >= max_temp)
{
goto Fan_ON;
}
asm {CLRWDT}
Thermo_LED();
}
Fan_ON: fan = 1;
while(1)
{
temperature = Adc_Read(ANS0) >> 2;
if(temperature <= min_temp)
{
goto Fan_OFF;
}
asm {CLRWDT}
Thermo_LED();
}
}