|
@@ -37,6 +37,36 @@
|
37
|
37
|
|
38
|
38
|
#include "Sd2PinMap.h"
|
39
|
39
|
|
|
40
|
+//===========================================================================
|
|
41
|
+//================================== macros =================================
|
|
42
|
+//===========================================================================
|
|
43
|
+
|
|
44
|
+#if EXTRUDERS > 4
|
|
45
|
+ #error Unsupported number of extruders
|
|
46
|
+#elif EXTRUDERS > 3
|
|
47
|
+ #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1, v2, v3, v4 }
|
|
48
|
+#elif EXTRUDERS > 2
|
|
49
|
+ #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1, v2, v3 }
|
|
50
|
+#elif EXTRUDERS > 1
|
|
51
|
+ #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1, v2 }
|
|
52
|
+#else
|
|
53
|
+ #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1 }
|
|
54
|
+#endif
|
|
55
|
+
|
|
56
|
+#define PIN_EXISTS(PIN) (defined(PIN) && PIN >= 0)
|
|
57
|
+#define HAS_TEMP_0 PIN_EXISTS(TEMP_0_PIN)
|
|
58
|
+#define HAS_TEMP_1 PIN_EXISTS(TEMP_1_PIN)
|
|
59
|
+#define HAS_TEMP_2 PIN_EXISTS(TEMP_2_PIN)
|
|
60
|
+#define HAS_TEMP_3 PIN_EXISTS(TEMP_3_PIN)
|
|
61
|
+#define HAS_TEMP_BED PIN_EXISTS(TEMP_BED_PIN)
|
|
62
|
+#define HAS_FILAMENT_SENSOR (defined(FILAMENT_SENSOR) && PIN_EXISTS(FILWIDTH_PIN))
|
|
63
|
+#define HAS_HEATER_0 PIN_EXISTS(HEATER_0_PIN)
|
|
64
|
+#define HAS_HEATER_1 PIN_EXISTS(HEATER_1_PIN)
|
|
65
|
+#define HAS_HEATER_2 PIN_EXISTS(HEATER_2_PIN)
|
|
66
|
+#define HAS_HEATER_3 PIN_EXISTS(HEATER_3_PIN)
|
|
67
|
+#define HAS_HEATER_BED PIN_EXISTS(HEATER_BED_PIN)
|
|
68
|
+#define HAS_AUTO_FAN PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN) || \
|
|
69
|
+ PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_3_AUTO_FAN_PIN)
|
40
|
70
|
|
41
|
71
|
//===========================================================================
|
42
|
72
|
//============================= public variables ============================
|
|
@@ -117,24 +147,11 @@ static volatile bool temp_meas_ready = false;
|
117
|
147
|
#ifdef FAN_SOFT_PWM
|
118
|
148
|
static unsigned char soft_pwm_fan;
|
119
|
149
|
#endif
|
120
|
|
-#if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \
|
121
|
|
- (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \
|
122
|
|
- (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1)
|
|
150
|
+#if PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN) || \
|
|
151
|
+ PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_3_AUTO_FAN_PIN)
|
123
|
152
|
static unsigned long extruder_autofan_last_check;
|
124
|
153
|
#endif
|
125
|
154
|
|
126
|
|
-#if EXTRUDERS > 4
|
127
|
|
- #error Unsupported number of extruders
|
128
|
|
-#elif EXTRUDERS > 3
|
129
|
|
- #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1, v2, v3, v4 }
|
130
|
|
-#elif EXTRUDERS > 2
|
131
|
|
- #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1, v2, v3 }
|
132
|
|
-#elif EXTRUDERS > 1
|
133
|
|
- #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1, v2 }
|
134
|
|
-#else
|
135
|
|
- #define ARRAY_BY_EXTRUDERS(v1, v2, v3, v4) { v1 }
|
136
|
|
-#endif
|
137
|
|
-
|
138
|
155
|
#ifdef PIDTEMP
|
139
|
156
|
#ifdef PID_PARAMS_PER_EXTRUDER
|
140
|
157
|
float Kp[EXTRUDERS] = ARRAY_BY_EXTRUDERS(DEFAULT_Kp, DEFAULT_Kp, DEFAULT_Kp, DEFAULT_Kp);
|
|
@@ -192,13 +209,6 @@ static void updateTemperaturesFromRawValues();
|
192
|
209
|
static int read_max6675();
|
193
|
210
|
#endif
|
194
|
211
|
|
195
|
|
-#define HAS_TEMP_0 (defined(TEMP_0_PIN) && TEMP_0_PIN > -1)
|
196
|
|
-#define HAS_TEMP_1 (defined(TEMP_1_PIN) && TEMP_1_PIN > -1)
|
197
|
|
-#define HAS_TEMP_2 (defined(TEMP_2_PIN) && TEMP_2_PIN > -1)
|
198
|
|
-#define HAS_TEMP_3 (defined(TEMP_3_PIN) && TEMP_3_PIN > -1)
|
199
|
|
-#define HAS_TEMP_BED (defined(TEMP_BED_PIN) && TEMP_BED_PIN > -1)
|
200
|
|
-#define HAS_FILAMENT_SENSOR (defined(FILAMENT_SENSOR) && defined(FILWIDTH_PIN) && FILWIDTH_PIN > -1)
|
201
|
|
-
|
202
|
212
|
//===========================================================================
|
203
|
213
|
//============================= functions ============================
|
204
|
214
|
//===========================================================================
|
|
@@ -217,10 +227,8 @@ void PID_autotune(float temp, int extruder, int ncycles)
|
217
|
227
|
float Kp, Ki, Kd;
|
218
|
228
|
float max = 0, min = 10000;
|
219
|
229
|
|
220
|
|
- #if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \
|
221
|
|
- (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \
|
222
|
|
- (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1) || \
|
223
|
|
- (defined(EXTRUDER_3_AUTO_FAN_PIN) && EXTRUDER_3_AUTO_FAN_PIN > -1)
|
|
230
|
+ #if PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN) || \
|
|
231
|
+ PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_3_AUTO_FAN_PIN)
|
224
|
232
|
unsigned long extruder_autofan_last_check = temp_millis;
|
225
|
233
|
#endif
|
226
|
234
|
|
|
@@ -255,10 +263,8 @@ void PID_autotune(float temp, int extruder, int ncycles)
|
255
|
263
|
max = max(max, input);
|
256
|
264
|
min = min(min, input);
|
257
|
265
|
|
258
|
|
- #if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \
|
259
|
|
- (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \
|
260
|
|
- (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1) || \
|
261
|
|
- (defined(EXTRUDER_3_AUTO_FAN_PIN) && EXTRUDER_3_AUTO_FAN_PIN > -1)
|
|
266
|
+ #if PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN) || \
|
|
267
|
+ PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_3_AUTO_FAN_PIN)
|
262
|
268
|
if (ms > extruder_autofan_last_check + 2500) {
|
263
|
269
|
checkExtruderAutoFans();
|
264
|
270
|
extruder_autofan_last_check = ms;
|
|
@@ -336,7 +342,7 @@ void PID_autotune(float temp, int extruder, int ncycles)
|
336
|
342
|
return;
|
337
|
343
|
}
|
338
|
344
|
// Every 2 seconds...
|
339
|
|
- if (ms - temp_millis > 2000) {
|
|
345
|
+ if (ms > temp_millis + 2000) {
|
340
|
346
|
int p;
|
341
|
347
|
if (extruder < 0) {
|
342
|
348
|
p = soft_pwm_bed;
|
|
@@ -381,11 +387,10 @@ int getHeaterPower(int heater) {
|
381
|
387
|
return heater < 0 ? soft_pwm_bed : soft_pwm[heater];
|
382
|
388
|
}
|
383
|
389
|
|
384
|
|
-#if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \
|
385
|
|
- (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \
|
386
|
|
- (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1)
|
|
390
|
+#if PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN) || \
|
|
391
|
+ PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN)
|
387
|
392
|
|
388
|
|
- #if defined(FAN_PIN) && FAN_PIN > -1
|
|
393
|
+ #if PIN_EXISTS(FAN_PIN)
|
389
|
394
|
#if EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN
|
390
|
395
|
#error "You cannot set EXTRUDER_0_AUTO_FAN_PIN equal to FAN_PIN"
|
391
|
396
|
#endif
|
|
@@ -411,11 +416,11 @@ void checkExtruderAutoFans()
|
411
|
416
|
uint8_t fanState = 0;
|
412
|
417
|
|
413
|
418
|
// which fan pins need to be turned on?
|
414
|
|
- #if defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1
|
|
419
|
+ #if PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN)
|
415
|
420
|
if (current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE)
|
416
|
421
|
fanState |= 1;
|
417
|
422
|
#endif
|
418
|
|
- #if defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1
|
|
423
|
+ #if PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN)
|
419
|
424
|
if (current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE)
|
420
|
425
|
{
|
421
|
426
|
if (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN)
|
|
@@ -424,7 +429,7 @@ void checkExtruderAutoFans()
|
424
|
429
|
fanState |= 2;
|
425
|
430
|
}
|
426
|
431
|
#endif
|
427
|
|
- #if defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1
|
|
432
|
+ #if PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN)
|
428
|
433
|
if (current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE)
|
429
|
434
|
{
|
430
|
435
|
if (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN)
|
|
@@ -435,7 +440,7 @@ void checkExtruderAutoFans()
|
435
|
440
|
fanState |= 4;
|
436
|
441
|
}
|
437
|
442
|
#endif
|
438
|
|
- #if defined(EXTRUDER_3_AUTO_FAN_PIN) && EXTRUDER_3_AUTO_FAN_PIN > -1
|
|
443
|
+ #if PIN_EXISTS(EXTRUDER_3_AUTO_FAN_PIN)
|
439
|
444
|
if (current_temperature[3] > EXTRUDER_AUTO_FAN_TEMPERATURE)
|
440
|
445
|
{
|
441
|
446
|
if (EXTRUDER_3_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN)
|
|
@@ -450,19 +455,19 @@ void checkExtruderAutoFans()
|
450
|
455
|
#endif
|
451
|
456
|
|
452
|
457
|
// update extruder auto fan states
|
453
|
|
- #if defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1
|
|
458
|
+ #if PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN)
|
454
|
459
|
setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, (fanState & 1) != 0);
|
455
|
460
|
#endif
|
456
|
|
- #if defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1
|
|
461
|
+ #if PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN)
|
457
|
462
|
if (EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN)
|
458
|
463
|
setExtruderAutoFanState(EXTRUDER_1_AUTO_FAN_PIN, (fanState & 2) != 0);
|
459
|
464
|
#endif
|
460
|
|
- #if defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1
|
|
465
|
+ #if PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN)
|
461
|
466
|
if (EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN
|
462
|
467
|
&& EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN)
|
463
|
468
|
setExtruderAutoFanState(EXTRUDER_2_AUTO_FAN_PIN, (fanState & 4) != 0);
|
464
|
469
|
#endif
|
465
|
|
- #if defined(EXTRUDER_3_AUTO_FAN_PIN) && EXTRUDER_3_AUTO_FAN_PIN > -1
|
|
470
|
+ #if PIN_EXISTS(EXTRUDER_3_AUTO_FAN_PIN)
|
466
|
471
|
if (EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN
|
467
|
472
|
&& EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN
|
468
|
473
|
&& EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_2_AUTO_FAN_PIN)
|
|
@@ -475,22 +480,22 @@ void checkExtruderAutoFans()
|
475
|
480
|
//
|
476
|
481
|
// Error checking and Write Routines
|
477
|
482
|
//
|
478
|
|
-#if !defined(HEATER_0_PIN) || HEATER_0_PIN < 0
|
|
483
|
+#if !HAS_HEATER_0
|
479
|
484
|
#error HEATER_0_PIN not defined for this board
|
480
|
485
|
#endif
|
481
|
486
|
#define WRITE_HEATER_0P(v) WRITE(HEATER_0_PIN, v)
|
482
|
487
|
#if EXTRUDERS > 1 || defined(HEATERS_PARALLEL)
|
483
|
|
- #if !defined(HEATER_1_PIN) || HEATER_1_PIN < 0
|
|
488
|
+ #if !HAS_HEATER_1
|
484
|
489
|
#error HEATER_1_PIN not defined for this board
|
485
|
490
|
#endif
|
486
|
491
|
#define WRITE_HEATER_1(v) WRITE(HEATER_1_PIN, v)
|
487
|
492
|
#if EXTRUDERS > 2
|
488
|
|
- #if !defined(HEATER_2_PIN) || HEATER_2_PIN < 0
|
|
493
|
+ #if !HAS_HEATER_2
|
489
|
494
|
#error HEATER_2_PIN not defined for this board
|
490
|
495
|
#endif
|
491
|
496
|
#define WRITE_HEATER_2(v) WRITE(HEATER_2_PIN, v)
|
492
|
497
|
#if EXTRUDERS > 3
|
493
|
|
- #if !defined(HEATER_3_PIN) || HEATER_3_PIN < 0
|
|
498
|
+ #if !HAS_HEATER_3
|
494
|
499
|
#error HEATER_3_PIN not defined for this board
|
495
|
500
|
#endif
|
496
|
501
|
#define WRITE_HEATER_3(v) WRITE(HEATER_3_PIN, v)
|
|
@@ -502,7 +507,7 @@ void checkExtruderAutoFans()
|
502
|
507
|
#else
|
503
|
508
|
#define WRITE_HEATER_0(v) WRITE_HEATER_0P(v)
|
504
|
509
|
#endif
|
505
|
|
-#if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
|
|
510
|
+#if HAS_HEATER_BED
|
506
|
511
|
#define WRITE_HEATER_BED(v) WRITE(HEATER_BED_PIN, v)
|
507
|
512
|
#endif
|
508
|
513
|
|
|
@@ -626,9 +631,8 @@ void manage_heater() {
|
626
|
631
|
|
627
|
632
|
} // Extruders Loop
|
628
|
633
|
|
629
|
|
- #if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \
|
630
|
|
- (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \
|
631
|
|
- (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1)
|
|
634
|
+ #if PIN_EXISTS(EXTRUDER_0_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_1_AUTO_FAN_PIN) || \
|
|
635
|
+ PIN_EXISTS(EXTRUDER_2_AUTO_FAN_PIN) || PIN_EXISTS(EXTRUDER_3_AUTO_FAN_PIN)
|
632
|
636
|
if (ms > extruder_autofan_last_check + 2500) { // only need to check fan state very infrequently
|
633
|
637
|
checkExtruderAutoFans();
|
634
|
638
|
extruder_autofan_last_check = ms;
|
|
@@ -680,7 +684,7 @@ void manage_heater() {
|
680
|
684
|
#elif !defined(BED_LIMIT_SWITCHING)
|
681
|
685
|
// Check if temperature is within the correct range
|
682
|
686
|
if (current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP) {
|
683
|
|
- soft_pwm_bed = current_temperature_bed >= target_temperature_bed ? 0 : MAX_BED_POWER >> 1;
|
|
687
|
+ soft_pwm_bed = current_temperature_bed < target_temperature_bed ? MAX_BED_POWER >> 1 : 0;
|
684
|
688
|
}
|
685
|
689
|
else {
|
686
|
690
|
soft_pwm_bed = 0;
|
|
@@ -707,9 +711,9 @@ void manage_heater() {
|
707
|
711
|
meas_shift_index = delay_index1 - meas_delay_cm;
|
708
|
712
|
if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1; //loop around buffer if needed
|
709
|
713
|
|
710
|
|
- // Get the delayed info and add 100 to reconstitute to a percent of
|
|
714
|
+ // Get the delayed info and add 100 to reconstitute to a percent of
|
711
|
715
|
// the nominal filament diameter then square it to get an area
|
712
|
|
- meas_shift_index = constrain(meas_shift_index, 0, MAX_MEASUREMENT_DELAY);
|
|
716
|
+ meas_shift_index = constrain(meas_shift_index, 0, MAX_MEASUREMENT_DELAY);
|
713
|
717
|
float vm = pow((measurement_delay[meas_shift_index] + 100.0) / 100.0, 2);
|
714
|
718
|
if (vm < 0.01) vm = 0.01;
|
715
|
719
|
volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = vm;
|
|
@@ -722,9 +726,9 @@ void manage_heater() {
|
722
|
726
|
// For hot end temperature measurement.
|
723
|
727
|
static float analog2temp(int raw, uint8_t e) {
|
724
|
728
|
#ifdef TEMP_SENSOR_1_AS_REDUNDANT
|
725
|
|
- if(e > EXTRUDERS)
|
|
729
|
+ if (e > EXTRUDERS)
|
726
|
730
|
#else
|
727
|
|
- if(e >= EXTRUDERS)
|
|
731
|
+ if (e >= EXTRUDERS)
|
728
|
732
|
#endif
|
729
|
733
|
{
|
730
|
734
|
SERIAL_ERROR_START;
|
|
@@ -798,28 +802,26 @@ static float analog2tempBed(int raw) {
|
798
|
802
|
|
799
|
803
|
/* Called to get the raw values into the the actual temperatures. The raw values are created in interrupt context,
|
800
|
804
|
and this function is called from normal context as it is too slow to run in interrupts and will block the stepper routine otherwise */
|
801
|
|
-static void updateTemperaturesFromRawValues()
|
802
|
|
-{
|
803
|
|
- #ifdef HEATER_0_USES_MAX6675
|
804
|
|
- current_temperature_raw[0] = read_max6675();
|
805
|
|
- #endif
|
806
|
|
- for(uint8_t e=0;e<EXTRUDERS;e++)
|
807
|
|
- {
|
808
|
|
- current_temperature[e] = analog2temp(current_temperature_raw[e], e);
|
809
|
|
- }
|
810
|
|
- current_temperature_bed = analog2tempBed(current_temperature_bed_raw);
|
811
|
|
- #ifdef TEMP_SENSOR_1_AS_REDUNDANT
|
812
|
|
- redundant_temperature = analog2temp(redundant_temperature_raw, 1);
|
813
|
|
- #endif
|
814
|
|
- #if HAS_FILAMENT_SENSOR
|
815
|
|
- filament_width_meas = analog2widthFil();
|
816
|
|
- #endif
|
817
|
|
- //Reset the watchdog after we know we have a temperature measurement.
|
818
|
|
- watchdog_reset();
|
819
|
|
-
|
820
|
|
- CRITICAL_SECTION_START;
|
821
|
|
- temp_meas_ready = false;
|
822
|
|
- CRITICAL_SECTION_END;
|
|
805
|
+static void updateTemperaturesFromRawValues() {
|
|
806
|
+ #ifdef HEATER_0_USES_MAX6675
|
|
807
|
+ current_temperature_raw[0] = read_max6675();
|
|
808
|
+ #endif
|
|
809
|
+ for(uint8_t e = 0; e < EXTRUDERS; e++) {
|
|
810
|
+ current_temperature[e] = analog2temp(current_temperature_raw[e], e);
|
|
811
|
+ }
|
|
812
|
+ current_temperature_bed = analog2tempBed(current_temperature_bed_raw);
|
|
813
|
+ #ifdef TEMP_SENSOR_1_AS_REDUNDANT
|
|
814
|
+ redundant_temperature = analog2temp(redundant_temperature_raw, 1);
|
|
815
|
+ #endif
|
|
816
|
+ #if HAS_FILAMENT_SENSOR
|
|
817
|
+ filament_width_meas = analog2widthFil();
|
|
818
|
+ #endif
|
|
819
|
+ //Reset the watchdog after we know we have a temperature measurement.
|
|
820
|
+ watchdog_reset();
|
|
821
|
+
|
|
822
|
+ CRITICAL_SECTION_START;
|
|
823
|
+ temp_meas_ready = false;
|
|
824
|
+ CRITICAL_SECTION_END;
|
823
|
825
|
}
|
824
|
826
|
|
825
|
827
|
|
|
@@ -867,22 +869,22 @@ void tp_init()
|
867
|
869
|
#endif //PIDTEMPBED
|
868
|
870
|
}
|
869
|
871
|
|
870
|
|
- #if defined(HEATER_0_PIN) && (HEATER_0_PIN > -1)
|
|
872
|
+ #if HAS_HEATER_0
|
871
|
873
|
SET_OUTPUT(HEATER_0_PIN);
|
872
|
874
|
#endif
|
873
|
|
- #if defined(HEATER_1_PIN) && (HEATER_1_PIN > -1)
|
|
875
|
+ #if HAS_HEATER_1
|
874
|
876
|
SET_OUTPUT(HEATER_1_PIN);
|
875
|
877
|
#endif
|
876
|
|
- #if defined(HEATER_2_PIN) && (HEATER_2_PIN > -1)
|
|
878
|
+ #if HAS_HEATER_2
|
877
|
879
|
SET_OUTPUT(HEATER_2_PIN);
|
878
|
880
|
#endif
|
879
|
|
- #if defined(HEATER_3_PIN) && (HEATER_3_PIN > -1)
|
|
881
|
+ #if HAS_HEATER_3
|
880
|
882
|
SET_OUTPUT(HEATER_3_PIN);
|
881
|
883
|
#endif
|
882
|
|
- #if defined(HEATER_BED_PIN) && (HEATER_BED_PIN > -1)
|
|
884
|
+ #if HAS_HEATER_BED
|
883
|
885
|
SET_OUTPUT(HEATER_BED_PIN);
|
884
|
886
|
#endif
|
885
|
|
- #if defined(FAN_PIN) && (FAN_PIN > -1)
|
|
887
|
+ #if PIN_EXISTS(FAN_PIN)
|
886
|
888
|
SET_OUTPUT(FAN_PIN);
|
887
|
889
|
#ifdef FAST_PWM_FAN
|
888
|
890
|
setPwmFrequency(FAN_PIN, 1); // No prescaling. Pwm frequency = F_CPU/256/8
|
|
@@ -1130,7 +1132,7 @@ void disable_heater() {
|
1130
|
1132
|
#if HAS_TEMP_BED
|
1131
|
1133
|
target_temperature_bed = 0;
|
1132
|
1134
|
soft_pwm_bed = 0;
|
1133
|
|
- #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
|
|
1135
|
+ #if HAS_HEATER_BED
|
1134
|
1136
|
WRITE_HEATER_BED(LOW);
|
1135
|
1137
|
#endif
|
1136
|
1138
|
#endif
|
|
@@ -1163,7 +1165,7 @@ void min_temp_error(uint8_t e) {
|
1163
|
1165
|
}
|
1164
|
1166
|
|
1165
|
1167
|
void bed_max_temp_error(void) {
|
1166
|
|
- #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
|
|
1168
|
+ #if HAS_HEATER_BED
|
1167
|
1169
|
WRITE_HEATER_BED(0);
|
1168
|
1170
|
#endif
|
1169
|
1171
|
if (IsStopped() == false) {
|
|
@@ -1232,6 +1234,9 @@ void bed_max_temp_error(void) {
|
1232
|
1234
|
|
1233
|
1235
|
#endif //HEATER_0_USES_MAX6675
|
1234
|
1236
|
|
|
1237
|
+/**
|
|
1238
|
+ * Stages in the ISR loop
|
|
1239
|
+ */
|
1235
|
1240
|
enum TempState {
|
1236
|
1241
|
PrepareTemp_0,
|
1237
|
1242
|
MeasureTemp_0,
|
|
@@ -1284,7 +1289,7 @@ ISR(TIMER0_COMPB_vect) {
|
1284
|
1289
|
#endif
|
1285
|
1290
|
#endif
|
1286
|
1291
|
#endif
|
1287
|
|
- #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
|
|
1292
|
+ #if HAS_HEATER_BED
|
1288
|
1293
|
ISR_STATICS(BED);
|
1289
|
1294
|
#endif
|
1290
|
1295
|
|
|
@@ -1316,7 +1321,7 @@ ISR(TIMER0_COMPB_vect) {
|
1316
|
1321
|
#endif
|
1317
|
1322
|
#endif
|
1318
|
1323
|
|
1319
|
|
- #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
|
|
1324
|
+ #if HAS_HEATER_BED
|
1320
|
1325
|
soft_pwm_BED = soft_pwm_bed;
|
1321
|
1326
|
WRITE_HEATER_BED(soft_pwm_BED > 0 ? 1 : 0);
|
1322
|
1327
|
#endif
|
|
@@ -1337,7 +1342,7 @@ ISR(TIMER0_COMPB_vect) {
|
1337
|
1342
|
#endif
|
1338
|
1343
|
#endif
|
1339
|
1344
|
|
1340
|
|
- #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
|
|
1345
|
+ #if HAS_HEATER_BED
|
1341
|
1346
|
if (soft_pwm_BED < pwm_count) WRITE_HEATER_BED(0);
|
1342
|
1347
|
#endif
|
1343
|
1348
|
|
|
@@ -1398,7 +1403,7 @@ ISR(TIMER0_COMPB_vect) {
|
1398
|
1403
|
#endif
|
1399
|
1404
|
#endif
|
1400
|
1405
|
#endif
|
1401
|
|
- #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
|
|
1406
|
+ #if HAS_HEATER_BED
|
1402
|
1407
|
_SLOW_PWM_ROUTINE(BED, soft_pwm_bed); // BED
|
1403
|
1408
|
#endif
|
1404
|
1409
|
|
|
@@ -1414,7 +1419,7 @@ ISR(TIMER0_COMPB_vect) {
|
1414
|
1419
|
#endif
|
1415
|
1420
|
#endif
|
1416
|
1421
|
#endif
|
1417
|
|
- #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1
|
|
1422
|
+ #if HAS_HEATER_BED
|
1418
|
1423
|
PWM_OFF_ROUTINE(BED); // BED
|
1419
|
1424
|
#endif
|
1420
|
1425
|
|
|
@@ -1445,7 +1450,7 @@ ISR(TIMER0_COMPB_vect) {
|
1445
|
1450
|
#endif
|
1446
|
1451
|
#endif
|
1447
|
1452
|
#endif
|
1448
|
|
- #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 // BED
|
|
1453
|
+ #if HAS_HEATER_BED
|
1449
|
1454
|
if (state_timer_heater_BED > 0) state_timer_heater_BED--;
|
1450
|
1455
|
#endif
|
1451
|
1456
|
} // (pwm_count % 64) == 0
|