Changed AVR interrupt priorities to fix random loss of serial data when VFD running...
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Wed, 16 Jan 2019 01:47:07 +0000 (17:47 -0800)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Wed, 16 Jan 2019 01:47:07 +0000 (17:47 -0800)
CHANGELOG.md
package-lock.json
package.json
src/avr/src/i2c.c
src/avr/src/modbus.c
src/avr/src/state.c
src/avr/src/state.h
src/avr/src/vars.def
src/py/bbctrl/Mach.py
src/py/bbctrl/Planner.py

index abe294c6fe811a7bd7054c94d6a07ec445dab440..55663650816ec3bbc4b6f3a55d08fb5c46b1e9d9 100644 (file)
@@ -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.
index 5cd908f2451403f446acc15eb7d0900392aeb1cc..1550f23fca68c47e49c8710d5580d7b57cd9d11c 100644 (file)
@@ -1,6 +1,6 @@
 {
   "name": "bbctrl",
-  "version": "0.4.4",
+  "version": "0.4.5",
   "lockfileVersion": 1,
   "requires": true,
   "dependencies": {
index 1e5a80d31e3515d55a65644b70fc8abae4c4851f..1ca3f5f5b538162661870d8e978e27841d6a83b1 100644 (file)
@@ -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+",
index 762e9753c39e962a70b5f7a8f1a0616c0213470f..d115a1bdaf88844bacd1d441cf1b01f227032807 100644 (file)
@@ -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;
 }
index d1a8eee76a88cd4956873aa8d48351e4f3bdcc5b..afdecb7448e9095597165cb797540829301e1da5 100644 (file)
@@ -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);
 }
 
 
index e4789415e4cab7dd80806ee546bdb50ba1f506b7..5e1ae586464f17f82b1fe7f971f78da019cd707c 100644 (file)
@@ -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();
 }
 
 
index 871a8d1afeb0e5a11ac38903e7465179e1fcfa04..d3488abf47da6af8ce4fc48d4676e084352625f5 100644 (file)
@@ -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;
 
index 50645b2723a24519c2eb4cc6d993df65ab065516..5e23021145fa049899ef07fa56ba032327d80400 100644 (file)
@@ -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
index 987015489d0b4403806c9e42a7950edf120c71f2..7a701aacb2c0b03154ebcb1d1e3cd2ced7a1748d 100644 (file)
@@ -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):
index 220d612f34018e7dbb2f3ca67e61b624deb57c71..b2e3866b556e73ed74a3caface49deee948808b0 100644 (file)
@@ -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)