PyTmcStepper 0.15.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pytmcstepper-0.15.0.dist-info/METADATA +338 -0
- pytmcstepper-0.15.0.dist-info/RECORD +56 -0
- pytmcstepper-0.15.0.dist-info/WHEEL +5 -0
- pytmcstepper-0.15.0.dist-info/licenses/LICENSE +683 -0
- pytmcstepper-0.15.0.dist-info/top_level.txt +1 -0
- tmc_driver/__init__.py +96 -0
- tmc_driver/_tmc_exceptions.py +21 -0
- tmc_driver/_tmc_math.py +122 -0
- tmc_driver/_tmc_stallguard.py +340 -0
- tmc_driver/_tmc_stepperdriver.py +210 -0
- tmc_driver/_tmc_validation.py +29 -0
- tmc_driver/_tmc_xxxx.py +489 -0
- tmc_driver/com/__init__.py +64 -0
- tmc_driver/com/_tmc_com.py +148 -0
- tmc_driver/com/_tmc_com_spi.py +81 -0
- tmc_driver/com/_tmc_com_spi_base.py +159 -0
- tmc_driver/com/_tmc_com_spi_ftdi.py +48 -0
- tmc_driver/com/_tmc_com_spi_micropython.py +99 -0
- tmc_driver/com/_tmc_com_uart.py +113 -0
- tmc_driver/com/_tmc_com_uart_base.py +386 -0
- tmc_driver/com/_tmc_com_uart_micropython.py +115 -0
- tmc_driver/enable_control/__init__.py +55 -0
- tmc_driver/enable_control/_tmc_ec.py +59 -0
- tmc_driver/enable_control/_tmc_ec_pin.py +48 -0
- tmc_driver/enable_control/_tmc_ec_toff.py +30 -0
- tmc_driver/motion_control/__init__.py +111 -0
- tmc_driver/motion_control/_tmc_mc.py +280 -0
- tmc_driver/motion_control/_tmc_mc_int_ramp_generator.py +218 -0
- tmc_driver/motion_control/_tmc_mc_step_dir.py +415 -0
- tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py +78 -0
- tmc_driver/motion_control/_tmc_mc_step_reg.py +36 -0
- tmc_driver/motion_control/_tmc_mc_vactual.py +221 -0
- tmc_driver/platform_utils.py +13 -0
- tmc_driver/reg/__init__.py +0 -0
- tmc_driver/reg/_tmc2209_reg.py +55 -0
- tmc_driver/reg/_tmc220x_reg.py +261 -0
- tmc_driver/reg/_tmc224x_reg.py +414 -0
- tmc_driver/reg/_tmc5160_reg.py +526 -0
- tmc_driver/reg/_tmc_reg.py +202 -0
- tmc_driver/reg/_tmc_shared_regs.py +314 -0
- tmc_driver/tmc_2208.py +17 -0
- tmc_driver/tmc_2209.py +75 -0
- tmc_driver/tmc_220x.py +383 -0
- tmc_driver/tmc_2240.py +340 -0
- tmc_driver/tmc_5160.py +344 -0
- tmc_driver/tmc_gpio/__init__.py +101 -0
- tmc_driver/tmc_gpio/_tmc_gpio_board_base.py +106 -0
- tmc_driver/tmc_gpio/_tmc_gpio_board_ftdi.py +162 -0
- tmc_driver/tmc_gpio/_tmc_gpio_board_gpiozero.py +135 -0
- tmc_driver/tmc_gpio/_tmc_gpio_board_micropython.py +108 -0
- tmc_driver/tmc_gpio/_tmc_gpio_board_periphery.py +87 -0
- tmc_driver/tmc_gpio/_tmc_gpio_board_rpi_gpio.py +182 -0
- tmc_driver/tmc_logger/__init__.py +15 -0
- tmc_driver/tmc_logger/_tmc_logger_base.py +111 -0
- tmc_driver/tmc_logger/_tmc_logger_cpython.py +155 -0
- tmc_driver/tmc_logger/_tmc_logger_micropython.py +52 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# pylint: disable=too-many-instance-attributes
|
|
2
|
+
# pylint: disable=too-many-arguments
|
|
3
|
+
# pylint: disable=too-many-public-methods
|
|
4
|
+
# pylint: disable=too-many-branches
|
|
5
|
+
# pylint: disable=too-many-positional-arguments
|
|
6
|
+
"""
|
|
7
|
+
VActual Motion Control module
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import time
|
|
11
|
+
from ._tmc_mc import TmcMotionControl, MovementAbsRel, StopMode
|
|
12
|
+
from ..tmc_logger import Loglevel
|
|
13
|
+
from .. import _tmc_math as tmc_math
|
|
14
|
+
from ..reg import _tmc_shared_regs as tmc_shared_reg
|
|
15
|
+
from ..platform_utils import get_time_us
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class TmcMotionControlVActual(TmcMotionControl):
|
|
19
|
+
"""VActual Motion Control class"""
|
|
20
|
+
|
|
21
|
+
def __init__(self):
|
|
22
|
+
"""constructor"""
|
|
23
|
+
super().__init__()
|
|
24
|
+
self._starttime: int = 0
|
|
25
|
+
|
|
26
|
+
def make_a_step(self):
|
|
27
|
+
"""method that makes on step"""
|
|
28
|
+
raise NotImplementedError
|
|
29
|
+
|
|
30
|
+
def stop(self, stop_mode=StopMode.HARDSTOP):
|
|
31
|
+
"""stop the current movement
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
stop_mode (enum): whether the movement should be stopped immediately or softly
|
|
35
|
+
(Default value = StopMode.HARDSTOP)
|
|
36
|
+
"""
|
|
37
|
+
super().stop(stop_mode)
|
|
38
|
+
self.set_vactual(0)
|
|
39
|
+
|
|
40
|
+
def run_to_position_steps(
|
|
41
|
+
self, steps, movement_abs_rel: MovementAbsRel | None = None
|
|
42
|
+
) -> StopMode:
|
|
43
|
+
"""runs the motor to the given position.
|
|
44
|
+
with acceleration and deceleration
|
|
45
|
+
blocks the code until finished or stopped from a different thread!
|
|
46
|
+
returns true when the movement if finished normally and false,
|
|
47
|
+
when the movement was stopped
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
steps (int): amount of steps; can be negative
|
|
51
|
+
movement_abs_rel (enum): whether the movement should be absolut or relative
|
|
52
|
+
(Default value = None)
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
stop (enum): how the movement was finished
|
|
56
|
+
"""
|
|
57
|
+
self._tmc_logger.log(
|
|
58
|
+
f"cur: {self._current_pos} | tar: {self._target_pos}", Loglevel.MOVEMENT
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
self._stop = StopMode.NO
|
|
62
|
+
if movement_abs_rel is None:
|
|
63
|
+
movement_abs_rel = self._movement_abs_rel
|
|
64
|
+
|
|
65
|
+
if movement_abs_rel == MovementAbsRel.ABSOLUTE:
|
|
66
|
+
steps = steps - self.current_pos
|
|
67
|
+
|
|
68
|
+
rps = tmc_math.steps_to_rps(self.max_speed_fullstep, self.steps_per_rev)
|
|
69
|
+
self.set_vactual_rps(rps, revolutions=round(steps / self.steps_per_rev))
|
|
70
|
+
|
|
71
|
+
self.current_pos += steps
|
|
72
|
+
return self._stop
|
|
73
|
+
|
|
74
|
+
def set_vactual(self, vactual: int):
|
|
75
|
+
"""sets the register bit "VACTUAL" to to a given value
|
|
76
|
+
VACTUAL allows moving the motor by UART control.
|
|
77
|
+
It gives the motor velocity in +-(2^23)-1 [μsteps / t]
|
|
78
|
+
0: Normal operation. Driver reacts to STEP input
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
vactual (int): value for VACTUAL
|
|
82
|
+
"""
|
|
83
|
+
vactual_reg: tmc_shared_reg.VActual = self.get_register("vactual")
|
|
84
|
+
vactual_reg.modify("vactual", vactual)
|
|
85
|
+
|
|
86
|
+
def set_vactual_dur(
|
|
87
|
+
self,
|
|
88
|
+
vactual,
|
|
89
|
+
duration=0,
|
|
90
|
+
acceleration=0,
|
|
91
|
+
show_stallguard_result=False,
|
|
92
|
+
show_tstep=False,
|
|
93
|
+
) -> StopMode:
|
|
94
|
+
"""sets the register bit "VACTUAL" to to a given value
|
|
95
|
+
VACTUAL allows moving the motor by UART control.
|
|
96
|
+
It gives the motor velocity in +-(2^23)-1 [μsteps / t]
|
|
97
|
+
0: Normal operation. Driver reacts to STEP input
|
|
98
|
+
|
|
99
|
+
Args:
|
|
100
|
+
vactual (int): value for VACTUAL
|
|
101
|
+
duration (int): after this vactual will be set to 0 (Default value = 0)
|
|
102
|
+
acceleration (int): use this for a velocity ramp (Default value = 0)
|
|
103
|
+
show_stallguard_result (bool): prints StallGuard Result during movement
|
|
104
|
+
(Default value = False)
|
|
105
|
+
show_tstep (bool): prints TStep during movement (Default value = False)
|
|
106
|
+
|
|
107
|
+
Returns:
|
|
108
|
+
stop (enum): how the movement was finished
|
|
109
|
+
"""
|
|
110
|
+
self._stop = StopMode.NO
|
|
111
|
+
current_vactual = 0
|
|
112
|
+
sleeptime = 0.05
|
|
113
|
+
time_to_stop = 0
|
|
114
|
+
if vactual < 0:
|
|
115
|
+
acceleration = -acceleration
|
|
116
|
+
|
|
117
|
+
if duration != 0:
|
|
118
|
+
self._tmc_logger.log(
|
|
119
|
+
f"vactual: {vactual} for {duration} sec", Loglevel.INFO
|
|
120
|
+
)
|
|
121
|
+
else:
|
|
122
|
+
self._tmc_logger.log(f"vactual: {vactual}", Loglevel.INFO)
|
|
123
|
+
self._tmc_logger.log(str(bin(vactual)), Loglevel.INFO)
|
|
124
|
+
|
|
125
|
+
self._tmc_logger.log("writing vactual", Loglevel.INFO)
|
|
126
|
+
if acceleration == 0:
|
|
127
|
+
self.set_vactual(int(round(vactual)))
|
|
128
|
+
|
|
129
|
+
if duration == 0:
|
|
130
|
+
return self._stop
|
|
131
|
+
duration_us = duration * 1000 * 1000
|
|
132
|
+
|
|
133
|
+
self._starttime = get_time_us()
|
|
134
|
+
current_time = get_time_us()
|
|
135
|
+
while current_time < self._starttime + duration_us:
|
|
136
|
+
if self._stop == StopMode.HARDSTOP:
|
|
137
|
+
break
|
|
138
|
+
if acceleration != 0:
|
|
139
|
+
time_to_stop = (
|
|
140
|
+
self._starttime + duration_us - abs(current_vactual / acceleration)
|
|
141
|
+
)
|
|
142
|
+
if self._stop == StopMode.SOFTSTOP:
|
|
143
|
+
time_to_stop = current_time - 1
|
|
144
|
+
if acceleration != 0 and current_time > time_to_stop:
|
|
145
|
+
current_vactual -= acceleration * sleeptime
|
|
146
|
+
self.set_vactual(int(round(current_vactual)))
|
|
147
|
+
time.sleep(sleeptime)
|
|
148
|
+
elif acceleration != 0 and abs(current_vactual) < abs(vactual):
|
|
149
|
+
current_vactual += acceleration * sleeptime
|
|
150
|
+
self.set_vactual(int(round(current_vactual)))
|
|
151
|
+
time.sleep(sleeptime)
|
|
152
|
+
if show_stallguard_result:
|
|
153
|
+
# self._tmc_logger.log(f"StallGuard result: {self.get_stallguard_result()}",
|
|
154
|
+
# Loglevel.INFO)
|
|
155
|
+
time.sleep(0.1)
|
|
156
|
+
if show_tstep:
|
|
157
|
+
# self._tmc_logger.log(f"TStep result: {self.get_tstep()}",
|
|
158
|
+
# Loglevel.INFO)
|
|
159
|
+
time.sleep(0.1)
|
|
160
|
+
current_time = get_time_us()
|
|
161
|
+
self.set_vactual(0)
|
|
162
|
+
return self._stop
|
|
163
|
+
|
|
164
|
+
def set_vactual_rps(
|
|
165
|
+
self, rps, duration=0, revolutions=0, acceleration=0
|
|
166
|
+
) -> StopMode:
|
|
167
|
+
"""converts the rps parameter to a vactual value which represents
|
|
168
|
+
rotation speed in revolutions per second
|
|
169
|
+
With internal oscillator:
|
|
170
|
+
VACTUAL[2209] = v[Hz] / 0.715Hz
|
|
171
|
+
|
|
172
|
+
Args:
|
|
173
|
+
rps (int): value for vactual in rps
|
|
174
|
+
duration (int): after this vactual will be set to 0 (Default value = 0)
|
|
175
|
+
revolutions (int): after this vactual will be set to 0 (Default value = 0)
|
|
176
|
+
acceleration (int): use this for a velocity ramp (Default value = 0)
|
|
177
|
+
|
|
178
|
+
Returns:
|
|
179
|
+
stop (enum): how the movement was finished
|
|
180
|
+
"""
|
|
181
|
+
vactual = tmc_math.rps_to_vactual(rps, self._steps_per_rev)
|
|
182
|
+
if revolutions != 0:
|
|
183
|
+
duration = abs(revolutions / rps)
|
|
184
|
+
if revolutions < 0:
|
|
185
|
+
vactual = -vactual
|
|
186
|
+
return self.set_vactual_dur(vactual, duration, acceleration=acceleration)
|
|
187
|
+
|
|
188
|
+
def set_vactual_rpm(
|
|
189
|
+
self, rpm, duration=0, revolutions=0, acceleration=0
|
|
190
|
+
) -> StopMode:
|
|
191
|
+
"""converts the rps parameter to a vactual value which represents
|
|
192
|
+
rotation speed in revolutions per minute
|
|
193
|
+
|
|
194
|
+
Args:
|
|
195
|
+
rpm (int): value for vactual in rpm
|
|
196
|
+
duration (int): after this vactual will be set to 0 (Default value = 0)
|
|
197
|
+
revolutions (int): after this vactual will be set to 0 (Default value = 0)
|
|
198
|
+
acceleration (int): use this for a velocity ramp (Default value = 0)
|
|
199
|
+
|
|
200
|
+
Returns:
|
|
201
|
+
stop (enum): how the movement was finished
|
|
202
|
+
"""
|
|
203
|
+
return self.set_vactual_rps(rpm / 60, duration, revolutions, acceleration)
|
|
204
|
+
|
|
205
|
+
def run_speed(self, speed: int):
|
|
206
|
+
"""runs the motor
|
|
207
|
+
does not block the code
|
|
208
|
+
|
|
209
|
+
Args:
|
|
210
|
+
speed (int): speed in µsteps per second
|
|
211
|
+
"""
|
|
212
|
+
self.set_vactual(round(speed / 0.715))
|
|
213
|
+
|
|
214
|
+
def run_speed_fullstep(self, speed: int):
|
|
215
|
+
"""runs the motor
|
|
216
|
+
does not block the code
|
|
217
|
+
|
|
218
|
+
Args:
|
|
219
|
+
speed (int): speed in fullsteps per second
|
|
220
|
+
"""
|
|
221
|
+
self.run_speed(speed * self.mres)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Platform utility functions for TMC Driver library"""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
import time
|
|
5
|
+
|
|
6
|
+
MICROPYTHON = sys.implementation.name == "micropython"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def get_time_us():
|
|
10
|
+
"""Get current time in microseconds, compatible with both CPython and MicroPython"""
|
|
11
|
+
if MICROPYTHON:
|
|
12
|
+
return time.ticks_us() # pylint: disable=no-member
|
|
13
|
+
return time.time_ns() // 1000
|
|
File without changes
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# pylint: disable=too-many-instance-attributes
|
|
2
|
+
# pylint: disable=wildcard-import
|
|
3
|
+
# pylint: disable=unused-wildcard-import
|
|
4
|
+
"""
|
|
5
|
+
Register module
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from ._tmc220x_reg import *
|
|
9
|
+
from . import _tmc_shared_regs as shared
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class TCoolThrs(shared.TCoolThrs):
|
|
13
|
+
"""TCOOLTHRS register class"""
|
|
14
|
+
|
|
15
|
+
ADDR = 0x14
|
|
16
|
+
|
|
17
|
+
tcoolthrs: int
|
|
18
|
+
_REG_MAP = (TmcRegField("tcoolthrs", 0, 0xFFFFF, int, None, ""),)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class SgThrs(shared.SgThrs):
|
|
22
|
+
"""SGTHRS register class"""
|
|
23
|
+
|
|
24
|
+
ADDR = 0x40
|
|
25
|
+
|
|
26
|
+
sgthrs: int
|
|
27
|
+
_REG_MAP = (TmcRegField("sgthrs", 0, 0xFFFFF, int, None, ""),)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class SgResult(shared.SgResult):
|
|
31
|
+
"""SGRESULT register class"""
|
|
32
|
+
|
|
33
|
+
ADDR = 0x41
|
|
34
|
+
|
|
35
|
+
sgresult: int
|
|
36
|
+
_REG_MAP = (TmcRegField("sgresult", 0, 0xFFFFF, int, None, ""),)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class CoolConf(shared.CoolConf):
|
|
40
|
+
"""COOLCONF register class"""
|
|
41
|
+
|
|
42
|
+
ADDR = 0x42
|
|
43
|
+
|
|
44
|
+
seimin: bool
|
|
45
|
+
sedn: int
|
|
46
|
+
semax: int
|
|
47
|
+
seup: int
|
|
48
|
+
semin: int
|
|
49
|
+
_REG_MAP = (
|
|
50
|
+
TmcRegField("seimin", 15, 0x1, bool, None, ""),
|
|
51
|
+
TmcRegField("sedn", 13, 0x3, int, None, ""),
|
|
52
|
+
TmcRegField("semax", 8, 0xF, int, None, ""),
|
|
53
|
+
TmcRegField("seup", 5, 0x3, int, None, ""),
|
|
54
|
+
TmcRegField("semin", 0, 0xF, int, None, ""),
|
|
55
|
+
)
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# pylint: disable=too-many-instance-attributes
|
|
2
|
+
"""
|
|
3
|
+
Register module
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import math
|
|
7
|
+
from ._tmc_reg import TmcRegField
|
|
8
|
+
from . import _tmc_shared_regs as shared
|
|
9
|
+
from .._tmc_exceptions import TmcDriverException
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class GConf(shared.GConf):
|
|
13
|
+
"""GCONF register class"""
|
|
14
|
+
|
|
15
|
+
ADDR = 0x0
|
|
16
|
+
|
|
17
|
+
test_mode: bool
|
|
18
|
+
multistep_filt: bool
|
|
19
|
+
mstep_reg_select: bool
|
|
20
|
+
pdn_disable: bool
|
|
21
|
+
index_step: bool
|
|
22
|
+
index_otpw: bool
|
|
23
|
+
shaft: bool
|
|
24
|
+
en_spreadcycle: bool
|
|
25
|
+
internal_rsense: bool
|
|
26
|
+
i_scale_analog: bool
|
|
27
|
+
_REG_MAP = (
|
|
28
|
+
TmcRegField("test_mode", 9, 0x1, bool, None, ""),
|
|
29
|
+
TmcRegField("multistep_filt", 8, 0x1, bool, None, ""),
|
|
30
|
+
TmcRegField("mstep_reg_select", 7, 0x1, bool, None, ""),
|
|
31
|
+
TmcRegField("pdn_disable", 6, 0x1, bool, None, ""),
|
|
32
|
+
TmcRegField("index_step", 5, 0x1, bool, None, ""),
|
|
33
|
+
TmcRegField("index_otpw", 4, 0x1, bool, None, ""),
|
|
34
|
+
TmcRegField("shaft", 3, 0x1, bool, None, ""),
|
|
35
|
+
TmcRegField("en_spreadcycle", 2, 0x1, bool, None, ""),
|
|
36
|
+
TmcRegField("internal_rsense", 1, 0x1, bool, None, ""),
|
|
37
|
+
TmcRegField("i_scale_analog", 0, 0x1, bool, None, ""),
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class GStat(shared.GStat):
|
|
42
|
+
"""GSTAT register class"""
|
|
43
|
+
|
|
44
|
+
ADDR = 0x1
|
|
45
|
+
|
|
46
|
+
uv_cp: bool
|
|
47
|
+
drv_err: bool
|
|
48
|
+
reset: bool
|
|
49
|
+
_REG_MAP = (
|
|
50
|
+
TmcRegField("uv_cp", 2, 0x1, bool, None, "", 1),
|
|
51
|
+
TmcRegField("drv_err", 1, 0x1, bool, None, "", 1),
|
|
52
|
+
TmcRegField("reset", 0, 0x1, bool, None, "", 1),
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
def check(self):
|
|
56
|
+
"""check if the driver is ok"""
|
|
57
|
+
self.read()
|
|
58
|
+
if self.reset:
|
|
59
|
+
raise TmcDriverException("TMC220X: reset detected")
|
|
60
|
+
if self.uv_cp:
|
|
61
|
+
raise TmcDriverException("TMC220X: undervoltage detected")
|
|
62
|
+
if self.drv_err:
|
|
63
|
+
raise TmcDriverException("TMC220X: driver error detected")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class IfCnt(shared.IfCnt):
|
|
67
|
+
"""IFCNT register class"""
|
|
68
|
+
|
|
69
|
+
ADDR = 0x2
|
|
70
|
+
|
|
71
|
+
ifcnt: int
|
|
72
|
+
_REG_MAP = (TmcRegField("ifcnt", 0, 0xFF, int, None, ""),)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class Ioin(shared.Ioin):
|
|
76
|
+
"""IOIN register class"""
|
|
77
|
+
|
|
78
|
+
ADDR = 0x6
|
|
79
|
+
DRIVER_NAME = "TMC220X"
|
|
80
|
+
|
|
81
|
+
version: int
|
|
82
|
+
dir: bool
|
|
83
|
+
spread: bool
|
|
84
|
+
step: bool
|
|
85
|
+
ms2: bool
|
|
86
|
+
ms1: bool
|
|
87
|
+
enn: bool
|
|
88
|
+
_REG_MAP = (
|
|
89
|
+
TmcRegField("version", 24, 0xFF, int, None, ""),
|
|
90
|
+
TmcRegField("dir", 9, 0x1, bool, None, ""),
|
|
91
|
+
TmcRegField("spread", 8, 0x1, bool, None, ""),
|
|
92
|
+
TmcRegField("step", 7, 0x1, bool, None, ""),
|
|
93
|
+
TmcRegField("ms2", 3, 0x1, bool, None, ""),
|
|
94
|
+
TmcRegField("ms1", 2, 0x1, bool, None, ""),
|
|
95
|
+
TmcRegField("enn", 0, 0x1, bool, None, ""),
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class IHoldIRun(shared.IHoldIRun):
|
|
100
|
+
"""IHOLD_IRUN register class"""
|
|
101
|
+
|
|
102
|
+
ADDR = 0x10
|
|
103
|
+
|
|
104
|
+
iholddelay: int
|
|
105
|
+
irun: int
|
|
106
|
+
ihold: int
|
|
107
|
+
_REG_MAP = (
|
|
108
|
+
TmcRegField("iholddelay", 16, 0xF, int, None, ""),
|
|
109
|
+
TmcRegField("irun", 8, 0x1F, int, None, ""),
|
|
110
|
+
TmcRegField("ihold", 0, 0x1F, int, None, ""),
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class TPowerDown(shared.TPowerDown):
|
|
115
|
+
"""TPowerDown register class"""
|
|
116
|
+
|
|
117
|
+
ADDR = 0x11
|
|
118
|
+
|
|
119
|
+
tpowerdown: int
|
|
120
|
+
_REG_MAP = (TmcRegField("tpowerdown", 0, 0xFF, int, None, ""),)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class TStep(shared.TStep):
|
|
124
|
+
"""TSTEP register class"""
|
|
125
|
+
|
|
126
|
+
ADDR = 0x12
|
|
127
|
+
|
|
128
|
+
tstep: int
|
|
129
|
+
_REG_MAP = (TmcRegField("tstep", 0, 0xFFFFF, int, None, ""),)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
class TPwmThrs(shared.TPwmThrs):
|
|
133
|
+
"""TPWMTHRS register class"""
|
|
134
|
+
|
|
135
|
+
ADDR = 0x13
|
|
136
|
+
|
|
137
|
+
tpwmthrs: int
|
|
138
|
+
_REG_MAP = (TmcRegField("tpwmthrs", 0, 0xFFFFF, int, None, ""),)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
class VActual(shared.VActual):
|
|
142
|
+
"""VACTUAL register class"""
|
|
143
|
+
|
|
144
|
+
ADDR = 0x22
|
|
145
|
+
|
|
146
|
+
vactual: int
|
|
147
|
+
_REG_MAP = (TmcRegField("vactual", 0, 0xFFFFFF, int, None, "", signed=True),)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
class MsCnt(shared.MsCnt):
|
|
151
|
+
"""MSCNT register class"""
|
|
152
|
+
|
|
153
|
+
ADDR = 0x6A
|
|
154
|
+
|
|
155
|
+
mscnt: int
|
|
156
|
+
_REG_MAP = (TmcRegField("mscnt", 0, 0xFF, int, None, ""),)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
class ChopConf(shared.ChopConf):
|
|
160
|
+
"""CHOPCONF register class"""
|
|
161
|
+
|
|
162
|
+
ADDR = 0x6C
|
|
163
|
+
|
|
164
|
+
diss2vs: bool
|
|
165
|
+
diss2g: bool
|
|
166
|
+
dedge: bool
|
|
167
|
+
intpol: bool
|
|
168
|
+
mres: int
|
|
169
|
+
vsense: bool
|
|
170
|
+
tbl: int
|
|
171
|
+
hend: int
|
|
172
|
+
hstrt: int
|
|
173
|
+
toff: int
|
|
174
|
+
_REG_MAP = (
|
|
175
|
+
TmcRegField("diss2vs", 31, 0x1, bool, None, ""),
|
|
176
|
+
TmcRegField("diss2g", 30, 0x1, bool, None, ""),
|
|
177
|
+
TmcRegField("dedge", 29, 0x1, bool, None, ""),
|
|
178
|
+
TmcRegField("intpol", 28, 0x1, bool, None, ""),
|
|
179
|
+
TmcRegField("mres", 24, 0xF, int, "mres_ms", "mStep"),
|
|
180
|
+
TmcRegField("vsense", 17, 0x1, bool, None, ""),
|
|
181
|
+
TmcRegField("tbl", 15, 0x3, int, None, ""),
|
|
182
|
+
TmcRegField("hend", 7, 0xF, int, None, ""),
|
|
183
|
+
TmcRegField("hstrt", 4, 0x7, int, None, ""),
|
|
184
|
+
TmcRegField("toff", 0, 0xF, int, None, ""),
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
@property
|
|
188
|
+
def mres_ms(self) -> int:
|
|
189
|
+
"""return µstep resolution"""
|
|
190
|
+
return int(math.pow(2, 8 - self.mres))
|
|
191
|
+
|
|
192
|
+
@mres_ms.setter
|
|
193
|
+
def mres_ms(self, mres: int):
|
|
194
|
+
"""set µstep resolution"""
|
|
195
|
+
mres_bit = int(math.log2(mres))
|
|
196
|
+
mres_bit = 8 - mres_bit
|
|
197
|
+
self.mres = mres_bit
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
class PwmConf(shared.PwmConf):
|
|
201
|
+
"""PWMCONF register class"""
|
|
202
|
+
|
|
203
|
+
ADDR = 0x70
|
|
204
|
+
|
|
205
|
+
pwm_lim: int
|
|
206
|
+
pwm_reg: int
|
|
207
|
+
freewheel: int
|
|
208
|
+
pwm_autograd: bool
|
|
209
|
+
pwm_autoscale: bool
|
|
210
|
+
pwm_freq: int
|
|
211
|
+
pwm_grad: int
|
|
212
|
+
pwm_ofs: int
|
|
213
|
+
_REG_MAP = (
|
|
214
|
+
TmcRegField("pwm_lim", 28, 0xF, int, None, ""),
|
|
215
|
+
TmcRegField("pwm_reg", 24, 0xF, int, None, ""),
|
|
216
|
+
TmcRegField("freewheel", 20, 0x3, int, None, ""),
|
|
217
|
+
TmcRegField("pwm_autograd", 19, 0x1, bool, None, ""),
|
|
218
|
+
TmcRegField("pwm_autoscale", 18, 0x1, bool, None, ""),
|
|
219
|
+
TmcRegField("pwm_freq", 16, 0x3, int, None, ""),
|
|
220
|
+
TmcRegField("pwm_grad", 8, 0xFF, int, None, ""),
|
|
221
|
+
TmcRegField("pwm_ofs", 0, 0xFF, int, None, ""),
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
class DrvStatus(shared.DrvStatus):
|
|
226
|
+
"""DRVSTATUS register class"""
|
|
227
|
+
|
|
228
|
+
ADDR = 0x6F
|
|
229
|
+
|
|
230
|
+
stst: bool
|
|
231
|
+
stealth: bool
|
|
232
|
+
cs_actual: int
|
|
233
|
+
t157: bool
|
|
234
|
+
t150: bool
|
|
235
|
+
t143: bool
|
|
236
|
+
t120: bool
|
|
237
|
+
olb: bool
|
|
238
|
+
ola: bool
|
|
239
|
+
s2vsb: bool
|
|
240
|
+
s2vsa: bool
|
|
241
|
+
s2gb: bool
|
|
242
|
+
s2ga: bool
|
|
243
|
+
ot: bool
|
|
244
|
+
otpw: bool
|
|
245
|
+
_REG_MAP = (
|
|
246
|
+
TmcRegField("stst", 31, 0x1, bool, None, ""),
|
|
247
|
+
TmcRegField("stealth", 30, 0x1, bool, None, ""),
|
|
248
|
+
TmcRegField("cs_actual", 16, 0x1F, int, None, ""),
|
|
249
|
+
TmcRegField("t157", 11, 0x1, bool, None, ""),
|
|
250
|
+
TmcRegField("t150", 10, 0x1, bool, None, ""),
|
|
251
|
+
TmcRegField("t143", 9, 0x1, bool, None, ""),
|
|
252
|
+
TmcRegField("t120", 8, 0x1, bool, None, ""),
|
|
253
|
+
TmcRegField("olb", 7, 0x1, bool, None, ""),
|
|
254
|
+
TmcRegField("ola", 6, 0x1, bool, None, ""),
|
|
255
|
+
TmcRegField("s2vsb", 5, 0x1, bool, None, ""),
|
|
256
|
+
TmcRegField("s2vsa", 4, 0x1, bool, None, ""),
|
|
257
|
+
TmcRegField("s2gb", 3, 0x1, bool, None, ""),
|
|
258
|
+
TmcRegField("s2ga", 2, 0x1, bool, None, ""),
|
|
259
|
+
TmcRegField("ot", 1, 0x1, bool, None, ""),
|
|
260
|
+
TmcRegField("otpw", 0, 0x1, bool, None, ""),
|
|
261
|
+
)
|