瀏覽代碼

use defines for adc pins, temp table for PIDNA update

PavelSindler 6 年之前
父節點
當前提交
78f9f6b611
共有 3 個文件被更改,包括 44 次插入14 次删除
  1. 1 1
      Firmware/pins_Einsy_1_0.h
  2. 37 7
      Firmware/temperature.cpp
  3. 6 6
      Firmware/ultralcd.cpp

+ 1 - 1
Firmware/pins_Einsy_1_0.h

@@ -73,7 +73,7 @@
 #define HEATER_2_PIN        -1
 #define TEMP_2_PIN          -1
 
-#define TEMP_AMBIENT_PIN     6 //A6
+#define TEMP_AMBIENT_PIN     5 //A5
 
 #define TEMP_PINDA_PIN       3 //A3
 

+ 37 - 7
Firmware/temperature.cpp

@@ -182,6 +182,7 @@ static int bed_maxttemp_raw = HEATER_BED_RAW_HI_TEMP;
 static float analog2temp(int raw, uint8_t e);
 static float analog2tempBed(int raw);
 static float analog2tempAmbient(int raw);
+static float analog2tempPINDA(int raw);
 static void updateTemperaturesFromRawValues();
 
 enum TempRunawayStates
@@ -922,6 +923,35 @@ static float analog2tempBed(int raw) {
   #endif
 }
 
+#ifdef PINDA_THERMISTOR
+
+static float analog2tempPINDA(int raw) {
+
+	float celsius = 0;
+	byte i;
+
+	for (i = 1; i<BEDTEMPTABLE_LEN; i++)
+	{
+		if (PGM_RD_W(BEDTEMPTABLE[i][0]) > raw)
+		{
+			celsius = PGM_RD_W(BEDTEMPTABLE[i - 1][1]) +
+				(raw - PGM_RD_W(BEDTEMPTABLE[i - 1][0])) *
+				(float)(PGM_RD_W(BEDTEMPTABLE[i][1]) - PGM_RD_W(BEDTEMPTABLE[i - 1][1])) /
+				(float)(PGM_RD_W(BEDTEMPTABLE[i][0]) - PGM_RD_W(BEDTEMPTABLE[i - 1][0]));
+			break;
+		}
+	}
+
+	// Overflow: Set to last value in the table
+	if (i == BEDTEMPTABLE_LEN) celsius = PGM_RD_W(BEDTEMPTABLE[i - 1][1]);
+
+	return celsius;
+}
+
+
+#endif //PINDA_THERMISTOR
+
+
 #ifdef AMBIENT_THERMISTOR
 static float analog2tempAmbient(int raw)
 {
@@ -955,7 +985,7 @@ static void updateTemperaturesFromRawValues()
     }
 
 #ifdef PINDA_THERMISTOR
-	current_temperature_pinda = analog2tempBed(current_temperature_raw_pinda); //thermistor for pinda is the same as for bed
+	current_temperature_pinda = analog2tempPINDA(current_temperature_raw_pinda);
 #endif
 
 #ifdef AMBIENT_THERMISTOR
@@ -1504,17 +1534,17 @@ extern "C" {
 
 void adc_ready(void) //callback from adc when sampling finished
 {
-	current_temperature_raw[0] = adc_values[0];
-	current_temperature_raw_pinda = adc_values[1];
-	current_temperature_bed_raw = adc_values[2];	
+	current_temperature_raw[0] = adc_values[TEMP_0_PIN]; //heater
+	current_temperature_raw_pinda = adc_values[TEMP_PINDA_PIN];
+	current_temperature_bed_raw = adc_values[TEMP_BED_PIN];
 #ifdef VOLT_PWR_PIN
-	current_voltage_raw_pwr = adc_values[4];
+	current_voltage_raw_pwr = adc_values[VOLT_PWR_PIN];
 #endif
 #ifdef AMBIENT_THERMISTOR
-	current_temperature_raw_ambient = adc_values[5];
+	current_temperature_raw_ambient = adc_values[TEMP_AMBIENT_PIN];
 #endif //AMBIENT_THERMISTOR
 #ifdef VOLT_BED_PIN
-	current_voltage_raw_bed = adc_values[6];
+	current_voltage_raw_bed = adc_values[VOLT_BED_PIN]; // 6->9
 #endif
 	temp_meas_ready = true;
 }

+ 6 - 6
Firmware/ultralcd.cpp

@@ -1695,7 +1695,7 @@ static void lcd_menu_temperatures()
     }
 }
 
-#ifdef defined(VOLT_BED_PIN) || defined(VOLT_BED_PIN)
+#if defined VOLT_BED_PIN || defined VOLT_PWR_PIN
 #define VOLT_DIV_R1 10000
 #define VOLT_DIV_R2 2370
 #define VOLT_DIV_FAC ((float)VOLT_DIV_R2 / (VOLT_DIV_R2 + VOLT_DIV_R1))
@@ -1703,8 +1703,8 @@ static void lcd_menu_temperatures()
 static void lcd_menu_voltages()
 {
 	float volt_pwr = VOLT_DIV_REF * ((float)current_voltage_raw_pwr / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC;
-	//float volt_bed = VOLT_DIV_REF * ((float)current_voltage_raw_bed / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC;
-	//fprintf_P(lcdout, PSTR(ESC_H(1,1)"PWR:      %d.%01dV" ESC_H(1,2)"BED:      %d.%01dV"), (int)volt_pwr, (int)(10*fabs(volt_pwr - (int)volt_pwr)), (int)volt_bed, (int)(10*fabs(volt_bed - (int)volt_bed)));
+	float volt_bed = VOLT_DIV_REF * ((float)current_voltage_raw_bed / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC;
+	fprintf_P(lcdout, PSTR(ESC_H(1,1)"PWR:      %d.%01dV" ESC_H(1,2)"BED:      %d.%01dV"), (int)volt_pwr, (int)(10*fabs(volt_pwr - (int)volt_pwr)), (int)volt_bed, (int)(10*fabs(volt_bed - (int)volt_bed)));
     fprintf_P(lcdout, PSTR( ESC_H(1,1)"PWR:      %d.%01dV"), (int)volt_pwr, (int)(10*fabs(volt_pwr - (int)volt_pwr))) ;
     if (lcd_clicked())
     {
@@ -1712,7 +1712,7 @@ static void lcd_menu_voltages()
         lcd_return_to_status();
     }
 }
-#endif //defined(VOLT_BED_PIN) || defined(VOLT_BED_PIN)
+#endif //defined VOLT_BED_PIN || defined VOLT_PWR_PIN
 
 #ifdef TMC2130
 static void lcd_menu_belt_status()
@@ -1824,9 +1824,9 @@ static void lcd_support_menu()
     
   MENU_ITEM(submenu, MSG_MENU_TEMPERATURES, lcd_menu_temperatures);
 
-#ifdef defined(VOLT_BED_PIN) || defined(VOLT_BED_PIN)
+#if defined VOLT_BED_PIN || defined VOLT_BED_PIN
   MENU_ITEM(submenu, MSG_MENU_VOLTAGES, lcd_menu_voltages);
-#endif //defined(VOLT_BED_PIN) || defined(VOLT_BED_PIN)
+#endif //defined VOLT_BED_PIN || defined VOLT_BED_PIN
 
 #ifdef DEBUG_BUILD
   MENU_ITEM(submenu, PSTR("Debug"), lcd_menu_debug);