measuring pulse width: initial version

This commit is contained in:
PavelSindler 2017-10-26 17:42:27 +02:00
parent 0f2c7af1fb
commit f4d5d891df
3 changed files with 38 additions and 4 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

@ -106,6 +106,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
@ -287,6 +289,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;
@ -1097,6 +1100,7 @@ void setup()
check_babystep(); //checking if Z babystep is in allowed range
setup_uvlo_interrupt();
setup_fan_interrupt();
#ifndef DEBUG_DISABLE_STARTMSGS
@ -7073,6 +7077,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