Using the MAX22200PMB# with TMCM-0960-MotionPy
Abstract
The basic functions of the MAX22200, Octal Integrated Serial-Controlled Solenoid and Motor Driver, can be implemented in a MicroPython environment using a MAX22200PMB# peripheral module and the TMCM-0960-MotionPy. This application note provides example Python code including setup, configuration, and monitoring functions.
Introduction
This document introduces the use of the MAX22200PMB# with the TMCM-0960-MotionPy V2.1. The MAX22200PMB# is a peripheral module that provides a quick prototype for the MAX22200 solenoid and motor driver device. This device offers eight individually configurable channels that can be used to drive solenoids and motors in a half, parallel, or full bridge configuration. For more information, refer to the MAX22200 data sheet and the MAX22200PMB# product page. The basic functions of the MAX22200 are implemented in a MicroPython environment for use on a TMCM-0960-MotionPy board. This document provides a brief overview of how to use these basic functions and how to set up the example.


Requirements
- MAX22200PMB#, including a 24V DC power adapter.
- USB-C cable
- TMCM-0960-MotionPy V2.1, set up as shown in AN061.
- Terminal connection to the TMCM-0960-MotionPy board.
Connecting the Pmod™ Board
The MAX22200 communicates with a host controller using an SPI interface, which can be accessed through the PMOD1 and PMOD2 connectors on the TMCM-0960-MotionPy V2.1 board. The default connection corresponds to the PMOD1 connector as shown in Table 1 and Figure 2, where the MAX22200PMB# is the target device and the TMCM-0960-MotionPy is the master device. In addition to the four SPI signals (CS, SCLK, MOSI, and MISO), the CMD, FAULT, ENABLE, and TRIG signals can be accessed through the appropriate GPIO pins.


MAX22200PMB# J1 Signals | MAX22200PMB# J1 PIN NO. (Note 2) | TMCM-0960-MotionPy PMOD1 Signals | TMCM-0960-MotionPy PMOD1 PIN NO. (Note 2) | Description |
CSB | 1 | CS01 | 1 | Chip Select |
SDI | 2 | SPI1_MOSI | 3 | Master Serial Data Out, Device Serial Data In |
SDO | 3 | SPI1_MISO | 5 | Master Serial Data In, Device Serial Data Out |
SCK | 4 | SPI1_SCK | 7 | Serial Clock |
CMD | 7 | CS02 | 2 | MAX22200 Command Input |
NFAULT | 8 | GP01 | 4 | MAX22200 Diagnostic Fault Output |
ENABLE | 9 | GP02 | 6 | MAX22200 Enable Input |
TRIG | 10 | GP03 | 8 | MAX22200 External Trigger |
Note 1: On the TMCM-0960-MotionPy V2.1 schematic, the Pmod connectors are labeled PMOD0 and PMOD1, but on the PCB silkscreen they are labeled PMOD1 and PMOD2. In the Python driver, the connector variables are called pmod1 and pmod2.
Note 2: On the MAX22200PMB#, the connector J1 numbering convention is 1 to 6 for the outside row and 7 to 12 for the inside row. However, on the TMCM-0960-MotionPy V2.1, the Pmod connector numbering convention is 1, 3, 5, 7, 9, 11 on one row and 2, 4, 6, 8, 10, 12 on the other row. Despite the different numbering, the physical signal mapping is consistent.
Structure and Functions
The MAX22200 communicates with a host controller through SPI. SPI initialization, register read/write, and basic configuration and monitoring are implemented in the max22200.py script. For more information on TMCM-0960-MotionPy and its file system, refer to AN061.
The basic functions read_32bit(), write_8bit(), write_32bit(), and write_command_reg() are used to read and write registers in the MAX22200.
Each pair of contiguous channels can be set in one of three different bridge configurations (half, parallel, or full) using the function status_reg(), which also sets the fault masking bits and main frequency (80 kHz or 100 kHz). Each channel can then be independently configured using the function config_reg(). The user can choose between full-scale or half full-scale operation, SPI trigger or external trigger, current-drive or voltage-drive regulation, low-side or high-side drive, and fast mode or slew-rate controlled mode. The HOLD value, HIT value, HIT time, and chopping frequency can also be set for each channel, along with the option to enable or disable the open-load, plunger movement, and HIT detections. If the mode is current-drive regulation (CDR), the parameters for the detection of plunger movement can be set using the CFG_DPM() function.
There are a few diagnostic functions, including read_output() and read_faults(). The function read_output() returns the contents stored in the configuration register for that specific output channel. The function read_faults() returns all seven channels' faults as 0/1 string with Channel 0 appearing as the LSB.
Once the MAX22200 is initialized and properly set up, certain “on-the-fly” operations can be performed. The functions channel_on_off_spi() and channel_on_off_trig() control the on/off status of the channels, HFS_HOLD() allows the user to update the half full-scale bit and HOLD inputs while the device is active, and channel_config() allows the user to edit the configuration register settings for each channel.
Table 2 contains a full list of functions implemented in the max22200.py. For the complete register map and device features, refer to the MAX22200 data sheet.
Example Functions List
read_32bit()- Arguments: N/A
- Description: Returns 32 bits read from the register in a 0/1 string
- Arguments:
- data (str): binary string to write to register
- Description: Writes 8 bits of data provided as 0/1 string
- Arguments:
- data (str): binary string to write to register
- Description: Writes 32 bits of data provided as 0/1 string
- Arguments:
- rw (int): 0 (read), 1 (write)
- addr (hex/int): valid register address
- msb (int): 0 (access 32-bit register bank), 1 (access 8 MSB of register bank)
- Description: Writes 8 bits of data provided as 0/1 string to command register
- Arguments: N/A
- Description: Reads and prints fault flag bits in status register
- Arguments:
- M_OVT (int): 0 (fault is not masked), 1 (fault is masked)
- M_OCP (int): 0 (fault is not masked), 1 (fault is masked)
- M_OLF (int): 0 (fault is not masked), 1 (fault is masked)
- M_HHF (int): 0 (fault is not masked), 1 (fault is masked)
- M_DPM (int): 0 (fault is not masked), 1 (fault is masked)
- M_COM (int): 0 (fault is not masked), 1 (fault is masked)
- M_UVM (int): 0 (fault is not masked), 1 (fault is masked)
- FREQM (str): “80kHz”, “100kHz”
- ch7_6 (str): “half”, “parallel”, “full”
- ch5_4 (str): “half”, “parallel”, “full”
- ch3_2 (str): “half”, “parallel”, “full”
- ch1_0 (str): “half”, “parallel”, “full”
- active (int): 0 (device is not active), 1 (device is active)
- Description: Sets parameters for status register
- OVT: overtemperature fault flag
- OCP: overcurrent fault flag
- OLF: open-load fault flag
- HHF: HIT current not reached fault flag
- DPM: detection of plunger movement fault flag
- COM: communication error fault flag
- UVM: undervoltage fault flag
- Arguments:
- channel (int): 0, 1, 2, 3, 4, 5, 6, 7
- HFS (int): 0 (full-scale), 1 (half full-scale)
- HOLD (int): integer between 0 and 127 (inclusive)
- TRGnSPI (int): 0 (SPI trigger), 1 (external trigger)
- HIT (int): integer between 0 and 127 (inclusive)
- HIT_time (int): integer between 0 and 255 (inclusive)
- VDRnCDR (int): 0 (current drive), 1 (voltage drive)
- HSnLS (int): 0 (low-side drive), 1 (high-side drive)
- FREQ_CFG (float): 0.25, 0.33, 0.5, 1
- SRC (int): 0 (fast mode), 1 (slew-rate controlled mode)
- OL (int): 0 (disable detection), 1 (enable detection)
- DPM (int): 0 (disable detection), 1 (enable detection)
- HHF (int): 0 (disable detection), 1 (enable detection)
- Description: Sets configuration register for specified channel
- 0.25 = FREQM/4
- 0.33 = FREQM/3
- 0.5 = FREQM/2
- 1 = FREQM
- OL: open-load detection
- DPM: detection of plunger movement
- HHF: HIT current detection
- Arguments:
- channel (int): 0, 1, 2, 3, 4, 5, 6, 7
- Description: Returns 32-bit string of current values stored in configuration register for specified channel
- Arguments: N/A
- Description: Returns all seven channels' faults as 0/1 string (CH0 is LSB)
- Arguments:
- DPM_ISTART (int): integer between 0 and 127 (inclusive)
- DPM_TDEB (int): integer between 0 and 15 (inclusive)
- DPM_ITPH (int): integer between 0 and 15 (inclusive)
- HFS (int): 0 (full-scale), 1 (half full-scale)
- FREQM (str): “80kHz”, “100kHz”
- FREQ_CFG (float): 0.25, 0.33, 0.5, 1
- Description: Set parameters for detection of plunger movement (only available in CDR mode), HFS/FREQM/FREQ_CFG bits only used for calculations and do not actually set bits in the register
- 0.25 = FREQM/4
- 0.33 = FREQM/3
- 0.5 = FREQM/2
- 1 = FREQM
- Arguments:
- channel (int): 0, 1, 2, 3, 4, 5, 6, 7
- status (int): 0 (off), 1 (on)
- Description: Turns specified channel on or off on the fly
- Arguments:
- status (int): 0 (off), 1 (on)
- Description: Turns channels 0, 2, 4, 6 (TRIGA) on or off on the fly
- Arguments:
- channel (int): 0, 1, 2, 3, 4, 5, 6, 7
- HFS (int): 0 (full-scale), 1 (half full-scale)
- HOLD (int): integer between 0 and 127 (inclusive)
- Description: Adjusts half full-scale bit and HOLD value for specified channel on the fly
- Arguments:
- channel (int): 0, 1, 2, 3, 4, 5, 6, 7
- HFS (int): 0 (full-scale), 1 (half full-scale)
- HOLD (int): integer between 0 and 127 (inclusive)
- TRGnSPI (int): 0 (SPI trigger), 1 (external trigger)
- HIT (int): integer between 0 and 127 (inclusive)
- HIT_time (int): integer between 0 and 255 (inclusive)
- VDRnCDR (int): 0 (current drive), 1 (voltage drive)
- HSnLS (int): 0 (low-side drive), 1 (high-side drive)
- FREQ_CFG (float): 0.25, 0.33, 0.5, 1
- SRC (int): 0 (fast mode), 1 (slew-rate controlled mode)
- OL (int): 0 (disable detection), 1 (enable detection)
- DPM (int): 0 (disable detection), 1 (enable detection)
- HHF (int): 0 (disable detection), 1 (enable detection)
- Description: Sets configuration register for specified channel on the fly
- 0.25 = FREQM/4
- 0.33 = FREQM/3
- 0.5 = FREQM/2
- 1 = FREQM
- OL: open-load detection
- DPM: detection of plunger movement
- HHF: HIT current detection
Running the Example
To begin, use the example script max22200pmb.py. Connect the MAX22200PMB# to the TMCM-0960-MotionPy and a 24V power adapter to the MAX22200PMB# connector J4 (Figure 2). Connect the TMCM-0960-MotionPy to the PC using a USB-C cable and start a serial terminal connection. The example script can be executed with the following command:
>>> exec(open("PyTrinamicMicro/platforms/motionpy2/examples/modules/max/max22200pmb.py").read())
The example script sets Channel 0 to a half-bridge configuration in a low-side current-drive regulation mode. The HIT current is set to 45 and the HOLD current is set to 10, with the main and chopping frequencies set at 100 kHz. Channel 0 is set to full-scale operation, fast mode, and SPI trigger. The open-load, plunger movement, and HIT detections are all disabled. The script runs once, and the terminal displays each read/write to the register for user confirmation, as shown here.
Read Status Register Write to Command Register: 00000000 Fault Flags: 00000010
Device Setup Write to Command Register: 10000000 Write to Register: 00000001000000000000000000000000
Channel Configuration Write to Command Register: 10000010 Write to Register: 00110010011001000010110100001010
Read Status Register Write to Command Register: 00000000 Fault Flags: 00000011
Read Status Register Again Write to Command Register: 00000000 Fault Flags: 00000001
Turn Channel 0 On Write to Command Register: 00000000 Channel [7:0] Current Status: 00000000 Write to Command Register: 10000001 Channel [7:0] New Status: 00000001
The example has other commands set up as comments for the user to modify and experiment. Once the script is run and the device is properly set up, the user can also directly enter commands into the terminal window to control the channels.
Pmod is a registered trademark and service mark of Digilent Inc.