TMCStepper
TMC5130Stepper.cpp
Go to the documentation of this file.
1 #include "TMCStepper.h"
2 #include "TMC_MACROS.h"
3 
4 TMC5130Stepper::TMC5130Stepper(uint16_t pinCS, float RS, int8_t link) : TMC2160Stepper(pinCS, RS, link)
5  { defaults(); }
6 TMC5130Stepper::TMC5130Stepper(uint16_t pinCS, float RS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK, int8_t link):
7  TMC2160Stepper(pinCS, RS, pinMOSI, pinMISO, pinSCK, link)
8  { defaults(); }
9 TMC5130Stepper::TMC5130Stepper(uint16_t pinCS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK, int8_t link) :
10  TMC2160Stepper(pinCS, default_RS, pinMOSI, pinMISO, pinSCK, link)
11  { defaults(); }
12 
15 
16  XTARGET(0);
17  XACTUAL(0);
18  //while (( RAMP_STAT() & cfg.VZERO_bm) != cfg.VZERO_bm) {}
19 }
20 
22  OUTPUT_register.sr = 1;
23  ENC_CONST_register.sr = 65536;
24  //MSLUT0_register.sr = ???;
25  //MSLUT1_register.sr = ???;
26  //MSLUT2_register.sr = ???;
27  //MSLUT3_register.sr = ???;
28  //MSLUT4_register.sr = ???;
29  //MSLUT5_register.sr = ???;
30  //MSLUT6_register.sr = ???;
31  //MSLUT7_register.sr = ???;
32  //MSLUTSEL_register.sr = ???;
33  //MSLUTSTART_register.start_sin = 0;
34  //MSLUTSTART_register.start_sin90 = 247;
35  PWMCONF_register.sr = 0x00050480;
36 }
37 
39  IHOLD_IRUN(IHOLD_IRUN_register.sr);
40  TPOWERDOWN(TPOWERDOWN_register.sr);
41  TPWMTHRS(TPWMTHRS_register.sr);
42  GCONF(GCONF_register.sr);
43  TCOOLTHRS(TCOOLTHRS_register.sr);
44  THIGH(THIGH_register.sr);
45  XDIRECT(XDIRECT_register.sr);
46  VDCMIN(VDCMIN_register.sr);
47  CHOPCONF(CHOPCONF_register.sr);
48  COOLCONF(COOLCONF_register.sr);
49  DCCTRL(DCCTRL_register.sr);
50  PWMCONF(PWMCONF_register.sr);
51  ENCM_CTRL(ENCM_CTRL_register.sr);
52  DRV_CONF(DRV_CONF_register.sr);
53  SLAVECONF(SLAVECONF_register.sr);
54  TMC_OUTPUT(OUTPUT_register.sr);
55  X_COMPARE(X_COMPARE_register.sr);
56  RAMPMODE(RAMPMODE_register.sr);
57  XACTUAL(XACTUAL_register.sr);
58  VSTART(VSTART_register.sr);
59  A1(A1_register.sr);
60  V1(V1_register.sr);
61  AMAX(AMAX_register.sr);
62  VMAX(VMAX_register.sr);
63  DMAX(DMAX_register.sr);
64  D1(D1_register.sr);
65  VSTOP(VSTOP_register.sr);
66  TZEROWAIT(TZEROWAIT_register.sr);
67  SW_MODE(SW_MODE_register.sr);
68  ENCMODE(ENCMODE_register.sr);
69  ENC_CONST(ENC_CONST_register.sr);
70 }
71 
73 // R: IFCNT
76 // W: SLAVECONF
77 uint16_t TMC5130Stepper::SLAVECONF() { return SLAVECONF_register.sr; }
78 void TMC5130Stepper::SLAVECONF(uint16_t input) {
79  SLAVECONF_register.sr = input;
80  write(SLAVECONF_register.address, SLAVECONF_register.sr);
81 }
83 // R: IOIN
86 }
87 bool TMC5130Stepper::refl_step() { TMC5130_n::IOIN_t r{0}; r.sr = IOIN(); return r.refl_step; }
88 bool TMC5130Stepper::refr_dir() { TMC5130_n::IOIN_t r{0}; r.sr = IOIN(); return r.refr_dir; }
89 bool TMC5130Stepper::encb_dcen_cfg4() { TMC5130_n::IOIN_t r{0}; r.sr = IOIN(); return r.encb_dcen_cfg4; }
90 bool TMC5130Stepper::enca_dcin_cfg5() { TMC5130_n::IOIN_t r{0}; r.sr = IOIN(); return r.enca_dcin_cfg5; }
91 bool TMC5130Stepper::drv_enn_cfg6() { TMC5130_n::IOIN_t r{0}; r.sr = IOIN(); return r.drv_enn_cfg6; }
92 bool TMC5130Stepper::enc_n_dco() { TMC5130_n::IOIN_t r{0}; r.sr = IOIN(); return r.enc_n_dco; }
93 bool TMC5130Stepper::sd_mode() { TMC5130_n::IOIN_t r{0}; r.sr = IOIN(); return r.sd_mode; }
94 bool TMC5130Stepper::swcomp_in() { TMC5130_n::IOIN_t r{0}; r.sr = IOIN(); return r.swcomp_in; }
95 uint8_t TMC5130Stepper::version() { TMC5130_n::IOIN_t r{0}; r.sr = IOIN(); return r.version; }
97 // W: OUTPUT
98 bool TMC5130Stepper::TMC_OUTPUT() { return OUTPUT_register.sr; }
99 void TMC5130Stepper::TMC_OUTPUT(bool input) {
100  OUTPUT_register.sr = input;
101  write(OUTPUT_register.address, OUTPUT_register.sr);
102 }
104 // W: X_COMPARE
105 uint32_t TMC5130Stepper::X_COMPARE() { return X_COMPARE_register.sr; }
106 void TMC5130Stepper::X_COMPARE(uint32_t input) {
107  X_COMPARE_register.sr = input;
108  write(X_COMPARE_register.address, X_COMPARE_register.sr);
109 }
111 // RW: RAMPMODE
112 uint8_t TMC5130Stepper::RAMPMODE() { return read(RAMPMODE_register.address); }
113 void TMC5130Stepper::RAMPMODE(uint8_t input) {
114  RAMPMODE_register.sr = input;
115  write(RAMPMODE_register.address, RAMPMODE_register.sr);
116 }
118 // RW: XACTUAL
119 int32_t TMC5130Stepper::XACTUAL() { return read(XACTUAL_register.address); }
120 void TMC5130Stepper::XACTUAL(int32_t input) {
121  write(XACTUAL_register.address, input);
122 }
124 // R: VACTUAL
126  uint32_t int24 = read(VACTUAL_t::address);
127  if((int24 >> 23) & 0x01) {
128  int24 |= 0xFF000000;
129  }
130  return int24;
131 }
133 // W: VSTART
134 uint32_t TMC5130Stepper::VSTART() { return VSTART_register.sr; }
135 void TMC5130Stepper::VSTART(uint32_t input) {
136  VSTART_register.sr = input;
137  write(VSTART_register.address, VSTART_register.sr);
138 }
140 // W: A1
141 uint16_t TMC5130Stepper::A1() { return A1_register.sr; }
142 void TMC5130Stepper::A1(uint16_t input) {
143  A1_register.sr = input;
144  write(A1_register.address, A1_register.sr);
145 }
147 // W: V1
148 uint32_t TMC5130Stepper::V1() { return V1_register.sr; }
149 void TMC5130Stepper::V1(uint32_t input) {
150  V1_register.sr = input;
151  write(V1_register.address, V1_register.sr);
152 }
154 // W: AMAX
155 uint16_t TMC5130Stepper::AMAX() { return AMAX_register.sr; }
156 void TMC5130Stepper::AMAX(uint16_t input) {
157  AMAX_register.sr = input;
158  write(AMAX_register.address, AMAX_register.sr);
159 }
161 // W: VMAX
162 uint32_t TMC5130Stepper::VMAX() { return VMAX_register.sr; }
163 void TMC5130Stepper::VMAX(uint32_t input) {
164  VMAX_register.sr = input;
165  write(VMAX_register.address, VMAX_register.sr);
166 }
168 // W: DMAX
169 uint16_t TMC5130Stepper::DMAX() { return DMAX_register.sr; }
170 void TMC5130Stepper::DMAX(uint16_t input) {
171  DMAX_register.sr = input;
172  write(DMAX_register.address, DMAX_register.sr);
173 }
175 // W: D1
176 uint16_t TMC5130Stepper::D1() { return D1_register.sr; }
177 void TMC5130Stepper::D1(uint16_t input) {
178  D1_register.sr = input;
179  write(D1_register.address, D1_register.sr);
180 }
182 // W: VSTOP
183 uint32_t TMC5130Stepper::VSTOP() { return VSTOP_register.sr; }
184 void TMC5130Stepper::VSTOP(uint32_t input) {
185  if (input == 0 && RAMPMODE() == 0) return;
186  VSTOP_register.sr = input;
187  write(VSTOP_register.address, VSTOP_register.sr);
188 }
190 // W: TZEROWAIT
191 uint16_t TMC5130Stepper::TZEROWAIT() { return TZEROWAIT_register.sr; }
192 void TMC5130Stepper::TZEROWAIT(uint16_t input) {
193  TZEROWAIT_register.sr = input;
194  write(TZEROWAIT_register.address, TZEROWAIT_register.sr);
195 }
197 // RW: XTARGET
199 void TMC5130Stepper::XTARGET(int32_t input) {
200  write(XTARGET_t::address, input);
201 }
203 // R: XLATCH
206 // RW: X_ENC
208 void TMC5130Stepper::X_ENC(int32_t input) {
209  write(X_ENC_t::address, input);
210 }
212 // W: ENC_CONST
213 uint32_t TMC5130Stepper::ENC_CONST() { return ENC_CONST_register.sr; }
214 void TMC5130Stepper::ENC_CONST(uint32_t input) {
215  ENC_CONST_register.sr = input;
216  write(ENC_CONST_register.address, ENC_CONST_register.sr);
217 }
219 // R: ENC_STATUS
222 // R: ENC_LATCH
TMC5130Stepper::X_COMPARE
uint32_t X_COMPARE()
Definition: TMC5130Stepper.cpp:105
TMC5130Stepper::XACTUAL
int32_t XACTUAL()
Definition: TMC5130Stepper.cpp:119
TMC5130Stepper::XTARGET
int32_t XTARGET()
Definition: TMC5130Stepper.cpp:198
TMC5130Stepper::sd_mode
bool sd_mode()
Definition: TMC5130Stepper.cpp:93
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
TMC5130Stepper::ENC_LATCH
uint32_t ENC_LATCH()
Definition: TMC5130Stepper.cpp:223
TMC2130Stepper::ENCM_CTRL
uint8_t ENCM_CTRL()
Definition: TMC2130Stepper.cpp:302
TMC5130Stepper::TMC5130Stepper
TMC5130Stepper(uint16_t pinCS, float RS=default_RS, int8_t link_index=-1)
Definition: TMC5130Stepper.cpp:4
TMC5130Stepper::IFCNT
uint8_t IFCNT()
Definition: TMC5130Stepper.cpp:74
TMC5130Stepper::push
void push()
Definition: TMC5130Stepper.cpp:38
TMC5130Stepper::version
uint8_t version()
Definition: TMC5130Stepper.cpp:95
TMC2130Stepper::DCCTRL
uint32_t DCCTRL()
Definition: TMC2130Stepper.cpp:284
TMC5130Stepper::RAMPMODE
uint8_t RAMPMODE()
Definition: TMC5130Stepper.cpp:112
TMC5130Stepper::defaults
void defaults()
Definition: TMC5130Stepper.cpp:21
TMC5130Stepper::TZEROWAIT
uint16_t TZEROWAIT()
Definition: TMC5130Stepper.cpp:191
TMC2130Stepper::COOLCONF
uint32_t COOLCONF()
Definition: COOLCONF.cpp:8
TMC2160Stepper
Definition: TMCStepper.h:360
TMC5130Stepper::VACTUAL
int32_t VACTUAL()
Definition: TMC5130Stepper.cpp:125
TMCStepper.h
TMC5130Stepper::SW_MODE
uint32_t SW_MODE()
Definition: SW_MODE.cpp:8
TMC5130Stepper::IFCNT_t::address
constexpr static uint8_t address
Definition: TMCStepper.h:654
TMC2130Stepper::VDCMIN
uint32_t VDCMIN()
Definition: TMC2130Stepper.cpp:264
TMC5130Stepper::IOIN
uint32_t IOIN()
Definition: TMC5130Stepper.cpp:84
TMC2160Stepper::PWMCONF
uint32_t PWMCONF()
Definition: PWMCONF.cpp:28
TMC5130Stepper::X_ENC_t::address
constexpr static uint8_t address
Definition: TMCStepper.h:658
TMC2130Stepper::read
uint32_t read(uint8_t addressByte)
Definition: TMC2130Stepper.cpp:65
TMC5130Stepper::refr_dir
bool refr_dir()
Definition: TMC5130Stepper.cpp:88
TMC5130Stepper::enca_dcin_cfg5
bool enca_dcin_cfg5()
Definition: TMC5130Stepper.cpp:90
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
TMC5130Stepper::encb_dcen_cfg4
bool encb_dcen_cfg4()
Definition: TMC5130Stepper.cpp:89
TMC2130Stepper::CHOPCONF
uint32_t CHOPCONF()
Definition: CHOPCONF.cpp:7
TMC2160Stepper::begin
void begin()
Definition: TMC2160Stepper.cpp:13
TMC5130_n::IOIN_t
Definition: TMC5130_bitfields.h:16
TMC5130Stepper::A1
uint16_t A1()
Definition: TMC5130Stepper.cpp:141
TMC5130Stepper::ENC_LATCH_t::address
constexpr static uint8_t address
Definition: TMCStepper.h:660
TMC5130_n::IOIN_t::sr
uint32_t sr
Definition: TMC5130_bitfields.h:19
TMC5130Stepper::SLAVECONF
uint16_t SLAVECONF()
Definition: TMC5130Stepper.cpp:77
TMC5130Stepper::VMAX
uint32_t VMAX()
Definition: TMC5130Stepper.cpp:162
TMC5130Stepper::ENC_STATUS
bool ENC_STATUS()
Definition: TMC5130Stepper.cpp:220
TMC5130Stepper::ENC_CONST
uint32_t ENC_CONST()
Definition: TMC5130Stepper.cpp:213
TMC5130Stepper::XTARGET_t::address
constexpr static uint8_t address
Definition: TMCStepper.h:656
TMCStepper::TPOWERDOWN
uint8_t TPOWERDOWN()
Definition: TMCStepper.cpp:123
TMC5130Stepper::XLATCH_t::address
constexpr static uint8_t address
Definition: TMCStepper.h:657
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
TMC5130Stepper::enc_n_dco
bool enc_n_dco()
Definition: TMC5130Stepper.cpp:92
TMC5130_n::IOIN_t::address
constexpr static uint8_t address
Definition: TMC5130_bitfields.h:17
TMC5130Stepper::XLATCH
uint32_t XLATCH()
Definition: TMC5130Stepper.cpp:204
TMC2130Stepper::write
void write(uint8_t addressByte, uint32_t config)
Definition: TMC2130Stepper.cpp:148
TMC5130Stepper::drv_enn_cfg6
bool drv_enn_cfg6()
Definition: TMC5130Stepper.cpp:91
TMC5130Stepper::VACTUAL_t::address
constexpr static uint8_t address
Definition: TMCStepper.h:655
TMC5130Stepper::ENCMODE
uint32_t ENCMODE()
Definition: ENCMODE.cpp:8
TMC5130Stepper::swcomp_in
bool swcomp_in()
Definition: TMC5130Stepper.cpp:94
TMC5130Stepper::refl_step
bool refl_step()
Definition: TMC5130Stepper.cpp:87
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
TMC5130Stepper::X_ENC
int32_t X_ENC()
Definition: TMC5130Stepper.cpp:207
TMC2130Stepper::XDIRECT
uint32_t XDIRECT()
Definition: TMC2130Stepper.cpp:251
TMC5130Stepper::begin
void begin()
Definition: TMC5130Stepper.cpp:13