Browse Source

Changed min max temperature code.

Erik van der Zalm 13 years ago
parent
commit
2e43f9c809
2 changed files with 76 additions and 80 deletions
  1. 1
    1
      Marlin/Configuration.h
  2. 75
    79
      Marlin/temperature.cpp

+ 1
- 1
Marlin/Configuration.h View File

@@ -80,7 +80,7 @@
80 80
 // This feature exists to protect your hotend from overheating accidentally, but *NOT* from thermistor short/failure!
81 81
 // You should use MINTEMP for thermistor short/failure protection.
82 82
 #define HEATER_0_MAXTEMP 275
83
-//#define_HEATER_1_MAXTEMP 275
83
+//#define HEATER_1_MAXTEMP 275
84 84
 //#define BED_MAXTEMP 150
85 85
 
86 86
 

+ 75
- 79
Marlin/temperature.cpp View File

@@ -90,50 +90,12 @@ static unsigned long previous_millis_heater, previous_millis_bed_heater;
90 90
 #endif //WATCHPERIOD
91 91
 
92 92
 // Init min and max temp with extreme values to prevent false errors during startup
93
-#ifdef HEATER_0_MINTEMP
94
-  #ifdef HEATER_0_USES_AD595
95
-    static int minttemp_0 = 0;
96
-  #else
97
-    static int minttemp_0 = 16383;
98
-  #endif
99
-#endif //MINTEMP
100
-#ifdef HEATER_0_MAXTEMP
101
-  #ifdef HEATER_0_USES_AD595
102
-    static int maxttemp_0 = 16383;
103
-  #else
104
-    static int maxttemp_0 = 0;
105
-  #endif
106
-#endif //MAXTEMP
107
-
108
-#ifdef HEATER_1_MINTEMP
109
-  #ifdef HEATER_1_USES_AD595
110
-    static int minttemp_1 = 0;
111
-  #else
112
-    static int minttemp_1 = 16383;
113
-  #endif
114
-#endif //MINTEMP
115
-#ifdef HEATER_1_MAXTEMP
116
-  #ifdef HEATER_1_USES_AD595
117
-    static int maxttemp_1 = 16383;
118
-  #else
119
-    static int maxttemp_1 = 0;
120
-  #endif
121
-#endif //MAXTEMP
122
-
123
-#ifdef BED_MINTEMP
124
-  #ifdef BED_USES_AD595
125
-    static int bed_minttemp = 0;
126
-  #else
127
-    static int bed_minttemp = 16383;
128
-  #endif
129
-#endif //BED_MINTEMP
130
-#ifdef BED_MAXTEMP
131
-  #ifdef BED_USES_AD595
132
-    static int bed_maxttemp = 16383;
133
-  #else
134
-    static int bed_maxttemp = 0;
135
-  #endif
136
-#endif //BED_MAXTEMP
93
+  static int minttemp_0   = 0;
94
+  static int maxttemp_0   = 16383;
95
+  static int minttemp_1   = 0;
96
+  static int maxttemp_1   = 16383;
97
+  static int bed_minttemp = 0;
98
+  static int bed_maxttemp = 16383;
137 99
 
138 100
 //===========================================================================
139 101
 //=============================functions         ============================
@@ -198,18 +160,28 @@ void manage_heater()
198 160
      //SERIAL_ECHOLN(" PIDDEBUG Input "<<pid_input<<" Output "<<pid_output" pTerm "<<pTerm<<" iTerm "<<iTerm<<" dTerm "<<dTerm);  
199 161
     #endif //PID_DEBUG
200 162
     HeaterPower=pid_output;
201
-    analogWrite(HEATER_0_PIN, pid_output);
163
+    // Check if temperature is within the correct range
164
+    if((current_raw[TEMPSENSOR_HOTEND_0] > minttemp_0) && (current_raw[TEMPSENSOR_HOTEND_0] < maxttemp_0)) {
165
+      analogWrite(HEATER_0_PIN, pid_output);
166
+    }
167
+    else {
168
+      analogWrite(HEATER_0_PIN, 0);
169
+    }
202 170
   #endif //PIDTEMP
203 171
 
204 172
   #ifndef PIDTEMP
205
-    if(current_raw[0] >= target_raw[0])
206
-    {
207
-      WRITE(HEATER_0_PIN,LOW);
208
-    }
209
-    else 
210
-    {
211
-      WRITE(HEATER_0_PIN,HIGH);
173
+    // Check if temperature is within the correct range
174
+    if((current_raw[TEMPSENSOR_HOTEND_0] > minttemp_0) && (current_raw[TEMPSENSOR_HOTEND_0] < maxttemp_0)) {
175
+      if(current_raw[TEMPSENSOR_HOTEND_0] >= target_raw[TEMPSENSOR_HOTEND_0]) {
176
+        WRITE(HEATER_0_PIN,LOW);
177
+      }
178
+      else {
179
+        WRITE(HEATER_0_PIN,HIGH);
180
+      }
212 181
     }
182
+    else {
183
+      WRITE(HEATER_0_PIN,LOW);
184
+    }    
213 185
   #endif
214 186
     
215 187
   if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL)
@@ -217,14 +189,20 @@ void manage_heater()
217 189
   previous_millis_bed_heater = millis();
218 190
   
219 191
   #if TEMP_1_PIN > -1
220
-    if(current_raw[TEMPSENSOR_BED] >= target_raw[TEMPSENSOR_BED])
221
-    {
222
-      WRITE(HEATER_1_PIN,LOW);
223
-    }
224
-    else 
225
-    {
226
-      WRITE(HEATER_1_PIN,HIGH);
192
+    // Check if temperature is within the correct range
193
+    if((current_raw[TEMPSENSOR_BED] > bed_minttemp) && (current_raw[TEMPSENSOR_BED] < bed_maxttemp)) {
194
+      if(current_raw[TEMPSENSOR_BED] >= target_raw[TEMPSENSOR_BED])
195
+      {
196
+        WRITE(HEATER_1_PIN,LOW);
197
+      }
198
+      else 
199
+      {
200
+        WRITE(HEATER_1_PIN,HIGH);
201
+      }
227 202
     }
203
+    else {
204
+      WRITE(HEATER_1_PIN,LOW);
205
+    }  
228 206
   #endif
229 207
 }
230 208
 
@@ -370,6 +348,34 @@ void tp_init()
370 348
 
371 349
   // Set analog inputs
372 350
   ADCSRA = 1<<ADEN | 1<<ADSC | 1<<ADIF | 0x07;
351
+  DIDR0 = 0;
352
+  #ifdef DIDR2
353
+    DIDR2 = 0;
354
+  #endif
355
+  #if (TEMP_0_PIN > -1)
356
+    #if TEMP_0_PIN < 8
357
+       DIDR0 |= 1 << TEMP_0_PIN; 
358
+    #else
359
+       DIDR2 |= 1<<(TEMP_0_PIN - 8); 
360
+       ADCSRB = 1<<MUX5;
361
+    #endif
362
+  #endif
363
+  #if (TEMP_1_PIN > -1)
364
+    #if TEMP_1_PIN < 8
365
+       DIDR0 |= 1<<TEMP_1_PIN; 
366
+    #else
367
+       DIDR2 |= 1<<(TEMP_1_PIN - 8); 
368
+       ADCSRB = 1<<MUX5;
369
+    #endif
370
+  #endif
371
+  #if (TEMP_2_PIN > -1)
372
+    #if TEMP_2_PIN < 8
373
+       DIDR0 |= 1 << TEMP_2_PIN; 
374
+    #else
375
+       DIDR2 = 1<<(TEMP_2_PIN - 8); 
376
+       ADCSRB = 1<<MUX5;
377
+    #endif
378
+  #endif
373 379
   
374 380
   // Use timer0 for temperature measurement
375 381
   // Interleave temperature interrupt with millies interrupt
@@ -456,10 +462,7 @@ ISR(TIMER0_COMPB_vect)
456 462
   switch(temp_state) {
457 463
     case 0: // Prepare TEMP_0
458 464
       #if (TEMP_0_PIN > -1)
459
-        #if TEMP_0_PIN < 8
460
-          DIDR0 = 1 << TEMP_0_PIN; 
461
-        #else
462
-          DIDR2 = 1<<(TEMP_0_PIN - 8); 
465
+        #if TEMP_0_PIN > 7
463 466
           ADCSRB = 1<<MUX5;
464 467
         #endif
465 468
         ADMUX = ((1 << REFS0) | (TEMP_0_PIN & 0x07));
@@ -478,10 +481,7 @@ ISR(TIMER0_COMPB_vect)
478 481
       break;
479 482
     case 2: // Prepare TEMP_1
480 483
       #if (TEMP_1_PIN > -1)
481
-        #if TEMP_1_PIN < 7
482
-          DIDR0 = 1<<TEMP_1_PIN; 
483
-        #else
484
-          DIDR2 = 1<<(TEMP_1_PIN - 8); 
484
+        #if TEMP_1_PIN > 7
485 485
           ADCSRB = 1<<MUX5;
486 486
         #endif
487 487
         ADMUX = ((1 << REFS0) | (TEMP_1_PIN & 0x07));
@@ -500,10 +500,7 @@ ISR(TIMER0_COMPB_vect)
500 500
       break;
501 501
     case 4: // Prepare TEMP_2
502 502
       #if (TEMP_2_PIN > -1)
503
-        #if TEMP_2_PIN < 7
504
-          DIDR0 = 1 << TEMP_2_PIN; 
505
-        #else
506
-          DIDR2 = 1<<(TEMP_2_PIN - 8); 
503
+        #if TEMP_2_PIN > 7
507 504
           ADCSRB = 1<<MUX5;
508 505
         #endif
509 506
         ADMUX = ((1 << REFS0) | (TEMP_2_PIN & 0x07));
@@ -556,7 +553,7 @@ ISR(TIMER0_COMPB_vect)
556 553
       #if (HEATER_0_PIN > -1)
557 554
         if(current_raw[TEMPSENSOR_HOTEND_0] >= maxttemp_0) {
558 555
           target_raw[TEMPSENSOR_HOTEND_0] = 0;
559
-          analogWrite(HEATER_0_PIN, 0);
556
+          digitalWrite(HEATER_0_PIN, 0);
560 557
           SERIAL_ERROR_START;
561 558
           SERIAL_ERRORLNPGM("Temperature extruder 0 switched off. MAXTEMP triggered !!");
562 559
           kill();
@@ -567,11 +564,10 @@ ISR(TIMER0_COMPB_vect)
567 564
     #if (HEATER_1_PIN > -1)
568 565
       if(current_raw[TEMPSENSOR_HOTEND_1] >= maxttemp_1) {
569 566
         target_raw[TEMPSENSOR_HOTEND_1] = 0;
570
-      if(current_raw[2] >= maxttemp_1) {
571
-        analogWrite(HEATER_2_PIN, 0);
567
+        digitalWrite(HEATER_2_PIN, 0);
572 568
         SERIAL_ERROR_START;
573 569
         SERIAL_ERRORLNPGM("Temperature extruder 1 switched off. MAXTEMP triggered !!");
574
-        kill()
570
+        kill();
575 571
       }
576 572
     #endif
577 573
   #endif //MAXTEMP
@@ -580,7 +576,7 @@ ISR(TIMER0_COMPB_vect)
580 576
     #if (HEATER_0_PIN > -1)
581 577
       if(current_raw[TEMPSENSOR_HOTEND_0] <= minttemp_0) {
582 578
         target_raw[TEMPSENSOR_HOTEND_0] = 0;
583
-        analogWrite(HEATER_0_PIN, 0);
579
+        digitalWrite(HEATER_0_PIN, 0);
584 580
         SERIAL_ERROR_START;
585 581
         SERIAL_ERRORLNPGM("Temperature extruder 0 switched off. MINTEMP triggered !!");
586 582
         kill();
@@ -592,7 +588,7 @@ ISR(TIMER0_COMPB_vect)
592 588
     #if (HEATER_2_PIN > -1)
593 589
       if(current_raw[TEMPSENSOR_HOTEND_1] <= minttemp_1) {
594 590
         target_raw[TEMPSENSOR_HOTEND_1] = 0;
595
-        analogWrite(HEATER_2_PIN, 0);
591
+        digitalWrite(HEATER_2_PIN, 0);
596 592
         SERIAL_ERROR_START;
597 593
         SERIAL_ERRORLNPGM("Temperature extruder 1 switched off. MINTEMP triggered !!");
598 594
         kill();
@@ -604,7 +600,7 @@ ISR(TIMER0_COMPB_vect)
604 600
     #if (HEATER_1_PIN > -1)
605 601
       if(current_raw[1] <= bed_minttemp) {
606 602
         target_raw[1] = 0;
607
-        WRITE(HEATER_1_PIN, 0);
603
+        digitalWrite(HEATER_1_PIN, 0);
608 604
         SERIAL_ERROR_START;
609 605
         SERIAL_ERRORLNPGM("Temperatur heated bed switched off. MINTEMP triggered !!");
610 606
         kill();
@@ -616,7 +612,7 @@ ISR(TIMER0_COMPB_vect)
616 612
     #if (HEATER_1_PIN > -1)
617 613
       if(current_raw[1] >= bed_maxttemp) {
618 614
         target_raw[1] = 0;
619
-        WRITE(HEATER_1_PIN, 0);
615
+        digitalWrite(HEATER_1_PIN, 0);
620 616
         SERIAL_ERROR_START;
621 617
         SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !!");
622 618
         kill();

Loading…
Cancel
Save