diff --git a/application.c b/application.c index d079696..fb122ca 100644 --- a/application.c +++ b/application.c @@ -337,12 +337,41 @@ static float bed_tophalf_temperature(void) // convert to °C // calibrated using a DS18B20 (accuracy = +- 0.5°C), with 12-bit precision - // 558 = 19.500 °C, 1624 = 50.625, 2850 = 82.250 - // 616 = 21.8 C, 2926 = 83.625 + // 558 = 19.500 °C, 616 = 21.8 °C, 1624 = 50.625 °C, 2850 = 82.250 °C, 2926 = 83.625 °C - return measurement * 0.0273778 + 4.22317; + return measurement * 0.0270798 + 4.38946; } +/** read bed bottom half temperature + * @return temperature in °C + */ +static float bed_bothalf_temperature(void) +{ + const uint16_t measurement = sensor_max1247_read(1); // read measured value from corresponding thermistor + + // convert to °C + // calibrated using a DS18B20 (accuracy = +- 0.5°C), with 12-bit precision + // 549 = 19.312 °C, 12 = 63.3 °C + + return measurement * 0.0270798 + 4.38946; +} + +/** read bed tube temperature + * @return temperature in °C + */ +/* +static float bed_tube_temperature(void) +{ + const uint16_t measurement = sensor_max1247_read(3); // read measured value from corresponding thermistor + + // convert to °C + // calibrated using a DS18B20 (accuracy = +- 0.5°C), with 12-bit precision + // 19.312 °C = 564 + + return measurement * 0.0270798 + 4.38946; +} +*/ + /** read heat sink temperature * @return temperature in °C */ @@ -352,14 +381,11 @@ static float bed_heatsink_temperature(void) // convert to °C // calibrated using a DS18B20 (accuracy = +- 0.5°C), with 12-bit precision - // + // 557 = 19.312 °C, 1624 = 50.625 °C - return measurement * 0.0273778 + 4.22317; // TODO this values are from the bed top half + return measurement * 0.0273778 + 4.22317; } -// bottom 12 = 63.3 °C -// heat sink - /** run PID control for bed temperature (using the top half) */ static void bed_pid(void) { @@ -403,10 +429,6 @@ static void bed_pid(void) tec_power((uint16_t)power); // set power } -// bottom 19.312 = 549 -// sink 19.312 = 557 -// tube 19.312 = 564 - /** display available commands * @param[in] argument no argument required */ @@ -1020,10 +1042,11 @@ void main(void) // read temperatures const float lid_temp = lid_temperature(); const float heatsink_temp = bed_heatsink_temperature(); - const float bed_temp = bed_tophalf_temperature(); + const float top_temp = bed_tophalf_temperature(); + const float bot_temp = bed_bothalf_temperature(); // read bed temperatures - printf("bed: top=%.2f, bottom=%u, sink=%u %.02f, tube=%u; 393-A=%u; 339-3=%u\n", bed_temp, sensor_max1247_read(1), sensor_max1247_read(2), heatsink_temp, sensor_max1247_read(3), gpio_get(GPIO_PORT(BED_PIN_393A), GPIO_PIN(BED_PIN_393A)) ? 1 : 0, gpio_get(GPIO_PORT(BED_PIN_3393), GPIO_PIN(BED_PIN_3393)) ? 1 : 0); - printf("lid: %.02f V\n", lid_temp); + printf("bed: top=%u %.2f, bottom=%u %.02f, sink=%u %.02f, tube=%u; 393-A=%u; 339-3=%u\n",sensor_max1247_read(0), top_temp, sensor_max1247_read(1), bot_temp, sensor_max1247_read(2), heatsink_temp, sensor_max1247_read(3), gpio_get(GPIO_PORT(BED_PIN_393A), GPIO_PIN(BED_PIN_393A)) ? 1 : 0, gpio_get(GPIO_PORT(BED_PIN_3393), GPIO_PIN(BED_PIN_3393)) ? 1 : 0); + printf("lid: %.04f °C\n", lid_temp); if (ds18b20_present) { const float temp = sensor_ds18b20_temperature(0); // get temperature sensor_ds18b20_convert(0); // start next conversion (since it takes almost 1 s) @@ -1032,9 +1055,9 @@ void main(void) // time to check if everything is OK if (!error && STATE_SAFE != state) { // only check if we are not in the safe state // check lid temperature - if (lid_temp < 5.0) { // voltage is at the upper limit (3.3V), meaning it is directly connected to the 5V pull-up resistor, and the lid thermistor does not pull it to ground + if (lid_temp < 5.0) { // voltage is at the upper limit (3.3V), meaning it is directly connected to the 3.3V pull-up resistor, and the lid thermistor does not pull it to ground error = "lid thermistor is probably not connected"; - } else if (lid_temp > 100) { + } else if (lid_temp > 100.0) { error = "lid is getting too warm"; } // check fan