diff --git a/src/pwmout.c b/src/pwmout.c --- a/src/pwmout.c +++ b/src/pwmout.c @@ -3,47 +3,61 @@ // #include "pwmout.h" +#include "gpio.h" #include "flash.h" static uint32_t last_ssr_on = 0; -static uint32_t last_vcp_tx = 0; -static uint32_t last_led = 0; void pwmout_init(void) { + GPIO_InitTypeDef GPIO_InitStruct; + + // Configure LED GPIO pins + GPIO_InitStruct.Pin = SSR_PIN; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(SSR_GPIO_Port, &GPIO_InitStruct); } + +// freaking integral term isn't compatible with both heating and cooling... due to the discard +// functionality. this is a problem. + +// also duty cycling isn't working correctly... void pwmout_process(float duty) { - // // Kill SSR once the desired on-time has elapsed - // if(set.val.control_mode == MODE_PID && (HAL_GetTick() - last_ssr_on > ssr_output || ssr_output <= 0)) - // { - // HAL_GPIO_WritePin(SSR_PIN, 0); - // HAL_GPIO_WritePin(LED_POWER, 0); - // } - // - // - // // Every 200ms, set the SSR on unless output is 0 - // if(set.val.control_mode == MODE_PID && HAL_GetTick() - last_ssr_on > SSR_PERIOD) - // { - // // Heat or cool, if we need to - // if(ssr_output > 0) - // { - // HAL_GPIO_WritePin(SSR_PIN, 1); - // HAL_GPIO_WritePin(LED_POWER, 1); - // last_ssr_on = HAL_GetTick(); - // } - // else { - // // Make sure everything is off - // HAL_GPIO_WritePin(SSR_PIN, 0); - // HAL_GPIO_WritePin(LED_POWER, 0); - // } - // - // } + uint32_t ssr_output = duty; // meh + + // Kill SSR once the desired on-time has elapsed + if(flash_getsettings()->val.control_mode == MODE_PID && ((HAL_GetTick() - last_ssr_on > ssr_output) || ssr_output <= 0)) + { + HAL_GPIO_WritePin(SSR, 0); + HAL_GPIO_WritePin(LED, 0); + } + + + // Every 200ms, set the SSR on unless output is 0 + if(flash_getsettings()->val.control_mode == MODE_PID && HAL_GetTick() - last_ssr_on > SSR_PERIOD) + { + // Heat or cool, if we need to + if(ssr_output > 0) + { + HAL_GPIO_WritePin(SSR, 1); + HAL_GPIO_WritePin(LED, 1); + last_ssr_on = HAL_GetTick(); + } + else { + // Make sure everything is off + HAL_GPIO_WritePin(SSR, 0); + HAL_GPIO_WritePin(LED, 0); + } + + } }