Skip to content

Commit

Permalink
Merge branch 'feature_add_tmc9660_reg'
Browse files Browse the repository at this point in the history
  • Loading branch information
trinamic-bp committed Jan 6, 2025
2 parents deccf3e + 44f643f commit caa9ea8
Show file tree
Hide file tree
Showing 12 changed files with 12,388 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
################################################################################
# Copyright © 2024 Analog Devices Inc. All Rights Reserved.
# This software is proprietary to Analog Devices, Inc. and its licensors.
################################################################################
"""Minimal example on how to use PyTrinamic with TMC9660-3PH-EVAL/TMC9660-STEPPER-EVAL.
The TMC9660-3PH-EVAL/TMC9660-STEPPER-EVAL is used in headless mode for this example.
Note: To run this script the EVAL first needs an uploaded/burned configuration
and the register app must have been started.
--------+
| USB-UART Cable - Connected to the machine running this script.
+--|-----------------+
| | |
| |
|TMC9660-3PH-EVAL or |
|TMC9660-STEPPER-EVAL|
+--------------------+
"""

import time

from pytrinamic.connections import ConnectionManager

from pytrinamic.ic import TMC9660



com_port = "COM5" # Note: Change this to the com port of the USB-UART cable used.

with ConnectionManager(f"--interface serial_tmcl --port {com_port}").connect() as my_interface:

tmc9660 = TMC9660(my_interface)

tmc9660.write(TMC9660.MCC.MOTOR_CONFIG.TYPE.choice["NONE No motor"])
tmc9660.write(TMC9660.MCC.MOTOR_CONFIG.N_POLE_PAIRS, 4)

for _ in range(20):
print(f"I0 = {tmc9660.read(TMC9660.MCC.ADC_I1_I0_SCALED.ADC_SCALED_I0)}")
print(f"I1 = {tmc9660.read(TMC9660.MCC.ADC_I1_I0_SCALED.ADC_SCALED_I1)}")
time.sleep(0.2)
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
################################################################################
# Copyright © 2024 Analog Devices Inc. All Rights Reserved.
# This software is proprietary to Analog Devices, Inc. and its licensors.
################################################################################
"""Example on how to use TMC9660-3PH-EVKIT.
Note: To run this script the TMC9660-3PH-EVAL first needs an uploaded/burned configuration
and the register app must have been started.
+-----+ +-------------------+
USB | |==| |
-------| |==| |
Connected to the machine | |==| |
running this script. |LB |==|TMC9660-3PH-EVAL |
+-----+ +-------------------+
"""

import time

from pytrinamic.connections import ConnectionManager

from pytrinamic.ic import TMC9660
from pytrinamic.evalboards import TMC9660_3PH_eval


with ConnectionManager().connect() as my_interface:

tmc9660_eval = TMC9660_3PH_eval(my_interface)

tmc9660_eval.write(TMC9660.MCC.MOTOR_CONFIG.TYPE.choice["BLDC Three phase BLDC motor"])
tmc9660_eval.write(TMC9660.MCC.MOTOR_CONFIG.N_POLE_PAIRS, 4)

for _ in range(20):
print(f"I0 = {tmc9660_eval.read(TMC9660.MCC.ADC_I1_I0_SCALED.ADC_SCALED_I0)}")
print(f"I1 = {tmc9660_eval.read(TMC9660.MCC.ADC_I1_I0_SCALED.ADC_SCALED_I1)}")
time.sleep(0.2)
24 changes: 23 additions & 1 deletion pytrinamic/evalboards/TMC9660_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,37 @@

from pytrinamic.modules import ParameterApiDevice
from pytrinamic.ic import TMC9660
from pytrinamic.ic import RegisterApiDevice
from pytrinamic.tmcl import TMCLCommand


class TMC9660_eval(ParameterApiDevice):
class TMC9660_eval(RegisterApiDevice, ParameterApiDevice):
"""Generic class for TMC9660 eval boards."""
def __init__(self, connection, default_module_id=3):
self._connection = connection
self._ap_index_bit_width = 12
self._module_id = default_module_id
self.ics = [TMC9660()]

def write_register(self, register_address, block, value):
"""Implementation of the RegisterApiDevice::write_register() function."""
return self._connection.write_register(
register_address,
TMCLCommand.WRITE_MC,
block,
value,
module_id=self._module_id
)

def read_register(self, register_address, block, signed=False):
"""Implementation of the RegisterApiDevice::read_register() function."""
return self._connection.read_register(
register_address,
TMCLCommand.READ_MC,
block,
module_id=self._module_id,
signed=signed,
)

def _get_axis_parameter(self, index: int, signed: bool):
"""Implementation of the ParameterApiDevice::_get_axis_parameter() function."""
Expand Down
Loading

0 comments on commit caa9ea8

Please sign in to comment.