Skip to content

Commit

Permalink
Adding cutoff (ESTOP) support
Browse files Browse the repository at this point in the history
  • Loading branch information
RonGarrison committed Dec 9, 2011
1 parent 881d776 commit 97db22a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
8 changes: 8 additions & 0 deletions firmware/src/Motherboard/EepromMap.hh
Expand Up @@ -49,6 +49,14 @@ const static uint16_t MACHINE_NAME = 0x0020;
/// Default locations for the axis: 5 x 32 bit = 20 bytes
const static uint16_t AXIS_HOME_POSITIONS = 0x0060;

// Estop configuration byte: 1 byte.
const static uint16_t ESTOP_CONFIGURATION = 0x0074;

enum {
ESTOP_CONF_NONE = 0x0,
ESTOP_CONF_ACTIVE_HIGH = 0x1,
ESTOP_CONF_ACTIVE_LOW = 0x2
};

/// Reset all data in the EEPROM to a default.
void setDefaults();
Expand Down
2 changes: 1 addition & 1 deletion firmware/src/Motherboard/Errors.hh
Expand Up @@ -29,7 +29,7 @@
#define ERR_HOST_PACKET_TIMEOUT 4
#define ERR_HOST_PACKET_MISC 5
#define ERR_WDT_TIMEOUT 6

#define ERR_ESTOP 7
#define ERR_HOST_TRUNCATED_CMD 8

#endif /* ERRORS_HH_ */
24 changes: 24 additions & 0 deletions firmware/src/Motherboard/Main.cc
Expand Up @@ -28,6 +28,7 @@
#include "SDCard.hh"
#include "Eeprom.hh"
#include "EepromMap.hh"
#include "Errors.hh"

void reset(bool hard_reset) {
ATOMIC_BLOCK(ATOMIC_FORCEON) {
Expand All @@ -37,6 +38,16 @@ void reset(bool hard_reset) {
command::reset();
eeprom::init();
board.reset();
#if HAS_ESTOP
const uint8_t estop_conf = eeprom::getEeprom8(eeprom::ESTOP_CONFIGURATION, 0);
if (estop_conf == eeprom::ESTOP_CONF_ACTIVE_HIGH) {
ESTOP_ENABLE_RISING_INT;
} else if (estop_conf == eeprom::ESTOP_CONF_ACTIVE_LOW) {
ESTOP_ENABLE_FALLING_INT;
}
#endif


sei();
// If we've just come from a hard reset, wait for 2.5 seconds before
// trying to ping an extruder. This gives the extruder time to boot
Expand Down Expand Up @@ -72,3 +83,16 @@ int main() {
}
return 0;
}

ISR(ESTOP_vect, ISR_NOBLOCK) {
// Emergency stop triggered; reset everything and kill the interface to RepG
INTERFACE_BAR_PIN.setValue(true);
INTERFACE_BAR_PIN.setDirection(true);
tool::reset();
steppers::abort();
command::reset();
UART::getHostUART().enable(false);
Motherboard::getBoard().indicateError(ERR_ESTOP);

}

4 changes: 4 additions & 0 deletions firmware/src/Motherboard/boards/mb24/Configuration.hh
Expand Up @@ -73,6 +73,10 @@
#define HAS_ESTOP 1
// The pin connected to the emergency stop
#define ESTOP_PIN Pin(PortE,4)
// Macros for enabling interrupts on the the pin. In this case, INT4.
#define ESTOP_ENABLE_RISING_INT { EICRB = 0x03; EIMSK |= 0x10; }
#define ESTOP_ENABLE_FALLING_INT { EICRB = 0x02; EIMSK |= 0x10; }
#define ESTOP_vect INT4_vect


// --- Axis configuration ---
Expand Down
6 changes: 6 additions & 0 deletions firmware/src/Motherboard/boards/mb24/Motherboard.cc
Expand Up @@ -132,6 +132,12 @@ void Motherboard::reset() {
// Configure the debug pin.
DEBUG_PIN.setDirection(true);

#if HAS_ESTOP
// Configure the estop pin direction.
ESTOP_PIN.setDirection(false);
#endif


// Check if the interface board is attached
hasInterfaceBoard = interface::isConnected();

Expand Down

0 comments on commit 97db22a

Please sign in to comment.