Finally, all seems to work as expected. Eureka!

parent 50c07eba
...@@ -42,6 +42,10 @@ ...@@ -42,6 +42,10 @@
CardReader card; CardReader card;
#endif #endif
#if ENABLED(FLOWMETER_SENSOR) && ENABLED(MINFLOW_PROTECTION)
bool flow_firstread = false;
#endif
bool Running = true; bool Running = true;
bool Printing = false; bool Printing = false;
...@@ -749,6 +753,9 @@ void setup() { ...@@ -749,6 +753,9 @@ void setup() {
#endif #endif
#if ENABLED(FLOWMETER_SENSOR) #if ENABLED(FLOWMETER_SENSOR)
#if ENABLED(MINFLOW_PROTECTION)
flow_firstread=false;
#endif
flow_init(); flow_init();
#endif #endif
...@@ -2969,8 +2976,14 @@ inline void do_blocking_move_to_z(float z) { do_blocking_move_to(current_positio ...@@ -2969,8 +2976,14 @@ inline void do_blocking_move_to_z(float z) { do_blocking_move_to(current_positio
#if ENABLED(FLOWMETER_SENSOR) #if ENABLED(FLOWMETER_SENSOR)
void print_flowratestates() { void print_flowratestates() {
ECHO_MV(" FLOW: ", get_flowrate(), 1); float readval;
ECHO_M(" ml/min "); readval = get_flowrate();
#if ENABLED(MINFLOW_PROTECTION)
if(readval > MINFLOW_PROTECTION)
flow_firstread=true;
#endif
ECHO_MV(" FLOW: ", readval);
ECHO_M(" l/min ");
} }
#endif #endif
...@@ -9252,14 +9265,11 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) { ...@@ -9252,14 +9265,11 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
if (max_inactive_time && ELAPSED(ms, previous_cmd_ms + max_inactive_time)) kill(PSTR(MSG_KILLED)); if (max_inactive_time && ELAPSED(ms, previous_cmd_ms + max_inactive_time)) kill(PSTR(MSG_KILLED));
#if ENABLED(FLOWMETER_SENSOR) && ENABLED(MINFLOW_PROTECTION) #if ENABLED(FLOWMETER_SENSOR) && ENABLED(MINFLOW_PROTECTION)
if (get_flowrate() < (MINFLOW_PROTECTION*1000)) { if (flow_firstread && Printing && (get_flowrate() < (float)MINFLOW_PROTECTION)) {
if (Printing) flow_firstread = false;
kill(PSTR(MSG_KILLED)); kill(PSTR(MSG_KILLED));
//else
// stop();
} }
#endif #endif
if (stepper_inactive_time && ELAPSED(ms, previous_cmd_ms + stepper_inactive_time) if (stepper_inactive_time && ELAPSED(ms, previous_cmd_ms + stepper_inactive_time)
&& !ignore_stepper_queue && !blocks_queued()) { && !ignore_stepper_queue && !blocks_queued()) {
#if DISABLE_X == true #if DISABLE_X == true
...@@ -9480,6 +9490,9 @@ void kill(const char* lcd_msg) { ...@@ -9480,6 +9490,9 @@ void kill(const char* lcd_msg) {
#if ENABLED(KILL_METHOD) && KILL_METHOD == 1 #if ENABLED(KILL_METHOD) && KILL_METHOD == 1
HAL::resetHardware(); HAL::resetHardware();
#endif #endif
#if ENABLED(FLOWMETER_SENSOR) && ENABLED(MINFLOW_PROTECTION)
flow_firstread=false;
#endif
#if ENABLED(ULTRA_LCD) #if ENABLED(ULTRA_LCD)
lcd_setalertstatuspgm(lcd_msg); lcd_setalertstatuspgm(lcd_msg);
...@@ -9593,6 +9606,9 @@ void kill(const char* lcd_msg) { ...@@ -9593,6 +9606,9 @@ void kill(const char* lcd_msg) {
#endif // FAST_PWM_FAN #endif // FAST_PWM_FAN
void stop() { void stop() {
#if ENABLED(FLOWMETER_SENSOR) && ENABLED(MINFLOW_PROTECTION)
flow_firstread=false;
#endif
disable_all_heaters(); disable_all_heaters();
disable_all_coolers(); disable_all_coolers();
#ifdef LASER #ifdef LASER
......
...@@ -23,18 +23,16 @@ ...@@ -23,18 +23,16 @@
#if ENABLED(FLOWMETER_SENSOR) #if ENABLED(FLOWMETER_SENSOR)
volatile byte flowrate_pulsecount; volatile int flowrate_pulsecount;
float flowrate; float flowrate;
unsigned int flowml;
static millis_t flowmeter_timer = 0; static millis_t flowmeter_timer = 0;
static millis_t lastflow = 0;
void flowrate_pulsecounter(); void flowrate_pulsecounter();
void flow_init() { void flow_init() {
flowrate = 0; flowrate = 0;
flowrate_pulsecount = 0; flowrate_pulsecount = 0;
flowml = 0;
pinMode(FLOWMETER_PIN, INPUT); pinMode(FLOWMETER_PIN, INPUT);
attachInterrupt(digitalPinToInterrupt(FLOWMETER_PIN), flowrate_pulsecounter, FALLING); attachInterrupt(digitalPinToInterrupt(FLOWMETER_PIN), flowrate_pulsecounter, FALLING);
...@@ -45,18 +43,25 @@ void flowrate_manage() { ...@@ -45,18 +43,25 @@ void flowrate_manage() {
now = millis(); now = millis();
if(ELAPSED(now, flowmeter_timer)) { if(ELAPSED(now, flowmeter_timer)) {
detachInterrupt(digitalPinToInterrupt(FLOWMETER_PIN)); detachInterrupt(digitalPinToInterrupt(FLOWMETER_PIN));
flowrate = ((1000.0 / (now - flowmeter_timer)) * flowrate_pulsecount) / FLOWMETER_CALIBRATION; flowrate = (float)(((1000.0 / (float)((float)now - (float)lastflow)) * (float)flowrate_pulsecount) / (float)FLOWMETER_CALIBRATION);
#if ENABLED(FLOWMETER_DEBUG)
ECHO_M(" FLOWMETER DEBUG ");
ECHO_MV(" flowrate:", flowrate);
ECHO_MV(" flowrate_pulsecount:", flowrate_pulsecount);
ECHO_MV(" CALIBRATION:", FLOWMETER_CALIBRATION);
ECHO_E;
#endif
flowmeter_timer = now + 1000UL; flowmeter_timer = now + 1000UL;
flowml = (flowrate / 60.0) * 1000; lastflow = now;
flowrate_pulsecount = 0; flowrate_pulsecount = 0;
attachInterrupt(digitalPinToInterrupt(FLOWMETER_PIN), flowrate_pulsecounter, FALLING); attachInterrupt(digitalPinToInterrupt(FLOWMETER_PIN), flowrate_pulsecounter, FALLING);
} }
} }
int get_flowrate() { float get_flowrate() {
return flowml; return flowrate;
} }
void flowrate_pulsecounter() void flowrate_pulsecounter()
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#if ENABLED(FLOWMETER_SENSOR) #if ENABLED(FLOWMETER_SENSOR)
void flowrate_manage(); void flowrate_manage();
void flow_init(); void flow_init();
int get_flowrate(); float get_flowrate();
#endif #endif
......
...@@ -818,6 +818,10 @@ float get_pid_output(int h) { ...@@ -818,6 +818,10 @@ float get_pid_output(int h) {
#if ENABLED(PIDTEMPCOOLER) #if ENABLED(PIDTEMPCOOLER)
float get_pid_output_cooler() { float get_pid_output_cooler() {
float pid_output; float pid_output;
if(target_temperature_cooler == 0)
return 0
#if ENABLED(PID_OPENLOOP) #if ENABLED(PID_OPENLOOP)
pid_output = constrain(target_temperature_cooler, 0, MAX_COOLER_POWER); pid_output = constrain(target_temperature_cooler, 0, MAX_COOLER_POWER);
#else #else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment