Changeset - 953c718ee4cf
[Not reviewed]
default
0 8 0
Ethan Zonca (ethanzonca) - 8 years ago 2017-07-07 14:33:37
e@ethanzonca.com
Various changes forgotten to commit
8 files changed with 141 insertions and 89 deletions:
0 comments (0 inline, 0 general)
inc/pwmout.h
Show inline comments
 
@@ -2,6 +2,12 @@
 
#define PWMOUT_H
 

	
 

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

	
 

	
 

	
 
void pwmout_init(void);
 
void pwmout_process(float duty);
 

	
inc/system/gpio.h
Show inline comments
 
@@ -29,7 +29,6 @@
 
#define LED_GPIO_Port GPIOB
 
#define LED LED_GPIO_Port, LED_PIN
 
 
/// SSR PIN ???///
 
 
void user_input(uint16_t* to_modify);
 
void user_input_signed(int32_t* to_modify);
src/display.c
Show inline comments
 
@@ -45,6 +45,14 @@ void display_1hz(void)
 
	toggle = !toggle;
 
}
 

	
 
static char updown(void)
 
{
 
	if(toggle)
 
		return '\x8f';
 
	else
 
		return '\x90';
 
}
 

	
 
// Display state machine
 
void display_process(void)
 
{
 
@@ -165,6 +173,7 @@ void display_process(void)
 
            ssd1306_drawstring("Sensor Type", 0, 40);
 
            ssd1306_drawlogo();
 

	
 
            ssd1306_drawchar(updown(), 1, 52);
 
			ssd1306_drawstring(sensor_lookup[set->val.sensor_type], 1, 60);
 
            ssd1306_drawstring("Press to accept", 3, 40);
 

	
 
@@ -192,6 +201,9 @@ void display_process(void)
 
            ssd1306_drawstring("Control Mode", 0, 40);
 
            ssd1306_drawlogo();
 

	
 
            ssd1306_drawchar(updown(), 1, 52);
 

	
 

	
 
            if(set->val.control_mode == MODE_PID)
 
                ssd1306_drawstring("PID       ", 1, 60);
 
            else
 
@@ -223,6 +235,8 @@ void display_process(void)
 
            ssd1306_drawstring("Plant Type", 0, 40);
 
            ssd1306_drawlogo();
 

	
 
            ssd1306_drawchar(updown(), 1, 52	);
 

	
 
            if(set->val.plant_type == PLANT_HEATER)
 
                ssd1306_drawstring("Heater", 1, 60);
 
            else
 
@@ -250,33 +264,6 @@ void display_process(void)
 

	
 

	
 

	
 
        case STATE_SETHYSTERESIS:
 
        {
 
            // Write text to OLED
 
            ssd1306_drawstring("Hysteresis", 0, 40);
 
            ssd1306_drawlogo();
 

	
 
            char tempstr[6];
 
            itoa(set->val.hysteresis, tempstr, 10);
 
            ssd1306_drawstring("H=", 1, 45);
 
            ssd1306_drawstring("    ", 1, 57);
 
            ssd1306_drawstring(tempstr, 1, 57);
 

	
 
            ssd1306_drawstring("Press to accept", 3, 40);
 
            
 
            // Button handler
 
            if(SW_BTN_PRESSED) {
 
                status->state = STATE_SETBOOTTOBREW;
 
            }
 
            else {
 
                user_input((uint16_t*)&set->val.hysteresis);
 
            }
 

	
 
            // Event Handler
 
            // N/A
 
 
 
        } break;
 

	
 

	
 
        case STATE_SETP:
 
        {
 
@@ -286,12 +273,11 @@ void display_process(void)
 
            ssd1306_drawstring("Proportional", 0, 40);
 
            ssd1306_drawlogo();
 

	
 
            char tempstr[6];
 
            itoa(set->val.k_p, tempstr, 10);
 
            ssd1306_drawstring("P=", 1, 45);
 
            ssd1306_drawstring("    ", 1, 57);
 
            ssd1306_drawstring(tempstr, 1, 57);
 
            ssd1306_drawchar(updown(), 1, 52);
 

	
 
            char tempstr[12];
 
            snprintf(tempstr, 12, "P=%d", set->val.k_p);
 
            ssd1306_drawstring(tempstr, 1, 60);
 
            ssd1306_drawstring("Press to accept", 3, 40);
 
            
 
            // Button handler
 
@@ -315,11 +301,11 @@ void display_process(void)
 
            ssd1306_drawstring("Integral", 0, 40);
 
            ssd1306_drawlogo();
 

	
 
            char tempstr[6];
 
            itoa(set->val.k_i, tempstr, 10);
 
            ssd1306_drawstring("I=", 1, 45);
 
            ssd1306_drawstring("    ", 1, 57);
 
            ssd1306_drawstring(tempstr, 1, 57);
 
            ssd1306_drawchar(updown(), 1, 52);
 

	
 
            char tempstr[12];
 
            snprintf(tempstr, 12, "I=%d", set->val.k_i);
 
            ssd1306_drawstring(tempstr, 1, 60);
 

	
 
            ssd1306_drawstring("Press to accept", 3, 40);
 
            
 
@@ -344,11 +330,11 @@ void display_process(void)
 
            ssd1306_drawstring("Derivative", 0, 40);
 
            ssd1306_drawlogo();
 

	
 
            char tempstr[6];
 
            itoa(set->val.k_d, tempstr, 10);
 
            ssd1306_drawstring("D=", 1, 45);
 
            ssd1306_drawstring("    ", 1, 57);
 
            ssd1306_drawstring(tempstr, 1, 57);
 
            ssd1306_drawchar(updown(), 1, 52);
 

	
 
            char tempstr[12];
 
            snprintf(tempstr, 12, "D=%d", set->val.k_d);
 
            ssd1306_drawstring(tempstr, 1, 60);
 

	
 
            ssd1306_drawstring("Press to accept", 3, 40);
 

	
 
@@ -365,6 +351,36 @@ void display_process(void)
 
 
 
        } break;
 

	
 

	
 

	
 
        case STATE_SETHYSTERESIS:
 
        {
 
            // Write text to OLED
 
            ssd1306_drawstring("Hysteresis", 0, 40);
 
            ssd1306_drawlogo();
 

	
 
            ssd1306_drawchar(updown(), 1, 52);
 

	
 
            char tempstr[12];
 
            snprintf(tempstr, 12, "H=%d", set->val.hysteresis);
 
            ssd1306_drawstring(tempstr, 1, 60);
 

	
 
            ssd1306_drawstring("Press to accept", 3, 40);
 

	
 
            // Button handler
 
            if(SW_BTN_PRESSED) {
 
                status->state = STATE_SETBOOTTOBREW;
 
            }
 
            else {
 
                user_input((uint16_t*)&set->val.hysteresis);
 
            }
 

	
 
            // Event Handler
 
            // N/A
 

	
 
        } break;
 

	
 

	
 
        case STATE_SETWINDUP:
 
        {
 
            // Write text to OLED
 
@@ -373,11 +389,11 @@ void display_process(void)
 
            ssd1306_drawstring("Windup Guard", 0, 40);
 
            ssd1306_drawlogo();
 

	
 
            char tempstr[6];
 
            itoa(set->val.windup_guard, tempstr, 10);
 
            ssd1306_drawstring("G=", 1, 45);
 
            ssd1306_drawstring("    ", 1, 57);
 
            ssd1306_drawstring(tempstr, 1, 57);
 
            ssd1306_drawchar(updown(), 1, 52);
 

	
 
            char tempstr[12];
 
            snprintf(tempstr, 12, "G=%d", set->val.windup_guard);
 
            ssd1306_drawstring(tempstr, 1, 60);
 

	
 
            ssd1306_drawstring("Press to accept", 3, 40);
 

	
 
@@ -402,12 +418,14 @@ void display_process(void)
 
            ssd1306_drawstring("Start on Boot", 0, 40);
 
            ssd1306_drawlogo();
 

	
 
            ssd1306_drawstring("sob=", 1, 45);
 
            ssd1306_drawstring("sob=", 1, 50);
 
            
 
            ssd1306_drawchar(updown(), 1, 43);
 

	
 
            if(set->val.boottobrew)
 
                ssd1306_drawstring("Enabled ", 1, 70);
 
                ssd1306_drawstring("Enable ", 1, 75);
 
            else
 
                ssd1306_drawstring("Disabled", 1, 70);
 
                ssd1306_drawstring("Disable", 1, 75);
 

	
 
            ssd1306_drawstring("Press to accept", 3, 40);
 

	
 
@@ -435,6 +453,8 @@ void display_process(void)
 
            ssd1306_drawstring("Units: ", 0, 40);
 
            ssd1306_drawlogo();
 

	
 
            ssd1306_drawchar(updown(), 1, 52);
 

	
 
            if(set->val.temp_units == TEMP_UNITS_FAHRENHEIT)
 
                ssd1306_drawstring("Fahrenheit", 1, 60);
 
            else
 
@@ -467,11 +487,11 @@ void display_process(void)
 
            ssd1306_drawstring("Temp Cal Offset", 0, 40);
 
            ssd1306_drawlogo();
 

	
 
            char tempstr[6];
 
            itoa(set->val.temp_offset, tempstr, 10);
 
            ssd1306_drawstring("O=", 1, 45);
 
            ssd1306_drawstring("    ", 1, 57);
 
            ssd1306_drawstring(tempstr, 1, 57);
 
            ssd1306_drawchar(updown(), 1, 52);
 

	
 
            char tempstr[12];
 
            snprintf(tempstr, 12, "O=%d", set->val.temp_offset);
 
            ssd1306_drawstring(tempstr, 1, 60);
 

	
 
            ssd1306_drawstring("Press to accept", 3, 40);
 

	
 
@@ -709,8 +729,8 @@ static void draw_setpoint(therm_status_t
 
        ssd1306_drawstringbig(">", 3, 74);
 

	
 
    if(status->setpoint != setpoint_last || trigger_drawsetpoint) {
 
        char tempstr[5];
 
        snprintf(tempstr, 5, "%g     ", status->setpoint);
 
        char tempstr[4];
 
        snprintf(tempstr, 4, "%g     ", status->setpoint);
 
        ssd1306_drawstringbig(tempstr, 3, 90);
 
    }
 

	
src/main.c
Show inline comments
 
@@ -30,7 +30,7 @@ int main(void)
 
	// Startup screen
 
    display_startup_screen();
 
    HAL_Delay(2000);
 
 
    ssd1306_clearscreen();
 
	ssd1306_drawlogo();
 
 
    // Default status
 
@@ -50,6 +50,7 @@ int main(void)
 
    uint32_t last_pid = 0;
 
    uint32_t last_thermostat = 0;
 
    uint32_t last_1hz = 0;
 
    uint32_t last_5hz = 0;
 
 
	while (1)
 
	{
 
@@ -61,10 +62,17 @@ int main(void)
 
			last_1hz = HAL_GetTick();
 
		}
 
 
		if(HAL_GetTick() - last_5hz > 200)
 
		{
 
			tempsense_readtemp();
 
//			runtime_status = tempsense_gettemp();
 
			last_5hz = HAL_GetTick();
 
		}
 
 
        if(flash_getsettings()->val.control_mode == MODE_PID && (HAL_GetTick() - last_pid > PID_PERIOD))
 
        {
 
//        	runtime_status()->temp = tempsense_readtemp();
 
//        	duty = pid_process();
 
        	duty = pid_process();
 
            last_pid = HAL_GetTick();
 
        }
 
 
@@ -72,7 +80,7 @@ int main(void)
 
        if(flash_getsettings()->val.control_mode == MODE_THERMOSTAT && HAL_GetTick() - last_thermostat > SSR_PERIOD)
 
        {
 
//        	runtime_status()->temp = tempsense_readtemp();
 
//        	duty = thermostat_process();
 
        	duty = thermostat_process();
 
            last_thermostat = HAL_GetTick();
 
        }
 
src/pid.c
Show inline comments
 
@@ -44,7 +44,7 @@ float pid_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);
 
		snprintf(tempstr, 6, "%g", ssr_output);
 
		ssd1306_drawstring(tempstr, 0, 90);
 
	}
 
	else
src/pwmout.c
Show inline comments
 
@@ -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);
 
		}
 

	
 
	}
 
}
 

	
 

	
src/system/flash.c
Show inline comments
 
@@ -69,6 +69,10 @@ void flash_restoresettings(void)
 
	// No data in flash! Set defaults here
 
	else
 
	{
 
		settings.val.k_p = 10;
 
		settings.val.k_i = 0;
 
		settings.val.k_d = 0;
 
		settings.val.windup_guard = 300;
 
		//torestore.values.can_id = 22;
 
	}
 
}
src/tempsense.c
Show inline comments
 
@@ -50,3 +50,4 @@ float tempsense_readtemp(void)
 
}
 

	
 

	
 

	
0 comments (0 inline, 0 general)