Changeset - c1b2840961f0
[Not reviewed]
tip default
0 9 0
Ethan Zonca <ethanzonca> - 21 months ago 2023-07-17 17:16:01

Hacking thermostatic mode into operation. This code needs some love.
9 files changed with 49 insertions and 33 deletions:
0 comments (0 inline, 0 general)
.settings/language.settings.xml
Show inline comments
 
@@ -5,7 +5,7 @@
 
			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
 
			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
 
			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
 
			<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-372386926437939920" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
 
			<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="118157264982881376" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
 
				<language-scope id="org.eclipse.cdt.core.gcc"/>
 
				<language-scope id="org.eclipse.cdt.core.g++"/>
 
			</provider>
 
@@ -16,7 +16,7 @@
 
			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
 
			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
 
			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
 
			<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-352937073990100134" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
 
			<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="124662482003330422" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
 
				<language-scope id="org.eclipse.cdt.core.gcc"/>
 
				<language-scope id="org.eclipse.cdt.core.g++"/>
 
			</provider>
inc/config.h
Show inline comments
 
@@ -51,6 +51,9 @@
 
#define DEFAULT_SETPOINT_COUNT 1
 
#define DEFAULT_SETPOINT_AUX_SELECT_ENABLE 0
 
 
#define DEFAULT_CONTROL_MODE 1 // thermostat
 
#define DEFAULT_PLANT_TYPE 1
 
 
 
//////////////////////////////////////////////////////
 
// Watchdog Settings
inc/pwmout.h
Show inline comments
 
@@ -6,9 +6,6 @@
 
#include "flash.h"
 
#include "error.h"
 

	
 
#define SSR_PIN GPIO_PIN_7
 
#define SSR_GPIO_Port GPIOB
 
#define SSR SSR_GPIO_Port, SSR_PIN
 

	
 

	
 

	
inc/system/gpio.h
Show inline comments
 
@@ -43,6 +43,10 @@
 
#define AUX_RETURN_GPIO_Port GPIOA
 
#define AUX_RETURN AUX_RETURN_GPIO_Port , AUX_RETURN_Pin
 
 
#define SSR_PIN GPIO_PIN_7
 
#define SSR_GPIO_Port GPIOB
 
#define SSR SSR_GPIO_Port, SSR_PIN
 
 
 
void user_input(uint16_t* to_modify);
 
void user_input_min_max(uint16_t* to_modify, uint16_t min, uint16_t max);
src/main.c
Show inline comments
 
@@ -80,7 +80,7 @@ int main(void)
 
 
        if(flash_getsettings()->val.control_mode == MODE_PID && (HAL_GetTick() - last_pid > PID_PERIOD))
 
        {
 
            duty = pid_process();
 
            //duty = pid_process();
 
            last_pid = HAL_GetTick();
 
        }
 
 
@@ -91,7 +91,7 @@ int main(void)
 
            last_thermostat = HAL_GetTick();
 
        }
 
 
        pwmout_process((int16_t)duty);
 
        //pwmout_process((int16_t)duty);
 
        display_process();
 
        watchdog_feed();
 
src/pwmout.c
Show inline comments
 
@@ -88,8 +88,8 @@ void pwmout_process(int16_t duty)
 
{
 
    if(duty == 0)
 
    {
 
        HAL_GPIO_WritePin(SSR, 0);
 
        HAL_GPIO_WritePin(LED, 0);
 
//        HAL_GPIO_WritePin(SSR, 0);
 
//        HAL_GPIO_WritePin(LED, 0);
 
    }
 
    if(duty < 0)
 
        duty = 0;
src/system/flash.c
Show inline comments
 
@@ -77,6 +77,8 @@ void flash_restoresettings(void)
 
        settings.val.windup_guard = DEFAULT_WINDUP_GUARD;
 
        settings.val.sensor_type = 1;
 
        settings.val.setpoint_count = DEFAULT_SETPOINT_COUNT;
 
        settings.val.control_mode = DEFAULT_CONTROL_MODE;
 
        settings.val.plant_type = DEFAULT_PLANT_TYPE;
 
    }
 
}
 
src/system/interrupts.c
Show inline comments
 
@@ -66,8 +66,8 @@ void HAL_TIM_PWM_PulseFinishedCallback(T
 
{
 
    if(htim == pwmout_get_tim())
 
    {
 
        HAL_GPIO_WritePin(SSR, 0);
 
        HAL_GPIO_WritePin(LED, 0);
 
//        HAL_GPIO_WritePin(SSR, 0);
 
//        HAL_GPIO_WritePin(LED, 0);
 
    }
 
}
 
 
@@ -77,13 +77,13 @@ void HAL_TIM_PeriodElapsedCallback(TIM_H
 
    {
 
        if(htim->Instance->CCR1 == 0)
 
        {
 
            HAL_GPIO_WritePin(LED, 0);
 
            HAL_GPIO_WritePin(SSR, 0);
 
//            HAL_GPIO_WritePin(LED, 0);
 
//            HAL_GPIO_WritePin(SSR, 0);
 
        }
 
        else
 
        {
 
            HAL_GPIO_WritePin(LED, 1);
 
            HAL_GPIO_WritePin(SSR, 1);
 
//            HAL_GPIO_WritePin(LED, 1);
 
//            HAL_GPIO_WritePin(SSR, 1);
 
        }
 
    }
 
}
src/thermostat.c
Show inline comments
 
@@ -3,8 +3,10 @@
 
//
 

	
 
#include "thermostat.h"
 
#include "gpio.h"
 

	
 
// PID implementation
 
// Thermostatic control implementation
 
static uint8_t thermostat_plant_on = 0;
 

	
 
float thermostat_process(void)
 
{
 
@@ -15,23 +17,28 @@ float thermostat_process(void)
 
    //			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;
 

	
 
    float temp = runtime_status()->temp; // (scale to whole degrees)
 
    uint32_t hyst = flash_getsettings()->val.hysteresis;
 

	
 
    // 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;
 
    if(flash_getsettings()->val.plant_type == PLANT_HEATER)
 
    {
 
    	if(temp < runtime_status()->setpoint - hyst)
 
        		thermostat_plant_on = 1;
 
    	if(temp > runtime_status()->setpoint + hyst)
 
    		thermostat_plant_on = 0;
 
    }
 

	
 
    if(flash_getsettings()->val.plant_type == PLANT_COOLER)
 
	{
 
    	if(temp < runtime_status()->setpoint - hyst)
 
			thermostat_plant_on = 0;
 
    	if(temp > runtime_status()->setpoint + hyst)
 
    		thermostat_plant_on = 1;
 
	}
 

	
 
    // EMZ: TODO: Refactor to output_enabled or something
 
    if(runtime_status()->pid_enabled && thermostat_plant_on)
 
@@ -40,21 +47,24 @@ float thermostat_process(void)
 
        // 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);
 
        itoa(thermostat_plant_on, tempstr, 10);
 
        ssd1306_drawstring(tempstr, 0, 90);
 

	
 

	
 

	
 
        //                HAL_GPIO_WritePin(SSR_PIN, 1);
 
		HAL_GPIO_WritePin(SSR, 1);
 
        HAL_GPIO_WritePin(LED, 1);
 
    }
 
    else
 
    {
 
        //                HAL_GPIO_WritePin(SSR_PIN, 0);
 
        HAL_GPIO_WritePin(LED, 0);
 
		HAL_GPIO_WritePin(SSR, 0);
 
		HAL_GPIO_WritePin(LED, 0);
 
    }
 

	
 
    return ssr_output;
 
    if(thermostat_plant_on)
 
    	return 1000.0f;
 
    else
 
    	return 0.0f;
 
}
 

	
 

	
0 comments (0 inline, 0 general)