Hola buen día...
El asunto es que tengo un controlador de temperatura que es gobernado por un DS1822... no habia porblemas pero;
El control tiene 3 estados, todos dependen de la temperatura
1-.- enciende compresor (A los 7°C)
2.- Apaga compresor (a los 3°C)
3.- Venitacion controlada.
Cada una es una maquina de estado finito, pero estando aqui con el cliente me platico que el control hace cosas raras... lo estuve observando y cuando la temperatura llego a 6.75°C ... inicio el ciclo de refrigeracion... pero se detuvo por que la sonda marco 7.00 y despues 6.75... con el consiguiente descontrol.
Me gustaria saber si esta es la manera decuada de agregar una guarda boleana para que el programa una vez que inicia la maquina de estado finito... no se detenga hasta completarla...
(solo les dejo el codigo correspondiente, el completo es demasiado grande)
void thermostat()
{
//---------------thermostat sequence
if(tempC >= highTemp )
{
turnOnCompressor();
refrigerationBegin = true;
}
if(tempC <= lowTemp )
{
turnOffCompressor();
refrigerattionEnd = true;
}
if( cycleFansvar == true && refOff == false ) // to cycle only once the set of the instructions per cycle.)
{
if(tempC < highTemp -0.25) cycleFans();
}
Serial.print("temperatura = "); Serial.println(tempC);
}
Y aqui esta la supuesta guarda booleana en la maquina de esta finitio.. es correcto?
void turnOnCompressor(){
/*
This subrutine is intended to stop the refrigeration cycle
in the most ordered way, and keeping the refrigerant on
the high side of the system.
*/
// boolean refrigerattion = false; // var to handle ref status only once
// byte compOn = 0;
// byte pascomOn = 0; //to chek if the variable has updated.
// unsigned long comOnTime = 0;
// unsigend long comOnDelay = 1500;
// unsigend long comOnCT = 0; //the current time of the compressor.
//------for debug only
//Serial.print("comOnCT = "); Serial.println(comOnCT);
//Serial.print("comOnCT - millis() = "); Serial.println(millis() - comOnTime );
// Serial.println("INICIANDO REFRIGERACION");
if(refrigerationBegin == true )
{
if(refrigerattion == true && millis()- comOnTime >= comOnDelay ){
compOn ++;
comOnTime = millis();
/*
//--------for debug only
Serial.println("---------------------");
Serial.print("Var compOn "); Serial.println(compOn);
Serial.print("comoON "); Serial.println(compOn);
Serial.print("pascomON"); Serial.println(pascomOn);
Serial.println("---------------------");
*/
}
if(compOn > pascomOn ){
switch(compOn){
case(1):
lcd.setCursor(0,0); lcd.print(F(" CICLO DE "));
lcd.setCursor(0,1); lcd.print(F(" REFRIGERACION "));
lcd.setCursor(0,2); lcd.print(F(" "));
break;
case(2):
lcd.setCursor(0,0); lcd.print(F(" REFRIGERACION "));
lcd.setCursor(0,1); lcd.print(F(" ENCENDIENDO "));
lcd.setCursor(0,2); lcd.print(F(" VENT 1 "));
digitalWrite(dif1, LOW);
break;
case(3):
lcd.setCursor(0,0); lcd.print(F(" REFRIGERACION "));
lcd.setCursor(0,1); lcd.print(F(" ENCENDIENDO "));
lcd.setCursor(0,2); lcd.print(F(" VENT 2 "));
digitalWrite(dif2, LOW);
break;
case(4):
lcd.setCursor(0,0); lcd.print(F(" REFRIGERACION "));
lcd.setCursor(0,1); lcd.print(F(" ENCENDIENDO "));
lcd.setCursor(0,2); lcd.print(F(" SOLENOIDE "));
digitalWrite(solenoid, LOW);
break;
case(5):
lcd.setCursor(0,0); lcd.print(F(" REFRIGERACION "));
lcd.setCursor(0,1); lcd.print(F(" ENCENDIENDO "));
lcd.setCursor(0,2); lcd.print(F(" COMPRESOR "));
digitalWrite(compressor, LOW);
break;
case(6):
lcd.setCursor(0,1); lcd.print(F(" "));
lcd.setCursor(0,2); lcd.print(F(" "));
refrigerattion = false;
refOff = true ; // to cycle only once the set of the instructions per cycle.
compOn = 0;
cycleFansvar = false; //bool to chek the refrigerattion has stop
//--------------------------------
//refrigerattion = true; add this variable at the end of the off routine to cycle the
//operation otherwise will just start once
}
}
}
refrigerationBegin = false;
}
Gracias de antemano.
-Alex.