77 lines
1.8 KiB
C++
77 lines
1.8 KiB
C++
#include "thermo.h"
|
|
#include "controlloop.h"
|
|
|
|
MAX6675 thermocouple(THERM_SS, THERM_MISO, THERM_CLK);
|
|
|
|
uint32_t thermo_lastTime = 0;
|
|
|
|
double lastTemperature = 0;
|
|
|
|
bool simulation = true;
|
|
#define SIM_TEMP_STEP 1
|
|
#define SIM_TEMP_COOL 0.08
|
|
#define SIM_INTERVAL 100
|
|
uint32_t simTimer = 0;
|
|
|
|
void initThermo()
|
|
{
|
|
if(simulation)
|
|
{
|
|
lastTemperature = TEMPERATURE_ROOM-20;
|
|
}
|
|
}
|
|
|
|
void handleThermo(void)
|
|
{
|
|
if(simulation)
|
|
{
|
|
uint32_t timeNow = millis();
|
|
if(timeNow - simTimer > SIM_INTERVAL)
|
|
{
|
|
if(getOutputState())
|
|
{
|
|
lastTemperature += SIM_TEMP_STEP;
|
|
}
|
|
else
|
|
{
|
|
if(lastTemperature > TEMPERATURE_ROOM-20)
|
|
{
|
|
lastTemperature -= SIM_TEMP_COOL;
|
|
}
|
|
}
|
|
simTimer = timeNow;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
lastTemperature = thermocouple.readTempC();
|
|
|
|
}
|
|
}
|
|
|
|
double getTemperature(void)
|
|
{
|
|
return lastTemperature; //lastTemperature;
|
|
}
|
|
|
|
bool getThermoCoupleFault(void)
|
|
{
|
|
#ifdef MAX31856
|
|
uint8_t fault = thermocouple.readFault();
|
|
if (fault)
|
|
{
|
|
if (fault & MAX6675_FAULT_CJRANGE) //Serial.println("Cold Junction Range Fault");
|
|
if (fault & MAX31856_FAULT_TCRANGE) //Serial.println("Thermocouple Range Fault");
|
|
if (fault & MAX31856_FAULT_CJHIGH) //Serial.println("Cold Junction High Fault");
|
|
if (fault & MAX31856_FAULT_CJLOW) //Serial.println("Cold Junction Low Fault");
|
|
if (fault & MAX31856_FAULT_TCHIGH) //Serial.println("Thermocouple High Fault");
|
|
if (fault & MAX31856_FAULT_TCLOW) //Serial.println("Thermocouple Low Fault");
|
|
if (fault & MAX31856_FAULT_OVUV) //Serial.println("Over/Under Voltage Fault");
|
|
if (fault & MAX31856_FAULT_OPEN) //Serial.println("Thermocouple Open Fault");
|
|
return true;
|
|
}
|
|
#else
|
|
return false;
|
|
#endif
|
|
}
|