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

+ 75
- 79
Marlin/temperature.cpp View File

90
 #endif //WATCHPERIOD
90
 #endif //WATCHPERIOD
91
 
91
 
92
 // Init min and max temp with extreme values to prevent false errors during startup
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
 //=============================functions         ============================
101
 //=============================functions         ============================
198
      //SERIAL_ECHOLN(" PIDDEBUG Input "<<pid_input<<" Output "<<pid_output" pTerm "<<pTerm<<" iTerm "<<iTerm<<" dTerm "<<dTerm);  
160
      //SERIAL_ECHOLN(" PIDDEBUG Input "<<pid_input<<" Output "<<pid_output" pTerm "<<pTerm<<" iTerm "<<iTerm<<" dTerm "<<dTerm);  
199
     #endif //PID_DEBUG
161
     #endif //PID_DEBUG
200
     HeaterPower=pid_output;
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
   #endif //PIDTEMP
170
   #endif //PIDTEMP
203
 
171
 
204
   #ifndef PIDTEMP
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
   #endif
185
   #endif
214
     
186
     
215
   if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL)
187
   if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL)
217
   previous_millis_bed_heater = millis();
189
   previous_millis_bed_heater = millis();
218
   
190
   
219
   #if TEMP_1_PIN > -1
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
   #endif
206
   #endif
229
 }
207
 }
230
 
208
 
370
 
348
 
371
   // Set analog inputs
349
   // Set analog inputs
372
   ADCSRA = 1<<ADEN | 1<<ADSC | 1<<ADIF | 0x07;
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
   // Use timer0 for temperature measurement
380
   // Use timer0 for temperature measurement
375
   // Interleave temperature interrupt with millies interrupt
381
   // Interleave temperature interrupt with millies interrupt
456
   switch(temp_state) {
462
   switch(temp_state) {
457
     case 0: // Prepare TEMP_0
463
     case 0: // Prepare TEMP_0
458
       #if (TEMP_0_PIN > -1)
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
           ADCSRB = 1<<MUX5;
466
           ADCSRB = 1<<MUX5;
464
         #endif
467
         #endif
465
         ADMUX = ((1 << REFS0) | (TEMP_0_PIN & 0x07));
468
         ADMUX = ((1 << REFS0) | (TEMP_0_PIN & 0x07));
478
       break;
481
       break;
479
     case 2: // Prepare TEMP_1
482
     case 2: // Prepare TEMP_1
480
       #if (TEMP_1_PIN > -1)
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
           ADCSRB = 1<<MUX5;
485
           ADCSRB = 1<<MUX5;
486
         #endif
486
         #endif
487
         ADMUX = ((1 << REFS0) | (TEMP_1_PIN & 0x07));
487
         ADMUX = ((1 << REFS0) | (TEMP_1_PIN & 0x07));
500
       break;
500
       break;
501
     case 4: // Prepare TEMP_2
501
     case 4: // Prepare TEMP_2
502
       #if (TEMP_2_PIN > -1)
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
           ADCSRB = 1<<MUX5;
504
           ADCSRB = 1<<MUX5;
508
         #endif
505
         #endif
509
         ADMUX = ((1 << REFS0) | (TEMP_2_PIN & 0x07));
506
         ADMUX = ((1 << REFS0) | (TEMP_2_PIN & 0x07));
556
       #if (HEATER_0_PIN > -1)
553
       #if (HEATER_0_PIN > -1)
557
         if(current_raw[TEMPSENSOR_HOTEND_0] >= maxttemp_0) {
554
         if(current_raw[TEMPSENSOR_HOTEND_0] >= maxttemp_0) {
558
           target_raw[TEMPSENSOR_HOTEND_0] = 0;
555
           target_raw[TEMPSENSOR_HOTEND_0] = 0;
559
-          analogWrite(HEATER_0_PIN, 0);
556
+          digitalWrite(HEATER_0_PIN, 0);
560
           SERIAL_ERROR_START;
557
           SERIAL_ERROR_START;
561
           SERIAL_ERRORLNPGM("Temperature extruder 0 switched off. MAXTEMP triggered !!");
558
           SERIAL_ERRORLNPGM("Temperature extruder 0 switched off. MAXTEMP triggered !!");
562
           kill();
559
           kill();
567
     #if (HEATER_1_PIN > -1)
564
     #if (HEATER_1_PIN > -1)
568
       if(current_raw[TEMPSENSOR_HOTEND_1] >= maxttemp_1) {
565
       if(current_raw[TEMPSENSOR_HOTEND_1] >= maxttemp_1) {
569
         target_raw[TEMPSENSOR_HOTEND_1] = 0;
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
         SERIAL_ERROR_START;
568
         SERIAL_ERROR_START;
573
         SERIAL_ERRORLNPGM("Temperature extruder 1 switched off. MAXTEMP triggered !!");
569
         SERIAL_ERRORLNPGM("Temperature extruder 1 switched off. MAXTEMP triggered !!");
574
-        kill()
570
+        kill();
575
       }
571
       }
576
     #endif
572
     #endif
577
   #endif //MAXTEMP
573
   #endif //MAXTEMP
580
     #if (HEATER_0_PIN > -1)
576
     #if (HEATER_0_PIN > -1)
581
       if(current_raw[TEMPSENSOR_HOTEND_0] <= minttemp_0) {
577
       if(current_raw[TEMPSENSOR_HOTEND_0] <= minttemp_0) {
582
         target_raw[TEMPSENSOR_HOTEND_0] = 0;
578
         target_raw[TEMPSENSOR_HOTEND_0] = 0;
583
-        analogWrite(HEATER_0_PIN, 0);
579
+        digitalWrite(HEATER_0_PIN, 0);
584
         SERIAL_ERROR_START;
580
         SERIAL_ERROR_START;
585
         SERIAL_ERRORLNPGM("Temperature extruder 0 switched off. MINTEMP triggered !!");
581
         SERIAL_ERRORLNPGM("Temperature extruder 0 switched off. MINTEMP triggered !!");
586
         kill();
582
         kill();
592
     #if (HEATER_2_PIN > -1)
588
     #if (HEATER_2_PIN > -1)
593
       if(current_raw[TEMPSENSOR_HOTEND_1] <= minttemp_1) {
589
       if(current_raw[TEMPSENSOR_HOTEND_1] <= minttemp_1) {
594
         target_raw[TEMPSENSOR_HOTEND_1] = 0;
590
         target_raw[TEMPSENSOR_HOTEND_1] = 0;
595
-        analogWrite(HEATER_2_PIN, 0);
591
+        digitalWrite(HEATER_2_PIN, 0);
596
         SERIAL_ERROR_START;
592
         SERIAL_ERROR_START;
597
         SERIAL_ERRORLNPGM("Temperature extruder 1 switched off. MINTEMP triggered !!");
593
         SERIAL_ERRORLNPGM("Temperature extruder 1 switched off. MINTEMP triggered !!");
598
         kill();
594
         kill();
604
     #if (HEATER_1_PIN > -1)
600
     #if (HEATER_1_PIN > -1)
605
       if(current_raw[1] <= bed_minttemp) {
601
       if(current_raw[1] <= bed_minttemp) {
606
         target_raw[1] = 0;
602
         target_raw[1] = 0;
607
-        WRITE(HEATER_1_PIN, 0);
603
+        digitalWrite(HEATER_1_PIN, 0);
608
         SERIAL_ERROR_START;
604
         SERIAL_ERROR_START;
609
         SERIAL_ERRORLNPGM("Temperatur heated bed switched off. MINTEMP triggered !!");
605
         SERIAL_ERRORLNPGM("Temperatur heated bed switched off. MINTEMP triggered !!");
610
         kill();
606
         kill();
616
     #if (HEATER_1_PIN > -1)
612
     #if (HEATER_1_PIN > -1)
617
       if(current_raw[1] >= bed_maxttemp) {
613
       if(current_raw[1] >= bed_maxttemp) {
618
         target_raw[1] = 0;
614
         target_raw[1] = 0;
619
-        WRITE(HEATER_1_PIN, 0);
615
+        digitalWrite(HEATER_1_PIN, 0);
620
         SERIAL_ERROR_START;
616
         SERIAL_ERROR_START;
621
         SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !!");
617
         SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !!");
622
         kill();
618
         kill();

Loading…
Cancel
Save