2017-06-29 16:35:43 +00:00
|
|
|
#ifndef TMC2130_H
|
|
|
|
#define TMC2130_H
|
|
|
|
|
2017-07-12 15:36:50 +00:00
|
|
|
|
2017-07-03 05:43:50 +00:00
|
|
|
//mode
|
|
|
|
extern uint8_t tmc2130_mode;
|
2017-07-01 10:39:16 +00:00
|
|
|
//holding and running currents
|
|
|
|
extern uint8_t tmc2130_current_h[4];
|
|
|
|
extern uint8_t tmc2130_current_r[4];
|
2018-02-15 03:17:58 +00:00
|
|
|
//microstep resolution (0 means 256usteps, 8 means 1ustep
|
|
|
|
extern uint8_t tmc2130_mres[4];
|
2017-09-22 17:28:32 +00:00
|
|
|
|
2018-02-15 03:17:58 +00:00
|
|
|
//flags for axis stall detection
|
2017-09-25 23:43:56 +00:00
|
|
|
extern uint8_t tmc2130_sg_thr[4];
|
2017-09-22 17:28:32 +00:00
|
|
|
|
2017-09-23 13:01:31 +00:00
|
|
|
extern bool tmc2130_sg_stop_on_crash;
|
2018-01-30 12:10:36 +00:00
|
|
|
extern uint8_t tmc2130_sg_crash; //crash mask
|
2017-07-01 10:39:16 +00:00
|
|
|
|
2017-11-27 03:46:58 +00:00
|
|
|
extern uint8_t tmc2130_sg_meassure;
|
2018-03-01 13:34:21 +00:00
|
|
|
extern uint32_t tmc2130_sg_meassure_cnt;
|
2017-11-27 03:46:58 +00:00
|
|
|
extern uint32_t tmc2130_sg_meassure_val;
|
2017-07-01 10:39:16 +00:00
|
|
|
|
2018-04-03 16:26:39 +00:00
|
|
|
extern uint8_t tmc2130_sg_homing_axes_mask;
|
|
|
|
|
2017-07-03 05:43:50 +00:00
|
|
|
#define TMC2130_MODE_NORMAL 0
|
|
|
|
#define TMC2130_MODE_SILENT 1
|
2017-07-01 10:39:16 +00:00
|
|
|
|
2018-04-03 10:30:35 +00:00
|
|
|
#define TMC2130_WAVE_FAC1000_MIN 30
|
|
|
|
#define TMC2130_WAVE_FAC1000_MAX 200
|
2018-03-22 18:53:58 +00:00
|
|
|
#define TMC2130_WAVE_FAC1000_STP 1
|
2018-02-15 03:17:58 +00:00
|
|
|
|
2019-06-18 15:11:01 +00:00
|
|
|
#define TMC2130_MINIMUM_PULSE 0 // minimum pulse width in uS
|
|
|
|
#define TMC2130_SET_DIR_DELAY 20 // minimum delay after setting direction in uS
|
|
|
|
#define TMC2130_SET_PWR_DELAY 0 // minimum delay after changing pwr mode in uS
|
|
|
|
|
2021-01-26 18:37:14 +00:00
|
|
|
#ifdef TMC2130_DEDGE_STEPPING
|
2021-01-26 14:59:21 +00:00
|
|
|
#define TMC2130_MINIMUM_DELAY //NOP
|
2021-01-26 18:37:14 +00:00
|
|
|
#elif TMC2130_MINIMUM_PULSE == 0
|
|
|
|
#define TMC2130_MINIMUM_DELAY asm("nop")
|
2021-01-26 14:59:21 +00:00
|
|
|
#else
|
|
|
|
#define TMC2130_MINIMUM_DELAY delayMicroseconds(TMC2130_MINIMUM_PULSE)
|
|
|
|
#endif
|
|
|
|
|
2018-02-15 03:17:58 +00:00
|
|
|
extern uint8_t tmc2130_home_enabled;
|
|
|
|
extern uint8_t tmc2130_home_origin[2];
|
|
|
|
extern uint8_t tmc2130_home_bsteps[2];
|
|
|
|
extern uint8_t tmc2130_home_fsteps[2];
|
|
|
|
|
2018-04-03 10:30:35 +00:00
|
|
|
extern uint8_t tmc2130_wave_fac[4];
|
2018-02-15 03:17:58 +00:00
|
|
|
|
2018-07-09 14:44:10 +00:00
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uint8_t toff:4;
|
|
|
|
uint8_t hstr:3;
|
|
|
|
uint8_t hend:4;
|
|
|
|
uint8_t tbl:2;
|
|
|
|
uint8_t res:3;
|
|
|
|
} tmc2130_chopper_config_t;
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
extern tmc2130_chopper_config_t tmc2130_chopper_config[4];
|
2018-02-15 03:17:58 +00:00
|
|
|
|
2017-07-01 10:39:16 +00:00
|
|
|
//initialize tmc2130
|
2019-07-16 15:31:56 +00:00
|
|
|
#ifdef PSU_Delta
|
2019-06-05 17:22:04 +00:00
|
|
|
extern void tmc2130_init(bool bSupressFlag=false);
|
2019-07-16 15:31:56 +00:00
|
|
|
#else
|
|
|
|
extern void tmc2130_init();
|
|
|
|
#endif
|
2017-09-22 17:28:32 +00:00
|
|
|
//check diag pins (called from stepper isr)
|
2018-08-07 14:32:32 +00:00
|
|
|
extern void tmc2130_st_isr();
|
2017-07-01 10:39:16 +00:00
|
|
|
//update stall guard (called from st_synchronize inside the loop)
|
|
|
|
extern bool tmc2130_update_sg();
|
|
|
|
//temperature watching (called from )
|
|
|
|
extern void tmc2130_check_overtemp();
|
|
|
|
//enter homing (called from homeaxis before homing starts)
|
2017-07-12 15:36:50 +00:00
|
|
|
extern void tmc2130_home_enter(uint8_t axes_mask);
|
2017-07-01 10:39:16 +00:00
|
|
|
//exit homing (called from homeaxis after homing ends)
|
|
|
|
extern void tmc2130_home_exit();
|
|
|
|
|
2017-11-27 03:46:58 +00:00
|
|
|
//start stallguard meassuring for single axis
|
|
|
|
extern void tmc2130_sg_meassure_start(uint8_t axis);
|
|
|
|
//stop current stallguard meassuring and report result
|
|
|
|
extern uint16_t tmc2130_sg_meassure_stop();
|
|
|
|
|
2018-07-09 14:44:10 +00:00
|
|
|
extern void tmc2130_setup_chopper(uint8_t axis, uint8_t mres, uint8_t current_h, uint8_t current_r);
|
2017-11-27 03:46:58 +00:00
|
|
|
|
2017-07-03 08:39:56 +00:00
|
|
|
//set holding current for any axis (M911)
|
2017-07-01 10:39:16 +00:00
|
|
|
extern void tmc2130_set_current_h(uint8_t axis, uint8_t current);
|
2017-07-03 08:39:56 +00:00
|
|
|
//set running current for any axis (M912)
|
2017-07-01 10:39:16 +00:00
|
|
|
extern void tmc2130_set_current_r(uint8_t axis, uint8_t current);
|
2017-07-03 08:39:56 +00:00
|
|
|
//print currents (M913)
|
2017-07-01 10:39:16 +00:00
|
|
|
extern void tmc2130_print_currents();
|
|
|
|
|
2017-07-06 11:06:07 +00:00
|
|
|
//set PWM_AMPL for any axis (M917)
|
|
|
|
extern void tmc2130_set_pwm_ampl(uint8_t axis, uint8_t pwm_ampl);
|
|
|
|
//set PWM_GRAD for any axis (M918)
|
|
|
|
extern void tmc2130_set_pwm_grad(uint8_t axis, uint8_t pwm_ampl);
|
|
|
|
|
2017-07-03 08:39:56 +00:00
|
|
|
|
2018-02-15 03:17:58 +00:00
|
|
|
extern uint16_t tmc2130_rd_MSCNT(uint8_t axis);
|
|
|
|
extern uint32_t tmc2130_rd_MSCURACT(uint8_t axis);
|
|
|
|
|
2018-02-15 14:40:49 +00:00
|
|
|
extern uint8_t tmc2130_usteps2mres(uint16_t usteps);
|
|
|
|
#define tmc2130_mres2usteps(mres) ((uint16_t)256 >> mres)
|
2017-07-12 15:36:50 +00:00
|
|
|
|
2017-09-26 10:22:58 +00:00
|
|
|
extern bool tmc2130_wait_standstill_xy(int timeout);
|
2017-09-23 18:01:37 +00:00
|
|
|
|
2018-02-15 03:17:58 +00:00
|
|
|
extern uint16_t tmc2130_get_res(uint8_t axis);
|
2018-02-15 14:40:49 +00:00
|
|
|
extern void tmc2130_set_res(uint8_t axis, uint16_t res);
|
2018-02-15 03:17:58 +00:00
|
|
|
extern uint8_t tmc2130_get_pwr(uint8_t axis);
|
|
|
|
extern void tmc2130_set_pwr(uint8_t axis, uint8_t pwr);
|
|
|
|
extern uint8_t tmc2130_get_inv(uint8_t axis);
|
|
|
|
extern uint8_t tmc2130_get_dir(uint8_t axis);
|
|
|
|
extern void tmc2130_set_dir(uint8_t axis, uint8_t dir);
|
|
|
|
extern void tmc2130_do_step(uint8_t axis);
|
|
|
|
extern void tmc2130_do_steps(uint8_t axis, uint16_t steps, uint8_t dir, uint16_t delay_us);
|
|
|
|
extern void tmc2130_goto_step(uint8_t axis, uint8_t step, uint8_t dir, uint16_t delay_us, uint16_t microstep_resolution);
|
|
|
|
extern void tmc2130_get_wave(uint8_t axis, uint8_t* data, FILE* stream);
|
2018-04-03 10:30:35 +00:00
|
|
|
extern void tmc2130_set_wave(uint8_t axis, uint8_t amp, uint8_t fac1000);
|
2018-02-15 03:17:58 +00:00
|
|
|
|
2018-02-22 19:50:34 +00:00
|
|
|
extern bool tmc2130_home_calibrate(uint8_t axis);
|
2018-02-15 03:17:58 +00:00
|
|
|
|
2018-11-12 19:39:25 +00:00
|
|
|
extern uint8_t tmc2130_cur2val(float cur);
|
|
|
|
extern float tmc2130_val2cur(uint8_t val);
|
|
|
|
|
2018-03-22 18:53:58 +00:00
|
|
|
#endif //TMC2130_H
|