Prusa3d Marlin fork
Classes | Functions | Variables
tmc2130.cpp File Reference

Classes

union  ChopConfU
 
union  PWMConfU
 

Functions

constexpr uint32_t PWMCONF_REG (uint32_t PWM_AMPL, uint32_t PWM_GRAD, uint32_t PWM_FREQ, uint32_t PWM_AUTO)
 Helper function to set bit shifts in one line.
 
uint16_t tmc2130_rd_TSTEP (uint8_t axis)
 
uint16_t tmc2130_rd_MSCNT (uint8_t axis)
 
uint32_t tmc2130_rd_MSCURACT (uint8_t axis)
 
static void tmc2130_tx (uint8_t axis, uint8_t addr, uint32_t wval)
 
static uint8_t tmc2130_rx (uint8_t axis, uint8_t addr, uint32_t *rval)
 
uint16_t __tcoolthrs (uint8_t axis)
 
static void tmc2130_XYZ_reg_init (uint8_t axis)
 
void tmc2130_init (TMCInitParams params)
 
uint8_t tmc2130_sample_diag ()
 
void tmc2130_st_isr ()
 
void crashdet_use_eeprom_setting ()
 
bool tmc2130_update_sg ()
 
void tmc2130_home_enter (uint8_t axes_mask)
 
void tmc2130_home_exit ()
 
void tmc2130_sg_measure_start (uint8_t axis)
 
uint16_t tmc2130_sg_measure_stop ()
 
bool tmc2130_wait_standstill_xy (int timeout)
 
void tmc2130_check_overtemp ()
 
static constexpr bool getIntpolBit ([[maybe_unused]]const uint8_t axis, const uint8_t mres)
 Helper function to determine the value of the CHOPCONF intpol flag.
 
static void SetCurrents (const uint8_t axis, const MotorCurrents &curr)
 
void tmc2130_setup_chopper (uint8_t axis, uint8_t mres, const MotorCurrents *curr)
 
void tmc2130_print_currents ()
 
void tmc2130_set_pwm_ampl (uint8_t axis, uint8_t pwm_ampl)
 
void tmc2130_set_pwm_grad (uint8_t axis, uint8_t pwm_grad)
 
void tmc2130_wr_MSLUTSTART (uint8_t axis, uint8_t start_sin, uint8_t start_sin90)
 
void tmc2130_wr_MSLUTSEL (uint8_t axis, uint8_t x1, uint8_t x2, uint8_t x3, uint8_t w0, uint8_t w1, uint8_t w2, uint8_t w3)
 
void tmc2130_wr_MSLUT (uint8_t axis, uint8_t i, uint32_t val)
 
uint8_t tmc2130_usteps2mres (uint16_t usteps)
 
void tmc2130_cs_low (uint8_t axis)
 
void tmc2130_cs_high (uint8_t axis)
 
uint16_t tmc2130_get_res (uint8_t axis)
 
void tmc2130_set_res (uint8_t axis, uint16_t res)
 
uint8_t tmc2130_get_pwr (uint8_t axis)
 
void tmc2130_set_pwr (uint8_t axis, uint8_t pwr)
 
uint8_t tmc2130_get_inv (uint8_t axis)
 
uint8_t tmc2130_get_dir (uint8_t axis)
 
void tmc2130_set_dir (uint8_t axis, uint8_t dir)
 
void tmc2130_do_step (uint8_t axis)
 
void tmc2130_do_steps (uint8_t axis, uint16_t steps, uint8_t dir, uint16_t delay_us)
 
void tmc2130_goto_step (uint8_t axis, uint8_t step, uint8_t dir, uint16_t delay_us, uint16_t microstep_resolution)
 
void tmc2130_get_wave (uint8_t axis, uint8_t *data)
 
void tmc2130_set_wave (uint8_t axis, uint8_t amp, uint8_t fac1000)
 
void bubblesort_uint8 (uint8_t *data, uint8_t size, uint8_t *data2)
 
uint8_t clusterize_uint8 (uint8_t *data, uint8_t size, uint8_t *ccnt, uint8_t *cval, uint8_t tol)
 
bool tmc2130_home_calibrate (uint8_t axis)
 
uint8_t tmc2130_cur2val (float cur)
 Translate current to tmc2130 vsense and IHOLD or IRUN. More...
 
float tmc2130_val2cur (uint8_t val)
 

Variables

static constexpr uint8_t default_dedge_bit = 1
 
uint8_t tmc2130_mode = TMC2130_MODE_NORMAL
 
static constexpr uint8_t tmc2130_default_current_h [4] = TMC2130_CURRENTS_H
 
static constexpr uint8_t tmc2130_default_current_r [4] = TMC2130_CURRENTS_R
 
static constexpr uint8_t tmc2130_current_r_home [4] = TMC2130_CURRENTS_R_HOME
 
static constexpr MotorCurrents homing_currents_P[NUM_AXIS] PROGMEM
 
MotorCurrents currents [NUM_AXIS]
 
static constexpr uint32_t PWM_AMPL [NUM_AXIS] = {TMC2130_PWM_AMPL_X, TMC2130_PWM_AMPL_Y, TMC2130_PWM_AMPL_Z, TMC2130_PWM_AMPL_E}
 
static constexpr uint32_t PWM_GRAD [NUM_AXIS] = {TMC2130_PWM_GRAD_X, TMC2130_PWM_GRAD_Y, TMC2130_PWM_GRAD_Z, TMC2130_PWM_GRAD_E}
 
static constexpr uint32_t PWM_FREQ [NUM_AXIS] = {TMC2130_PWM_FREQ_X, TMC2130_PWM_FREQ_Y, TMC2130_PWM_FREQ_Z, TMC2130_PWM_FREQ_E}
 
static constexpr uint32_t PWM_AUTO [NUM_AXIS] = {TMC2130_PWM_AUTO_X, TMC2130_PWM_AUTO_Y, TMC2130_PWM_AUTO_Z, TMC2130_PWM_AUTO_E}
 
static PWMConfU pwmconf [NUM_AXIS]
 
static constexpr PWMConfU pwmconf_Ecool = PWMConfU(PWMCONF_REG(TMC2130_PWM_AMPL_Ecool, TMC2130_PWM_GRAD_Ecool, PWM_FREQ[E_AXIS], TMC2130_PWM_AUTO_Ecool))
 
uint8_t tmc2130_mres [4] = {0, 0, 0, 0}
 
uint8_t tmc2130_sg_thr [4] = {TMC2130_SG_THRS_X, TMC2130_SG_THRS_Y, TMC2130_SG_THRS_Z, TMC2130_SG_THRS_E}
 
static uint8_t tmc2130_sg_thr_home [4] = TMC2130_SG_THRS_HOME
 
uint8_t tmc2130_sg_homing_axes_mask = 0x00
 
static uint8_t tmc2130_sg_measure = 0xff
 
static uint32_t tmc2130_sg_measure_cnt = 0
 
static uint32_t tmc2130_sg_measure_val = 0
 
uint8_t tmc2130_home_enabled = 0
 
uint8_t tmc2130_home_origin [2] = {0, 0}
 
uint8_t tmc2130_home_bsteps [2] = {48, 48}
 
uint8_t tmc2130_home_fsteps [2] = {48, 48}
 
uint8_t tmc2130_wave_fac [4] = {0, 0, 0, 0}
 
tmc2130_chopper_config_t tmc2130_chopper_config [NUM_AXIS]
 
bool tmc2130_sg_stop_on_crash = true
 
uint8_t tmc2130_sg_crash = 0
 
static ShortTimer tmc2130_overtemp_timer
 

Function Documentation

◆ tmc2130_cur2val()

uint8_t tmc2130_cur2val ( float  cur)
Parameters
curcurrent in mA
Returns
0 .. 63
most significant bit is CHOPCONF vsense bit (sense resistor voltage based current scaling)
rest is to be used in IRUN or IHOLD register
mA trinamic register note
0 0 doesn't mean current off, lowest current is 1/32 current with vsense low range
30 1
40 2
60 3
90 4
100 5
120 6
130 7
150 8
180 9
190 10
210 11
230 12
240 13
250 13
260 14
280 15
300 16
320 17
340 18
350 19
370 20
390 21
410 22
430 23
450 24
460 25
480 26
500 27
520 28
535 29
N/D 30 extruder default
540 33
560 34
580 35
590 36 farm mode extruder default
610 37
630 38
640 39
660 40
670 41
690 42
710 43
720 44
730 45
760 46
770 47
790 48
810 49
820 50
840 51
850 52
870 53
890 54
900 55
920 56
940 57
950 58
970 59
980 60
1000 61
1020 62
1029 63

◆ tmc2130_set_pwr()

void tmc2130_set_pwr ( uint8_t  axis,
uint8_t  pwr 
)
pwr motor power
  • 0 disabled
  • non-zero enabled

Variable Documentation

◆ currents

MotorCurrents currents[NUM_AXIS]
Initial value:
= {
MotorCurrents(tmc2130_default_current_r[0], tmc2130_default_current_h[0]),
MotorCurrents(tmc2130_default_current_r[1], tmc2130_default_current_h[1]),
MotorCurrents(tmc2130_default_current_r[2], tmc2130_default_current_h[2]),
MotorCurrents(tmc2130_default_current_r[3], tmc2130_default_current_h[3])
}
Definition: tmc2130.h:62

◆ PROGMEM

const char eMotorCurrentScalingEnabled [] PROGMEM
staticconstexpr
Initial value:
= {
MotorCurrents(tmc2130_current_r_home[0], tmc2130_current_r_home[0]),
MotorCurrents(tmc2130_current_r_home[1], tmc2130_current_r_home[1]),
MotorCurrents(tmc2130_current_r_home[2], tmc2130_current_r_home[2]),
MotorCurrents(tmc2130_current_r_home[3], tmc2130_current_r_home[3])
}

◆ pwmconf

PWMConfU pwmconf[NUM_AXIS]
static
Initial value:
= {
PWMConfU(PWMCONF_REG(PWM_AMPL[X_AXIS], PWM_GRAD[X_AXIS], PWM_FREQ[X_AXIS], PWM_AUTO[X_AXIS])),
PWMConfU(PWMCONF_REG(PWM_AMPL[Y_AXIS], PWM_GRAD[Y_AXIS], PWM_FREQ[Y_AXIS], PWM_AUTO[Y_AXIS])),
PWMConfU(PWMCONF_REG(PWM_AMPL[Z_AXIS], PWM_GRAD[Z_AXIS], PWM_FREQ[Z_AXIS], PWM_AUTO[Z_AXIS])),
PWMConfU(PWMCONF_REG(PWM_AMPL[E_AXIS], PWM_GRAD[E_AXIS], PWM_FREQ[E_AXIS], PWM_AUTO[E_AXIS]))
}
constexpr uint32_t PWMCONF_REG(uint32_t PWM_AMPL, uint32_t PWM_GRAD, uint32_t PWM_FREQ, uint32_t PWM_AUTO)
Helper function to set bit shifts in one line.
Definition: tmc2130.cpp:119
Definition: tmc2130.cpp:99