diff --git a/display.c b/display.c --- a/display.c +++ b/display.c @@ -24,6 +24,7 @@ static uint8_t sw_right_last = 0; // States static uint8_t trigger_drawsetpoint = 1; static int16_t last_temp = 21245; +static int16_t last_state = STATE_IDLE; static uint8_t goto_mode = MODE_HEAT; static uint8_t reset_mode = RESET_REBOOT; @@ -32,7 +33,8 @@ static uint8_t reset_mode = RESET_REBOOT // Display state machine void display_process(therm_settings_t* set, therm_status_t* status) { - uint8_t last_state = status->state; + uint8_t state_changed = status->state != last_state; + last_state = status->state; uint8_t temp_changed = status->temp != last_temp; last_temp = status->temp; @@ -53,7 +55,7 @@ void display_process(therm_settings_t* s ssd1306_drawstring("therm :: idle ", 0, 40); status->pid_enabled = 0; - if(temp_changed) { + if(temp_changed || state_changed) { char tempstr[6]; itoa_fp(status->temp, status->temp_frac, tempstr); ssd1306_drawstring("Temp: ", 3, 40); @@ -61,7 +63,9 @@ void display_process(therm_settings_t* s ssd1306_drawstring(tempstr, 3, 72); } - ssd1306_drawlogo(); + if (state_changed) { + ssd1306_drawlogo(); + } switch(goto_mode) { diff --git a/max31865.c b/max31865.c --- a/max31865.c +++ b/max31865.c @@ -61,8 +61,6 @@ void max31865_readtemp(SPI_HandleTypeDef // 2-wire RTC or 2-wire (duh) NTC thermistor will be the only options // Need option for resistance of RTD // These options should be stored in the set structure and should be menu-selectable - // TODO: Read RTD msbs (0x01) - // TODO: Read RTD LSBs (0x02) // Assert CS HAL_GPIO_WritePin(MAX_CS, 0); @@ -80,7 +78,7 @@ void max31865_readtemp(SPI_HandleTypeDef HAL_GPIO_WritePin(MAX_CS, 1); // Assemble data array into one var - uint16_t temp_pre = (rxdatah[0]<<8) | rxdatal[0]; + uint16_t adc_count = ((rxdatah[0] & 0x7F) << 8) | rxdatal[0]; if((rxdatah[0] & 0x80) && !set->val.ignore_error) { @@ -89,7 +87,7 @@ void max31865_readtemp(SPI_HandleTypeDef uint8_t reg = MAX31865_REG_FAULTSTATUS; - uint8_t data[1] = {0x11}; + uint8_t data[1] = {0x00}; HAL_SPI_Transmit(hspi1, ®, 1, 100); HAL_SPI_Receive(hspi1, data, 1, 100); @@ -108,31 +106,48 @@ void max31865_readtemp(SPI_HandleTypeDef } else { - // Convert to decimal - //temp_pre = temp_pre >> 1; - uint16_t adc_count = temp_pre & 0x7FFF; //do some scaling? - // Convert to Fahrenheit if(set->val.temp_units == TEMP_UNITS_FAHRENHEIT) { - status->temp = adc_count; - //convert to fahrenheit + //use all fixed point math! + + //convert adc to resistance + //Rrtd = adc / range * Rref + status->temp = adc_count * 9830 * 10; + status->temp /= 32768; + //resistance to temp + //(x - in1) * (cal2 - cal1) / (in2 - in1) + cal1 + status->temp = ((status->temp * 100) - 100000) * (39200 - 3200) / (175860 - 100000) + 3200; + //grab the fraction + status->temp_frac = (status->temp / 10) % 10; + //scale back to degrees + status->temp = status->temp / 100; + //add in the offset status->temp += set->val.temp_offset; } - // Use Celsius values + // Convert to Celsius else { - //convert to celsius - int32_t temp = (((int32_t) adc_count) / 32) - 256; - status->temp = temp; + //use all fixed point math! + + //convert adc to resistance + //Rrtd = adc / range * Rref + status->temp = adc_count * 9830 * 10; + status->temp /= 32768; + //resistance to temp + //(x - in1) * (cal2 - cal1) / (in2 - in1) + cal1 + status->temp = ((status->temp * 10) - 10000) * (20000 - 0) / (17586 - 10000) + 0; + //grab the fraction + status->temp_frac = (status->temp / 10) % 10; + //scale back to degrees + status->temp = status->temp / 100; + //add in the offset status->temp += set->val.temp_offset; } } - - } // vim:softtabstop=4 shiftwidth=4 expandtab