Merge pull request #75 from PavelSindler/print_fan_speed

Print fan speed: measuring pulse width
This commit is contained in:
XPila 2017-10-27 14:56:52 +02:00 committed by GitHub
commit a6f3fb2d3b
3 changed files with 7417 additions and 7383 deletions

View File

@ -334,6 +334,7 @@ extern int fanSpeedBckp;
extern float pause_lastpos[4];
extern unsigned long pause_time;
extern unsigned long start_pause_print;
extern unsigned long t_fan_rising_edge;
extern bool mesh_bed_leveling_flag;
extern bool mesh_bed_run_from_menu;
@ -372,6 +373,7 @@ void serialecho_temperatures();
void uvlo_();
void recover_print(uint8_t automatic);
void setup_uvlo_interrupt();
void setup_fan_interrupt();
extern void recover_machine_state_after_power_panic();
extern void restore_print_from_eeprom();

View File

@ -107,6 +107,8 @@
#define TEST(n,b) (((n)&BIT(b))!=0)
#define SET_BIT(n,b,value) (n) ^= ((-value)^(n)) & (BIT(b))
//Macro for print fan speed
#define FAN_PULSE_WIDTH_LIMIT ((fanSpeed > 100) ? 3 : 4) //time in ms
// look here for descriptions of G-codes: http://linuxcnc.org/handbook/gcode/g-code.html
// http://objects.reprap.org/wiki/Mendel_User_Manual:_RepRapGCodes
@ -288,6 +290,7 @@ int fanSpeedBckp = 0;
float pause_lastpos[4];
unsigned long pause_time = 0;
unsigned long start_pause_print = millis();
unsigned long t_fan_rising_edge = millis();
unsigned long load_filament_time;
@ -988,9 +991,10 @@ void setup()
check_babystep(); //checking if Z babystep is in allowed range
setup_uvlo_interrupt();
setup_fan_interrupt();
fsensor_setup_interrupt();
#ifndef DEBUG_DISABLE_STARTMSGS
if (calibration_status() == CALIBRATION_STATUS_ASSEMBLED ||
@ -6990,6 +6994,34 @@ void uvlo_()
while(1);
}
void setup_fan_interrupt() {
//INT7
DDRE &= ~(1 << 7); //input pin
PORTE &= ~(1 << 7); //no internal pull-up
//start with sensing rising edge
EICRB &= ~(1 << 6);
EICRB |= (1 << 7);
//enable INT7 interrupt
EIMSK |= (1 << 7);
}
ISR(INT7_vect) {
//measuring speed now works for fanSpeed > 18 (approximately), which is sufficient because MIN_PRINT_FAN_SPEED is higher
if (fanSpeed < MIN_PRINT_FAN_SPEED) return;
if ((1 << 6) & EICRB) { //interrupt was triggered by rising edge
t_fan_rising_edge = millis();
}
else { //interrupt was triggered by falling edge
if ((millis() - t_fan_rising_edge) >= FAN_PULSE_WIDTH_LIMIT) {//this pulse was from sensor and not from pwm
fan_edge_counter[1] += 2; //we are currently counting all edges so lets count two edges for one pulse
}
}
EICRB ^= (1 << 6); //change edge
}
void setup_uvlo_interrupt() {
DDRE &= ~(1 << 4); //input pin
PORTE &= ~(1 << 4); //no internal pull-up

View File

@ -2178,10 +2178,10 @@ void check_fans() {
fan_edge_counter[0] ++;
fan_state[0] = !fan_state[0];
}
if (READ(TACH_1) != fan_state[1]) {
fan_edge_counter[1] ++;
fan_state[1] = !fan_state[1];
}
//if (READ(TACH_1) != fan_state[1]) {
// fan_edge_counter[1] ++;
// fan_state[1] = !fan_state[1];
//}
}
#ifdef PIDTEMP