Files
@ f153d4ca027c
Branch filter:
Location: therm-ng/src/thermostat.c - annotation
f153d4ca027c
1.8 KiB
text/plain
PID control kinda working, still can't do 0percent duty
2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da 2b4eb31dd8da | //
// Thermostat: Thermostatic controller
//
#include "thermostat.h"
#include "flash.h"
#include "gpio.h"
// PID implementation
float thermostat_process(void)
{
// #ifdef MAX31865_RTD_SENSOR
// max31865_readtemp(spi_get(), &set, &status);
// #else
// max31855_readtemp(spi_get(), &set, &status); // Read MAX31855
// #endif
float ssr_output = 0.0;
uint8_t thermostat_plant_on = 0;
// TODO: Migrate this FxP conversion to the readtemp code or similar
float temp = runtime_status()->temp;
// EMZ FIXME: This could be way simpler
if(flash_getsettings()->val.plant_type == PLANT_HEATER && runtime_status()->setpoint * 10 < temp - flash_getsettings()->val.hysteresis * 10)
thermostat_plant_on = 1;
else if(flash_getsettings()->val.plant_type == PLANT_HEATER && runtime_status()->setpoint * 10 > temp + flash_getsettings()->val.hysteresis * 10)
thermostat_plant_on = 0;
if(flash_getsettings()->val.plant_type == PLANT_COOLER && runtime_status()->setpoint * 10 > temp + flash_getsettings()->val.hysteresis * 10)
thermostat_plant_on = 1;
else if(flash_getsettings()->val.plant_type == PLANT_COOLER && runtime_status()->setpoint * 10 < temp - flash_getsettings()->val.hysteresis * 10)
thermostat_plant_on = 0;
// EMZ: TODO: Refactor to output_enabled or something
if(runtime_status()->pid_enabled && thermostat_plant_on)
{
// EMZ TODO: functionalize this
// put ssr output on display
ssd1306_drawstring(" ", 0, 90); //fixme: this is bad, but I can't get the old digits to clear otherwise
char tempstr[6];
itoa(ssr_output, tempstr, 10);
ssd1306_drawstring(tempstr, 0, 90);
// HAL_GPIO_WritePin(SSR_PIN, 1);
HAL_GPIO_WritePin(LED, 1);
}
else
{
// HAL_GPIO_WritePin(SSR_PIN, 0);
HAL_GPIO_WritePin(LED, 0);
}
return ssr_output;
}
|