Changeset - 0553e3d8cfb4
[Not reviewed]
cortex-f0
0 2 0
Ethan Zonca - 9 years ago 2015-11-28 14:02:25
ez@ethanzonca.com
Possibly fix runon heating bug
2 files changed with 30 insertions and 22 deletions:
flash.c
3
3
main.c
27
19
0 comments (0 inline, 0 general)
flash.c
Show inline comments
 
@@ -17,12 +17,12 @@ void flash_save(therm_settings_t* tosave
 
{
 
    ssd1306_clearscreen();
 
    ssd1306_DrawString("Erase...", 0, 0);
 
    HAL_Delay(1500);
 
    HAL_Delay(100);
 
    ssd1306_DrawString("Save...", 1, 0);
 
    __flash_write(tosave);
 
    HAL_Delay(1500);
 
    HAL_Delay(100);
 
    ssd1306_DrawString("Done!", 2, 0);
 
    HAL_Delay(1500);
 
    HAL_Delay(500);
 
}
 

	
 

	
main.c
Show inline comments
 
@@ -55,21 +55,21 @@ int main(void)
 
   
 
    // Default settings 
 
    set.val.boottobrew = 0;
 
    set.val.temp_units = TEMP_UNITS_CELSIUS;
 
    set.val.windup_guard = 1;
 
    set.val.k_p = 1;
 
    set.val.k_i = 1;
 
    set.val.temp_units = TEMP_UNITS_FAHRENHEIT;
 
    set.val.windup_guard = 200;
 
    set.val.k_p = 10;
 
    set.val.k_i = 10;
 
    set.val.k_d = 1;
 
    set.val.ignore_tc_error = 0;
 
    set.val.setpoint_brew = 0;
 
    set.val.setpoint_steam = 0;
 
    set.val.setpoint_brew = 70;
 
    set.val.setpoint_steam = 70;
 
 
    // Default status
 
    status.temp = 0;
 
    status.temp_frac = 0;
 
    status.state_resume = 0;
 
    status.state = STATE_IDLE;
 
    status.setpoint = 0;
 
    status.setpoint = 70;
 
    status.pid_enabled = 0;
 
 
    // Load settings (if any) from EEPROM
 
@@ -117,13 +117,12 @@ int main(void)
 
            max31865_readtemp(&set, &status);
 
            #endif
 
 
            HAL_GPIO_TogglePin(LED_POWER);
 
 
            if(status.pid_enabled) 
 
            {
 
                // Get ssr output for next time
 
                int16_t power_percent = pid_update(set.val.k_p, set.val.k_i, set.val.k_d, status.temp, status.temp_frac, status.setpoint, &set, &status);
 
                //power-percent is 0-1000
 
                //power-percent is 0-1000?
 
                ssr_output = power_percent; //(((uint32_t)SSR_PERIOD * (uint32_t)10 * (uint32_t)100) * power_percent) / (uint32_t)1000000;
 
            }
 
            else 
 
@@ -134,27 +133,36 @@ int main(void)
 
            last_pid = HAL_GetTick();
 
        }
 
 
        // Kill SSR once the desired on-time has elapsed
 
        if(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(HAL_GetTick() - last_ssr_on > SSR_PERIOD)
 
        {
 
 
            char tempstr[6];
 
            itoa(ssr_output, tempstr, 10);
 
            ssd1306_DrawString(tempstr, 0, 90);
 
 
 
            // Only support heating (ssr_output > 0) right now
 
            if(ssr_output > 0) {
 
 
                char tempstr[6];
 
                itoa(ssr_output, tempstr, 10);
 
                ssd1306_DrawString(tempstr, 0, 90);
 
 
                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);
 
            }
 
            
 
        }
 
        
 
        // Kill SSR after elapsed period less than SSR_PERIOD 
 
        if(HAL_GetTick() - last_ssr_on > ssr_output || ssr_output == 0)
 
        {
 
            HAL_GPIO_WritePin(SSR_PIN, 0);
 
        }
 
 
        if(HAL_GetTick() - last_vcp_tx > VCP_TX_FREQ)
 
        {
0 comments (0 inline, 0 general)