From b292426344a6114834e535128f5c19222330b345 Mon Sep 17 00:00:00 2001 From: Joseph Coffland Date: Tue, 15 Jan 2019 17:47:07 -0800 Subject: [PATCH] Changed AVR interrupt priorities to fix random loss of serial data when VFD running, Fix bug where planner would not continue after optional pause (M1). --- CHANGELOG.md | 6 +++++- package-lock.json | 2 +- package.json | 2 +- src/avr/src/i2c.c | 2 +- src/avr/src/modbus.c | 6 +++--- src/avr/src/state.c | 29 +++++++++++------------------ src/avr/src/state.h | 1 + src/avr/src/vars.def | 1 - src/py/bbctrl/Mach.py | 14 ++++++++++---- src/py/bbctrl/Planner.py | 2 ++ 10 files changed, 35 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index abe294c..5566365 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,11 @@ Buildbotics CNC Controller Firmware Changelog ============================================== -## v0.4.3 +## v0.4.5 + - Fix for random errors while running VFD. + - Fix bug where planner would not continue after optional pause (M1). + +## v0.4.4 - Write version to log file. - Write time to log file periodically. - Show simulation progress with or with out 3D view. diff --git a/package-lock.json b/package-lock.json index 5cd908f..1550f23 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "bbctrl", - "version": "0.4.4", + "version": "0.4.5", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 1e5a80d..1ca3f5f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bbctrl", - "version": "0.4.4", + "version": "0.4.5", "homepage": "http://buildbotics.com/", "repository": "https://github.com/buildbotics/bbctrl-firmware", "license": "GPL-3.0+", diff --git a/src/avr/src/i2c.c b/src/avr/src/i2c.c index 762e975..d115a1b 100644 --- a/src/avr/src/i2c.c +++ b/src/avr/src/i2c.c @@ -119,7 +119,7 @@ static uint8_t _i2c_default_write_cb(uint8_t offset, bool *done) { void i2c_init() { i2c_set_write_callback(_i2c_default_write_cb); - I2C_DEV.SLAVE.CTRLA = TWI_SLAVE_INTLVL_MED_gc | TWI_SLAVE_DIEN_bm | + I2C_DEV.SLAVE.CTRLA = TWI_SLAVE_INTLVL_LO_gc | TWI_SLAVE_DIEN_bm | TWI_SLAVE_ENABLE_bm | TWI_SLAVE_APIEN_bm | TWI_SLAVE_PIEN_bm; I2C_DEV.SLAVE.ADDR = I2C_ADDR << 1; } diff --git a/src/avr/src/modbus.c b/src/avr/src/modbus.c index d1a8eee..afdecb7 100644 --- a/src/avr/src/modbus.c +++ b/src/avr/src/modbus.c @@ -102,17 +102,17 @@ static void _set_write(bool x) {SET_PIN(RS485_RW_PIN, x);} static void _set_dre_interrupt(bool enable) { - INTLVL_ENABLE(RS485_PORT.CTRLA, USART_DRE, MED, enable); + INTLVL_ENABLE(RS485_PORT.CTRLA, USART_DRE, LO, enable); } static void _set_txc_interrupt(bool enable) { - INTLVL_ENABLE(RS485_PORT.CTRLA, USART_TXC, MED, enable); + INTLVL_ENABLE(RS485_PORT.CTRLA, USART_TXC, LO, enable); } static void _set_rxc_interrupt(bool enable) { - INTLVL_ENABLE(RS485_PORT.CTRLA, USART_RXC, MED, enable); + INTLVL_ENABLE(RS485_PORT.CTRLA, USART_RXC, LO, enable); } diff --git a/src/avr/src/state.c b/src/avr/src/state.c index e478941..5e1ae58 100644 --- a/src/avr/src/state.c +++ b/src/avr/src/state.c @@ -44,7 +44,6 @@ static struct { bool resuming; bool stop_requested; bool pause_requested; - bool optional_pause_requested; bool unpause_requested; state_t state; @@ -70,10 +69,11 @@ PGM_P state_get_pgmstr(state_t state) { PGM_P state_get_hold_reason_pgmstr(hold_reason_t reason) { switch (reason) { - case HOLD_REASON_USER_PAUSE: return PSTR("User pause"); - case HOLD_REASON_USER_STOP: return PSTR("User stop"); - case HOLD_REASON_PROGRAM_PAUSE: return PSTR("Program pause"); - case HOLD_REASON_SWITCH_FOUND: return PSTR("Switch found"); + case HOLD_REASON_USER_PAUSE: return PSTR("User pause"); + case HOLD_REASON_USER_STOP: return PSTR("User stop"); + case HOLD_REASON_PROGRAM_PAUSE: return PSTR("Program pause"); + case HOLD_REASON_OPTIONAL_PAUSE: return PSTR("Optional pause"); + case HOLD_REASON_SWITCH_FOUND: return PSTR("Switch found"); } return PSTR("INVALID"); @@ -139,12 +139,6 @@ void state_holding() { } -void state_pause() { - _set_hold_reason(HOLD_REASON_PROGRAM_PAUSE); - state_holding(); -} - - void state_running() { if (state_get() == STATE_READY) _set_state(STATE_RUNNING); } @@ -208,8 +202,6 @@ void state_callback() { // Var callbacks PGM_P get_state() {return state_get_pgmstr(state_get());} PGM_P get_hold_reason() {return state_get_hold_reason_pgmstr(s.hold_reason);} -bool get_optional_pause() {return s.optional_pause_requested;} -void set_optional_pause(bool x) {s.optional_pause_requested = x;} // Command callbacks @@ -229,13 +221,14 @@ unsigned command_pause_size() {return sizeof(pause_t);} void command_pause_exec(void *data) { switch (*(pause_t *)data) { case PAUSE_PROGRAM_OPTIONAL: - if (!s.optional_pause_requested) return; - s.optional_pause_requested = false; - // Fall through + _set_hold_reason(HOLD_REASON_OPTIONAL_PAUSE); + break; - case PAUSE_PROGRAM: state_pause(); break; - default: break; + case PAUSE_PROGRAM: _set_hold_reason(HOLD_REASON_PROGRAM_PAUSE); break; + default: return; } + + state_holding(); } diff --git a/src/avr/src/state.h b/src/avr/src/state.h index 871a8d1..d3488ab 100644 --- a/src/avr/src/state.h +++ b/src/avr/src/state.h @@ -46,6 +46,7 @@ typedef enum { HOLD_REASON_USER_PAUSE, HOLD_REASON_USER_STOP, HOLD_REASON_PROGRAM_PAUSE, + HOLD_REASON_OPTIONAL_PAUSE, HOLD_REASON_SWITCH_FOUND, } hold_reason_t; diff --git a/src/avr/src/vars.def b/src/avr/src/vars.def index 50645b2..5e23021 100644 --- a/src/avr/src/vars.def +++ b/src/avr/src/vars.def @@ -124,7 +124,6 @@ VAR(hy_status, hs, u8, 0, 0, 1) // Huanyang status flags VAR(id, id, u16, 0, 1, 1) // Last executed command ID VAR(feed_override, fo, u16, 0, 1, 1) // Feed rate override VAR(speed_override, so, u16, 0, 1, 1) // Spindle speed override -VAR(optional_pause, op, b8, 0, 1, 1) // Optional pause state // System VAR(velocity, v, f32, 0, 0, 1) // Current velocity diff --git a/src/py/bbctrl/Mach.py b/src/py/bbctrl/Mach.py index 9870154..7a701aa 100644 --- a/src/py/bbctrl/Mach.py +++ b/src/py/bbctrl/Mach.py @@ -100,7 +100,8 @@ class Mach(Comm): def _is_paused(self): if not self._is_holding() or self.unpausing: return False - return self._get_pause_reason() in ('User pause', 'Program pause') + return self._get_pause_reason() in ( + 'User pause', 'Program pause', 'Optional pause') def _begin_cycle(self, cycle): @@ -159,8 +160,11 @@ class Mach(Comm): self.ctrl.state.set('cycle', self.last_cycle) # Automatically unpause after seek or stop hold + op = self.ctrl.state.get('optional_pause', False) + pr = self._get_pause_reason() if (('xx' in update or 'pr' in update) and self._is_holding() and - self._get_pause_reason() in ('Switch found', 'User stop')): + (pr in ('Switch found', 'User stop') or + (pr == 'Optional pause' and not op))): self._unpause() @@ -304,11 +308,13 @@ class Mach(Comm): def unpause(self): - if self._is_paused(): self._unpause() + if self._is_paused(): + self.ctrl.state.set('optional_pause', False) + self._unpause() def optional_pause(self, enable = True): - super().queue_command('$op=%d' % enable) + self.ctrl.state.set('optional_pause', enable) def set_position(self, axis, position): diff --git a/src/py/bbctrl/Planner.py b/src/py/bbctrl/Planner.py index 220d612..b2e3866 100644 --- a/src/py/bbctrl/Planner.py +++ b/src/py/bbctrl/Planner.py @@ -264,8 +264,10 @@ class Planner(): return Cmd.dwell(block['seconds']) if type == 'pause': return Cmd.pause(block['pause-type']) + if type == 'seek': return Cmd.seek(block['switch'], block['active'], block['error']) + if type == 'end': return '' # Sends id raise Exception('Unknown planner command "%s"' % type) -- 2.27.0