forked from makerbot/G3Firmware
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Starting work on porting v2 firmware to new hardware.
- Loading branch information
Adam Mayer
authored and
Adam Mayer
committed
May 7, 2010
1 parent
abc3658
commit 9d048b6
Showing
12 changed files
with
844 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/* | ||
* Copyright 2010 by Adam Mayer <adam@makerbot.com> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
*/ | ||
|
||
#ifndef BOARDS_RRMBV22_CONFIGURATION_HH_ | ||
#define BOARDS_RRMBV22_CONFIGURATION_HH_ | ||
|
||
// This file details the pin assignments and features of the RepRap Motherboard | ||
// version 1.2 for the ordinary use case. | ||
|
||
#include "AvrPort.hh" | ||
|
||
// Interval for the stepper update in microseconds. This interval is the minimum | ||
// possible time between steps; in practical terms, your time between steps should | ||
// be at least eight times this large. Reducing the interval can cause resource | ||
// starvation; leave this at 64uS or greater unless you know what you're doing. | ||
#define INTERVAL_IN_MICROSECONDS 64 | ||
|
||
// --- Power Supply Unit configuration --- | ||
// Define as 1 if a PSU is present; 0 if not. | ||
#define HAS_PSU 0 | ||
|
||
// --- Secure Digital Card configuration --- | ||
// NOTE: If SD support is enabled, it is implicitly assumed that the | ||
// following pins are connected: | ||
// AVR | SD header | ||
//---------|-------------- | ||
// MISO | DATA_OUT | ||
// MOSI | DATA_IN | ||
// SCK | CLK | ||
|
||
// Define as 1 if and SD card slot is present; 0 if not. | ||
#define HAS_SD 1 | ||
// The pin that connects to the write protect line on the SD header. | ||
#define SD_WRITE_PIN Pin(PortC,5) | ||
// The pin that connects to the card detect line on the SD header. | ||
#define SD_DETECT_PIN Pin(PortD,1) | ||
// The pin that connects to the chip select line on the SD header. | ||
#define SD_SELECT_PIN Pin(PortB,0) | ||
|
||
// --- Slave UART configuration --- | ||
// The slave UART is presumed to be an RS485 connection through a sn75176 chip. | ||
// Define as 1 if the slave UART is present; 0 if not. | ||
#define HAS_SLAVE_UART 1 | ||
// The pin that connects to the driver enable line on the RS485 chip. | ||
#define TX_ENABLE_PIN Pin(PortC,5) | ||
// The pin that connects to the active-low recieve enable line on the RS485 chip. | ||
#define RX_ENABLE_PIN Pin(PortC,7) | ||
|
||
// --- Host UART configuration --- | ||
// The host UART is presumed to always be present on the RX/TX lines. | ||
|
||
// --- Piezo Buzzer configuration --- | ||
// Define as 1 if the piezo buzzer is present, 0 if not. | ||
#define HAS_BUZZER 1 | ||
// The pin that drives the buzzer | ||
#define BUZZER_PIN Pin(PortC,6) | ||
|
||
// --- Emergency Stop configuration --- | ||
// Define as 1 if the estop is present, 0 if not. | ||
#define HAS_ESTOP 1 | ||
// The pin connected to the emergency stop | ||
#define ESTOP_PIN Pin(PortE,4) | ||
|
||
// --- Axis configuration --- | ||
// Define the number of stepper axes supported by the board. The axes are | ||
// denoted by X, Y, Z, A and B. | ||
#define STEPPER_COUNT 5 | ||
|
||
// --- Stepper and endstop configuration --- | ||
// Pins should be defined for each axis present on the board. They are denoted | ||
// X, Y, Z, A and B respectively. | ||
|
||
// This indicates the default interpretation of the endstop values. | ||
// If your endstops are based on the H21LOB, they are inverted; | ||
// if they are based on the H21LOI, they are not. | ||
#define DEFAULT_INVERTED_ENDSTOPS 1 | ||
|
||
// The X stepper step pin (active on rising edge) | ||
#define X_STEP_PIN Pin(PortA,6) | ||
// The X direction pin (forward on logic high) | ||
#define X_DIR_PIN Pin(PortA,5) | ||
// The X stepper enable pin (active low) | ||
#define X_ENABLE_PIN Pin(PortA,4) | ||
// The X minimum endstop pin (active high) | ||
#define X_MIN_PIN Pin(PortB,6) | ||
// The X maximum endstop pin (active high) | ||
#define X_MAX_PIN Pin(PortB,5) | ||
|
||
// The Y stepper step pin (active on rising edge) | ||
#define Y_STEP_PIN Pin(PortA,3) | ||
// The Y direction pin (forward on logic high) | ||
#define Y_DIR_PIN Pin(PortA,2) | ||
// The Y stepper enable pin (active low) | ||
#define Y_ENABLE_PIN Pin(PortA,1) | ||
// The Y minimum endstop pin (active high) | ||
#define Y_MIN_PIN Pin(PortB,4) | ||
// The Y maximum endstop pin (active high) | ||
#define Y_MAX_PIN Pin(PortH,6) | ||
|
||
// The Z stepper step pin (active on rising edge) | ||
#define Z_STEP_PIN Pin(PortA,0) | ||
// The Z direction pin (forward on logic high) | ||
#define Z_DIR_PIN Pin(PortH,0) | ||
// The Z stepper enable pin (active low) | ||
#define Z_ENABLE_PIN Pin(PortH,1) | ||
// The Z minimum endstop pin (active high) | ||
#define Z_MIN_PIN Pin(PortH,5) | ||
// The Z maximum endstop pin (active high) | ||
#define Z_MAX_PIN Pin(PortH,4) | ||
|
||
// The A stepper step pin (active on rising edge) | ||
#define A_STEP_PIN Pin(PortJ,0) | ||
// The A direction pin (forward on logic high) | ||
#define A_DIR_PIN Pin(PortJ,1) | ||
// The A stepper enable pin (active low) | ||
#define A_ENABLE_PIN Pin(PortE,5) | ||
|
||
// The B stepper step pin (active on rising edge) | ||
#define B_STEP_PIN Pin(PortG,5) | ||
// The B direction pin (forward on logic high) | ||
#define B_DIR_PIN Pin(PortE,3) | ||
// The B stepper enable pin (active low) | ||
#define B_ENABLE_PIN Pin(PortH,3) | ||
|
||
// --- Debugging configuration --- | ||
// The pin which controls the debug LED (active high) | ||
#define DEBUG_PIN Pin(PortB,7) | ||
// By default, debugging packets should be honored; this is made | ||
// configurable if we're short on cycles or EEPROM. | ||
// Define as 1 if debugging packets are honored; 0 if not. | ||
#define HONOR_DEBUG_PACKETS 1 | ||
|
||
#endif // BOARDS_RRMBV12_CONFIGURATION_HH_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
/* | ||
* Copyright 2010 by Adam Mayer <adam@makerbot.com> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
*/ | ||
|
||
#include <stdint.h> | ||
#include <avr/interrupt.h> | ||
#include <avr/io.h> | ||
#include <util/atomic.h> | ||
#include "Motherboard.hh" | ||
#include "Configuration.hh" | ||
#include "Steppers.hh" | ||
#include "Command.hh" | ||
|
||
/// Instantiate static motherboard instance | ||
Motherboard Motherboard::motherboard; | ||
|
||
/// Create motherboard object | ||
Motherboard::Motherboard() { | ||
/// Set up the stepper pins on board creation | ||
#if STEPPER_COUNT > 0 | ||
stepper[0] = StepperInterface(X_DIR_PIN,X_STEP_PIN,X_ENABLE_PIN,X_MAX_PIN,X_MIN_PIN); | ||
#endif | ||
#if STEPPER_COUNT > 1 | ||
stepper[1] = StepperInterface(Y_DIR_PIN,Y_STEP_PIN,Y_ENABLE_PIN,Y_MAX_PIN,Y_MIN_PIN); | ||
#endif | ||
#if STEPPER_COUNT > 2 | ||
stepper[2] = StepperInterface(Z_DIR_PIN,Z_STEP_PIN,Z_ENABLE_PIN,Z_MAX_PIN,Z_MIN_PIN); | ||
#endif | ||
#if STEPPER_COUNT > 3 | ||
stepper[3] = StepperInterface(A_DIR_PIN,A_STEP_PIN,A_ENABLE_PIN,A_MAX_PIN,A_MIN_PIN); | ||
#endif | ||
#if STEPPER_COUNT > 4 | ||
stepper[4] = StepperInterface(B_DIR_PIN,B_STEP_PIN,B_ENABLE_PIN,B_MAX_PIN,B_MIN_PIN); | ||
#endif | ||
} | ||
|
||
/// Reset the motherboard to its initial state. | ||
/// This only resets the board, and does not send a reset | ||
/// to any attached toolheads. | ||
void Motherboard::reset() { | ||
indicateError(0); // turn off blinker | ||
// Init and turn on power supply | ||
getPSU().init(); | ||
getPSU().turnOn(true); | ||
// Init steppers | ||
for (int i = 0; i < STEPPER_COUNT; i++) { | ||
stepper[i].init(i); | ||
} | ||
// Initialize the host and slave UARTs | ||
getHostUART().enable(true); | ||
getHostUART().in.reset(); | ||
getSlaveUART().enable(true); | ||
getSlaveUART().in.reset(); | ||
// Reset and configure timer 1, the microsecond and stepper | ||
// interrupt timer. | ||
TCCR1A = 0x00; | ||
TCCR1B = 0x09; | ||
TCCR1C = 0x00; | ||
OCR1A = INTERVAL_IN_MICROSECONDS * 16; | ||
TIMSK1 = 0x02; // turn on OCR1A match interrupt | ||
// Reset and configure timer 2, the debug LED flasher timer. | ||
TCCR2A = 0x00; | ||
TCCR2B = 0x07; // prescaler at 1/1024 | ||
TIMSK2 = 0x01; // OVF flag on | ||
// Configure the debug pin. | ||
DEBUG_PIN.setDirection(true); | ||
} | ||
|
||
/// Get the number of microseconds that have passed since | ||
/// the board was booted. | ||
micros_t Motherboard::getCurrentMicros() { | ||
micros_t micros_snapshot; | ||
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { | ||
micros_snapshot = micros; | ||
} | ||
return micros_snapshot; | ||
} | ||
|
||
/// Run the motherboard interrupt | ||
void Motherboard::doInterrupt() { | ||
micros += INTERVAL_IN_MICROSECONDS; | ||
// Do not move steppers if the board is in a paused state | ||
if (command::isPaused()) return; | ||
steppers::doInterrupt(); | ||
} | ||
|
||
/// Timer one comparator match interrupt | ||
ISR(TIMER1_COMPA_vect) { | ||
Motherboard::getBoard().doInterrupt(); | ||
} | ||
|
||
/// Number of times to blink the debug LED on each cycle | ||
volatile uint8_t blink_count = 0; | ||
|
||
/// The current state of the debug LED | ||
enum { | ||
BLINK_NONE, | ||
BLINK_ON, | ||
BLINK_OFF, | ||
BLINK_PAUSE | ||
} blink_state = BLINK_NONE; | ||
|
||
/// Write an error code to the debug pin. | ||
void Motherboard::indicateError(int error_code) { | ||
if (error_code == 0) { | ||
blink_state = BLINK_NONE; | ||
DEBUG_PIN.setValue(false); | ||
} | ||
else if (blink_count != error_code) { | ||
blink_state = BLINK_OFF; | ||
} | ||
blink_count = error_code; | ||
} | ||
|
||
/// Get the current error code. | ||
uint8_t Motherboard::getCurrentError() { | ||
return blink_count; | ||
} | ||
|
||
/// Timer2 overflow cycles that the LED remains on while blinking | ||
#define OVFS_ON 18 | ||
/// Timer2 overflow cycles that the LED remains off while blinking | ||
#define OVFS_OFF 18 | ||
/// Timer2 overflow cycles between flash cycles | ||
#define OVFS_PAUSE 80 | ||
|
||
/// Number of overflows remaining on the current blink cycle | ||
int blink_ovfs_remaining = 0; | ||
/// Number of blinks performed in the current cycle | ||
int blinked_so_far = 0; | ||
|
||
/// Timer 2 overflow interrupt | ||
ISR(TIMER2_OVF_vect) { | ||
if (blink_ovfs_remaining > 0) { | ||
blink_ovfs_remaining--; | ||
} else { | ||
if (blink_state == BLINK_ON) { | ||
blinked_so_far++; | ||
blink_state = BLINK_OFF; | ||
blink_ovfs_remaining = OVFS_OFF; | ||
DEBUG_PIN.setValue(false); | ||
} else if (blink_state == BLINK_OFF) { | ||
if (blinked_so_far >= blink_count) { | ||
blink_state = BLINK_PAUSE; | ||
blink_ovfs_remaining = OVFS_PAUSE; | ||
} else { | ||
blink_state = BLINK_ON; | ||
blink_ovfs_remaining = OVFS_ON; | ||
DEBUG_PIN.setValue(true); | ||
} | ||
} else if (blink_state == BLINK_PAUSE) { | ||
blinked_so_far = 0; | ||
blink_state = BLINK_ON; | ||
blink_ovfs_remaining = OVFS_ON; | ||
DEBUG_PIN.setValue(true); | ||
} | ||
} | ||
} |
Oops, something went wrong.