Changeset - 6d43230d5986
[Not reviewed]
tip rtd
0 3 0
matthewreed - 6 years ago 2018-11-25 21:08:06

Untested changes for RTDs
3 files changed with 30 insertions and 14 deletions:
display.c
16
3
max31865.c
13
10
pid.c
1
1
0 comments (0 inline, 0 general)
display.c
Show inline comments
 
@@ -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);
max31865.c
Show inline comments
 
@@ -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
pid.c
Show inline comments
 
@@ -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;
0 comments (0 inline, 0 general)