TMCStepper
TMC5160Stepper.cpp
Go to the documentation of this file.
1 #include "TMCStepper.h"
2 #include "TMC_MACROS.h"
3 
4 TMC5160Stepper::TMC5160Stepper(uint16_t pinCS, float RS, int8_t link) : TMC5130Stepper(pinCS, RS, link)
5  { defaults(); }
6 TMC5160Stepper::TMC5160Stepper(uint16_t pinCS, float RS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK, int8_t link) :
7  TMC5130Stepper(pinCS, RS, pinMOSI, pinMISO, pinSCK, link)
8  { defaults(); }
9 TMC5160Stepper::TMC5160Stepper(uint16_t pinCS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK, int8_t link) :
10  TMC5130Stepper(pinCS, default_RS, pinMOSI, pinMISO, pinSCK, link)
11  { defaults(); }
12 
14  SHORT_CONF_register.s2vs_level = 6;
15  SHORT_CONF_register.s2g_level = 6;
16  SHORT_CONF_register.shortfilter = 0b01;
17  SHORT_CONF_register.shortdelay = 0;
18  DRV_CONF_register.bbmtime = 0;
19  DRV_CONF_register.bbmclks = 4;
20  DRV_CONF_register.otselect = 0b00;
21  DRV_CONF_register.drvstrength = 0b10;
22  DRV_CONF_register.filt_isense = 0b00;
23  TPOWERDOWN_register.sr = 10;
24  VSTOP_register.sr = 1;
25  ENC_CONST_register.sr = 65536;
26  //MSLUT0_register.sr = ???;
27  //MSLUT1_register.sr = ???;
28  //MSLUT2_register.sr = ???;
29  //MSLUT3_register.sr = ???;
30  //MSLUT4_register.sr = ???;
31  //MSLUT5_register.sr = ???;
32  //MSLUT6_register.sr = ???;
33  //MSLUT7_register.sr = ???;
34  //MSLUTSEL_register.sr = ???;
35  //MSLUTSTART_register.start_sin = 0;
36  //MSLUTSTART_register.start_sin90 = 247;
37  CHOPCONF_register.sr = 0x10410150;
38  PWMCONF_register.sr = 0xC40C001E;
39 }
40 
42  IHOLD_IRUN(IHOLD_IRUN_register.sr);
43  TPOWERDOWN(TPOWERDOWN_register.sr);
44  TPWMTHRS(TPWMTHRS_register.sr);
45  GCONF(GCONF_register.sr);
46  TCOOLTHRS(TCOOLTHRS_register.sr);
47  THIGH(THIGH_register.sr);
48  XDIRECT(XDIRECT_register.sr);
49  VDCMIN(VDCMIN_register.sr);
50  CHOPCONF(CHOPCONF_register.sr);
51  COOLCONF(COOLCONF_register.sr);
52  DCCTRL(DCCTRL_register.sr);
53  PWMCONF(PWMCONF_register.sr);
54  SHORT_CONF(SHORT_CONF_register.sr);
55  DRV_CONF(DRV_CONF_register.sr);
56  GLOBAL_SCALER(GLOBAL_SCALER_register.sr);
57  SLAVECONF(SLAVECONF_register.sr);
58  TMC_OUTPUT(OUTPUT_register.sr);
59  X_COMPARE(X_COMPARE_register.sr);
60  RAMPMODE(RAMPMODE_register.sr);
61  XACTUAL(XACTUAL_register.sr);
62  VSTART(VSTART_register.sr);
63  A1(A1_register.sr);
64  V1(V1_register.sr);
65  AMAX(AMAX_register.sr);
66  VMAX(VMAX_register.sr);
67  DMAX(DMAX_register.sr);
68  D1(D1_register.sr);
69  VSTOP(VSTOP_register.sr);
70  TZEROWAIT(TZEROWAIT_register.sr);
71  SW_MODE(SW_MODE_register.sr);
72  ENCMODE(ENCMODE_register.sr);
73  ENC_CONST(ENC_CONST_register.sr);
74  ENC_DEVIATION(ENC_DEVIATION_register.sr);
75 }
76 
77 // R+WC: ENC_STATUS
79 void TMC5160Stepper::ENC_STATUS(uint8_t input) {
80  write(ENC_STATUS_t::address, input & 0x3);
81 }
82 
83 // W: ENC_DEVIATION
84 uint32_t TMC5160Stepper::ENC_DEVIATION() { return ENC_DEVIATION_register.sr; }
85 void TMC5160Stepper::ENC_DEVIATION(uint32_t input) {
86  ENC_DEVIATION_register.sr = input;
87  write(ENC_DEVIATION_register.address, ENC_DEVIATION_register.sr);
88 }
89 
90 // R: PWM_AUTO
92  return read(PWM_AUTO_t::address);
93 }
94 uint8_t TMC5160Stepper::pwm_ofs_auto() { PWM_AUTO_t r{0}; r.sr = PWM_AUTO(); return r.pwm_ofs_auto; }
95 uint8_t TMC5160Stepper::pwm_grad_auto() { PWM_AUTO_t r{0}; r.sr = PWM_AUTO(); return r.pwm_grad_auto; }
TMC5130Stepper::X_COMPARE
uint32_t X_COMPARE()
Definition: TMC5130Stepper.cpp:105
TMC5130Stepper::XACTUAL
int32_t XACTUAL()
Definition: TMC5130Stepper.cpp:119
TMC5160Stepper::TMC5160Stepper
TMC5160Stepper(uint16_t pinCS, float RS=default_RS, int8_t link_index=-1)
Definition: TMC5160Stepper.cpp:4
PWM_AUTO_t::sr
uint32_t sr
Definition: TMC5160_bitfields.h:52
TMC2130Stepper::THIGH
uint32_t THIGH()
Definition: TMC2130Stepper.cpp:244
TMC5130Stepper::VSTART
uint32_t VSTART()
Definition: TMC5130Stepper.cpp:134
TMC2160Stepper::DRV_CONF
uint32_t DRV_CONF()
Definition: DRV_CONF.cpp:8
TMC2160Stepper::SHORT_CONF
uint32_t SHORT_CONF()
Definition: SHORT_CONF.cpp:7
TMC2160Stepper::GLOBAL_SCALER
uint8_t GLOBAL_SCALER()
Definition: TMC2160Stepper.cpp:145
TMC5160Stepper::push
void push()
Definition: TMC5160Stepper.cpp:41
TMC2130Stepper::DCCTRL
uint32_t DCCTRL()
Definition: TMC2130Stepper.cpp:284
TMC5160Stepper::ENC_STATUS
uint8_t ENC_STATUS()
Definition: TMC5160Stepper.cpp:78
TMC5130Stepper::RAMPMODE
uint8_t RAMPMODE()
Definition: TMC5130Stepper.cpp:112
TMC5130Stepper::TZEROWAIT
uint16_t TZEROWAIT()
Definition: TMC5130Stepper.cpp:191
TMC2130Stepper::COOLCONF
uint32_t COOLCONF()
Definition: COOLCONF.cpp:8
TMCStepper.h
TMC5130Stepper::SW_MODE
uint32_t SW_MODE()
Definition: SW_MODE.cpp:8
TMC5160Stepper::PWM_AUTO
uint32_t PWM_AUTO()
Definition: TMC5160Stepper.cpp:91
TMC5130Stepper
Definition: TMCStepper.h:459
TMC2130Stepper::VDCMIN
uint32_t VDCMIN()
Definition: TMC2130Stepper.cpp:264
TMC2160Stepper::PWMCONF
uint32_t PWMCONF()
Definition: PWMCONF.cpp:28
PWM_AUTO_t
Definition: TMC5160_bitfields.h:49
TMC2130Stepper::read
uint32_t read(uint8_t addressByte)
Definition: TMC2130Stepper.cpp:65
TMC5130Stepper::V1
uint32_t V1()
Definition: TMC5130Stepper.cpp:148
TMC5130Stepper::TMC_OUTPUT
bool TMC_OUTPUT()
Definition: TMC5130Stepper.cpp:98
TMC2130Stepper::GCONF
uint32_t GCONF()
Definition: GCONF.cpp:7
TMC_MACROS.h
TMC5130Stepper::AMAX
uint16_t AMAX()
Definition: TMC5130Stepper.cpp:155
TMC2130Stepper::CHOPCONF
uint32_t CHOPCONF()
Definition: CHOPCONF.cpp:7
PWM_AUTO_t::address
constexpr static uint8_t address
Definition: TMC5160_bitfields.h:50
TMC5130Stepper::A1
uint16_t A1()
Definition: TMC5130Stepper.cpp:141
TMC5130Stepper::SLAVECONF
uint16_t SLAVECONF()
Definition: TMC5130Stepper.cpp:77
TMC5130Stepper::VMAX
uint32_t VMAX()
Definition: TMC5130Stepper.cpp:162
TMC5130Stepper::ENC_CONST
uint32_t ENC_CONST()
Definition: TMC5130Stepper.cpp:213
TMC5160Stepper::pwm_ofs_auto
uint8_t pwm_ofs_auto()
Definition: TMC5160Stepper.cpp:94
TMC5160Stepper::ENC_DEVIATION
uint32_t ENC_DEVIATION()
Definition: TMC5160Stepper.cpp:84
TMCStepper::TPOWERDOWN
uint8_t TPOWERDOWN()
Definition: TMCStepper.cpp:123
TMC2130Stepper::TCOOLTHRS
uint32_t TCOOLTHRS()
Definition: TMC2130Stepper.cpp:237
TMC5130Stepper::ENC_STATUS_t::address
constexpr static uint8_t address
Definition: TMCStepper.h:659
TMC5130Stepper::D1
uint16_t D1()
Definition: TMC5130Stepper.cpp:176
TMC2130Stepper::write
void write(uint8_t addressByte, uint32_t config)
Definition: TMC2130Stepper.cpp:148
TMC5130Stepper::ENCMODE
uint32_t ENCMODE()
Definition: ENCMODE.cpp:8
TMCStepper::IHOLD_IRUN
uint32_t IHOLD_IRUN()
Definition: IHOLD_IRUN.cpp:8
TMC5130Stepper::DMAX
uint16_t DMAX()
Definition: TMC5130Stepper.cpp:169
TMC5130Stepper::VSTOP
uint32_t VSTOP()
Definition: TMC5130Stepper.cpp:183
TMCStepper::TPWMTHRS
uint32_t TPWMTHRS()
Definition: TMCStepper.cpp:133
TMC5160Stepper::defaults
void defaults()
Definition: TMC5160Stepper.cpp:13
TMC2130Stepper::XDIRECT
uint32_t XDIRECT()
Definition: TMC2130Stepper.cpp:251
TMC5160Stepper::pwm_grad_auto
uint8_t pwm_grad_auto()
Definition: TMC5160Stepper.cpp:95