From: Joseph Coffland Date: Sat, 1 Oct 2016 21:02:26 +0000 (-0700) Subject: Changes for v3 board wiring X-Git-Url: https://git.buildbotics.com/?a=commitdiff_plain;h=c8baa1f41f63911eebadc7a5ec71c3175472b539;p=bbctrl-firmware Changes for v3 board wiring --- diff --git a/src/config.h b/src/config.h index 3d5a2bd..450acb8 100644 --- a/src/config.h +++ b/src/config.h @@ -36,6 +36,64 @@ // Pins +enum { + ENABLE_X_PIN = PORT_A << 3, + ENABLE_Y_PIN, + ENABLE_Z_PIN, + ENABLE_A_PIN, + SPIN_DIR_PIN, + SPIN_ENABLE_PIN, + ANALOG_PIN, + PROBE_PIN, + + MIN_X_PIN = PORT_B << 3, + MAX_X_PIN, + MIN_A_PIN, + MAX_A_PIN, + MIN_Y_PIN, + MAX_Y_PIN, + MIN_Z_PIN, + MAX_Z_PIN, + + SDA_PIN = PORT_C << 3, + SCL_PIN, + SERIAL_RX_PIN, + SERIAL_TX_PIN, + SERIAL_CTS_PIN, + SPI_CLK_PIN, + SPI_MISO_PIN, + SPI_MOSI_PIN, + + STEP_X_PIN = PORT_D << 3, + SPI_CS_X_PIN, + SPI_CS_A_PIN, + SPI_CS_Z_PIN, + SPIN_PWM_PIN, + SWITCH_1_PIN, + RS485_RO_PIN, + RS485_DI_PIN, + + STEP_Y_PIN = PORT_E << 3, + SPI_CS_Y_PIN, + DIR_X_PIN, + DIR_Y_PIN, + STEP_A_PIN, + SWITCH_2_PIN, + DIR_Z_PIN, + DIR_A_PIN, + + STEP_Z_PIN = PORT_F << 3, + RS485_RW_PIN, + FAULT_PIN, + ESTOP_PIN, + FAULT_X_PIN, + FAULT_Y_PIN, + FAULT_Z_PIN, + FAULT_A_PIN, +}; + + +#if 0 enum { STEP_X_PIN = PORT_A << 3, DIR_X_PIN, @@ -91,6 +149,7 @@ enum { MIN_A_PIN, MAX_A_PIN, }; +#endif // Compile-time settings @@ -299,20 +358,20 @@ typedef enum { #define TIMER_TMC2660 TCC1 // TMC2660 timer (see tmc2660.h) #define TIMER_PWM TCD1 // PWM timer (see pwm_spindle.c) -#define M1_TIMER TCE1 -#define M2_TIMER TCF0 -#define M3_TIMER TCE0 -#define M4_TIMER TCD0 +#define M1_TIMER TCD0 +#define M2_TIMER TCE0 +#define M3_TIMER TCF0 +#define M4_TIMER TCE1 #define M1_DMA_CH DMA.CH0 #define M2_DMA_CH DMA.CH1 #define M3_DMA_CH DMA.CH2 #define M4_DMA_CH DMA.CH3 -#define M1_DMA_TRIGGER DMA_CH_TRIGSRC_TCE1_CCA_gc -#define M2_DMA_TRIGGER DMA_CH_TRIGSRC_TCF0_CCA_gc -#define M3_DMA_TRIGGER DMA_CH_TRIGSRC_TCE0_CCA_gc -#define M4_DMA_TRIGGER DMA_CH_TRIGSRC_TCD0_CCA_gc +#define M1_DMA_TRIGGER DMA_CH_TRIGSRC_TCD0_CCA_gc +#define M2_DMA_TRIGGER DMA_CH_TRIGSRC_TCE0_CCA_gc +#define M3_DMA_TRIGGER DMA_CH_TRIGSRC_TCF0_CCA_gc +#define M4_DMA_TRIGGER DMA_CH_TRIGSRC_TCE1_CCA_gc // Timer setup for stepper and dwells @@ -334,8 +393,8 @@ typedef enum { #define TMC2660_OVF_vect TCC1_OVF_vect #define TMC2660_SPI_SS_PIN SERIAL_CTS_PIN #define TMC2660_SPI_SCK_PIN SPI_CLK_PIN -#define TMC2660_SPI_MISO_PIN SPI_MOSI_PIN -#define TMC2660_SPI_MOSI_PIN SPI_MISO_PIN +#define TMC2660_SPI_MISO_PIN SPI_MISO_PIN +#define TMC2660_SPI_MOSI_PIN SPI_MOSI_PIN #define TMC2660_TIMER TIMER_TMC2660 #define TMC2660_TIMER_ENABLE TC_CLKSEL_DIV64_gc #define TMC2660_POLL_RATE 0.001 // sec. Must be in (0, 1] diff --git a/src/huanyang.c b/src/huanyang.c index bd8ade6..1abe98b 100644 --- a/src/huanyang.c +++ b/src/huanyang.c @@ -156,14 +156,8 @@ static void _set_baud(uint16_t bsel, uint8_t bscale) { static void _set_write(bool x) { - if (x) { - OUTSET_PIN(RS485_RE_PIN); // High - OUTSET_PIN(RS485_DE_PIN); // High - - } else { - OUTCLR_PIN(RS485_RE_PIN); // Low - OUTCLR_PIN(RS485_DE_PIN); // Low - } + if (x) OUTSET_PIN(RS485_RW_PIN); // High + else OUTCLR_PIN(RS485_RW_PIN); // Low } @@ -431,10 +425,8 @@ void huanyang_init() { DIRCLR_PIN(RS485_RO_PIN); // Input OUTSET_PIN(RS485_DI_PIN); // High DIRSET_PIN(RS485_DI_PIN); // Output - OUTSET_PIN(RS485_RE_PIN); // High - DIRSET_PIN(RS485_RE_PIN); // Output - OUTSET_PIN(RS485_DE_PIN); // High - DIRSET_PIN(RS485_DE_PIN); // Output + OUTSET_PIN(RS485_RW_PIN); // High + DIRSET_PIN(RS485_RW_PIN); // Output _set_baud(3325, 0b1101); // 9600 @ 32MHz with 2x USART diff --git a/src/motor.c b/src/motor.c index 61a64cd..9ea14ef 100644 --- a/src/motor.c +++ b/src/motor.c @@ -105,7 +105,7 @@ static motor_t motors[MOTORS] = { .step_pin = STEP_X_PIN, .dir_pin = DIR_X_PIN, .enable_pin = ENABLE_X_PIN, - .timer = (TC0_t *)&M1_TIMER, + .timer = &M1_TIMER, .dma = &M1_DMA_CH, .dma_trigger = M1_DMA_TRIGGER, }, { @@ -144,7 +144,7 @@ static motor_t motors[MOTORS] = { .step_pin = STEP_A_PIN, .dir_pin = DIR_A_PIN, .enable_pin = ENABLE_A_PIN, - .timer = &M4_TIMER, + .timer = (TC0_t *)&M4_TIMER, .dma = &M4_DMA_CH, .dma_trigger = M4_DMA_TRIGGER, } @@ -154,13 +154,6 @@ static motor_t motors[MOTORS] = { static uint8_t _dummy; -/// Special interrupt for X-axis -ISR(TCE1_CCA_vect) { - OUTTGL_PIN(STEP_X_PIN); - motors[0].steps++; -} - - void motor_init() { // Enable DMA DMA.CTRL = DMA_RESET_bm; @@ -179,8 +172,6 @@ void motor_init() { // Setup motor timer m->timer->CTRLB = TC_WGMODE_FRQ_gc | TC1_CCAEN_bm; - if (!motor) continue; // Don't configure DMA for motor 0 - // Setup DMA channel as timer event counter m->dma->ADDRCTRL = DMA_CH_SRCDIR_FIXED_gc | DMA_CH_DESTDIR_FIXED_gc; m->dma->TRIGSRC = m->dma_trigger; @@ -200,9 +191,6 @@ void motor_init() { DMA_CH_REPEAT_bm | DMA_CH_SINGLE_bm | DMA_CH_BURSTLEN_1BYTE_gc; m->dma->CTRLA |= DMA_CH_ENABLE_bm; } - - // Setup special interrupt for X-axis mapping - M1_TIMER.INTCTRLB = TC_CCAINTLVL_HI_gc; } @@ -234,7 +222,7 @@ int32_t motor_get_encoder(int motor) {return motors[motor].encoder;} void motor_set_encoder(int motor, float encoder) { - if (st_is_busy()) ALARM(STAT_INTERNAL_ERROR); + //if (st_is_busy()) ALARM(STAT_INTERNAL_ERROR); TODO motor_t *m = &motors[motor]; m->encoder = m->position = m->commanded = round(encoder); @@ -337,7 +325,7 @@ void motor_error_callback(int motor, motor_flags_t errors) { m->flags |= errors; report_request(); - if (false && motor_error(motor)) { + if (motor_error(motor)) { if (m->flags & MOTOR_FLAG_STALLED_bm) ALARM(STAT_MOTOR_STALLED); if (m->flags & MOTOR_FLAG_OVERTEMP_WARN_bm) ALARM(STAT_MOTOR_OVERTEMP_WARN); if (m->flags & MOTOR_FLAG_OVERTEMP_bm) ALARM(STAT_MOTOR_OVERTEMP); @@ -381,11 +369,6 @@ void motor_load_move(int motor) { else OUTSET_PIN(m->dir_pin); // Accumulate encoder - // TODO we currently accumulate the x-axis here - if (!motor) { - steps = m->steps; - m->steps = 0; - } if (!m->wasEnabled) steps = 0; m->encoder += m->last_negative ? -(int32_t)steps : steps; diff --git a/src/tmc2660.c b/src/tmc2660.c index 59382e6..3252845 100644 --- a/src/tmc2660.c +++ b/src/tmc2660.c @@ -300,7 +300,7 @@ void tmc2660_init() { DIRSET_PIN(TMC2660_SPI_SS_PIN); // Output OUTSET_PIN(TMC2660_SPI_SCK_PIN); // High DIRSET_PIN(TMC2660_SPI_SCK_PIN); // Output - DIRCLR_PIN(TMC2660_SPI_MISO_PIN); // Intput + DIRCLR_PIN(TMC2660_SPI_MISO_PIN); // Input OUTSET_PIN(TMC2660_SPI_MOSI_PIN); // High DIRSET_PIN(TMC2660_SPI_MOSI_PIN); // Output