Procházet zdrojové kódy

Revert "this is not working. Do you maybe know why?"

This reverts commit 8bcdb9f5f0.
Bernhard Kubicek před 13 roky
rodič
revize
b9ea0651ec
8 změnil soubory, kde provedl 182 přidání a 268 odebrání
  1. 8
    8
      Marlin/EEPROMwrite.h
  2. 0
    1
      Marlin/Marlin.h
  3. 40
    40
      Marlin/Marlin.pde
  4. 1
    1
      Marlin/planner.cpp
  5. 1
    1
      Marlin/stepper.cpp
  6. 68
    60
      Marlin/temperature.cpp
  7. 21
    110
      Marlin/temperature.h
  8. 43
    47
      Marlin/ultralcd.pde

+ 8
- 8
Marlin/EEPROMwrite.h Zobrazit soubor

@@ -48,9 +48,9 @@ void StoreSettings() {
48 48
   EEPROM_writeAnything(i,max_xy_jerk);
49 49
   EEPROM_writeAnything(i,max_z_jerk);
50 50
   #ifdef PIDTEMP
51
-  EEPROM_writeAnything(i,Heater::Kp);
52
-  EEPROM_writeAnything(i,Heater::Ki);
53
-  EEPROM_writeAnything(i,Heater::Kd);
51
+  EEPROM_writeAnything(i,Kp);
52
+  EEPROM_writeAnything(i,Ki);
53
+  EEPROM_writeAnything(i,Kd);
54 54
 #else
55 55
   EEPROM_writeAnything(i,3000);
56 56
   EEPROM_writeAnything(i,0);
@@ -81,11 +81,11 @@ void RetrieveSettings(bool def=false){  // if def=true, the default values will
81 81
       EEPROM_readAnything(i,max_xy_jerk);
82 82
       EEPROM_readAnything(i,max_z_jerk);
83 83
 #ifndef PIDTEMP
84
-      float Kp,Ki,Kd; //read and ignore..
84
+      float Kp,Ki,Kd;
85 85
 #endif
86
-      EEPROM_readAnything(i,Heater::Kp);
87
-      EEPROM_readAnything(i,Heater::Ki);
88
-      EEPROM_readAnything(i,Heater::Kd);
86
+      EEPROM_readAnything(i,Kp);
87
+      EEPROM_readAnything(i,Ki);
88
+      EEPROM_readAnything(i,Kd);
89 89
 
90 90
       ECHOLN("Stored settings retreived:");
91 91
   }
@@ -119,7 +119,7 @@ void RetrieveSettings(bool def=false){  // if def=true, the default values will
119 119
   ECHOLN("   M205 S"  <<_FLOAT(minimumfeedrate/60,2) << " T" << _FLOAT(mintravelfeedrate/60,2) << " B" << _FLOAT(minsegmenttime,2) << " X" << _FLOAT(max_xy_jerk/60,2) << " Z" << _FLOAT(max_z_jerk/60,2));
120 120
 #ifdef PIDTEMP
121 121
   ECHOLN("PID settings:");
122
-  ECHOLN("   M301 P"  << _FLOAT(Heater::Kp,3) << " I" << _FLOAT(Heater::Ki,3) << " D" << _FLOAT(Heater::Kd,3));  
122
+  ECHOLN("   M301 P"  << _FLOAT(Kp,3) << " I" << _FLOAT(Ki,3) << " D" << _FLOAT(Kd,3));  
123 123
 #endif
124 124
   
125 125
 }  

+ 0
- 1
Marlin/Marlin.h Zobrazit soubor

@@ -10,7 +10,6 @@
10 10
 #define ECHO(x) Serial << "echo: " << x;
11 11
 #define ECHOLN(x) Serial << "echo: "<<x<<endl;
12 12
 
13
-
14 13
 void get_command();
15 14
 void process_commands();
16 15
 

+ 40
- 40
Marlin/Marlin.pde Zobrazit soubor

@@ -40,7 +40,6 @@
40 40
   #include "Simplelcd.h"
41 41
 #endif
42 42
 
43
-Heater htr;
44 43
 char version_string[] = "1.0.0 Alpha 1";
45 44
 
46 45
 #ifdef SDSUPPORT
@@ -264,7 +263,7 @@ void setup()
264 263
 #endif //SDSUPPORT
265 264
   plan_init();  // Initialize planner;
266 265
   st_init();    // Initialize stepper;
267
-  //tp_init();    // Initialize temperature loop is now done by the constructor of the Heater class
266
+  tp_init();    // Initialize temperature loop
268 267
 	//checkautostart();
269 268
 }
270 269
 
@@ -368,7 +367,7 @@ void loop()
368 367
     bufindr = (bufindr + 1)%BUFSIZE;
369 368
   }
370 369
   //check heater every n milliseconds
371
-  Heater::manage_heater();
370
+  manage_heater();
372 371
   manage_inactivity(1);
373 372
   LCD_STATUS;
374 373
 }
@@ -548,7 +547,7 @@ inline void process_commands()
548 547
       if(code_seen('S')) codenum = code_value() * 1000; // seconds to wait
549 548
       codenum += millis();  // keep track of when we started waiting
550 549
       while(millis()  < codenum ){
551
-        Heater::manage_heater();
550
+        manage_heater();
552 551
       }
553 552
       break;
554 553
     case 28: //G28 Home all Axis one at a time
@@ -802,9 +801,12 @@ inline void process_commands()
802 801
         }
803 802
         break;
804 803
       case 104: // M104
805
-        if (code_seen('S')) Heater::setCelsius(TEMPSENSOR_HOTEND,code_value());
804
+                if (code_seen('S')) target_raw[TEMPSENSOR_HOTEND] = temp2analog(code_value());
805
+#ifdef PIDTEMP
806
+                pid_setpoint = code_value();
807
+#endif //PIDTEM
806 808
         #ifdef WATCHPERIOD
807
-            if(Heater::isHeating(TEMPSENSOR_HOTEND)){
809
+            if(target_raw[TEMPSENSOR_HOTEND] > current_raw[TEMPSENSOR_HOTEND]){
808 810
                 watchmillis = max(1,millis());
809 811
                 watch_raw[TEMPSENSOR_HOTEND] = current_raw[TEMPSENSOR_HOTEND];
810 812
             }else{
@@ -813,14 +815,14 @@ inline void process_commands()
813 815
         #endif
814 816
         break;
815 817
       case 140: // M140 set bed temp
816
-                if (code_seen('S')) Heater::setCelsius(TEMPSENSOR_BED,code_value());
818
+                if (code_seen('S')) target_raw[TEMPSENSOR_BED] = temp2analogBed(code_value());
817 819
         break;
818 820
       case 105: // M105
819 821
         #if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595)
820
-                tt = Heater::celsius(TEMPSENSOR_HOTEND);
822
+                tt = analog2temp(current_raw[TEMPSENSOR_HOTEND]);
821 823
         #endif
822 824
         #if TEMP_1_PIN > -1
823
-                bt = Heater::celsius(TEMPSENSOR_BED);
825
+                bt = analog2tempBed(current_raw[TEMPSENSOR_BED]);
824 826
         #endif
825 827
         #if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595)
826 828
             Serial.print("ok T:");
@@ -831,14 +833,14 @@ inline void process_commands()
831 833
 #ifdef PIDTEMP
832 834
             Serial.print(" B:");
833 835
             #if TEMP_1_PIN > -1
834
-	      Serial.println(bt); 
836
+            Serial.println(bt); 
835 837
             #else
836
-	      Serial.println(Heater::HeaterPower); 
838
+            Serial.println(HeaterPower); 
837 839
             #endif
838 840
 #else
839 841
             Serial.println();
840 842
 #endif
841
-          #else<
843
+          #else
842 844
             Serial.println();
843 845
           #endif
844 846
         #else
@@ -848,12 +850,14 @@ inline void process_commands()
848 850
         //break;
849 851
       case 109: {// M109 - Wait for extruder heater to reach target.
850 852
             LCD_MESSAGE("Heating...");
851
-               if (code_seen('S')) Heater::setCelsius(TEMPSENSOR_HOTEND,code_value());
852
-            
853
+               if (code_seen('S')) target_raw[TEMPSENSOR_HOTEND] = temp2analog(code_value());
854
+            #ifdef PIDTEMP
855
+            pid_setpoint = code_value();
856
+            #endif //PIDTEM
853 857
             #ifdef WATCHPERIOD
854
-          if(Heater::isHeating(TEMPSENSOR_HOTEND)){
858
+          if(target_raw[TEMPSENSOR_HOTEND]>current_raw[TEMPSENSOR_HOTEND]){
855 859
               watchmillis = max(1,millis());
856
-              watch_raw[TEMPSENSOR_HOTEND] = Heater::current_raw[TEMPSENSOR_HOTEND];
860
+              watch_raw[TEMPSENSOR_HOTEND] = current_raw[TEMPSENSOR_HOTEND];
857 861
             } else {
858 862
               watchmillis = 0;
859 863
             }
@@ -861,31 +865,31 @@ inline void process_commands()
861 865
             codenum = millis(); 
862 866
      
863 867
                /* See if we are heating up or cooling down */
864
-              bool target_direction = Heater::isHeating(TEMPSENSOR_HOTEND); // true if heating, false if cooling
868
+              bool target_direction = (current_raw[0] < target_raw[0]); // true if heating, false if cooling
865 869
 
866 870
             #ifdef TEMP_RESIDENCY_TIME
867 871
             long residencyStart;
868 872
             residencyStart = -1;
869 873
             /* continue to loop until we have reached the target temp   
870 874
               _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */
871
-            while((target_direction ? Heater::isHeating(TEMPSENSOR_HOTEND) : Heater::isCooling(TEMPSENSOR_HOTEND)) ||
875
+            while((target_direction ? (current_raw[0] < target_raw[0]) : (current_raw[0] > target_raw[0])) ||
872 876
                     (residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) {
873 877
             #else
874
-            while ( target_direction ? Heater::isHeating(TEMPSENSOR_HOTEND) : Heater::isCooling(TEMPSENSOR_HOTEND) ) {
878
+            while ( target_direction ? (current_raw[0] < target_raw[0]) : (current_raw[0] > target_raw[0]) ) {
875 879
             #endif //TEMP_RESIDENCY_TIME
876 880
               if( (millis() - codenum) > 1000 ) { //Print Temp Reading every 1 second while heating up/cooling down
877 881
                 Serial.print("T:");
878
-              Serial.println( Heater::celsius(TEMPSENSOR_HOTEND) ); 
882
+              Serial.println( analog2temp(current_raw[TEMPSENSOR_HOTEND]) ); 
879 883
                 codenum = millis();
880 884
               }
881
-              Heater::manage_heater();
885
+              manage_heater();
882 886
               LCD_STATUS;
883 887
               #ifdef TEMP_RESIDENCY_TIME
884 888
                /* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time
885 889
                   or when current temp falls outside the hysteresis after target temp was reached */
886
-              if ((residencyStart == -1 &&  target_direction && !Heater::isHeating(TEMPSENSOR_HOTEND)) ||
887
-                  (residencyStart == -1 && !target_direction && !Heater::isCooling(TEMPSENSOR_HOTEND)) ||
888
-                  (residencyStart > -1 && labs(Heater::celsius(TEMPSENSOR_HOTEND) - Heater::celsiusTarget(TEMPSENSOR_HOTEND)) > TEMP_HYSTERESIS) ) {
890
+              if ((residencyStart == -1 &&  target_direction && current_raw[0] >= target_raw[0]) ||
891
+                  (residencyStart == -1 && !target_direction && current_raw[0] <= target_raw[0]) ||
892
+                  (residencyStart > -1 && labs(analog2temp(current_raw[0]) - analog2temp(target_raw[0])) > TEMP_HYSTERESIS) ) {
889 893
                 residencyStart = millis();
890 894
               }
891 895
               #endif //TEMP_RESIDENCY_TIME
@@ -895,22 +899,22 @@ inline void process_commands()
895 899
           break;
896 900
       case 190: // M190 - Wait bed for heater to reach target.
897 901
       #if TEMP_1_PIN > -1
898
-          if (code_seen('S')) Heater::setCelsius(TEMPSENSOR_BED,code_value());
902
+          if (code_seen('S')) target_raw[TEMPSENSOR_BED] = temp2analog(code_value());
899 903
         codenum = millis(); 
900
-          while(Heater::isHeating(TEMPSENSOR_BED)) 
901
-          {
904
+          while(current_raw[TEMPSENSOR_BED] < target_raw[TEMPSENSOR_BED]) 
905
+                                {
902 906
           if( (millis()-codenum) > 1000 ) //Print Temp Reading every 1 second while heating up.
903 907
           {
904
-            float tt=Heater::celsius(TEMPSENSOR_HOTEND);
908
+            float tt=analog2temp(current_raw[TEMPSENSOR_HOTEND]);
905 909
             Serial.print("T:");
906 910
             Serial.println( tt );
907 911
             Serial.print("ok T:");
908 912
             Serial.print( tt ); 
909 913
             Serial.print(" B:");
910
-            Serial.println( Heater::celsius(TEMPSENSOR_BED) ); 
914
+            Serial.println( analog2temp(current_raw[TEMPSENSOR_BED]) ); 
911 915
             codenum = millis(); 
912 916
           }
913
-            Heater::manage_heater();
917
+            manage_heater();
914 918
         }
915 919
       #endif
916 920
       break;
@@ -1062,13 +1066,9 @@ inline void process_commands()
1062 1066
       break;
1063 1067
 #ifdef PIDTEMP
1064 1068
     case 301: // M301
1065
-      if(code_seen('P')) Heater::Kp = code_value();
1066
-      if(code_seen('I')) Heater::Ki = code_value()*PID_dT;
1067
-      if(code_seen('D')) Heater::Kd = code_value()/PID_dT;
1068
-      #ifdef PID_ADD_EXTRUSION_RATE
1069
-	 if(code_seen('C')) Heater::Kc = code_value();
1070
-      #endif
1071
-
1069
+      if(code_seen('P')) Kp = code_value();
1070
+      if(code_seen('I')) Ki = code_value()*PID_dT;
1071
+      if(code_seen('D')) Kd = code_value()/PID_dT;
1072 1072
 //      ECHOLN("Kp "<<_FLOAT(Kp,2));
1073 1073
 //      ECHOLN("Ki "<<_FLOAT(Ki/PID_dT,2));
1074 1074
 //      ECHOLN("Kd "<<_FLOAT(Kd*PID_dT,2));
@@ -1194,19 +1194,19 @@ void wd_reset() {
1194 1194
 inline void kill()
1195 1195
 {
1196 1196
   #if TEMP_0_PIN > -1
1197
-  Heater::setCelsius(TEMPSENSOR_HOTEND,0);
1197
+  target_raw[0]=0;
1198 1198
    #if HEATER_0_PIN > -1  
1199 1199
      WRITE(HEATER_0_PIN,LOW);
1200 1200
    #endif
1201 1201
   #endif
1202 1202
   #if TEMP_1_PIN > -1
1203
-  Heater::setCelsius(TEMPSENSOR_BED,0);
1203
+  target_raw[1]=0;
1204 1204
   #if HEATER_1_PIN > -1 
1205 1205
     WRITE(HEATER_1_PIN,LOW);
1206 1206
   #endif
1207 1207
   #endif
1208 1208
   #if TEMP_2_PIN > -1
1209
-  Heater::setCelsius(TEMPSENSOR_AUX,0);
1209
+  target_raw[2]=0;
1210 1210
   #if HEATER_2_PIN > -1  
1211 1211
     WRITE(HEATER_2_PIN,LOW);
1212 1212
   #endif

+ 1
- 1
Marlin/planner.cpp Zobrazit soubor

@@ -388,7 +388,7 @@ void plan_buffer_line(float x, float y, float z, float e, float feed_rate) {
388 388
   // If the buffer is full: good! That means we are well ahead of the robot. 
389 389
   // Rest here until there is room in the buffer.
390 390
   while(block_buffer_tail == next_buffer_head) { 
391
-    htr.manage_heater(); 
391
+    manage_heater(); 
392 392
     manage_inactivity(1); 
393 393
     LCD_STATUS;
394 394
   }

+ 1
- 1
Marlin/stepper.cpp Zobrazit soubor

@@ -585,7 +585,7 @@ void st_init()
585 585
 void st_synchronize()
586 586
 {
587 587
   while(plan_get_current_block()) {
588
-    htr.manage_heater();
588
+    manage_heater();
589 589
     manage_inactivity(1);
590 590
     LCD_STATUS;
591 591
   }   

+ 68
- 60
Marlin/temperature.cpp Zobrazit soubor

@@ -37,11 +37,52 @@
37 37
 #include "streaming.h"
38 38
 #include "temperature.h"
39 39
 
40
+int target_bed_raw = 0;
41
+int current_bed_raw = 0;
40 42
 
43
+int target_raw[3] = {0, 0, 0};
44
+int current_raw[3] = {0, 0, 0};
45
+unsigned char temp_meas_ready = false;
41 46
 
47
+unsigned long previous_millis_heater, previous_millis_bed_heater;
42 48
 
49
+#ifdef PIDTEMP
50
+  double temp_iState = 0;
51
+  double temp_dState = 0;
52
+  double pTerm;
53
+  double iTerm;
54
+  double dTerm;
55
+      //int output;
56
+  double pid_error;
57
+  double temp_iState_min;
58
+  double temp_iState_max;
59
+  double pid_setpoint = 0.0;
60
+  double pid_input;
61
+  double pid_output;
62
+  bool pid_reset;
63
+  float HeaterPower;
64
+  
65
+  float Kp=DEFAULT_Kp;
66
+  float Ki=DEFAULT_Ki;
67
+  float Kd=DEFAULT_Kd;
68
+  float Kc=DEFAULT_Kc;
69
+#endif //PIDTEMP
70
+
71
+#ifdef MINTEMP
72
+int minttemp = temp2analog(MINTEMP);
73
+#endif //MINTEMP
74
+#ifdef MAXTEMP
75
+int maxttemp = temp2analog(MAXTEMP);
76
+#endif //MAXTEMP
77
+
78
+#ifdef BED_MINTEMP
79
+int bed_minttemp = temp2analog(BED_MINTEMP);
80
+#endif //BED_MINTEMP
81
+#ifdef BED_MAXTEMP
82
+int bed_maxttemp = temp2analog(BED_MAXTEMP);
83
+#endif //BED_MAXTEMP
43 84
 
44
-void static Heater::manage_heater()
85
+void manage_heater()
45 86
 {
46 87
 #ifdef USE_WATCHDOG
47 88
   wd_reset();
@@ -49,11 +90,11 @@ void static Heater::manage_heater()
49 90
   
50 91
   float pid_input;
51 92
   float pid_output;
52
-  if(htr.temp_meas_ready != true)   //better readability
93
+  if(temp_meas_ready != true)   //better readability
53 94
     return; 
54 95
 
55 96
 CRITICAL_SECTION_START;
56
-    htr.temp_meas_ready = false;
97
+    temp_meas_ready = false;
57 98
 CRITICAL_SECTION_END;
58 99
 
59 100
 #ifdef PIDTEMP
@@ -135,8 +176,7 @@ CRITICAL_SECTION_END;
135 176
 // For a thermistor, it uses the RepRap thermistor temp table.
136 177
 // This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.
137 178
 // This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware.
138
-float const static temp2analog(const int celsius)
139
-{
179
+float temp2analog(int celsius) {
140 180
   #ifdef HEATER_USES_THERMISTOR_1
141 181
     int raw = 0;
142 182
     byte i;
@@ -167,8 +207,7 @@ float const static temp2analog(const int celsius)
167 207
 // For a thermistor, it uses the RepRap thermistor temp table.
168 208
 // This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.
169 209
 // This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware.
170
-float const static temp2analogBed(const int celsius)
171
-{
210
+float temp2analogBed(int celsius) {
172 211
   #ifdef BED_USES_THERMISTOR
173 212
 
174 213
     int raw = 0;
@@ -198,7 +237,7 @@ float const static temp2analogBed(const int celsius)
198 237
 
199 238
 // Derived from RepRap FiveD extruder::getTemperature()
200 239
 // For hot end temperature measurement.
201
-float const static Heater::analog2temp(const int raw) {
240
+float analog2temp(int raw) {
202 241
   #ifdef HEATER_1_USES_THERMISTOR
203 242
     int celsius = 0;
204 243
     byte i;  
@@ -227,7 +266,7 @@ float const static Heater::analog2temp(const int raw) {
227 266
 
228 267
 // Derived from RepRap FiveD extruder::getTemperature()
229 268
 // For bed temperature measurement.
230
-float const static Heater::analog2tempBed(const int raw) {
269
+float analog2tempBed(int raw) {
231 270
   #ifdef BED_USES_THERMISTOR
232 271
     int celsius = 0;
233 272
     byte i;
@@ -257,28 +296,8 @@ float const static Heater::analog2tempBed(const int raw) {
257 296
   #endif
258 297
 }
259 298
 
260
-Heater::Heater()
299
+void tp_init()
261 300
 {
262
-  for(short i=0;i<3;i++)
263
-  {
264
-    target_raw[i]=0;
265
-    current_raw[i] =0;
266
-  }
267
-  htr.temp_meas_ready = false;
268
-  #ifdef MINTEMP
269
-  minttemp = temp2analog(MINTEMP);
270
-  #endif //MINTEMP
271
-  #ifdef MAXTEMP
272
-  maxttemp = temp2analog(MAXTEMP);
273
-  #endif //MAXTEMP
274
-
275
-  #ifdef BED_MINTEMP
276
-  bed_minttemp = temp2analog(BED_MINTEMP);
277
-  #endif //BED_MINTEMP
278
-  #ifdef BED_MAXTEMP
279
-  bed_maxttemp = temp2analog(BED_MAXTEMP);
280
-  #endif //BED_MAXTEMP
281
-  
282 301
 #if (HEATER_0_PIN > -1) 
283 302
   SET_OUTPUT(HEATER_0_PIN);
284 303
 #endif  
@@ -292,14 +311,6 @@ Heater::Heater()
292 311
 #ifdef PIDTEMP
293 312
   temp_iState_min = 0.0;
294 313
   temp_iState_max = PID_INTEGRAL_DRIVE_MAX / Ki;
295
-  temp_iState = 0;
296
-  temp_dState = 0;
297
-  Kp=DEFAULT_Kp;
298
-  Ki=DEFAULT_Ki;
299
-  Kd=DEFAULT_Kd;
300
-  Kc=DEFAULT_Kc;
301
-  pid_setpoint = 0.0;
302
-
303 314
 #endif //PIDTEMP
304 315
 
305 316
 // Set analog inputs
@@ -396,39 +407,39 @@ ISR(TIMER0_COMPB_vect)
396 407
   if(temp_count >= 16) // 6 ms * 16 = 96ms.
397 408
   {
398 409
     #ifdef HEATER_1_USES_AD595
399
-      htr.current_raw[0] = raw_temp_0_value;
410
+      current_raw[0] = raw_temp_0_value;
400 411
     #else
401
-      htr.current_raw[0] = 16383 - raw_temp_0_value;
412
+      current_raw[0] = 16383 - raw_temp_0_value;
402 413
     #endif
403 414
     
404 415
     #ifdef HEATER_2_USES_AD595
405
-      htr.current_raw[2] = raw_temp_2_value;
416
+      current_raw[2] = raw_temp_2_value;
406 417
     #else
407
-      htr.current_raw[2] = 16383 - raw_temp_2_value;
418
+      current_raw[2] = 16383 - raw_temp_2_value;
408 419
     #endif
409 420
     
410 421
     #ifdef BED_USES_AD595
411
-      htr.current_raw[1] = raw_temp_1_value;
422
+      current_raw[1] = raw_temp_1_value;
412 423
     #else
413
-      htr.current_raw[1] = 16383 - raw_temp_1_value;
424
+      current_raw[1] = 16383 - raw_temp_1_value;
414 425
     #endif
415 426
     
416
-   htr.temp_meas_ready = true;
427
+    temp_meas_ready = true;
417 428
     temp_count = 0;
418 429
     raw_temp_0_value = 0;
419 430
     raw_temp_1_value = 0;
420 431
     raw_temp_2_value = 0;
421 432
 #ifdef MAXTEMP
422 433
   #if (HEATER_0_PIN > -1)
423
-    if(htr.current_raw[TEMPSENSOR_HOTEND] >= htr.maxttemp) {
424
-      htr.target_raw[TEMPSENSOR_HOTEND] = 0;
434
+    if(current_raw[TEMPSENSOR_HOTEND] >= maxttemp) {
435
+      target_raw[TEMPSENSOR_HOTEND] = 0;
425 436
       analogWrite(HEATER_0_PIN, 0);
426 437
       Serial.println("!! Temperature extruder 0 switched off. MAXTEMP triggered !!");
427 438
     }
428 439
   #endif
429 440
   #if (HEATER_2_PIN > -1)
430
-    if(htr.current_raw[TEMPSENSOR_AUX] >= htr.maxttemp) {
431
-      htr.target_raw[TEMPSENSOR_AUX] = 0;
441
+    if(current_raw[TEMPSENSOR_AUX] >= maxttemp) {
442
+      target_raw[TEMPSENSOR_AUX] = 0;
432 443
       analogWrite(HEATER_2_PIN, 0);
433 444
       Serial.println("!! Temperature extruder 1 switched off. MAXTEMP triggered !!");
434 445
     }
@@ -436,15 +447,15 @@ ISR(TIMER0_COMPB_vect)
436 447
 #endif //MAXTEMP
437 448
 #ifdef MINTEMP
438 449
   #if (HEATER_0_PIN > -1)
439
-    if(htr.current_raw[TEMPSENSOR_HOTEND] <= htr.minttemp) {
440
-      htr.target_raw[TEMPSENSOR_HOTEND] = 0;
450
+    if(current_raw[TEMPSENSOR_HOTEND] <= minttemp) {
451
+      target_raw[TEMPSENSOR_HOTEND] = 0;
441 452
       analogWrite(HEATER_0_PIN, 0);
442 453
       Serial.println("!! Temperature extruder 0 switched off. MINTEMP triggered !!");
443 454
     }
444 455
   #endif
445 456
   #if (HEATER_2_PIN > -1)
446
-    if(htr.current_raw[TEMPSENSOR_AUX] <= htr.minttemp) {
447
-      htr.target_raw[TEMPSENSOR_AUX] = 0;
457
+    if(current_raw[TEMPSENSOR_AUX] <= minttemp) {
458
+      target_raw[TEMPSENSOR_AUX] = 0;
448 459
       analogWrite(HEATER_2_PIN, 0);
449 460
       Serial.println("!! Temperature extruder 1 switched off. MINTEMP triggered !!");
450 461
     }
@@ -452,8 +463,8 @@ ISR(TIMER0_COMPB_vect)
452 463
 #endif //MAXTEMP
453 464
 #ifdef BED_MINTEMP
454 465
   #if (HEATER_1_PIN > -1)
455
-    if(htr.current_raw[1] <= htr.bed_minttemp) {
456
-      htr.target_raw[1] = 0;
466
+    if(current_raw[1] <= bed_minttemp) {
467
+      target_raw[1] = 0;
457 468
       WRITE(HEATER_1_PIN, 0);
458 469
       Serial.println("!! Temperatur heated bed switched off. MINTEMP triggered !!");
459 470
     }
@@ -461,8 +472,8 @@ ISR(TIMER0_COMPB_vect)
461 472
 #endif
462 473
 #ifdef BED_MAXTEMP
463 474
   #if (HEATER_1_PIN > -1)
464
-    if(htr.current_raw[1] >= htr.bed_maxttemp) {
465
-      htr.target_raw[1] = 0;
475
+    if(current_raw[1] >= bed_maxttemp) {
476
+      target_raw[1] = 0;
466 477
       WRITE(HEATER_1_PIN, 0);
467 478
       Serial.println("!! Temperature heated bed switched off. MAXTEMP triggered !!");
468 479
     }
@@ -470,6 +481,3 @@ ISR(TIMER0_COMPB_vect)
470 481
 #endif
471 482
   }
472 483
 }
473
-
474
-//Heater htr;
475
-

+ 21
- 110
Marlin/temperature.h Zobrazit soubor

@@ -25,116 +25,14 @@
25 25
 #ifdef PID_ADD_EXTRUSION_RATE
26 26
   #include "stepper.h"
27 27
 #endif
28
-
29
-enum TempSensor {TEMPSENSOR_HOTEND=0,TEMPSENSOR_BED=1, TEMPSENSOR_AUX=2};
30
-
31
-// ther must be only one instance of this class, and it is created in temperature.cpp by itself and is called "htr".
32
-// all the variables are static, so that of the compiler optimization is more easy.
33
-// I honestly hope that this increases readability and structure.
34
-// none of the variables or routines should be called from an secondary process/interrupt with the exceptino of current_raw[].
35
-
36
-class Heater
37
-{
38
-public:
39
-  Heater(); //treplaces tp_init();
40
-  ~Heater(); 
41
-  
42
-  void static manage_heater(); /// it is critical that this is called continously. 
43
-  
44
-  // conversion routines, const since they don't change any class variables.
45
-  float const static temp2analog(const int celsius);
46
-  float const static temp2analogBed(const int celsius);
47
-  float const static analog2temp(const int raw);
48
-  float const static analog2tempBed(const int raw);
49
-  
50
-  inline float const static celsius(const TempSensor s) 
51
-    {
52
-      if(s==TEMPSENSOR_BED) 
53
-	return analog2tempBed(Heater::current_raw[s]); 
54
-      else 
55
-	return analog2temp(Heater::current_raw[s]);
56
-    };
57
-  inline float const static celsiusTarget(const TempSensor s) 
58
-    {
59
-      if(s==TEMPSENSOR_BED) 
60
-	return analog2tempBed(Heater::target_raw[s]); 
61
-      else 
62
-	return analog2temp(Heater::target_raw[s]);
63
-    };
64
-  inline float static setCelsius(const TempSensor s, const int celsius) 
65
-    {
66
-      #ifdef PIDTEMP
67
-	if(s==TEMPSENSOR_HOTEND)
68
-            Heater::pid_setpoint = celsius;
69
-      #endif //PIDTEM
70
-      if(s==TEMPSENSOR_BED) 
71
-	Heater::target_raw[s] = temp2analog(celsius); 
72
-      else 
73
-	Heater::target_raw[s] = temp2analogBed(celsius); 
74
-    };
75
-
76
-   inline bool const static isHeating(TempSensor s)
77
-   { return (Heater::target_raw[s]>Heater::current_raw[s]);};
78
-   inline bool const static isCooling(TempSensor s)
79
-   { return (Heater::target_raw[s]<Heater::current_raw[s]);};
80
-
81
-public:
82
-  #ifdef PIDTEMP
83
-    static float Kp;
84
-    static float Ki;
85
-    static float Kd;
86
-    static float Kc;
87
-  #endif
88
-  
89
-  static int target_raw[3];
90
-  static float pid_setpoint;
91
-  
92
-  volatile static int current_raw[3]; //this are written by an ISR, so volatile.
93
-  volatile static bool temp_meas_ready ; //also this is set by the ISR
94
-  
95
-  
96
-private:
97
- 
98
-  
99
-
100
-  static unsigned long previous_millis_heater, previous_millis_bed_heater;
101
-
102
-  #ifdef PIDTEMP
103
-    static float temp_iState;
104
-    static float temp_dState;
105
-    static float pTerm;
106
-    static float iTerm;
107
-    static float dTerm;
108
-	//int output;
109
-    static float pid_error;
110
-    static float temp_iState_min;
111
-    static float temp_iState_max;
112
-    static float pid_input;
113
-    static float pid_output;
114
-    
115
-    static bool pid_reset;
116
-    static float HeaterPower;
117
-    
118
-  #endif //PIDTEMP
119
-
120
-public: //but only accesed from the ISR hence not volatile
121
-   #ifdef MINTEMP
122
-  static int minttemp;
123
-  #endif //MINTEMP
124
-  #ifdef MAXTEMP
125
-  static int maxttemp;
126
-  #endif //MAXTEMP
127
-
128
-  #ifdef BED_MINTEMP
129
-  static int bed_minttemp ;
130
-  #endif //BED_MINTEMP
131
-  #ifdef BED_MAXTEMP
132
-  static int bed_maxttemp;
133
-  #endif //BED_MAXTEMP
134
-  
135
-};
136
-
137
-extern Heater htr; //this creates the single, global instance 
28
+void tp_init();
29
+void manage_heater();
30
+//int temp2analogu(int celsius, const short table[][2], int numtemps);
31
+//float analog2tempu(int raw, const short table[][2], int numtemps);
32
+float temp2analog(int celsius);
33
+float temp2analogBed(int celsius);
34
+float analog2temp(int raw);
35
+float analog2tempBed(int raw);
138 36
 
139 37
 #ifdef HEATER_USES_THERMISTOR
140 38
     #define HEATERSOURCE 1
@@ -143,5 +41,18 @@ extern Heater htr; //this creates the single, global instance
143 41
     #define BEDSOURCE 1
144 42
 #endif
145 43
 
44
+//#define temp2analogh( c ) temp2analogu((c),temptable,NUMTEMPS)
45
+//#define analog2temp( c ) analog2tempu((c),temptable,NUMTEMPS
46
+
47
+
48
+extern float Kp;
49
+extern float Ki;
50
+extern float Kd;
51
+extern float Kc;
52
+
53
+enum {TEMPSENSOR_HOTEND=0,TEMPSENSOR_BED=1, TEMPSENSOR_AUX=2};
54
+extern int target_raw[3];
55
+extern int current_raw[3];
56
+extern double pid_setpoint;
146 57
 
147 58
 #endif

+ 43
- 47
Marlin/ultralcd.pde Zobrazit soubor

@@ -1,5 +1,5 @@
1 1
 #include "ultralcd.h"
2
-#include "temperature.h"
2
+
3 3
 
4 4
 #ifdef ULTRA_LCD
5 5
 extern volatile int feedmultiply;
@@ -238,8 +238,8 @@ extern volatile bool feedmultiplychanged;
238 238
 void MainMenu::showStatus()
239 239
 { 
240 240
 #if LCD_HEIGHT==4
241
-  static int oldcurrent=-1;
242
-  static int oldtarget=-1;
241
+  static int oldcurrentraw=-1;
242
+  static int oldtargetraw=-1;
243 243
   //force_lcd_update=true;
244 244
   if(force_lcd_update||feedmultiplychanged)  //initial display of content
245 245
   {
@@ -252,36 +252,33 @@ void MainMenu::showStatus()
252 252
 #endif
253 253
   }
254 254
     
255
-  int tt=Heater::celsius(TEMPSENSOR_HOTEND);
256
-  if((abs(tt-oldcurrent)>1)||force_lcd_update)
255
+
256
+  if((abs(current_raw[TEMPSENSOR_HOTEND]-oldcurrentraw)>3)||force_lcd_update)
257 257
   {
258 258
     lcd.setCursor(1,0);
259
-    lcd.print(ftostr3(tt));
260
-    oldcurrent=tt;
259
+    lcd.print(ftostr3(analog2temp(current_raw[TEMPSENSOR_HOTEND])));
260
+    oldcurrentraw=current_raw[TEMPSENSOR_HOTEND];
261 261
   }
262
-  int ttg=Heater::celsiusTarget(TEMPSENSOR_HOTEND);
263
-  if((ttg!=oldtarget)||force_lcd_update)
262
+  if((target_raw[TEMPSENSOR_HOTEND]!=oldtargetraw)||force_lcd_update)
264 263
   {
265 264
     lcd.setCursor(5,0);
266
-    lcd.print(ftostr3(ttg));
267
-    oldtarget=ttg;
265
+    lcd.print(ftostr3(analog2temp(target_raw[TEMPSENSOR_HOTEND])));
266
+    oldtargetraw=target_raw[TEMPSENSOR_HOTEND];
268 267
   }
269 268
   #if defined BED_USES_THERMISTOR || defined BED_USES_AD595 
270
-  static int oldcurrentbed=-1;
271
-  static int oldtargetbed=-1;
272
-  int tb=Heater::celsius(TEMPSENSOR_BED);
273
-  if((tb!=oldcurrentbed)||force_lcd_update)
269
+  static int oldcurrentbedraw=-1;
270
+  static int oldtargetbedraw=-1; 
271
+  if((current_bed_raw!=oldcurrentbedraw)||force_lcd_update)
274 272
   {
275 273
     lcd.setCursor(1,0);
276
-    lcd.print(ftostr3(tb));
277
-    oldcurrentbed=tb;
274
+    lcd.print(ftostr3(analog2temp(current_bed_raw)));
275
+    oldcurrentraw=current_raw[TEMPSENSOR_BED];
278 276
   }
279
-  int tg=Heater::celsiusTarget(TEMPSENSOR_BED);
280
-  if((tg!=oldtargebed)||force_lcd_update)
277
+  if((target_bed_raw!=oldtargebedtraw)||force_lcd_update)
281 278
   {
282 279
     lcd.setCursor(5,0);
283
-    lcd.print(Heater::celsiusTarget(TEMPSENSOR_BED));
284
-    oldtargebed=tg;
280
+    lcd.print(ftostr3(analog2temp(target_bed_raw)));
281
+    oldtargetraw=target_bed_raw;
285 282
   }
286 283
   #endif
287 284
   //starttime=2;
@@ -330,8 +327,8 @@ void MainMenu::showStatus()
330 327
     messagetext[0]='\0';
331 328
   }
332 329
 #else //smaller LCDS----------------------------------
333
-  static int oldcurrent=-1;
334
-  static int oldtarget=-1;
330
+  static int oldcurrentraw=-1;
331
+  static int oldtargetraw=-1;
335 332
   if(force_lcd_update)  //initial display of content
336 333
   {
337 334
     encoderpos=feedmultiply;
@@ -341,19 +338,18 @@ void MainMenu::showStatus()
341 338
     #endif
342 339
   }
343 340
     
344
-  int tt=Heater::celsius(TEMPSENSOR_HOTEND);
345
-  if((abs(tt-oldcurrent)>1)||force_lcd_update)
341
+
342
+  if((abs(current_raw[TEMPSENSOR_HOTEND]-oldcurrentraw)>3)||force_lcd_update)
346 343
   {
347 344
     lcd.setCursor(1,0);
348
-    lcd.print(ftostr3(tt));
349
-    oldcurrent=tt;
345
+    lcd.print(ftostr3(analog2temp(current_raw[TEMPSENSOR_HOTEND])));
346
+    oldcurrentraw=current_raw[TEMPSENSOR_HOTEND];
350 347
   }
351
-  int ttg=Heater::celsiusTarget(TEMPSENSOR_HOTEND);
352
-  if((ttg!=oldtarget)||force_lcd_update)
348
+  if((target_raw[TEMPSENSOR_HOTEND]!=oldtargetraw)||force_lcd_update)
353 349
   {
354 350
     lcd.setCursor(5,0);
355
-    lcd.print(ftostr3(ttg));
356
-    oldtarge=ttg;
351
+    lcd.print(ftostr3(analog2temp(target_raw[TEMPSENSOR_HOTEND])));
352
+    oldtargetraw=target_raw[TEMPSENSOR_HOTEND];
357 353
   }
358 354
 
359 355
   if(messagetext[0]!='\0')
@@ -430,7 +426,7 @@ void MainMenu::showPrepare()
430 426
         if((activeline==line) && CLICKED)
431 427
         {
432 428
           BLOCK
433
-          Heater::setCelsius(TEMPSENSOR_HOTEND, 170);
429
+          target_raw[TEMPSENSOR_HOTEND] = temp2analog(170);
434 430
           beepshort();
435 431
         }
436 432
       }break;
@@ -535,7 +531,7 @@ void MainMenu::showControl()
535 531
         if(force_lcd_update)
536 532
         {
537 533
           lcd.setCursor(0,line);lcd.print(" \002Nozzle:");
538
-          lcd.setCursor(13,line);lcd.print(ftostr3(Heater::celsiusTarget(TEMPSENSOR_HOTEND)));
534
+          lcd.setCursor(13,line);lcd.print(ftostr3(analog2temp(target_raw[TEMPSENSOR_HOTEND])));
539 535
         }
540 536
         
541 537
         if((activeline==line) )
@@ -545,11 +541,11 @@ void MainMenu::showControl()
545 541
             linechanging=!linechanging;
546 542
             if(linechanging)
547 543
             {
548
-               encoderpos=(int)Heater::celsiusTarget(TEMPSENSOR_HOTEND);
544
+               encoderpos=(int)analog2temp(target_raw[TEMPSENSOR_HOTEND]);
549 545
             }
550 546
             else
551 547
             {
552
-              Heater::setCelsius(TEMPSENSOR_HOTEND,encoderpos);
548
+              target_raw[TEMPSENSOR_HOTEND] = temp2analog(encoderpos);
553 549
               encoderpos=activeline*lcdslow;
554 550
               beepshort();
555 551
             }
@@ -673,7 +669,7 @@ void MainMenu::showControl()
673 669
       if(force_lcd_update)
674 670
         {
675 671
           lcd.setCursor(0,line);lcd.print(" PID-P: ");
676
-          lcd.setCursor(13,line);lcd.print(itostr4(Heater::Kp));
672
+          lcd.setCursor(13,line);lcd.print(itostr4(Kp));
677 673
         }
678 674
         
679 675
         if((activeline==line) )
@@ -683,11 +679,11 @@ void MainMenu::showControl()
683 679
             linechanging=!linechanging;
684 680
             if(linechanging)
685 681
             {
686
-               encoderpos=(int)Heater::Kp/5;
682
+               encoderpos=(int)Kp/5;
687 683
             }
688 684
             else
689 685
             {
690
-              Heater::Kp= encoderpos*5;
686
+              Kp= encoderpos*5;
691 687
               encoderpos=activeline*lcdslow;
692 688
                 
693 689
             }
@@ -707,7 +703,7 @@ void MainMenu::showControl()
707 703
       if(force_lcd_update)
708 704
         {
709 705
           lcd.setCursor(0,line);lcd.print(" PID-I: ");
710
-          lcd.setCursor(13,line);lcd.print(ftostr51(Heater::Ki));
706
+          lcd.setCursor(13,line);lcd.print(ftostr51(Ki));
711 707
         }
712 708
         
713 709
         if((activeline==line) )
@@ -717,11 +713,11 @@ void MainMenu::showControl()
717 713
             linechanging=!linechanging;
718 714
             if(linechanging)
719 715
             {
720
-               encoderpos=(int)(Heater::Ki*10);
716
+               encoderpos=(int)(Ki*10);
721 717
             }
722 718
             else
723 719
             {
724
-              Heater::Ki= encoderpos/10.;
720
+              Ki= encoderpos/10.;
725 721
               encoderpos=activeline*lcdslow;
726 722
                 
727 723
             }
@@ -741,7 +737,7 @@ void MainMenu::showControl()
741 737
       if(force_lcd_update)
742 738
         {
743 739
           lcd.setCursor(0,line);lcd.print(" PID-D: ");
744
-          lcd.setCursor(13,line);lcd.print(itostr4(Heater::Kd));
740
+          lcd.setCursor(13,line);lcd.print(itostr4(Kd));
745 741
         }
746 742
         
747 743
         if((activeline==line) )
@@ -751,11 +747,11 @@ void MainMenu::showControl()
751 747
             linechanging=!linechanging;
752 748
             if(linechanging)
753 749
             {
754
-               encoderpos=(int)(Heater::Kd/5.);
750
+               encoderpos=(int)Kd/5;
755 751
             }
756 752
             else
757 753
             {
758
-              Heater::Kd= encoderpos*5;
754
+              Kd= encoderpos*5;
759 755
               encoderpos=activeline*lcdslow;
760 756
                 
761 757
             }
@@ -778,7 +774,7 @@ void MainMenu::showControl()
778 774
       if(force_lcd_update)
779 775
         {
780 776
           lcd.setCursor(0,line);lcd.print(" PID-C: ");
781
-          lcd.setCursor(13,line);lcd.print(itostr3(Heater::Kc));
777
+          lcd.setCursor(13,line);lcd.print(itostr3(Kc));
782 778
         }
783 779
         
784 780
         if((activeline==line) )
@@ -788,11 +784,11 @@ void MainMenu::showControl()
788 784
             linechanging=!linechanging;
789 785
             if(linechanging)
790 786
             {
791
-               encoderpos=(int)Heater::Kc;
787
+               encoderpos=(int)Kc;
792 788
             }
793 789
             else
794 790
             {
795
-              Heater::Kc= encoderpos;
791
+              Kc= encoderpos;
796 792
               encoderpos=activeline*lcdslow;
797 793
                 
798 794
             }

Loading…
Zrušit
Uložit