MAX22200 Driver
API reference
Loading...
Searching...
No Matches
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
max22200 Namespace Reference

Namespaces

namespace  CfgChReg
 Channel configuration register bit field definitions.
 
namespace  CfgDpmReg
 CFG_DPM register bit field definitions.
 
namespace  CommandReg
 Command Register bit field definitions and helper functions.
 
namespace  FaultReg
 FAULT register bit field definitions.
 
namespace  RegBank
 Register bank addresses for MAX22200.
 
namespace  StatusReg
 STATUS register bit field definitions.
 

Classes

struct  BoardConfig
 Board/scale configuration for unit-based APIs. More...
 
struct  ChannelConfig
 Channel configuration structure. More...
 
struct  DpmConfig
 DPM (Detection of Plunger Movement) algorithm configuration. More...
 
struct  DriverStatistics
 Driver runtime statistics. More...
 
struct  DutyLimits
 Duty cycle limits (δMIN, δMAX) for a given configuration. More...
 
struct  FaultStatus
 Per-channel fault information from FAULT register (0x09) More...
 
class  MAX22200
 Main driver class for MAX22200 IC. More...
 
class  SpiInterface
 CRTP-based template interface for SPI communication. More...
 
struct  StatusConfig
 STATUS register structure. More...
 

Typedefs

using ChannelConfigArray = std::array< ChannelConfig, NUM_CHANNELS_ >
 Array type for channel configurations.
 
using FaultCallback = void(*)(uint8_t channel, FaultType fault_type, void *user_data)
 Callback function type for fault events.
 
using StateChangeCallback = void(*)(uint8_t channel, ChannelState old_state, ChannelState new_state, void *user_data)
 Callback function type for channel state changes.
 

Enumerations

enum class  CtrlPin : uint8_t { ENABLE = 0 , FAULT , CMD }
 Identifies the hardware control pins of the MAX22200. More...
 
enum class  GpioSignal : uint8_t { INACTIVE = 0 , ACTIVE = 1 }
 Abstract signal level for control pins. More...
 
enum class  DriveMode : uint8_t { CDR = 0 , VDR = 1 }
 Drive mode enumeration (VDRnCDR bit in CFG_CHx[7]) More...
 
enum class  SideMode : uint8_t { LOW_SIDE = 0 , HIGH_SIDE = 1 }
 High-side / Low-side selection (HSnLS bit in CFG_CHx[6]) More...
 
enum class  ChannelMode : uint8_t { INDEPENDENT = 0 , PARALLEL = 1 , HBRIDGE = 2 }
 Channel-pair mode (CMxy bits in STATUS[15:8]) More...
 
enum class  ChopFreq : uint8_t { FMAIN_DIV4 = 0 , FMAIN_DIV3 = 1 , FMAIN_DIV2 = 2 , FMAIN = 3 }
 Chopping frequency setting (FREQ_CFG bits in CFG_CHx[5:4]) More...
 
enum class  FaultType : uint8_t {
  OCP = 0 , HHF = 1 , OLF = 2 , DPM = 3 ,
  OVT = 4 , UVM = 5 , COMER = 6
}
 Fault type enumeration. More...
 
enum class  FullBridgeState : uint8_t { HiZ = 0 , Forward = 1 , Reverse = 2 , Brake = 3 }
 Full-bridge state for a channel pair (datasheet Table 7) More...
 
enum class  DriverStatus : uint8_t {
  OK = 0 , INITIALIZATION_ERROR , COMMUNICATION_ERROR , INVALID_PARAMETER ,
  HARDWARE_FAULT , TIMEOUT
}
 Driver operation result codes. More...
 
enum class  ChannelState : uint8_t {
  DISABLED = 0 , ENABLED , HIT_PHASE , HOLD_PHASE ,
  FAULT
}
 Logical channel state for application callbacks. More...
 

Functions

const char * GetDriverVersion () noexcept
 Get the compiled driver version string (namespace-level convenience)
 
constexpr uint8_t getChannelCfgBank (uint8_t channel)
 Get channel configuration register bank address.
 
uint32_t getChopFreqKhz (bool master_clock_80khz, ChopFreq cf)
 Get chopping frequency in kHz for conversion (FREQM + FREQ_CFG)
 
float getChopFreqKhzExact (bool master_clock_80khz, ChopFreq cf)
 Exact chopping frequency in kHz (FREQM + FREQ_CFG, datasheet Table 1)
 
uint8_t currentMaToRaw (uint32_t full_scale_current_ma, uint32_t ma)
 Convert current in mA to 7-bit raw value (0–127) for CDR.
 
uint8_t dutyPercentToRaw (float percent)
 Convert a VDR duty cycle in percent to the 7-bit HIT/HOLD field.
 
float dutyRawToPercent (uint8_t raw)
 Convert the 7-bit VDR HIT/HOLD field to a duty cycle in percent (datasheet Table 3)
 
uint8_t hitTimeMsToRaw (float ms, bool master_clock_80khz, ChopFreq cf)
 Convert HIT time in ms to 8-bit raw value (0–255)
 
float getMaxHitTimeMs (bool master_clock_80khz, ChopFreq cf)
 Maximum representable HIT time in ms for raw values 1–254 (255 = continuous).
 
const char * FaultTypeToStr (FaultType ft)
 Human-readable fault type name (for logging and tests)
 
const char * DriverStatusToStr (DriverStatus s)
 Return a human-readable string for DriverStatus (for logging and tests)
 

Variables

constexpr uint8_t NUM_CHANNELS_ = 8
 Number of channels on the MAX22200.
 
constexpr uint32_t MAX_SPI_FREQ_STANDALONE_ = 10000000
 Maximum SPI clock frequency without daisy chaining (Hz)
 
constexpr uint32_t MAX_SPI_FREQ_DAISY_CHAIN_ = 5000000
 Maximum SPI clock frequency with daisy chaining (Hz)
 
constexpr uint32_t ENABLE_TIME_US_ = 500
 Enable time tEN: ENABLE rising edge to SPI ready (us)
 
constexpr uint32_t WAKE_UP_TIME_US_ = 2500
 Wake-up time tWU: ACTIVE = 1 to normal operation, outputs active (us)
 

Typedef Documentation

◆ ChannelConfigArray

Array type for channel configurations.

◆ FaultCallback

using max22200::FaultCallback = typedef void (*)(uint8_t channel, FaultType fault_type, void *user_data)

Callback function type for fault events.

Parameters
channelChannel index (0–7) associated with the fault, or 0xFF if global
fault_typeFault category (OCP, HHF, OLF, DPM, OVT, UVM, COMER)
user_dataApplication context pointer from SetFaultCallback()
Note
Called by the driver for every fault it reads from FAULT (per channel) or, after Initialize(), from STATUS (OVT, UVM, COMER with channel 0xFF); see SetFaultCallback().

◆ StateChangeCallback

using max22200::StateChangeCallback = typedef void (*)(uint8_t channel, ChannelState old_state, ChannelState new_state, void *user_data)

Callback function type for channel state changes.

Parameters
channelChannel index (0–7)
old_statePrevious logical state
new_stateNew logical state
user_dataApplication context pointer from SetStateChangeCallback()
Note
Stored by the driver; not invoked automatically.

Enumeration Type Documentation

◆ ChannelMode

enum class max22200::ChannelMode : uint8_t
strong

Channel-pair mode (CMxy bits in STATUS[15:8])

Configures pairs of contiguous channels (0-1, 2-3, 4-5, 6-7) for different operating modes. These bits can only be written when both channels in the pair are OFF (ONCHx = 0, ONCHy = 0).

INDEPENDENT (CMxy = 00)

  • Each channel operates independently
  • Standard half-bridge operation
  • Each channel uses its own configuration register (CFG_CHx)

PARALLEL (CMxy = 01)

  • Two channels connected in parallel to double current capability
  • Output pins must be connected together externally
  • Configuration taken from lower channel number (e.g., CFG_CH0 for pair 0-1)
  • Higher channel's configuration register is ignored
  • Activation remains independent (ONCHx and ONCHy control individually)
  • TRGnSPI bits determine trigger source (see datasheet Table 6)

HBRIDGE (CMxy = 10)

  • Two channels form a full-bridge (H-bridge) for bidirectional drive
  • Used for latched (bi-stable) solenoid valves or brushed DC motors
  • Four states: Hi-Z, Forward, Reverse, Brake (see datasheet Table 7)
  • Forward mode uses CFG_CHy settings, Reverse mode uses CFG_CHx settings
  • HSnLS bit is ignored in full-bridge mode
  • TRGnSPI bits determine trigger source (see datasheet Table 8)
Note
Channel pairs: CM10 (ch0-1), CM32 (ch2-3), CM54 (ch4-5), CM76 (ch6-7)
CMxy = 11 is reserved — do not use
Enumerator
INDEPENDENT 

Channels independently controlled (CMxy = 00)

PARALLEL 

Channels in parallel mode (CMxy = 01) — double current.

HBRIDGE 

Channels in H-bridge mode (CMxy = 10) — bidirectional drive.

◆ ChannelState

enum class max22200::ChannelState : uint8_t
strong

Logical channel state for application callbacks.

Used with StateChangeCallback. The driver does not track HIT/HOLD phase internally; these values are for application-level state machines.

Enumerator
DISABLED 

Channel OFF (ONCHx = 0)

ENABLED 

Channel ON, not necessarily in HIT or HOLD phase.

HIT_PHASE 

Application-defined: channel in HIT excitation window.

HOLD_PHASE 

Application-defined: channel in HOLD regulation.

FAULT 

Application-defined: channel has an active fault condition.

◆ ChopFreq

enum class max22200::ChopFreq : uint8_t
strong

Chopping frequency setting (FREQ_CFG bits in CFG_CHx[5:4])

Selects the chopping frequency divider relative to the master frequency (FREQM). The actual chopping frequency fCHOP depends on both FREQM (STATUS[16]) and FREQ_CFG:

FREQM FREQ_CFG fCHOP (kHz) Period (μs)
0 00 25 40
0 01 33.33 30
0 10 50 20
0 11 100 10
1 00 20 50
1 01 26.66 37.5
1 10 40 25
1 11 80 12.5

Effects of Chopping Frequency

  • Higher frequency: Lower current ripple, better average current control, but higher switching losses and EMI
  • Lower frequency: Higher current ripple, but lower switching losses

Duty Cycle Limits

Minimum and maximum duty cycles (δMIN, δMAX) depend on FREQM, FREQ_CFG, and SRC:

  • SRC = 0 (Fast Mode):
    • FREQ_CFG = 11: δMIN = 8%, δMAX = 92%
    • Other FREQ_CFG: δMIN = 4%, δMAX = 96%
  • SRC = 1 (Slew-Rate Controlled):
    • FREQ_CFG = 01 or 00: δMIN = 7%, δMAX = 93%
    • FREQ_CFG = 10 (FREQM=1 only): δMIN = 7%, δMAX = 93%

SRC + fCHOP restriction (datasheet)

SRC mode is only available for switching frequencies less than 50 kHz. When SRC = 1, use only FREQ_CFG that yields fCHOP < 50 kHz:

  • FREQM = 0: use FMAIN_DIV4 (25 kHz) or FMAIN_DIV3 (33.33 kHz); do not use FMAIN_DIV2 (50 kHz) or FMAIN (100 kHz).
  • FREQM = 1: use FMAIN_DIV4 (20 kHz), FMAIN_DIV3 (26.66 kHz), or FMAIN_DIV2 (40 kHz); do not use FMAIN (80 kHz).
Note
FREQ_CFG can be changed "on-the-fly" while channel is operating.
FREQM is a global setting in STATUS register (affects all channels).
Enumerator
FMAIN_DIV4 

FreqMain / 4 (fCHOP = 25kHz if FREQM=0, 20kHz if FREQM=1). Valid with SRC=1.

FMAIN_DIV3 

FreqMain / 3 (fCHOP = 33.33kHz if FREQM=0, 26.66kHz if FREQM=1). Valid with SRC=1.

FMAIN_DIV2 

FreqMain / 2 (fCHOP = 50kHz if FREQM=0, 40kHz if FREQM=1). With SRC=1 use only if FREQM=1 (40kHz).

FMAIN 

FreqMain (fCHOP = 100kHz if FREQM=0, 80kHz if FREQM=1). Not valid with SRC=1.

◆ CtrlPin

enum class max22200::CtrlPin : uint8_t
strong

Identifies the hardware control pins of the MAX22200.

Used with GpioSet() / GpioRead() / GpioSetActive() / GpioSetInactive() to control the IC's dedicated GPIO pins through the SpiInterface.

The mapping from GpioSignal::ACTIVE / INACTIVE to physical HIGH / LOW is determined by the platform bus implementation, based on the board's active-level design:

  • ENABLE: Active-high (ACTIVE → physical HIGH, enables driver outputs)
  • FAULT: Active-low (ACTIVE → physical LOW, fault condition present)
  • CMD: Active-high (ACTIVE → physical HIGH, SPI register mode)
Enumerator
ENABLE 

ENABLE pin — active-high; device sleep when INACTIVE.

FAULT 

nFAULT pin — active-low open-drain fault output (read via GpioRead)

CMD 

CMD pin — ACTIVE = Command Register phase; INACTIVE = data phase.

◆ DriveMode

enum class max22200::DriveMode : uint8_t
strong

Drive mode enumeration (VDRnCDR bit in CFG_CHx[7])

Determines how the channel regulates output current/voltage.

CDR (Current Drive Regulation)

  • Uses integrated lossless current sensing (ICS)
  • Regulates peak current cycle-by-cycle
  • More efficient than VDR (no design margin needed)
  • Only supported in low-side mode (HSnLS = 0)
  • Current accuracy: ±6% for 71-100% of IFS, ±10% for 20-70%, ±15% for 10-20%, ±25% for 5-10%

VDR (Voltage Drive Regulation)

  • Outputs PWM voltage with programmable duty cycle
  • Duty cycle resolution: 1% steps
  • Supported in both low-side and high-side modes
  • Output current proportional to duty cycle for given supply voltage and load resistance
Note
VDRnCDR bit can only be changed when all channels are OFF and both TRIGA and TRIGB inputs are logic-low.
Enumerator
CDR 

Current Drive Regulation (VDRnCDR = 0) — low-side only.

VDR 

Voltage Drive Regulation (VDRnCDR = 1) — low-side or high-side.

◆ DriverStatus

enum class max22200::DriverStatus : uint8_t
strong

Driver operation result codes.

Returned by public MAX22200 methods to indicate success or failure category.

Enumerator
OK 

Operation completed successfully.

INITIALIZATION_ERROR 

SPI/GPIO setup or ENABLE sequencing failed during init.

COMMUNICATION_ERROR 

SPI transfer failed or COMER fault byte (0x04) detected.

INVALID_PARAMETER 

Channel index, IFS, or unit conversion argument out of range.

HARDWARE_FAULT 

Reserved for hardware fault detection (not currently returned)

TIMEOUT 

Reserved for timed operations (not currently returned)

◆ FaultType

enum class max22200::FaultType : uint8_t
strong

Fault type enumeration.

Enumerator
OCP 

Overcurrent protection (OCP)

HHF 

HIT current not reached (HHF)

OLF 

Open-load detection (OLF)

DPM 

Detection of plunger movement (DPM)

OVT 

Overtemperature (OVT, from STATUS)

UVM 

Undervoltage lockout (UVM, from STATUS)

COMER 

Communication error (COMER, from STATUS)

◆ FullBridgeState

enum class max22200::FullBridgeState : uint8_t
strong

Full-bridge state for a channel pair (datasheet Table 7)

For a pair (x, y) = (0,1), (2,3), (4,5), or (6,7): ONCHy and ONCHx determine the bridge state. Forward uses CFG_CHy; Reverse uses CFG_CHx.

Enumerator
HiZ 

ONCHx=0, ONCHy=0 — high impedance (both switches off)

Forward 

ONCHx=1, ONCHy=0 — forward (control from CFG_CHy)

Reverse 

ONCHx=0, ONCHy=1 — reverse (control from CFG_CHx)

Brake 

ONCHx=1, ONCHy=1 — brake (both outputs driven to GND)

◆ GpioSignal

enum class max22200::GpioSignal : uint8_t
strong

Abstract signal level for control pins.

Decouples the driver's intent from the physical pin polarity. The platform bus implementation translates ACTIVE / INACTIVE to the correct electrical level for each pin.

Enumerator
INACTIVE 

Pin function deasserted (ENABLE off, CMD low, no fault on FAULT)

ACTIVE 

Pin function asserted (ENABLE on, CMD high, fault present on FAULT)

◆ SideMode

enum class max22200::SideMode : uint8_t
strong

High-side / Low-side selection (HSnLS bit in CFG_CHx[6])

Determines whether the channel drives the load connected to the positive rail (low-side) or to ground (high-side).

Low-Side Mode (HSnLS = 0)

  • Load connected between OUTx and VM (positive rail)
  • Supports both CDR and VDR modes
  • Supports HFS (half full-scale) bit for improved accuracy at low currents
  • Supports SRC (slew rate control) and DPM (plunger movement detection)

High-Side Mode (HSnLS = 1)

  • Load connected between OUTx and GND
  • Only supports VDR mode (CDR not available)
  • HFS, SRC, and DPM functions are not supported in high-side mode
Note
HSnLS bit can only be changed when all channels are OFF and both TRIGA and TRIGB inputs are logic-low.
Enumerator
LOW_SIDE 

Low-side driver (HSnLS = 0) — supports CDR and VDR.

HIGH_SIDE 

High-side driver (HSnLS = 1) — VDR only, no CDR/HFS/SRC/DPM.

Function Documentation

◆ currentMaToRaw()

uint8_t max22200::currentMaToRaw ( uint32_t  full_scale_current_ma,
uint32_t  ma 
)
inline

Convert current in mA to 7-bit raw value (0–127) for CDR.

Parameters
full_scale_current_maFull-scale current in mA (must be > 0)
maDesired current in mA
Returns
Raw 7-bit value; clamped to 127 if ma >= full_scale_current_ma

◆ DriverStatusToStr()

const char * max22200::DriverStatusToStr ( DriverStatus  s)
inline

Return a human-readable string for DriverStatus (for logging and tests)

Parameters
sStatus value
Returns
Non-null C string (e.g. "OK", "COMMUNICATION_ERROR")

◆ dutyPercentToRaw()

uint8_t max22200::dutyPercentToRaw ( float  percent)
inline

Convert a VDR duty cycle in percent to the 7-bit HIT/HOLD field.

In VDR the HIT[6:0] and HOLD[6:0] fields hold the duty cycle in percent (datasheet Table 3, "VDR Duty Cycle"): 0 is 0 %, values from δMIN to δMAX are that duty in 1 % steps, 100 and above is 100 %. The chip clamps 1..δMIN and δMAX..99 to δMIN / δMAX itself.

Parameters
percentDuty cycle in percent
Returns
Raw 7-bit value: round(percent), 0 for percent <= 0, 100 for percent >= 100

◆ dutyRawToPercent()

float max22200::dutyRawToPercent ( uint8_t  raw)
inline

Convert the 7-bit VDR HIT/HOLD field to a duty cycle in percent (datasheet Table 3)

Parameters
rawHIT[6:0] or HOLD[6:0]
Returns
Duty cycle in percent; raw values of 100 and above read as 100 %

◆ FaultTypeToStr()

const char * max22200::FaultTypeToStr ( FaultType  ft)
inline

Human-readable fault type name (for logging and tests)

Parameters
ftFaultType value
Returns
Non-null C string (e.g. "Overcurrent", "HIT not reached")

◆ getChannelCfgBank()

constexpr uint8_t max22200::getChannelCfgBank ( uint8_t  channel)
constexpr

Get channel configuration register bank address.

Returns the A_BNK address for a channel's configuration register.

Parameters
channelChannel number (0-7)
Returns
Register bank address (0x01-0x08) for the specified channel
Example
uint8_t bank = getChannelCfgBank(0); // Returns 0x01 (CFG_CH0)
uint8_t bank = getChannelCfgBank(3); // Returns 0x04 (CFG_CH3)
constexpr uint8_t getChannelCfgBank(uint8_t channel)
Get channel configuration register bank address.
Definition max22200_registers.hpp:550

◆ getChopFreqKhz()

uint32_t max22200::getChopFreqKhz ( bool  master_clock_80khz,
ChopFreq  cf 
)
inline

Get chopping frequency in kHz for conversion (FREQM + FREQ_CFG)

Parameters
master_clock_80khzfalse = 100 kHz base, true = 80 kHz base
cfChannel ChopFreq (FREQ_CFG)
Returns
fCHOP in kHz (e.g. 25, 33, 50, 100 for 100 kHz base)

◆ getChopFreqKhzExact()

float max22200::getChopFreqKhzExact ( bool  master_clock_80khz,
ChopFreq  cf 
)
inline

Exact chopping frequency in kHz (FREQM + FREQ_CFG, datasheet Table 1)

Parameters
master_clock_80khzfalse = 100 kHz base, true = 80 kHz base
cfChannel ChopFreq (FREQ_CFG)
Returns
fCHOP in kHz without rounding (e.g. 33.33 for FMAIN_DIV3 at 100 kHz)

◆ GetDriverVersion()

const char * max22200::GetDriverVersion ( )
inlinenoexcept

Get the compiled driver version string (namespace-level convenience)

Returns
Null-terminated version string (same as MAX22200::GetDriverVersion())

◆ getMaxHitTimeMs()

float max22200::getMaxHitTimeMs ( bool  master_clock_80khz,
ChopFreq  cf 
)
inline

Maximum representable HIT time in ms for raw values 1–254 (255 = continuous).

Parameters
master_clock_80khzfalse = 100 kHz base, true = 80 kHz base
cfChopping frequency (FREQ_CFG)
Returns
Max finite hit time in ms; values above this map to raw 255 (continuous)

◆ hitTimeMsToRaw()

uint8_t max22200::hitTimeMsToRaw ( float  ms,
bool  master_clock_80khz,
ChopFreq  cf 
)
inline

Convert HIT time in ms to 8-bit raw value (0–255)

Parameters
msHIT time in ms (0 = no HIT; < 0 or very large = continuous, 255)
master_clock_80khzfalse = 100 kHz base, true = 80 kHz base
cfChopping frequency (FREQ_CFG)
Returns
Raw 8-bit HIT_T; 255 = continuous

Variable Documentation

◆ ENABLE_TIME_US_

constexpr uint32_t max22200::ENABLE_TIME_US_ = 500
constexpr

Enable time tEN: ENABLE rising edge to SPI ready (us)

Datasheet Electrical Characteristics: tEN = 0.5 ms maximum.

◆ MAX_SPI_FREQ_DAISY_CHAIN_

constexpr uint32_t max22200::MAX_SPI_FREQ_DAISY_CHAIN_ = 5000000
constexpr

Maximum SPI clock frequency with daisy chaining (Hz)

When multiple MAX22200 devices are connected in a daisy chain, the maximum SPI clock frequency is reduced to 5 MHz.

◆ MAX_SPI_FREQ_STANDALONE_

constexpr uint32_t max22200::MAX_SPI_FREQ_STANDALONE_ = 10000000
constexpr

Maximum SPI clock frequency without daisy chaining (Hz)

Per datasheet: "The SPI supports daisy-chain configurations and can operate up to 5MHz" (with daisy chain), and "10MHz without Daisy Chain" (standalone).

Note
Use MAX_SPI_FREQ_DAISY_CHAIN_ when multiple devices are daisy-chained.

◆ NUM_CHANNELS_

constexpr uint8_t max22200::NUM_CHANNELS_ = 8
constexpr

Number of channels on the MAX22200.

The MAX22200 is an octal (8-channel) driver.

◆ WAKE_UP_TIME_US_

constexpr uint32_t max22200::WAKE_UP_TIME_US_ = 2500
constexpr

Wake-up time tWU: ACTIVE = 1 to normal operation, outputs active (us)

Datasheet Electrical Characteristics: tWU = 2.5 ms maximum. Initialize() waits this long after it writes ACTIVE = 1.