Changeset - f34fa8317622
[Not reviewed]
cortex-f0
0 3 0
matthewreed - 9 years ago 2015-12-30 16:41:13

updated RTD code to support higher resolution readings and made some fixes to displaying them.
3 files changed with 18 insertions and 14 deletions:
0 comments (0 inline, 0 general)
display.c
Show inline comments
 
@@ -21,26 +21,28 @@ static uint8_t sw_right_last = 0;
 
#define SW_RIGHT_PRESSED (sw_right_last == 0 && sw_right == 1)
 

	
 

	
 
// States
 
static uint8_t trigger_drawsetpoint = 1;
 
static int16_t last_temp = 21245;
 
static int16_t last_temp_frac = 21245;
 
static int16_t last_state = STATE_IDLE;
 
static uint8_t goto_mode = MODE_HEAT;
 
static uint8_t reset_mode = RESET_REBOOT;
 

	
 

	
 

	
 
// Display state machine
 
void display_process(therm_settings_t* set, therm_status_t* status)
 
{
 
    uint8_t state_changed = status->state != last_state;
 
    last_state = status->state;
 
    
 
    uint8_t temp_changed = status->temp != last_temp;
 
    uint8_t temp_changed = status->temp != last_temp || status->temp_frac != last_temp_frac;
 
    last_temp = status->temp;
 
    last_temp_frac = status->temp_frac;
 

	
 
    uint8_t sw_btn = !HAL_GPIO_ReadPin(SW_BTN);
 
    uint8_t sw_up = !HAL_GPIO_ReadPin(SW_UP);
 
    uint8_t sw_down = !HAL_GPIO_ReadPin(SW_DOWN);
 
    uint8_t sw_left = !HAL_GPIO_ReadPin(SW_LEFT);
 
    uint8_t sw_right = !HAL_GPIO_ReadPin(SW_RIGHT);
 
@@ -537,18 +539,19 @@ void display_process(therm_settings_t* s
 
    sw_left_last = sw_left;
 
    sw_right_last = sw_right;
 
}
 

	
 

	
 
static int32_t temp_last = 43002;
 
static int32_t temp_frac_last = 43002;
 
static int32_t setpoint_last = 10023;
 

	
 
// Draw current setpoint on display
 
static void draw_setpoint(therm_status_t* status) {
 
    // FIXME: need to do this when switching modes too
 
    if(status->temp != temp_last || trigger_drawsetpoint) { 
 
    if(status->temp != temp_last || status->temp_frac != temp_frac_last || trigger_drawsetpoint) {
 
        char tempstr[3];
 
        itoa_fp(status->temp, status->temp_frac, tempstr);
 
        ssd1306_drawstringbig("      ", 3, 0);
 
        ssd1306_drawstringbig(tempstr, 3, 0);
 
    }
 

	
 
@@ -562,12 +565,13 @@ static void draw_setpoint(therm_status_t
 
        ssd1306_drawstringbig(tempstr, 3, 90);
 
    }
 

	
 
    trigger_drawsetpoint = 0;
 
    setpoint_last = status->setpoint;
 
    temp_last = status->temp;
 
    temp_frac_last = status->temp_frac;
 
}
 

	
 
void display_startup_screen() {
 
    ssd1306_clearscreen();
 
    ssd1306_drawstring("therm v0.2", 1, 40);
 
    ssd1306_drawstring("protofusion.org/therm", 3, 0);
max31865.c
Show inline comments
 
@@ -104,41 +104,41 @@ void max31865_readtemp(SPI_HandleTypeDef
 
        if(set->val.temp_units == TEMP_UNITS_FAHRENHEIT)
 
        {
 
        	//use all fixed point math!
 

	
 
        	//convert adc to resistance
 
        	//Rrtd = adc / range * Rref
 
        	status->temp = adc_count * 9830 * 10;
 
        	status->temp /= 32768;
 
        	status->temp = (int32_t) adc_count * 48600L;
 
        	status->temp /= 32768L;
 
        	//resistance to temp
 
        	//(x - in1) * (cal2 - cal1) / (in2 - in1) + cal1
 
        	status->temp = ((status->temp * 100) - 100000) * (39200 - 3200) / (175860 - 100000) + 3200;
 
        	status->temp = ((status->temp) - 10000L) * (39200L - 3200L) / (17586L - 10000L) + 3200L;
 
        	//grab the fraction
 
        	status->temp_frac = (status->temp / 10) % 10;
 
        	status->temp_frac = (status->temp / 10) % 10L;
 
        	//scale back to degrees
 
        	status->temp = status->temp / 100;
 
        	status->temp = status->temp / 100L;
 
        	//add in the offset
 
            status->temp += set->val.temp_offset;
 
        }
 

	
 
        // Convert to Celsius
 
        else
 
        {
 
        	//use all fixed point math!
 

	
 
        	//convert adc to resistance
 
        	//Rrtd = adc / range * Rref
 
        	status->temp = adc_count * 9830 * 10;
 
        	status->temp /= 32768;
 
        	status->temp = (int32_t) adc_count * 48600L;
 
        	status->temp /= 32768L;
 
        	//resistance to temp
 
        	//(x - in1) * (cal2 - cal1) / (in2 - in1) + cal1
 
        	status->temp = ((status->temp * 10) - 10000) * (20000 - 0) / (17586 - 10000) + 0;
 
        	status->temp = (((status->temp) - 10000L) * (20000L- 0L)) / (17586L - 10000L) + 0L;
 
        	//grab the fraction
 
        	status->temp_frac = (status->temp / 10) % 10;
 
        	status->temp_frac = (status->temp / 10) % 100L;
 
        	//scale back to degrees
 
        	status->temp = status->temp / 100;
 
        	status->temp = status->temp / 100L;
 
        	//add in the offset
 
            status->temp += set->val.temp_offset;
 
        }
 
    }
 

	
 

	
system/stringhelpers.c
Show inline comments
 
#include <inttypes.h>
 

	
 
char const digit[] = "0123456789";
 

	
 
char* zitoa(int16_t i, char b[]){
 

	
 
    char const digit[] = "0123456789";
 
    char* p = b;
 
    if(i<0){
 
        *p++ = '-';
 
        i *= -1;
 
    }
 
    uint16_t shifter = i;
 
@@ -19,13 +20,12 @@ char* zitoa(int16_t i, char b[]){
 
        i = i/10;
 
    }while(i);
 
    return b;
 
}
 

	
 
char* itoa_fp(int16_t i, uint8_t frac, char b[]){
 
    char const digit[] = "0123456789";
 

	
 
    // set p to beginning of char array
 
    char* p = b;
 

	
 
    // If negative, set current char to '-' and inc, unnegate number
 
    if(i<0){
0 comments (0 inline, 0 general)