Sfoglia il codice sorgente

Big temperature code update. No longer converts back and forwards between temperature and raw sample value. Reducing complexity, removing code. Also named some variables better. While keeping the safety intact and functionality the same.

daid303 11 anni fa
parent
commit
52158dffcc
3 ha cambiato i file con 291 aggiunte e 266 eliminazioni
  1. 204
    193
      Marlin/temperature.cpp
  2. 14
    43
      Marlin/temperature.h
  3. 73
    30
      Marlin/thermistortables.h

+ 204
- 193
Marlin/temperature.cpp Vedi File

@@ -37,19 +37,14 @@
37 37
 //===========================================================================
38 38
 //=============================public variables============================
39 39
 //===========================================================================
40
-int target_raw[EXTRUDERS] = { 0 };
41
-int target_raw_bed = 0;
42
-#ifdef BED_LIMIT_SWITCHING
43
-int target_bed_low_temp =0;  
44
-int target_bed_high_temp =0;
45
-#endif
46
-int current_raw[EXTRUDERS] = { 0 };
47
-int current_raw_bed = 0;
40
+int target_temperature[EXTRUDERS] = { 0 };
41
+int target_temperature_bed = 0;
42
+int current_temperature_raw[EXTRUDERS] = { 0 };
43
+float current_temperature[EXTRUDERS] = { 0 };
44
+int current_temperature_bed_raw = 0;
45
+float current_temperature_bed = 0;
48 46
 
49 47
 #ifdef PIDTEMP
50
-  // used external
51
-  float pid_setpoint[EXTRUDERS] = { 0.0 };
52
-  
53 48
   float Kp=DEFAULT_Kp;
54 49
   float Ki=(DEFAULT_Ki*PID_dT);
55 50
   float Kd=(DEFAULT_Kd/PID_dT);
@@ -59,9 +54,6 @@ int current_raw_bed = 0;
59 54
 #endif //PIDTEMP
60 55
 
61 56
 #ifdef PIDTEMPBED
62
-  // used external
63
-  float pid_setpoint_bed = { 0.0 };
64
-  
65 57
   float bedKp=DEFAULT_bedKp;
66 58
   float bedKi=(DEFAULT_bedKi*PID_dT);
67 59
   float bedKd=(DEFAULT_bedKd/PID_dT);
@@ -116,12 +108,20 @@ static volatile bool temp_meas_ready = false;
116 108
 #endif
117 109
 
118 110
 // Init min and max temp with extreme values to prevent false errors during startup
119
-static int minttemp[EXTRUDERS] = ARRAY_BY_EXTRUDERS(0, 0, 0);
120
-static int maxttemp[EXTRUDERS] = ARRAY_BY_EXTRUDERS(16383, 16383, 16383); // the first value used for all
121
-static int bed_minttemp = 0;
122
-static int bed_maxttemp = 16383;
123
-static void *heater_ttbl_map[EXTRUDERS] = ARRAY_BY_EXTRUDERS((void *)heater_0_temptable, (void *)heater_1_temptable, (void *)heater_2_temptable);
124
-static int heater_ttbllen_map[EXTRUDERS] = ARRAY_BY_EXTRUDERS(heater_0_temptable_len, heater_1_temptable_len, heater_2_temptable_len);
111
+static int minttemp_raw[EXTRUDERS] = ARRAY_BY_EXTRUDERS( HEATER_0_RAW_LO_TEMP , HEATER_1_RAW_LO_TEMP , HEATER_2_RAW_LO_TEMP );
112
+static int maxttemp_raw[EXTRUDERS] = ARRAY_BY_EXTRUDERS( HEATER_0_RAW_HI_TEMP , HEATER_1_RAW_HI_TEMP , HEATER_2_RAW_HI_TEMP );
113
+static int minttemp[EXTRUDERS] = ARRAY_BY_EXTRUDERS( 0, 0, 0 );
114
+static int maxttemp[EXTRUDERS] = ARRAY_BY_EXTRUDERS( 16383, 16383, 16383 );
115
+//static int bed_minttemp_raw = HEATER_BED_RAW_LO_TEMP; /* No bed mintemp error implemented?!? */
116
+#ifdef BED_MAXTEMP
117
+static int bed_maxttemp_raw = HEATER_BED_RAW_HI_TEMP;
118
+#endif
119
+static void *heater_ttbl_map[EXTRUDERS] = ARRAY_BY_EXTRUDERS( (void *)HEATER_0_TEMPTABLE, (void *)HEATER_1_TEMPTABLE, (void *)HEATER_2_TEMPTABLE );
120
+static int heater_ttbllen_map[EXTRUDERS] = ARRAY_BY_EXTRUDERS( HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN, HEATER_2_TEMPTABLE_LEN );
121
+
122
+static float analog2temp(int raw, uint8_t e);
123
+static float analog2tempBed(int raw);
124
+static void updateTemperaturesFromRawValues();
125 125
 
126 126
 #ifdef WATCH_TEMP_PERIOD
127 127
 int watch_start_temp[EXTRUDERS] = ARRAY_BY_EXTRUDERS(0,0,0);
@@ -179,13 +179,9 @@ void PID_autotune(float temp, int extruder, int ncycles)
179 179
  for(;;) {
180 180
 
181 181
     if(temp_meas_ready == true) { // temp sample ready
182
-      //Reset the watchdog after we know we have a temperature measurement.
183
-      watchdog_reset();
184
-      
185
-      CRITICAL_SECTION_START;
186
-      temp_meas_ready = false;
187
-      CRITICAL_SECTION_END;
188
-      input = (extruder<0)?analog2tempBed(current_raw_bed):analog2temp(current_raw[extruder], extruder);
182
+      updateTemperaturesFromRawValues();
183
+
184
+      input = (extruder<0)?current_temperature_bed:current_temperature[extruder];
189 185
 
190 186
       max=max(max,input);
191 187
       min=min(min,input);
@@ -313,21 +309,16 @@ void manage_heater()
313 309
   if(temp_meas_ready != true)   //better readability
314 310
     return; 
315 311
 
316
-  //Reset the watchdog after we know we have a temperature measurement.
317
-  watchdog_reset();
318
-
319
-  CRITICAL_SECTION_START;
320
-  temp_meas_ready = false;
321
-  CRITICAL_SECTION_END;
312
+  updateTemperaturesFromRawValues();
322 313
 
323 314
   for(int e = 0; e < EXTRUDERS; e++) 
324 315
   {
325 316
 
326 317
   #ifdef PIDTEMP
327
-    pid_input = analog2temp(current_raw[e], e);
318
+    pid_input = current_temperature[e];
328 319
 
329 320
     #ifndef PID_OPENLOOP
330
-        pid_error[e] = pid_setpoint[e] - pid_input;
321
+        pid_error[e] = target_temperature[e] - pid_input;
331 322
         if(pid_error[e] > 10) {
332 323
           pid_output = PID_MAX;
333 324
           pid_reset[e] = true;
@@ -354,20 +345,20 @@ void manage_heater()
354 345
           pid_output = constrain(pTerm[e] + iTerm[e] - dTerm[e], 0, PID_MAX);
355 346
         }
356 347
     #else 
357
-          pid_output = constrain(pid_setpoint[e], 0, PID_MAX);
348
+          pid_output = constrain(target_temperature[e], 0, PID_MAX);
358 349
     #endif //PID_OPENLOOP
359 350
     #ifdef PID_DEBUG
360 351
     SERIAL_ECHOLN(" PIDDEBUG "<<e<<": Input "<<pid_input<<" Output "<<pid_output" pTerm "<<pTerm[e]<<" iTerm "<<iTerm[e]<<" dTerm "<<dTerm[e]);  
361 352
     #endif //PID_DEBUG
362 353
   #else /* PID off */
363 354
     pid_output = 0;
364
-    if(current_raw[e] < target_raw[e]) {
355
+    if(current_temperature[e] < target_temperature[e]) {
365 356
       pid_output = PID_MAX;
366 357
     }
367 358
   #endif
368 359
 
369 360
     // Check if temperature is within the correct range
370
-    if((current_raw[e] > minttemp[e]) && (current_raw[e] < maxttemp[e])) 
361
+    if((current_temperature[e] > minttemp[e]) && (current_temperature[e] < maxttemp[e])) 
371 362
     {
372 363
       soft_pwm[e] = (int)pid_output >> 1;
373 364
     }
@@ -393,19 +384,19 @@ void manage_heater()
393 384
   } // End extruder for loop
394 385
   
395 386
 
396
-		#ifndef PIDTEMPBED
387
+  #ifndef PIDTEMPBED
397 388
   if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL)
398 389
     return;
399 390
   previous_millis_bed_heater = millis();
400
-    #endif
391
+  #endif
401 392
 
402
-  #if TEMP_BED_PIN > -1
393
+  #if TEMP_SENSOR_BED != 0
403 394
   
404
-		#ifdef PIDTEMPBED
405
-    pid_input = analog2tempBed(current_raw_bed);
395
+  #ifdef PIDTEMPBED
396
+    pid_input = current_temperature_bed;
406 397
 
407 398
     #ifndef PID_OPENLOOP
408
-		  pid_error_bed = pid_setpoint_bed - pid_input;
399
+		  pid_error_bed = target_temperature_bed - pid_input;
409 400
 		  pTerm_bed = bedKp * pid_error_bed;
410 401
 		  temp_iState_bed += pid_error_bed;
411 402
 		  temp_iState_bed = constrain(temp_iState_bed, temp_iState_min_bed, temp_iState_max_bed);
@@ -419,10 +410,10 @@ void manage_heater()
419 410
 		  pid_output = constrain(pTerm_bed + iTerm_bed - dTerm_bed, 0, MAX_BED_POWER);
420 411
 
421 412
     #else 
422
-      pid_output = constrain(pid_setpoint_bed, 0, MAX_BED_POWER);
413
+      pid_output = constrain(target_temperature_bed, 0, MAX_BED_POWER);
423 414
     #endif //PID_OPENLOOP
424 415
 
425
-	  if((current_raw_bed > bed_minttemp) && (current_raw_bed < bed_maxttemp)) 
416
+	  if((current_temperature_bed > BED_MINTEMP) && (current_temperature_bed < BED_MAXTEMP)) 
426 417
 	  {
427 418
 	    soft_pwm_bed = (int)pid_output >> 1;
428 419
 	  }
@@ -432,35 +423,38 @@ void manage_heater()
432 423
 
433 424
     #elif not defined BED_LIMIT_SWITCHING
434 425
       // Check if temperature is within the correct range
435
-      if((current_raw_bed > bed_minttemp) && (current_raw_bed < bed_maxttemp)) {
436
-        if(current_raw_bed >= target_raw_bed)
426
+      if((current_temperature_bed > BED_MAXTEMP) && (current_temperature_bed < BED_MINTEMP))
427
+      {
428
+        if(current_temperature_bed >= target_temperature_bed)
437 429
         {
438
-					soft_pwm_bed = 0;
430
+          soft_pwm_bed = 0;
439 431
         }
440 432
         else 
441 433
         {
442
-					soft_pwm_bed = MAX_BED_POWER>>1;
434
+          soft_pwm_bed = MAX_BED_POWER>>1;
443 435
         }
444 436
       }
445
-      else {
446
-					soft_pwm_bed = 0;
437
+      else
438
+      {
439
+        soft_pwm_bed = 0;
447 440
         WRITE(HEATER_BED_PIN,LOW);
448 441
       }
449 442
     #else //#ifdef BED_LIMIT_SWITCHING
450 443
       // Check if temperature is within the correct band
451
-      if((current_raw_bed > bed_minttemp) && (current_raw_bed < bed_maxttemp)) {
452
-        if(current_raw_bed > target_bed_high_temp)
444
+      if((current_temperature_bed > BED_MINTEMP) && (current_temperature_bed < BED_MAXTEMP))
445
+      {
446
+        if(current_temperature_bed > target_temperature_bed + BED_HYSTERESIS)
453 447
         {
454
-					soft_pwm_bed = 0;
448
+          soft_pwm_bed = 0;
455 449
         }
456
-        else 
457
-          if(current_raw_bed <= target_bed_low_temp)
450
+        else if(current_temperature_bed <= target_temperature_bed - BED_HYSTERESIS)
458 451
         {
459
-					soft_pwm_bed = MAX_BED_POWER>>1;
452
+          soft_pwm_bed = MAX_BED_POWER>>1;
460 453
         }
461 454
       }
462
-      else {
463
-					soft_pwm_bed = 0;
455
+      else
456
+      {
457
+        soft_pwm_bed = 0;
464 458
         WRITE(HEATER_BED_PIN,LOW);
465 459
       }
466 460
     #endif
@@ -468,86 +462,9 @@ void manage_heater()
468 462
 }
469 463
 
470 464
 #define PGM_RD_W(x)   (short)pgm_read_word(&x)
471
-// Takes hot end temperature value as input and returns corresponding raw value. 
472
-// For a thermistor, it uses the RepRap thermistor temp table.
473
-// This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.
474
-// This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware.
475
-int temp2analog(int celsius, uint8_t e) {
476
-  if(e >= EXTRUDERS)
477
-  {
478
-      SERIAL_ERROR_START;
479
-      SERIAL_ERROR((int)e);
480
-      SERIAL_ERRORLNPGM(" - Invalid extruder number!");
481
-      kill();
482
-  }
483
-  #ifdef HEATER_0_USES_MAX6675
484
-    if (e == 0)
485
-    {
486
-      return celsius * 4;
487
-    }
488
-  #endif
489
-  if(heater_ttbl_map[e] != 0)
490
-  {
491
-    int raw = 0;
492
-    byte i;
493
-    short (*tt)[][2] = (short (*)[][2])(heater_ttbl_map[e]);
494
-
495
-    for (i=1; i<heater_ttbllen_map[e]; i++)
496
-    {
497
-      if (PGM_RD_W((*tt)[i][1]) < celsius)
498
-      {
499
-        raw = PGM_RD_W((*tt)[i-1][0]) + 
500
-          (celsius - PGM_RD_W((*tt)[i-1][1])) * 
501
-          (PGM_RD_W((*tt)[i][0]) - PGM_RD_W((*tt)[i-1][0])) /
502
-          (PGM_RD_W((*tt)[i][1]) - PGM_RD_W((*tt)[i-1][1]));  
503
-        break;
504
-      }
505
-    }
506
-
507
-    // Overflow: Set to last value in the table
508
-    if (i == heater_ttbllen_map[e]) raw = PGM_RD_W((*tt)[i-1][0]);
509
-
510
-    return (1023 * OVERSAMPLENR) - raw;
511
-  }
512
-  return ((celsius-TEMP_SENSOR_AD595_OFFSET)/TEMP_SENSOR_AD595_GAIN) * (1024.0 / (5.0 * 100.0) ) * OVERSAMPLENR;
513
-}
514
-
515
-// Takes bed temperature value as input and returns corresponding raw value. 
516
-// For a thermistor, it uses the RepRap thermistor temp table.
517
-// This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.
518
-// This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware.
519
-int temp2analogBed(int celsius) {
520
-#ifdef BED_USES_THERMISTOR
521
-    int raw = 0;
522
-    byte i;
523
-    
524
-    for (i=1; i<bedtemptable_len; i++)
525
-    {
526
-      if (PGM_RD_W(bedtemptable[i][1]) < celsius)
527
-      {
528
-        raw = PGM_RD_W(bedtemptable[i-1][0]) + 
529
-          (celsius - PGM_RD_W(bedtemptable[i-1][1])) * 
530
-          (PGM_RD_W(bedtemptable[i][0]) - PGM_RD_W(bedtemptable[i-1][0])) /
531
-          (PGM_RD_W(bedtemptable[i][1]) - PGM_RD_W(bedtemptable[i-1][1]));
532
-      
533
-        break;
534
-      }
535
-    }
536
-
537
-    // Overflow: Set to last value in the table
538
-    if (i == bedtemptable_len) raw = PGM_RD_W(bedtemptable[i-1][0]);
539
-
540
-    return (1023 * OVERSAMPLENR) - raw;
541
-#elif defined BED_USES_AD595
542
-    return lround(((celsius-TEMP_SENSOR_AD595_OFFSET)/TEMP_SENSOR_AD595_GAIN) * (1024.0 * OVERSAMPLENR/ (5.0 * 100.0) ) );
543
-#else
544
-    return 0;
545
-#endif
546
-}
547
-
548 465
 // Derived from RepRap FiveD extruder::getTemperature()
549 466
 // For hot end temperature measurement.
550
-float analog2temp(int raw, uint8_t e) {
467
+static float analog2temp(int raw, uint8_t e) {
551 468
   if(e >= EXTRUDERS)
552 469
   {
553 470
       SERIAL_ERROR_START;
@@ -565,10 +482,9 @@ float analog2temp(int raw, uint8_t e) {
565 482
   if(heater_ttbl_map[e] != NULL)
566 483
   {
567 484
     float celsius = 0;
568
-    byte i;  
485
+    byte i;
569 486
     short (*tt)[][2] = (short (*)[][2])(heater_ttbl_map[e]);
570 487
 
571
-    raw = (1023 * OVERSAMPLENR) - raw;
572 488
     for (i=1; i<heater_ttbllen_map[e]; i++)
573 489
     {
574 490
       if (PGM_RD_W((*tt)[i][0]) > raw)
@@ -591,13 +507,11 @@ float analog2temp(int raw, uint8_t e) {
591 507
 
592 508
 // Derived from RepRap FiveD extruder::getTemperature()
593 509
 // For bed temperature measurement.
594
-float analog2tempBed(int raw) {
510
+static float analog2tempBed(int raw) {
595 511
   #ifdef BED_USES_THERMISTOR
596 512
     float celsius = 0;
597 513
     byte i;
598 514
 
599
-    raw = (1023 * OVERSAMPLENR) - raw;
600
-
601 515
     for (i=1; i<bedtemptable_len; i++)
602 516
     {
603 517
       if (PGM_RD_W(bedtemptable[i][0]) > raw)
@@ -621,6 +535,24 @@ float analog2tempBed(int raw) {
621 535
   #endif
622 536
 }
623 537
 
538
+/* Called to get the raw values into the the actual temperatures. The raw values are created in interrupt context,
539
+    and this function is called from normal context as it is too slow to run in interrupts and will block the stepper routine otherwise */
540
+static void updateTemperaturesFromRawValues()
541
+{
542
+    for(uint8_t e=0;e<EXTRUDERS;e++)
543
+    {
544
+        current_temperature[e] = analog2temp(current_temperature_raw[e], e);
545
+    }
546
+    current_temperature_bed = analog2tempBed(current_temperature_bed_raw);
547
+
548
+    //Reset the watchdog after we know we have a temperature measurement.
549
+    watchdog_reset();
550
+
551
+    CRITICAL_SECTION_START;
552
+    temp_meas_ready = false;
553
+    CRITICAL_SECTION_END;
554
+}
555
+
624 556
 void tp_init()
625 557
 {
626 558
   // Finish init of mult extruder arrays 
@@ -716,31 +648,87 @@ void tp_init()
716 648
   delay(250);
717 649
 
718 650
 #ifdef HEATER_0_MINTEMP
719
-  minttemp[0] = temp2analog(HEATER_0_MINTEMP, 0);
651
+  minttemp[0] = HEATER_0_MINTEMP;
652
+  while(analog2temp(minttemp_raw[0], 0) < HEATER_0_MINTEMP) {
653
+#if HEATER_0_RAW_LO_TEMP < HEATER_0_RAW_HI_TEMP
654
+    minttemp_raw[0] += OVERSAMPLENR;
655
+#else
656
+    minttemp_raw[0] -= OVERSAMPLENR;
657
+#endif
658
+  }
720 659
 #endif //MINTEMP
721 660
 #ifdef HEATER_0_MAXTEMP
722
-  maxttemp[0] = temp2analog(HEATER_0_MAXTEMP, 0);
661
+  maxttemp[0] = HEATER_0_MAXTEMP;
662
+  while(analog2temp(maxttemp_raw[0], 0) > HEATER_0_MAXTEMP) {
663
+#if HEATER_0_RAW_LO_TEMP < HEATER_0_RAW_HI_TEMP
664
+    maxttemp_raw[0] -= OVERSAMPLENR;
665
+#else
666
+    maxttemp_raw[0] += OVERSAMPLENR;
667
+#endif
668
+  }
723 669
 #endif //MAXTEMP
724 670
 
725 671
 #if (EXTRUDERS > 1) && defined(HEATER_1_MINTEMP)
726
-  minttemp[1] = temp2analog(HEATER_1_MINTEMP, 1);
672
+  minttemp[1] = HEATER_1_MINTEMP;
673
+  while(analog2temp(minttemp_raw[1], 1) > HEATER_1_MINTEMP) {
674
+#if HEATER_1_RAW_LO_TEMP < HEATER_1_RAW_HI_TEMP
675
+    minttemp_raw[1] += OVERSAMPLENR;
676
+#else
677
+    minttemp_raw[1] -= OVERSAMPLENR;
678
+#endif
679
+  }
727 680
 #endif // MINTEMP 1
728 681
 #if (EXTRUDERS > 1) && defined(HEATER_1_MAXTEMP)
729
-  maxttemp[1] = temp2analog(HEATER_1_MAXTEMP, 1);
682
+  maxttemp[1] = HEATER_1_MAXTEMP;
683
+  while(analog2temp(maxttemp_raw[1], 1) > HEATER_1_MAXTEMP) {
684
+#if HEATER_1_RAW_LO_TEMP < HEATER_1_RAW_HI_TEMP
685
+    maxttemp_raw[1] -= OVERSAMPLENR;
686
+#else
687
+    maxttemp_raw[1] += OVERSAMPLENR;
688
+#endif
689
+  }
730 690
 #endif //MAXTEMP 1
731 691
 
732 692
 #if (EXTRUDERS > 2) && defined(HEATER_2_MINTEMP)
733
-  minttemp[2] = temp2analog(HEATER_2_MINTEMP, 2);
693
+  minttemp[2] = HEATER_2_MINTEMP;
694
+  while(analog2temp(minttemp_raw[2], 2) > HEATER_2_MINTEMP) {
695
+#if HEATER_2_RAW_LO_TEMP < HEATER_2_RAW_HI_TEMP
696
+    minttemp_raw[2] += OVERSAMPLENR;
697
+#else
698
+    minttemp_raw[2] -= OVERSAMPLENR;
699
+#endif
700
+  }
734 701
 #endif //MINTEMP 2
735 702
 #if (EXTRUDERS > 2) && defined(HEATER_2_MAXTEMP)
736
-  maxttemp[2] = temp2analog(HEATER_2_MAXTEMP, 2);
703
+  maxttemp[2] = HEATER_2_MAXTEMP;
704
+  while(analog2temp(maxttemp_raw[2], 2) > HEATER_2_MAXTEMP) {
705
+#if HEATER_2_RAW_LO_TEMP < HEATER_2_RAW_HI_TEMP
706
+    maxttemp_raw[2] -= OVERSAMPLENR;
707
+#else
708
+    maxttemp_raw[2] += OVERSAMPLENR;
709
+#endif
710
+  }
737 711
 #endif //MAXTEMP 2
738 712
 
739 713
 #ifdef BED_MINTEMP
740
-  bed_minttemp = temp2analogBed(BED_MINTEMP);
714
+  /* No bed MINTEMP error implemented?!? */ /*
715
+  while(analog2tempBed(bed_minttemp_raw) < BED_MINTEMP) {
716
+#if HEATER_BED_RAW_LO_TEMP < HEATER_BED_RAW_HI_TEMP
717
+    bed_minttemp_raw += OVERSAMPLENR;
718
+#else
719
+    bed_minttemp_raw -= OVERSAMPLENR;
720
+#endif
721
+  }
722
+  */
741 723
 #endif //BED_MINTEMP
742 724
 #ifdef BED_MAXTEMP
743
-  bed_maxttemp = temp2analogBed(BED_MAXTEMP);
725
+  while(analog2tempBed(bed_maxttemp_raw) > BED_MAXTEMP) {
726
+#if HEATER_BED_RAW_LO_TEMP < HEATER_BED_RAW_HI_TEMP
727
+    bed_maxttemp_raw -= OVERSAMPLENR;
728
+#else
729
+    bed_maxttemp_raw += OVERSAMPLENR;
730
+#endif
731
+  }
744 732
 #endif //BED_MAXTEMP
745 733
 }
746 734
 
@@ -765,7 +753,7 @@ void disable_heater()
765 753
     setTargetHotend(0,i);
766 754
   setTargetBed(0);
767 755
   #if TEMP_0_PIN > -1
768
-  target_raw[0]=0;
756
+  target_temperature[0]=0;
769 757
   soft_pwm[0]=0;
770 758
    #if HEATER_0_PIN > -1  
771 759
      WRITE(HEATER_0_PIN,LOW);
@@ -773,7 +761,7 @@ void disable_heater()
773 761
   #endif
774 762
      
775 763
   #if TEMP_1_PIN > -1
776
-    target_raw[1]=0;
764
+    target_temperature[1]=0;
777 765
     soft_pwm[1]=0;
778 766
     #if HEATER_1_PIN > -1 
779 767
       WRITE(HEATER_1_PIN,LOW);
@@ -781,7 +769,7 @@ void disable_heater()
781 769
   #endif
782 770
       
783 771
   #if TEMP_2_PIN > -1
784
-    target_raw[2]=0;
772
+    target_temperature[2]=0;
785 773
     soft_pwm[2]=0;
786 774
     #if HEATER_2_PIN > -1  
787 775
       WRITE(HEATER_2_PIN,LOW);
@@ -789,7 +777,7 @@ void disable_heater()
789 777
   #endif 
790 778
 
791 779
   #if TEMP_BED_PIN > -1
792
-    target_raw_bed=0;
780
+    target_temperature_bed=0;
793 781
     soft_pwm_bed=0;
794 782
     #if HEATER_BED_PIN > -1  
795 783
       WRITE(HEATER_BED_PIN,LOW);
@@ -1031,33 +1019,16 @@ ISR(TIMER0_COMPB_vect)
1031 1019
     
1032 1020
   if(temp_count >= 16) // 8 ms * 16 = 128ms.
1033 1021
   {
1034
-    #if defined(HEATER_0_USES_AD595) || defined(HEATER_0_USES_MAX6675)
1035
-      current_raw[0] = raw_temp_0_value;
1036
-    #else
1037
-      current_raw[0] = 16383 - raw_temp_0_value;
1038
-    #endif
1039
-
1040
-#if EXTRUDERS > 1    
1041
-    #ifdef HEATER_1_USES_AD595
1042
-      current_raw[1] = raw_temp_1_value;
1043
-    #else
1044
-      current_raw[1] = 16383 - raw_temp_1_value;
1045
-    #endif
1022
+    if (!temp_meas_ready) //Only update the raw values if they have been read. Else we could be updating them during reading.
1023
+    {
1024
+      current_temperature_raw[0] = raw_temp_0_value;
1025
+#if EXTRUDERS > 1
1026
+      current_temperature_raw[1] = raw_temp_0_value;
1046 1027
 #endif
1047
-    
1048 1028
 #if EXTRUDERS > 2
1049
-    #ifdef HEATER_2_USES_AD595
1050
-      current_raw[2] = raw_temp_2_value;
1051
-    #else
1052
-      current_raw[2] = 16383 - raw_temp_2_value;
1053
-    #endif
1029
+      current_temperature_raw[2] = raw_temp_0_value;
1054 1030
 #endif
1055
-    
1056
-    #ifdef BED_USES_AD595
1057
-      current_raw_bed = raw_temp_bed_value;
1058
-    #else
1059
-      current_raw_bed = 16383 - raw_temp_bed_value;
1060
-    #endif
1031
+    }
1061 1032
     
1062 1033
     temp_meas_ready = true;
1063 1034
     temp_count = 0;
@@ -1066,23 +1037,63 @@ ISR(TIMER0_COMPB_vect)
1066 1037
     raw_temp_2_value = 0;
1067 1038
     raw_temp_bed_value = 0;
1068 1039
 
1069
-    for(unsigned char e = 0; e < EXTRUDERS; e++) {
1070
-       if(current_raw[e] >= maxttemp[e]) {
1071
-          target_raw[e] = 0;
1072
-          max_temp_error(e);
1073
-       }
1074
-       if(current_raw[e] <= minttemp[e]) {
1075
-          target_raw[e] = 0;
1076
-          min_temp_error(e);
1077
-       }
1040
+#if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP
1041
+    if(current_temperature_raw[0] <= maxttemp_raw[0]) {
1042
+#else
1043
+    if(current_temperature_raw[0] >= maxttemp_raw[0]) {
1044
+#endif
1045
+        max_temp_error(0);
1046
+    }
1047
+#if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP
1048
+    if(current_temperature_raw[0] >= minttemp_raw[0]) {
1049
+#else
1050
+    if(current_temperature_raw[0] <= minttemp_raw[0]) {
1051
+#endif
1052
+        min_temp_error(0);
1053
+    }
1054
+#if EXTRUDERS > 1
1055
+#if HEATER_1_RAW_LO_TEMP > HEATER_1_RAW_HI_TEMP
1056
+    if(current_temperature_raw[1] <= maxttemp_raw[1]) {
1057
+#else
1058
+    if(current_temperature_raw[1] >= maxttemp_raw[1]) {
1059
+#endif
1060
+        max_temp_error(1);
1078 1061
     }
1062
+#if HEATER_1_RAW_LO_TEMP > HEATER_1_RAW_HI_TEMP
1063
+    if(current_temperature_raw[1] >= minttemp_raw[1]) {
1064
+#else
1065
+    if(current_temperature_raw[1] <= minttemp_raw[1]) {
1066
+#endif
1067
+        min_temp_error(1);
1068
+    }
1069
+#endif
1070
+#if EXTRUDERS > 2
1071
+#if HEATER_2_RAW_LO_TEMP > HEATER_2_RAW_HI_TEMP
1072
+    if(current_temperature_raw[2] <= maxttemp_raw[2]) {
1073
+#else
1074
+    if(current_temperature_raw[2] >= maxttemp_raw[2]) {
1075
+#endif
1076
+        max_temp_error(2);
1077
+    }
1078
+#if HEATER_2_RAW_LO_TEMP > HEATER_2_RAW_HI_TEMP
1079
+    if(current_temperature_raw[2] >= minttemp_raw[2]) {
1080
+#else
1081
+    if(current_temperature_raw[2] <= minttemp_raw[2]) {
1082
+#endif
1083
+        min_temp_error(2);
1084
+    }
1085
+#endif
1079 1086
   
1080
-#if defined(BED_MAXTEMP) && (HEATER_BED_PIN > -1)
1081
-    if(current_raw_bed >= bed_maxttemp) {
1082
-       target_raw_bed = 0;
1087
+  /* No bed MINTEMP error? */
1088
+#if defined(BED_MAXTEMP) && (TEMP_SENSOR_BED != 0)
1089
+# if HEATER_BED_RAW_LO_TEMP > HEATER_BED_RAW_HI_TEMP
1090
+    if(current_temperature_bed <= bed_maxttemp_raw) {
1091
+#else
1092
+    if(current_temperature_bed >= bed_maxttemp_raw) {
1093
+#endif
1094
+       target_temperature_bed = 0;
1083 1095
        bed_max_temp_error();
1084 1096
     }
1085 1097
 #endif
1086
-  }
1098
+  }  
1087 1099
 }
1088
-

+ 14
- 43
Marlin/temperature.h Vedi File

@@ -33,27 +33,16 @@ void manage_heater(); //it is critical that this is called periodically.
33 33
 
34 34
 //low leven conversion routines
35 35
 // do not use this routines and variables outsie of temperature.cpp
36
-int temp2analog(int celsius, uint8_t e);
37
-int temp2analogBed(int celsius);
38
-float analog2temp(int raw, uint8_t e);
39
-float analog2tempBed(int raw);
40
-extern int target_raw[EXTRUDERS];  
41
-extern int heatingtarget_raw[EXTRUDERS];  
42
-extern int current_raw[EXTRUDERS];
43
-extern int target_raw_bed;
44
-extern int current_raw_bed;
45
-#ifdef BED_LIMIT_SWITCHING
46
-  extern int target_bed_low_temp ;  
47
-  extern int target_bed_high_temp ;
48
-#endif
36
+extern int target_temperature[EXTRUDERS];  
37
+extern float current_temperature[EXTRUDERS];
38
+extern int target_temperature_bed;
39
+extern float current_temperature_bed;
49 40
 
50 41
 #ifdef PIDTEMP
51 42
   extern float Kp,Ki,Kd,Kc;
52
-  extern float pid_setpoint[EXTRUDERS];
53 43
 #endif
54 44
 #ifdef PIDTEMPBED
55 45
   extern float bedKp,bedKi,bedKd;
56
-  extern float pid_setpoint_bed;
57 46
 #endif
58 47
   
59 48
 //high level conversion routines, for use outside of temperature.cpp
@@ -61,61 +50,43 @@ extern int current_raw_bed;
61 50
 //deg=degreeCelsius
62 51
 
63 52
 FORCE_INLINE float degHotend(uint8_t extruder) {  
64
-  return analog2temp(current_raw[extruder], extruder);
53
+  return current_temperature[extruder];
65 54
 };
66 55
 
67 56
 FORCE_INLINE float degBed() {
68
-  return analog2tempBed(current_raw_bed);
57
+  return current_temperature_bed;
69 58
 };
70 59
 
71 60
 FORCE_INLINE float degTargetHotend(uint8_t extruder) {  
72
-  return analog2temp(target_raw[extruder], extruder);
61
+  return target_temperature[extruder];
73 62
 };
74 63
 
75 64
 FORCE_INLINE float degTargetBed() {   
76
-  return analog2tempBed(target_raw_bed);
65
+  return target_temperature_bed;
77 66
 };
78 67
 
79 68
 FORCE_INLINE void setTargetHotend(const float &celsius, uint8_t extruder) {  
80
-  target_raw[extruder] = temp2analog(celsius, extruder);
81
-#ifdef PIDTEMP
82
-  pid_setpoint[extruder] = celsius;
83
-#endif //PIDTEMP
69
+  target_temperature[extruder] = celsius;
84 70
 };
85 71
 
86 72
 FORCE_INLINE void setTargetBed(const float &celsius) {  
87
-  
88
-  target_raw_bed = temp2analogBed(celsius);
89
-	#ifdef PIDTEMPBED
90
-  pid_setpoint_bed = celsius;
91
-  #elif defined BED_LIMIT_SWITCHING
92
-    if(celsius>BED_HYSTERESIS)
93
-    {
94
-    target_bed_low_temp= temp2analogBed(celsius-BED_HYSTERESIS);
95
-    target_bed_high_temp= temp2analogBed(celsius+BED_HYSTERESIS);
96
-    }
97
-    else
98
-    { 
99
-      target_bed_low_temp=0;
100
-      target_bed_high_temp=0;
101
-    }
102
-  #endif
73
+  target_temperature_bed = celsius;
103 74
 };
104 75
 
105 76
 FORCE_INLINE bool isHeatingHotend(uint8_t extruder){  
106
-  return target_raw[extruder] > current_raw[extruder];
77
+  return target_temperature[extruder] > current_temperature[extruder];
107 78
 };
108 79
 
109 80
 FORCE_INLINE bool isHeatingBed() {
110
-  return target_raw_bed > current_raw_bed;
81
+  return target_temperature_bed > current_temperature_bed;
111 82
 };
112 83
 
113 84
 FORCE_INLINE bool isCoolingHotend(uint8_t extruder) {  
114
-  return target_raw[extruder] < current_raw[extruder];
85
+  return target_temperature[extruder] < current_temperature[extruder];
115 86
 };
116 87
 
117 88
 FORCE_INLINE bool isCoolingBed() {
118
-  return target_raw_bed < current_raw_bed;
89
+  return target_temperature_bed < current_temperature_bed;
119 90
 };
120 91
 
121 92
 #define degHotend0() degHotend(0)

+ 73
- 30
Marlin/thermistortables.h Vedi File

@@ -461,49 +461,92 @@ const short temptable_55[][2] PROGMEM = {
461 461
 #define TT_NAME(_N) _TT_NAME(_N)
462 462
 
463 463
 #ifdef THERMISTORHEATER_0
464
-  #define heater_0_temptable TT_NAME(THERMISTORHEATER_0)
465
-  #define heater_0_temptable_len (sizeof(heater_0_temptable)/sizeof(*heater_0_temptable))
464
+# define HEATER_0_TEMPTABLE TT_NAME(THERMISTORHEATER_0)
465
+# define HEATER_0_TEMPTABLE_LEN (sizeof(HEATER_0_TEMPTABLE)/sizeof(*HEATER_0_TEMPTABLE))
466 466
 #else
467
-#ifdef HEATER_0_USES_THERMISTOR
468
-  #error No heater 0 thermistor table specified
469
-#else  // HEATER_0_USES_THERMISTOR
470
-  #define heater_0_temptable 0
471
-  #define heater_0_temptable_len 0
472
-#endif // HEATER_0_USES_THERMISTOR
467
+# ifdef HEATER_0_USES_THERMISTOR
468
+#  error No heater 0 thermistor table specified
469
+# else  // HEATER_0_USES_THERMISTOR
470
+#  define HEATER_0_TEMPTABLE NULL
471
+#  define HEATER_0_TEMPTABLE_LEN 0
472
+# endif // HEATER_0_USES_THERMISTOR
473
+#endif
474
+
475
+//Set the high and low raw values for the heater, this indicates which raw value is a high or low temperature
476
+#ifndef HEATER_0_RAW_HI_TEMP
477
+# if HEATER_0_USES_THERMISTOR   //In case of a thermistor the highest temperature results in the lowest ADC value
478
+#  define HEATER_0_RAW_HI_TEMP 0
479
+#  define HEATER_0_RAW_LO_TEMP 16383
480
+# else                          //In case of an thermocouple the highest temperature results in the highest ADC value
481
+#  define HEATER_0_RAW_HI_TEMP 16383
482
+#  define HEATER_0_RAW_LO_TEMP 0
483
+# endif
473 484
 #endif
474 485
 
475 486
 #ifdef THERMISTORHEATER_1
476
-  #define heater_1_temptable TT_NAME(THERMISTORHEATER_1)
477
-  #define heater_1_temptable_len (sizeof(heater_1_temptable)/sizeof(*heater_1_temptable))
487
+# define HEATER_1_TEMPTABLE TT_NAME(THERMISTORHEATER_1)
488
+# define HEATER_1_TEMPTABLE_LEN (sizeof(HEATER_1_TEMPTABLE)/sizeof(*HEATER_1_TEMPTABLE))
478 489
 #else
479
-#ifdef HEATER_1_USES_THERMISTOR
480
-  #error No heater 1 thermistor table specified
481
-#else  // HEATER_1_USES_THERMISTOR
482
-  #define heater_1_temptable 0
483
-  #define heater_1_temptable_len 0
484
-#endif // HEATER_1_USES_THERMISTOR
490
+# ifdef HEATER_1_USES_THERMISTOR
491
+#  error No heater 1 thermistor table specified
492
+# else  // HEATER_1_USES_THERMISTOR
493
+#  define HEATER_1_TEMPTABLE NULL
494
+#  define HEATER_1_TEMPTABLE_LEN 0
495
+# endif // HEATER_1_USES_THERMISTOR
496
+#endif
497
+
498
+//Set the high and low raw values for the heater, this indicates which raw value is a high or low temperature
499
+#ifndef HEATER_1_RAW_HI_TEMP
500
+# if HEATER_1_USES_THERMISTOR   //In case of a thermistor the highest temperature results in the lowest ADC value
501
+#  define HEATER_1_RAW_HI_TEMP 0
502
+#  define HEATER_1_RAW_LO_TEMP 16383
503
+# else                          //In case of an thermocouple the highest temperature results in the highest ADC value
504
+#  define HEATER_1_RAW_HI_TEMP 16383
505
+#  define HEATER_1_RAW_LO_TEMP 0
506
+# endif
485 507
 #endif
486 508
 
487 509
 #ifdef THERMISTORHEATER_2
488
-  #define heater_2_temptable TT_NAME(THERMISTORHEATER_2)
489
-  #define heater_2_temptable_len (sizeof(heater_2_temptable)/sizeof(*heater_2_temptable))
510
+# define HEATER_2_TEMPTABLE TT_NAME(THERMISTORHEATER_2)
511
+# define HEATER_2_TEMPTABLE_LEN (sizeof(HEATER_2_TEMPTABLE)/sizeof(*HEATER_2_TEMPTABLE))
490 512
 #else
491
-#ifdef HEATER_2_USES_THERMISTOR
492
-  #error No heater 2 thermistor table specified
493
-#else  // HEATER_2_USES_THERMISTOR
494
-  #define heater_2_temptable 0
495
-  #define heater_2_temptable_len 0
496
-#endif // HEATER_2_USES_THERMISTOR
513
+# ifdef HEATER_2_USES_THERMISTOR
514
+#  error No heater 2 thermistor table specified
515
+# else  // HEATER_2_USES_THERMISTOR
516
+#  define HEATER_2_TEMPTABLE NULL
517
+#  define HEATER_2_TEMPTABLE_LEN 0
518
+# endif // HEATER_2_USES_THERMISTOR
519
+#endif
520
+
521
+//Set the high and low raw values for the heater, this indicates which raw value is a high or low temperature
522
+#ifndef HEATER_2_RAW_HI_TEMP
523
+# if HEATER_2_USES_THERMISTOR   //In case of a thermistor the highest temperature results in the lowest ADC value
524
+#  define HEATER_2_RAW_HI_TEMP 0
525
+#  define HEATER_2_RAW_LO_TEMP 16383
526
+# else                          //In case of an thermocouple the highest temperature results in the highest ADC value
527
+#  define HEATER_2_RAW_HI_TEMP 16383
528
+#  define HEATER_2_RAW_LO_TEMP 0
529
+# endif
497 530
 #endif
498 531
 
499 532
 #ifdef THERMISTORBED
500
-  #define bedtemptable TT_NAME(THERMISTORBED)
501
-  #define bedtemptable_len (sizeof(bedtemptable)/sizeof(*bedtemptable))
533
+# define BEDTEMPTABLE TT_NAME(THERMISTORBED)
534
+# define BEDTEMPTABLE_LEN (sizeof(BEDTEMPTABLE)/sizeof(*BEDTEMPTABLE))
502 535
 #else
503
-#ifdef BED_USES_THERMISTOR
504
-  #error No bed thermistor table specified
505
-#endif // BED_USES_THERMISTOR
536
+# ifdef BED_USES_THERMISTOR
537
+#  error No bed thermistor table specified
538
+# endif // BED_USES_THERMISTOR
506 539
 #endif
507 540
 
508
-#endif //THERMISTORTABLES_H_
541
+//Set the high and low raw values for the heater, this indicates which raw value is a high or low temperature
542
+#ifndef HEATER_BED_RAW_HI_TEMP
543
+# if BED_USES_THERMISTOR   //In case of a thermistor the highest temperature results in the lowest ADC value
544
+#  define HEATER_BED_RAW_HI_TEMP 0
545
+#  define HEATER_BED_RAW_LO_TEMP 16383
546
+# else                          //In case of an thermocouple the highest temperature results in the highest ADC value
547
+#  define HEATER_BED_RAW_HI_TEMP 16383
548
+#  define HEATER_BED_RAW_LO_TEMP 0
549
+# endif
550
+#endif
509 551
 
552
+#endif //THERMISTORTABLES_H_

Loading…
Annulla
Salva