Przeglądaj źródła

Queued fan control. Issue #90

Erik van der Zalm 13 lat temu
rodzic
commit
aac7aa3bf0
6 zmienionych plików z 29 dodań i 22 usunięć
  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 Wyświetl plik

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

+ 4
- 10
Marlin/Marlin.pde Wyświetl plik

131
 float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0 };
131
 float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0 };
132
 float add_homeing[3]={0,0,0};
132
 float add_homeing[3]={0,0,0};
133
 uint8_t active_extruder = 0;
133
 uint8_t active_extruder = 0;
134
+unsigned char FanSpeed=0;
134
 
135
 
135
 //===========================================================================
136
 //===========================================================================
136
 //=============================private variables=============================
137
 //=============================private variables=============================
145
 static bool relative_mode = false;  //Determines Absolute or Relative Coordinates
146
 static bool relative_mode = false;  //Determines Absolute or Relative Coordinates
146
 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
 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
 static char cmdbuffer[BUFSIZE][MAX_CMD_SIZE];
149
 static char cmdbuffer[BUFSIZE][MAX_CMD_SIZE];
151
 static bool fromsd[BUFSIZE];
150
 static bool fromsd[BUFSIZE];
152
 static int bufindr = 0;
151
 static int bufindr = 0;
938
     #if FAN_PIN > -1
937
     #if FAN_PIN > -1
939
       case 106: //M106 Fan On
938
       case 106: //M106 Fan On
940
         if (code_seen('S')){
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
         else {
942
         else {
946
-          WRITE(FAN_PIN,HIGH);
947
-          fanpwm=255;
948
-          analogWrite(FAN_PIN, fanpwm);			
943
+          FanSpeed=255;			
949
         }
944
         }
950
         break;
945
         break;
951
       case 107: //M107 Fan Off
946
       case 107: //M107 Fan Off
952
-        WRITE(FAN_PIN,LOW);
953
-        analogWrite(FAN_PIN, 0);
947
+        FanSpeed = 0;
954
         break;
948
         break;
955
     #endif //FAN_PIN
949
     #endif //FAN_PIN
956
 
950
 

+ 13
- 0
Marlin/planner.cpp Wyświetl plik

418
   unsigned char y_active = 0;  
418
   unsigned char y_active = 0;  
419
   unsigned char z_active = 0;
419
   unsigned char z_active = 0;
420
   unsigned char e_active = 0;
420
   unsigned char e_active = 0;
421
+  unsigned char fan_speed = 0;
422
+  unsigned char tail_fan_speed = 0;
421
   block_t *block;
423
   block_t *block;
422
 
424
 
423
   if(block_buffer_tail != block_buffer_head) {
425
   if(block_buffer_tail != block_buffer_head) {
424
     uint8_t block_index = block_buffer_tail;
426
     uint8_t block_index = block_buffer_tail;
427
+    tail_fan_speed = block_buffer[block_index].fan_speed;
425
     while(block_index != block_buffer_head) {
428
     while(block_index != block_buffer_head) {
426
       block = &block_buffer[block_index];
429
       block = &block_buffer[block_index];
427
       if(block->steps_x != 0) x_active++;
430
       if(block->steps_x != 0) x_active++;
428
       if(block->steps_y != 0) y_active++;
431
       if(block->steps_y != 0) y_active++;
429
       if(block->steps_z != 0) z_active++;
432
       if(block->steps_z != 0) z_active++;
430
       if(block->steps_e != 0) e_active++;
433
       if(block->steps_e != 0) e_active++;
434
+      if(block->fan_speed != 0) fan_speed++;
431
       block_index = (block_index+1) & (BLOCK_BUFFER_SIZE - 1);
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
   if((DISABLE_X) && (x_active == 0)) disable_x();
441
   if((DISABLE_X) && (x_active == 0)) disable_x();
435
   if((DISABLE_Y) && (y_active == 0)) disable_y();
442
   if((DISABLE_Y) && (y_active == 0)) disable_y();
436
   if((DISABLE_Z) && (z_active == 0)) disable_z();
443
   if((DISABLE_Z) && (z_active == 0)) disable_z();
437
   if((DISABLE_E) && (e_active == 0)) { disable_e0();disable_e1();disable_e2(); }
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
   // Bail if this is a zero-length block
509
   // Bail if this is a zero-length block
499
   if (block->step_event_count <=dropsegments) { return; };
510
   if (block->step_event_count <=dropsegments) { return; };
500
 
511
 
512
+  block->fan_speed = FanSpeed;
513
+  
501
   // Compute direction bits for this block 
514
   // Compute direction bits for this block 
502
   block->direction_bits = 0;
515
   block->direction_bits = 0;
503
   if (target[X_AXIS] < position[X_AXIS]) { block->direction_bits |= (1<<X_AXIS); }
516
   if (target[X_AXIS] < position[X_AXIS]) { block->direction_bits |= (1<<X_AXIS); }

+ 1
- 0
Marlin/planner.h Wyświetl plik

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

+ 2
- 4
Marlin/stepper.cpp Wyświetl plik

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

+ 8
- 8
Marlin/ultralcd.pde Wyświetl plik

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

Ładowanie…
Anuluj
Zapisz