Browse Source

Queued fan control. Issue #90

pull/1/head
Erik van der Zalm 13 years ago
parent
commit
aac7aa3bf0
  1. 1
      Marlin/Marlin.h
  2. 14
      Marlin/Marlin.pde
  3. 13
      Marlin/planner.cpp
  4. 1
      Marlin/planner.h
  5. 4
      Marlin/stepper.cpp
  6. 16
      Marlin/ultralcd.pde

1
Marlin/Marlin.h

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

14
Marlin/Marlin.pde

@ -131,6 +131,7 @@ volatile int extrudemultiply=100; //100->1 200->2
float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0 }; float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0 };
float add_homeing[3]={0,0,0}; float add_homeing[3]={0,0,0};
uint8_t active_extruder = 0; uint8_t active_extruder = 0;
unsigned char FanSpeed=0;
//=========================================================================== //===========================================================================
//=============================private variables============================= //=============================private variables=============================
@ -145,8 +146,6 @@ static long gcode_N, gcode_LastN;
static bool relative_mode = false; //Determines Absolute or Relative Coordinates static bool relative_mode = false; //Determines Absolute or Relative Coordinates
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. 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.
static uint8_t fanpwm=0;
static char cmdbuffer[BUFSIZE][MAX_CMD_SIZE]; static char cmdbuffer[BUFSIZE][MAX_CMD_SIZE];
static bool fromsd[BUFSIZE]; static bool fromsd[BUFSIZE];
static int bufindr = 0; static int bufindr = 0;
@ -938,19 +937,14 @@ void process_commands()
#if FAN_PIN > -1 #if FAN_PIN > -1
case 106: //M106 Fan On case 106: //M106 Fan On
if (code_seen('S')){ if (code_seen('S')){
WRITE(FAN_PIN,HIGH); FanSpeed=constrain(code_value(),0,255);
fanpwm=constrain(code_value(),0,255);
analogWrite(FAN_PIN, fanpwm);
} }
else { else {
WRITE(FAN_PIN,HIGH); FanSpeed=255;
fanpwm=255;
analogWrite(FAN_PIN, fanpwm);
} }
break; break;
case 107: //M107 Fan Off case 107: //M107 Fan Off
WRITE(FAN_PIN,LOW); FanSpeed = 0;
analogWrite(FAN_PIN, 0);
break; break;
#endif //FAN_PIN #endif //FAN_PIN

13
Marlin/planner.cpp

@ -418,23 +418,34 @@ void check_axes_activity() {
unsigned char y_active = 0; unsigned char y_active = 0;
unsigned char z_active = 0; unsigned char z_active = 0;
unsigned char e_active = 0; unsigned char e_active = 0;
unsigned char fan_speed = 0;
unsigned char tail_fan_speed = 0;
block_t *block; block_t *block;
if(block_buffer_tail != block_buffer_head) { if(block_buffer_tail != block_buffer_head) {
uint8_t block_index = block_buffer_tail; uint8_t block_index = block_buffer_tail;
tail_fan_speed = block_buffer[block_index].fan_speed;
while(block_index != block_buffer_head) { while(block_index != block_buffer_head) {
block = &block_buffer[block_index]; block = &block_buffer[block_index];
if(block->steps_x != 0) x_active++; if(block->steps_x != 0) x_active++;
if(block->steps_y != 0) y_active++; if(block->steps_y != 0) y_active++;
if(block->steps_z != 0) z_active++; if(block->steps_z != 0) z_active++;
if(block->steps_e != 0) e_active++; if(block->steps_e != 0) e_active++;
if(block->fan_speed != 0) fan_speed++;
block_index = (block_index+1) & (BLOCK_BUFFER_SIZE - 1); block_index = (block_index+1) & (BLOCK_BUFFER_SIZE - 1);
} }
} }
else {
if (FanSpeed != 0) analogWrite(FAN_PIN,FanSpeed); // If buffer is empty use current fan speed
}
if((DISABLE_X) && (x_active == 0)) disable_x(); if((DISABLE_X) && (x_active == 0)) disable_x();
if((DISABLE_Y) && (y_active == 0)) disable_y(); if((DISABLE_Y) && (y_active == 0)) disable_y();
if((DISABLE_Z) && (z_active == 0)) disable_z(); if((DISABLE_Z) && (z_active == 0)) disable_z();
if((DISABLE_E) && (e_active == 0)) { disable_e0();disable_e1();disable_e2(); } if((DISABLE_E) && (e_active == 0)) { disable_e0();disable_e1();disable_e2(); }
if((FanSpeed == 0) && (fan_speed ==0)) analogWrite(FAN_PIN, 0);
if (FanSpeed != 0 && tail_fan_speed !=0) {
analogWrite(FAN_PIN,tail_fan_speed);
}
} }
@ -498,6 +509,8 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
// Bail if this is a zero-length block // Bail if this is a zero-length block
if (block->step_event_count <=dropsegments) { return; }; if (block->step_event_count <=dropsegments) { return; };
block->fan_speed = FanSpeed;
// Compute direction bits for this block // Compute direction bits for this block
block->direction_bits = 0; block->direction_bits = 0;
if (target[X_AXIS] < position[X_AXIS]) { block->direction_bits |= (1<<X_AXIS); } if (target[X_AXIS] < position[X_AXIS]) { block->direction_bits |= (1<<X_AXIS); }

1
Marlin/planner.h

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

4
Marlin/stepper.cpp

@ -21,9 +21,6 @@
/* The timer calculations of this module informed by the 'RepRap cartesian firmware' by Zack Smith /* The timer calculations of this module informed by the 'RepRap cartesian firmware' by Zack Smith
and Philipp Tiefenbacher. */ and Philipp Tiefenbacher. */
#include "Marlin.h" #include "Marlin.h"
#include "stepper.h" #include "stepper.h"
#include "planner.h" #include "planner.h"
@ -304,6 +301,7 @@ ISR(TIMER1_COMPA_vect)
counter_z = counter_x; counter_z = counter_x;
counter_e = counter_x; counter_e = counter_x;
step_events_completed = 0; step_events_completed = 0;
#ifdef Z_LATE_ENABLE #ifdef Z_LATE_ENABLE
if(current_block->steps_z > 0) { if(current_block->steps_z > 0) {
enable_z(); enable_z();

16
Marlin/ultralcd.pde

@ -812,7 +812,7 @@ void MainMenu::showTune()
if(force_lcd_update) if(force_lcd_update)
{ {
lcd.setCursor(0,line);lcdprintPGM(MSG_FAN_SPEED); lcd.setCursor(0,line);lcdprintPGM(MSG_FAN_SPEED);
lcd.setCursor(13,line);lcd.print(ftostr3(fanpwm)); lcd.setCursor(13,line);lcd.print(ftostr3(FanSpeed));
} }
if((activeline!=line) ) if((activeline!=line) )
@ -823,7 +823,7 @@ void MainMenu::showTune()
linechanging=!linechanging; linechanging=!linechanging;
if(linechanging) if(linechanging)
{ {
encoderpos=fanpwm; encoderpos=FanSpeed;
} }
else else
{ {
@ -836,8 +836,8 @@ void MainMenu::showTune()
{ {
if(encoderpos<0) encoderpos=0; if(encoderpos<0) encoderpos=0;
if(encoderpos>255) encoderpos=255; if(encoderpos>255) encoderpos=255;
fanpwm=encoderpos; FanSpeed=encoderpos;
analogWrite(FAN_PIN, fanpwm); analogWrite(FAN_PIN, FanSpeed);
lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
} }
@ -1134,7 +1134,7 @@ void MainMenu::showControlTemp()
if(force_lcd_update) if(force_lcd_update)
{ {
lcd.setCursor(0,line);lcdprintPGM(MSG_FAN_SPEED); lcd.setCursor(0,line);lcdprintPGM(MSG_FAN_SPEED);
lcd.setCursor(13,line);lcd.print(ftostr3(fanpwm)); lcd.setCursor(13,line);lcd.print(ftostr3(FanSpeed));
} }
if((activeline!=line) ) if((activeline!=line) )
@ -1145,7 +1145,7 @@ void MainMenu::showControlTemp()
linechanging=!linechanging; linechanging=!linechanging;
if(linechanging) if(linechanging)
{ {
encoderpos=fanpwm; encoderpos=FanSpeed;
} }
else else
{ {
@ -1158,8 +1158,8 @@ void MainMenu::showControlTemp()
{ {
if(encoderpos<0) encoderpos=0; if(encoderpos<0) encoderpos=0;
if(encoderpos>255) encoderpos=255; if(encoderpos>255) encoderpos=255;
fanpwm=encoderpos; FanSpeed=encoderpos;
analogWrite(FAN_PIN, fanpwm); analogWrite(FAN_PIN, FanSpeed);
lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
} }

Loading…
Cancel
Save