Skip to content

Commit

Permalink
Spindle sync update
Browse files Browse the repository at this point in the history
Support external clock input on TI1FP1 or ETR pins.
Enable software pullup on external clock input.

Board map fix for prototype Octave board.
  • Loading branch information
dresco committed Aug 5, 2024
1 parent cb1bb13 commit a54f076
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
11 changes: 6 additions & 5 deletions Inc/dresco_octave_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,13 @@
#define MOTOR_FAULT_PIN AUXINPUT5_PIN
#endif

// Spindle encoder pins.
// Spindle encoder pins (index pin that must be interrupt capable).
#if SPINDLE_ENCODER_ENABLE
#define SPINDLE_INDEX_PORT GPIOB
#define SPINDLE_INDEX_PIN 4
#define SPINDLE_PULSE_PORT GPIOG
#define SPINDLE_PULSE_PIN 14
#define SPINDLE_INDEX_PORT GPIOG
#define SPINDLE_INDEX_PIN 14
#define SPINDLE_PULSE_PORT GPIOB
#define SPINDLE_PULSE_PIN 4
#define SPINDLE_ENCODER_CLK 1
#endif

#define CAN_PORT GPIOD
Expand Down
13 changes: 11 additions & 2 deletions Src/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
#include "grbl/spindle_sync.h"

#define RPM_TIMER_RESOLUTION 1
#define RPM_TIMER_COUNT RPM_TIMER->CNT

static spindle_data_t spindle_data;
static spindle_sync_t spindle_tracker;
Expand Down Expand Up @@ -2020,8 +2021,16 @@ static bool driver_setup (settings_t *settings)
RPM_TIMER->CR1 |= TIM_CR1_CEN;

RPM_COUNTER_CLKEN();
// RPM_COUNTER->SMCR = TIM_SMCR_SMS_0|TIM_SMCR_SMS_1|TIM_SMCR_SMS_2|TIM_SMCR_ETF_2|TIM_SMCR_ETF_3|TIM_SMCR_TS_0|TIM_SMCR_TS_1|TIM_SMCR_TS_2;

#if SPINDLE_ENCODER_CLK == 1 // External clock mode 1 (TI1FP1 pin)
RPM_COUNTER->SMCR = TIM_SMCR_SMS_0|TIM_SMCR_SMS_1|TIM_SMCR_SMS_2|TIM_SMCR_ETF_2|TIM_SMCR_ETF_3|TIM_SMCR_TS_0|TIM_SMCR_TS_2;
#elif SPINDLE_ENCODER_CLK == 2 // External clock mode 2 (ETR pin)
RPM_COUNTER->SMCR = TIM_SMCR_ECE;
#else
#error Spindle encoder clock mode not defined
#endif


RPM_COUNTER->PSC = 0;
RPM_COUNTER->ARR = 65535;
RPM_COUNTER->DIER = TIM_DIER_CC1IE;
Expand All @@ -2030,7 +2039,7 @@ static bool driver_setup (settings_t *settings)

GPIO_Init.Mode = GPIO_MODE_AF_PP;
GPIO_Init.Pin = SPINDLE_PULSE_BIT;
GPIO_Init.Pull = GPIO_NOPULL;
GPIO_Init.Pull = GPIO_PULLUP;
GPIO_Init.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_Init.Alternate = GPIO_AF2_TIM3;
HAL_GPIO_Init(SPINDLE_PULSE_PORT, &GPIO_Init);
Expand Down

0 comments on commit a54f076

Please sign in to comment.