Quellcode durchsuchen

Queued fan control. Issue #90

Erik van der Zalm vor 13 Jahren
Ursprung
Commit
aac7aa3bf0
6 geänderte Dateien mit 29 neuen und 22 gelöschten Zeilen
  1. 1
    0
      Marlin/Marlin.h
  2. 4
    10
      Marlin/Marlin.pde
  3. 13
    0
      Marlin/planner.cpp
  4. 1
    0
      Marlin/planner.h
  5. 2
    4
      Marlin/stepper.cpp
  6. 8
    8
      Marlin/ultralcd.pde

+ 1
- 0
Marlin/Marlin.h Datei anzeigen

@@ -175,6 +175,7 @@ extern float homing_feedrate[];
175 175
 extern bool axis_relative_modes[];
176 176
 extern float current_position[NUM_AXIS] ;
177 177
 extern float add_homeing[3];
178
+extern unsigned char FanSpeed;
178 179
 
179 180
 // Handling multiple extruders pins
180 181
 extern uint8_t active_extruder;

+ 4
- 10
Marlin/Marlin.pde Datei anzeigen

@@ -131,6 +131,7 @@ volatile int extrudemultiply=100; //100->1 200->2
131 131
 float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0 };
132 132
 float add_homeing[3]={0,0,0};
133 133
 uint8_t active_extruder = 0;
134
+unsigned char FanSpeed=0;
134 135
 
135 136
 //===========================================================================
136 137
 //=============================private variables=============================
@@ -145,8 +146,6 @@ static long gcode_N, gcode_LastN;
145 146
 static bool relative_mode = false;  //Determines Absolute or Relative Coordinates
146 147
 static bool relative_mode_e = false;  //Determines Absolute or Relative E Codes while in Absolute Coordinates mode. E is always relative in Relative Coordinates mode.
147 148
 
148
-static uint8_t fanpwm=0;
149
-
150 149
 static char cmdbuffer[BUFSIZE][MAX_CMD_SIZE];
151 150
 static bool fromsd[BUFSIZE];
152 151
 static int bufindr = 0;
@@ -938,19 +937,14 @@ void process_commands()
938 937
     #if FAN_PIN > -1
939 938
       case 106: //M106 Fan On
940 939
         if (code_seen('S')){
941
-            WRITE(FAN_PIN,HIGH);
942
-            fanpwm=constrain(code_value(),0,255);
943
-            analogWrite(FAN_PIN,  fanpwm);
940
+           FanSpeed=constrain(code_value(),0,255);
944 941
         }
945 942
         else {
946
-          WRITE(FAN_PIN,HIGH);
947
-          fanpwm=255;
948
-          analogWrite(FAN_PIN, fanpwm);			
943
+          FanSpeed=255;			
949 944
         }
950 945
         break;
951 946
       case 107: //M107 Fan Off
952
-        WRITE(FAN_PIN,LOW);
953
-        analogWrite(FAN_PIN, 0);
947
+        FanSpeed = 0;
954 948
         break;
955 949
     #endif //FAN_PIN
956 950
 

+ 13
- 0
Marlin/planner.cpp Datei anzeigen

@@ -418,23 +418,34 @@ void check_axes_activity() {
418 418
   unsigned char y_active = 0;  
419 419
   unsigned char z_active = 0;
420 420
   unsigned char e_active = 0;
421
+  unsigned char fan_speed = 0;
422
+  unsigned char tail_fan_speed = 0;
421 423
   block_t *block;
422 424
 
423 425
   if(block_buffer_tail != block_buffer_head) {
424 426
     uint8_t block_index = block_buffer_tail;
427
+    tail_fan_speed = block_buffer[block_index].fan_speed;
425 428
     while(block_index != block_buffer_head) {
426 429
       block = &block_buffer[block_index];
427 430
       if(block->steps_x != 0) x_active++;
428 431
       if(block->steps_y != 0) y_active++;
429 432
       if(block->steps_z != 0) z_active++;
430 433
       if(block->steps_e != 0) e_active++;
434
+      if(block->fan_speed != 0) fan_speed++;
431 435
       block_index = (block_index+1) & (BLOCK_BUFFER_SIZE - 1);
432 436
     }
433 437
   }
438
+  else {
439
+    if (FanSpeed != 0) analogWrite(FAN_PIN,FanSpeed); // If buffer is empty use current fan speed
440
+  }
434 441
   if((DISABLE_X) && (x_active == 0)) disable_x();
435 442
   if((DISABLE_Y) && (y_active == 0)) disable_y();
436 443
   if((DISABLE_Z) && (z_active == 0)) disable_z();
437 444
   if((DISABLE_E) && (e_active == 0)) { disable_e0();disable_e1();disable_e2(); }
445
+  if((FanSpeed == 0) && (fan_speed ==0)) analogWrite(FAN_PIN, 0);
446
+  if (FanSpeed != 0 && tail_fan_speed !=0) { 
447
+    analogWrite(FAN_PIN,tail_fan_speed);
448
+  }
438 449
 }
439 450
 
440 451
 
@@ -498,6 +509,8 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
498 509
   // Bail if this is a zero-length block
499 510
   if (block->step_event_count <=dropsegments) { return; };
500 511
 
512
+  block->fan_speed = FanSpeed;
513
+  
501 514
   // Compute direction bits for this block 
502 515
   block->direction_bits = 0;
503 516
   if (target[X_AXIS] < position[X_AXIS]) { block->direction_bits |= (1<<X_AXIS); }

+ 1
- 0
Marlin/planner.h Datei anzeigen

@@ -59,6 +59,7 @@ typedef struct {
59 59
   unsigned long initial_rate;                        // The jerk-adjusted step rate at start of block  
60 60
   unsigned long final_rate;                          // The minimal rate at exit
61 61
   unsigned long acceleration_st;                     // acceleration steps/sec^2
62
+  unsigned long fan_speed;
62 63
   volatile char busy;
63 64
 } block_t;
64 65
 

+ 2
- 4
Marlin/stepper.cpp Datei anzeigen

@@ -21,9 +21,6 @@
21 21
 /* The timer calculations of this module informed by the 'RepRap cartesian firmware' by Zack Smith
22 22
    and Philipp Tiefenbacher. */
23 23
 
24
-
25
-
26
-
27 24
 #include "Marlin.h"
28 25
 #include "stepper.h"
29 26
 #include "planner.h"
@@ -303,7 +300,8 @@ ISR(TIMER1_COMPA_vect)
303 300
       counter_y = counter_x;
304 301
       counter_z = counter_x;
305 302
       counter_e = counter_x;
306
-      step_events_completed = 0;
303
+      step_events_completed = 0; 
304
+      
307 305
       #ifdef Z_LATE_ENABLE 
308 306
         if(current_block->steps_z > 0) {
309 307
           enable_z();

+ 8
- 8
Marlin/ultralcd.pde Datei anzeigen

@@ -812,7 +812,7 @@ void MainMenu::showTune()
812 812
         if(force_lcd_update)
813 813
         {
814 814
           lcd.setCursor(0,line);lcdprintPGM(MSG_FAN_SPEED);
815
-          lcd.setCursor(13,line);lcd.print(ftostr3(fanpwm));
815
+          lcd.setCursor(13,line);lcd.print(ftostr3(FanSpeed));
816 816
         }
817 817
         
818 818
         if((activeline!=line) )
@@ -823,7 +823,7 @@ void MainMenu::showTune()
823 823
           linechanging=!linechanging;
824 824
           if(linechanging)
825 825
           {
826
-              encoderpos=fanpwm;
826
+              encoderpos=FanSpeed;
827 827
           }
828 828
           else
829 829
           {
@@ -836,8 +836,8 @@ void MainMenu::showTune()
836 836
         {
837 837
           if(encoderpos<0) encoderpos=0;
838 838
           if(encoderpos>255) encoderpos=255;
839
-          fanpwm=encoderpos;
840
-            analogWrite(FAN_PIN,  fanpwm);
839
+          FanSpeed=encoderpos;
840
+            analogWrite(FAN_PIN,  FanSpeed);
841 841
           lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
842 842
         }
843 843
         
@@ -1134,7 +1134,7 @@ void MainMenu::showControlTemp()
1134 1134
         if(force_lcd_update)
1135 1135
         {
1136 1136
           lcd.setCursor(0,line);lcdprintPGM(MSG_FAN_SPEED);
1137
-          lcd.setCursor(13,line);lcd.print(ftostr3(fanpwm));
1137
+          lcd.setCursor(13,line);lcd.print(ftostr3(FanSpeed));
1138 1138
         }
1139 1139
         
1140 1140
         if((activeline!=line) )
@@ -1145,7 +1145,7 @@ void MainMenu::showControlTemp()
1145 1145
           linechanging=!linechanging;
1146 1146
           if(linechanging)
1147 1147
           {
1148
-              encoderpos=fanpwm;
1148
+              encoderpos=FanSpeed;
1149 1149
           }
1150 1150
           else
1151 1151
           {
@@ -1158,8 +1158,8 @@ void MainMenu::showControlTemp()
1158 1158
         {
1159 1159
           if(encoderpos<0) encoderpos=0;
1160 1160
           if(encoderpos>255) encoderpos=255;
1161
-          fanpwm=encoderpos;
1162
-            analogWrite(FAN_PIN,  fanpwm);
1161
+          FanSpeed=encoderpos;
1162
+            analogWrite(FAN_PIN,  FanSpeed);
1163 1163
           lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
1164 1164
         }
1165 1165
         

Laden…
Abbrechen
Speichern