# HG changeset patch # User matthewreed # Date 2018-11-25 21:08:06 # Node ID 6d43230d598606cd753a2f99dbb7ce619dac0544 # Parent 9d6570f4456fb14a65d4b51cd5654e2b938a39d1 Untested changes for RTDs diff --git a/display.c b/display.c --- a/display.c +++ b/display.c @@ -25,7 +25,7 @@ static uint8_t sw_right_last = 0; 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 int16_t last_state = STATE_RESET; static uint8_t goto_mode = MODE_HEAT; static uint8_t reset_mode = RESET_REBOOT; @@ -409,8 +409,20 @@ void display_process(therm_settings_t* s itoa(status->error_code, tempstr, 10); ssd1306_drawstring(tempstr, 0, 57); - //TODO: add RTD error codes - + #ifdef MAX31865_RTD_SENSOR + // RTD error codes + if(status->error_code & 0b00000100) + ssd1306_drawstring(" RTD Over/Undervolt", 1, 0); + else if(status->error_code & 0b00001000) + ssd1306_drawstring(" RTD FORCE- Open", 1, 0); + else if(status->error_code & 0b00010000) + ssd1306_drawstring("RTD REF FORCE- Open", 1, 0); + else if(status->error_code & 0b00100000) + ssd1306_drawstring(" RTD REFIN- High", 1, 0); + else + ssd1306_drawstring("#?, Unknown Error", 1, 0); + #else + // TC error codes if(status->error_code == 1) ssd1306_drawstring(" TC Open Circuit", 1, 0); else if(status->error_code == 4) @@ -419,6 +431,7 @@ void display_process(therm_settings_t* s ssd1306_drawstring(" TC Short to VCC", 1, 0); else ssd1306_drawstring("#?, Unknown Error", 1, 0); + #endif ssd1306_drawstring(" ", 2, 0); ssd1306_drawstring("-> to ignore all or", 2, 0); diff --git a/max31865.c b/max31865.c --- a/max31865.c +++ b/max31865.c @@ -89,14 +89,17 @@ void max31865_readtemp(SPI_HandleTypeDef // Release CS HAL_GPIO_WritePin(MAX_CS, 1); - status->error_code = data[0]; - - HAL_Delay(400); // FIXME: remove? - status->state_resume = status->state; - status->state = STATE_TC_ERROR; - status->temp = 0; - status->temp_frac = 0; - + // check to see if it's an error we care about + if(data[0] & 0b00111100) { + status->error_code = data[0]; + status->state_resume = status->state; + status->state = STATE_TC_ERROR; + status->temp = 0; + status->temp_frac = 0; + } + else { + max31865_clear_errors(spi_get()); + } } else { @@ -107,7 +110,7 @@ void max31865_readtemp(SPI_HandleTypeDef //convert adc to resistance //Rrtd = adc / range * Rref - status->temp = (int32_t) adc_count * 48600L; + status->temp = (int32_t) adc_count * 40200L; status->temp /= 32768L; //resistance to temp //(x - in1) * (cal2 - cal1) / (in2 - in1) + cal1 @@ -127,7 +130,7 @@ void max31865_readtemp(SPI_HandleTypeDef //convert adc to resistance //Rrtd = adc / range * Rref - status->temp = (int32_t) adc_count * 48600L; + status->temp = (int32_t) adc_count * 40200L; status->temp /= 32768L; //resistance to temp //(x - in1) * (cal2 - cal1) / (in2 - in1) + cal1 diff --git a/pid.c b/pid.c --- a/pid.c +++ b/pid.c @@ -18,7 +18,7 @@ int16_t pid_update(therm_settings_t* set int32_t temp = (status->temp * 10) + temp_frac; // Calculate instantaneous error - int16_t error = status->setpoint * 10 - temp; // TODO: Use fixed point fraction + int16_t error = status->setpoint * 10 - temp; // Proportional component int32_t p_term = set->val.k_p * error;