21template <
typename SpiType>
24 last_fault_byte_(0xFF), cached_status_(), board_config_(),
28template <
typename SpiType>
31 last_fault_byte_(0xFF), cached_status_(), board_config_(
board_config),
35template <
typename SpiType>
46template <
typename SpiType>
54 updateStatistics(
false);
60 updateStatistics(
false);
66 spi_interface_.DelayUs(500);
77 updateStatistics(
false);
87 status.channels_on_mask = 0x00;
88 status.communication_error_masked =
true;
93 updateStatistics(
false);
107 updateStatistics(
false);
114 if (
status.undervoltage) {
121 updateStatistics(
true);
127 updateStatistics(
false);
131template <
typename SpiType>
141 cached_status_.
active =
false;
148 initialized_ =
false;
149 updateStatistics(
true);
153template <
typename SpiType>
162template <
typename SpiType>
173template <
typename SpiType>
187template <
typename SpiType>
191 updateStatistics(
false);
197 updateStatistics(
false);
202 if (
config.slew_rate_control_enabled &&
204 updateStatistics(
false);
214template <
typename SpiType>
218 updateStatistics(
false);
232template <
typename SpiType>
245template <
typename SpiType>
262template <
typename SpiType>
267template <
typename SpiType>
272template <
typename SpiType>
275 updateStatistics(
false);
286template <
typename SpiType>
291template <
typename SpiType>
296template <
typename SpiType>
302template <
typename SpiType>
310template <
typename SpiType>
314 updateStatistics(
false);
345template <
typename SpiType>
356template <
typename SpiType>
362template <
typename SpiType>
374template <
typename SpiType>
380 updateStatistics(
false);
393template <
typename SpiType>
398template <
typename SpiType>
409template <
typename SpiType>
420template <
typename SpiType>
427template <
typename SpiType>
436 if (
config.plunger_movement_detection_enabled !=
enable) {
447template <
typename SpiType>
452 updateStatistics(
false);
463 if (
config.plunger_movement_start_current > 127)
config.plunger_movement_start_current = 127;
479template <
typename SpiType>
484template <
typename SpiType>
489template <
typename SpiType>
496 updateStatistics(
true);
500template <
typename SpiType>
514template <
typename SpiType>
520template <
typename SpiType>
525template <
typename SpiType>
531template <
typename SpiType>
536template <
typename SpiType>
538 return last_fault_byte_;
545template <
typename SpiType>
550template <
typename SpiType>
559template <
typename SpiType>
566template <
typename SpiType>
585template <
typename SpiType>
619template <
typename SpiType>
620DriverStatus MAX22200<SpiType>::writeData32(uint32_t value)
const {
641template <
typename SpiType>
642DriverStatus MAX22200<SpiType>::readData32(uint32_t &value)
const {
658template <
typename SpiType>
659DriverStatus MAX22200<SpiType>::readData32WithTx(
const uint8_t tx[4],
660 uint32_t &value)
const {
680template <
typename SpiType>
681DriverStatus MAX22200<SpiType>::writeData8(uint8_t value)
const {
696template <
typename SpiType>
697DriverStatus MAX22200<SpiType>::readData8(uint8_t &value)
const {
710template <
typename SpiType>
712 uint32_t value)
const {
715 return writeData32(
value);
718template <
typename SpiType>
720 uint32_t &value)
const {
723 return readData32(
value);
726template <
typename SpiType>
727DriverStatus MAX22200<SpiType>::writeReg8(uint8_t bank, uint8_t value)
const {
730 return writeData8(
value);
733template <
typename SpiType>
734DriverStatus MAX22200<SpiType>::readReg8(uint8_t bank, uint8_t &value)
const {
737 return readData8(
value);
744template <
typename SpiType>
749template <
typename SpiType>
751 return board_config_;
758template <
typename SpiType>
761 updateStatistics(
false);
776 config.hit_setpoint =
static_cast<float>(
ma);
780template <
typename SpiType>
783 updateStatistics(
false);
797 config.hold_setpoint =
static_cast<float>(
ma);
801template <
typename SpiType>
806template <
typename SpiType>
811template <
typename SpiType>
814 updateStatistics(
false);
827template <
typename SpiType>
830 updateStatistics(
false);
841template <
typename SpiType>
844 updateStatistics(
false);
859template <
typename SpiType>
862 updateStatistics(
false);
877template <
typename SpiType>
881 updateStatistics(
false);
899template <
typename SpiType>
903 updateStatistics(
false);
925template <
typename SpiType>
928 updateStatistics(
false);
961template <
typename SpiType>
964 updateStatistics(
false);
993template <
typename SpiType>
997 updateStatistics(
false);
1012template <
typename SpiType>
1016 updateStatistics(
false);
1031template <
typename SpiType>
1045template <
typename SpiType>
1050 switch (chop_freq) {
1052 fchop_khz = master_clock_80khz ? 20 : 25;
1055 fchop_khz = master_clock_80khz ? 26 : 33;
1058 fchop_khz = master_clock_80khz ? 40 : 50;
1061 fchop_khz = master_clock_80khz ? 80 : 100;
1069 if (slew_rate_control_enabled) {
1099template <
typename SpiType>
1102 updateStatistics(
false);
1113 if (!std::isfinite(
ms)) {
1114 updateStatistics(
false);
1119 updateStatistics(
false);
1127template <
typename SpiType>
1130 updateStatistics(
false);
1149template <
typename SpiType>
1153 bool open_load_detection_enabled,
bool plunger_movement_detection_enabled,
1154 bool hit_current_check_enabled) {
1156 updateStatistics(
false);
1162 config.side_mode = side_mode;
1163 config.chop_freq = chop_freq;
1164 config.slew_rate_control_enabled = slew_rate_control_enabled;
1165 config.open_load_detection_enabled = open_load_detection_enabled;
1166 config.plunger_movement_detection_enabled = plunger_movement_detection_enabled;
1167 config.hit_current_check_enabled = hit_current_check_enabled;
1178 config.hit_setpoint =
static_cast<float>(hit_ma);
1179 config.hold_setpoint =
static_cast<float>(hold_ma);
1180 config.hit_time_ms = hit_time_ms;
1185template <
typename SpiType>
1187 uint8_t channel,
float hit_duty_percent,
float hold_duty_percent,
1189 bool slew_rate_control_enabled,
bool open_load_detection_enabled,
1190 bool plunger_movement_detection_enabled,
bool hit_current_check_enabled) {
1192 updateStatistics(
false);
1198 config.side_mode = side_mode;
1199 config.chop_freq = chop_freq;
1200 config.slew_rate_control_enabled = slew_rate_control_enabled;
1201 config.open_load_detection_enabled = open_load_detection_enabled;
1202 config.plunger_movement_detection_enabled = plunger_movement_detection_enabled;
1203 config.hit_current_check_enabled = hit_current_check_enabled;
1218 slew_rate_control_enabled,
limits);
1222 if (hit_duty_percent <
limits.min_percent) hit_duty_percent =
limits.min_percent;
1223 if (hit_duty_percent >
limits.max_percent) hit_duty_percent =
limits.max_percent;
1224 if (hold_duty_percent <
limits.min_percent) hold_duty_percent =
limits.min_percent;
1225 if (hold_duty_percent >
limits.max_percent) hold_duty_percent =
limits.max_percent;
1228 config.hit_setpoint = hit_duty_percent;
1229 config.hold_setpoint = hold_duty_percent;
1230 config.hit_time_ms = hit_time_ms;
1239template <
typename SpiType>
Definition max22200.hpp:133
DriverStatus ReadRegister8(uint8_t bank, uint8_t &value) const
Read 8-bit MSB of a register (fast 8-bit mode)
Definition max22200.ipp:526
DriverStatus SetChannelEnabled(uint8_t channel, bool enable)
Set a channel on or off (convenience when toggling from a variable)
Definition max22200.ipp:273
DriverStatus DisableDevice()
Disable device (ENABLE pin low); low-power state.
Definition max22200.ipp:485
DriverStatus SetDeviceEnable(bool enable)
Set ENABLE pin state (true = on, false = off)
Definition max22200.ipp:490
~MAX22200()
Destructor — calls Deinitialize() if initialized.
Definition max22200.ipp:36
DriverStatus WriteRegister8(uint8_t bank, uint8_t value)
Write 8-bit MSB of a register (fast 8-bit mode)
Definition max22200.ipp:532
DriverStatistics GetStatistics() const
Definition max22200.ipp:546
void SetBoardConfig(const BoardConfig &config)
Set board configuration (IFS, max current, max duty)
Definition max22200.ipp:745
bool IsInitialized() const
Check if driver is initialized.
Definition max22200.ipp:154
DriverStatus GetFaultPinState(bool &fault_active) const
Read nFAULT pin state (true = fault active, false = no fault)
Definition max22200.ipp:501
DriverStatus EnableDevice()
Enable device (ENABLE pin high); SPI and channels can be used.
Definition max22200.ipp:480
DriverStatus SetFullBridgeState(uint8_t pair_index, FullBridgeState state)
Set full-bridge state for a channel pair (datasheet Table 7)
Definition max22200.ipp:311
DriverStatus SetHoldDutyPercent(uint8_t channel, float percent)
Set HOLD duty cycle in percent (VDR mode)
Definition max22200.ipp:962
static DriverStatus GetDutyLimits(bool master_clock_80khz, ChopFreq chop_freq, bool slew_rate_control_enabled, DutyLimits &limits)
Get duty cycle limits (δMIN, δMAX) for a configuration.
Definition max22200.ipp:1046
DriverStatus ReadRegister32(uint8_t bank, uint32_t &value) const
Read a 32-bit register by bank address.
Definition max22200.ipp:515
DriverStatus ClearChannelFaults(uint8_t channel_mask, FaultStatus *out_faults=nullptr) const
Clear fault flags for selected channels only (MAX22200A)
Definition max22200.ipp:363
void SetFaultCallback(FaultCallback callback, void *user_data)
Definition max22200.ipp:560
DriverStatus ReadFaultFlags(StatusConfig &status) const
Read fault flags from STATUS register.
Definition max22200.ipp:394
DriverStatus Deinitialize()
Deinitialize — disable channels, ACTIVE=0, ENABLE low.
Definition max22200.ipp:132
DriverStatus ClearAllFaults()
Clear all fault flags (read FAULT register and discard)
Definition max22200.ipp:357
DriverStatus SetHoldCurrentA(uint8_t channel, float amps)
Set HOLD current in Amps (CDR mode)
Definition max22200.ipp:807
DriverStatus GetHitCurrentMa(uint8_t channel, uint32_t &ma) const
Get HIT current in milliamps (CDR mode)
Definition max22200.ipp:842
DriverStatus GetChannelConfig(uint8_t channel, ChannelConfig &config) const
Read a channel's configuration.
Definition max22200.ipp:215
DriverStatus WriteDpmConfig(const DpmConfig &config)
Write DPM algorithm configuration (CFG_DPM register)
Definition max22200.ipp:421
DriverStatus ConfigureAllChannels(const ChannelConfigArray &configs)
Configure all channels.
Definition max22200.ipp:233
DriverStatus GetAllChannelConfigs(ChannelConfigArray &configs) const
Get all channel configurations.
Definition max22200.ipp:246
static bool IsValidChannel(uint8_t channel)
Definition max22200.hpp:829
DriverStatus DisableAllChannels()
Turn off all channels.
Definition max22200.ipp:292
DriverStatus WriteStatus(const StatusConfig &status)
Write the STATUS register (writable bits only)
Definition max22200.ipp:174
DriverStatus SetHoldCurrentPercent(uint8_t channel, float percent)
Set HOLD current as percentage of IFS (CDR mode)
Definition max22200.ipp:828
DriverStatus GetHoldDutyPercent(uint8_t channel, float &percent) const
Get HOLD duty cycle in percent (VDR mode)
Definition max22200.ipp:1013
DriverStatus ConfigureDpm(float start_current_ma, float dip_threshold_ma, float debounce_ms)
Configure DPM in real units (easy API)
Definition max22200.ipp:448
DriverStatus SetHitCurrentA(uint8_t channel, float amps)
Set HIT current in Amps (CDR mode)
Definition max22200.ipp:802
DriverStatus ReadDpmConfig(DpmConfig &config) const
Read DPM algorithm configuration (CFG_DPM register)
Definition max22200.ipp:410
DriverStatus DisableChannel(uint8_t channel)
Turn off a channel (set ONCHx = 0)
Definition max22200.ipp:268
void ResetStatistics()
Definition max22200.ipp:551
DriverStatus SetHitCurrentMa(uint8_t channel, uint32_t ma)
Set HIT current in milliamps (CDR mode)
Definition max22200.ipp:759
DriverStatus SetChannelsOn(uint8_t channel_mask)
Definition max22200.ipp:303
BoardConfig GetBoardConfig() const
Get current board configuration.
Definition max22200.ipp:750
DriverStatus WriteRegister32(uint8_t bank, uint32_t value)
Write a 32-bit register by bank address.
Definition max22200.ipp:521
DriverStatus SetHitDutyPercent(uint8_t channel, float percent)
Set HIT duty cycle in percent (VDR mode)
Definition max22200.ipp:926
MAX22200(SpiType &spi_interface)
Constructor (SPI only; set board config later with SetBoardConfig())
Definition max22200.ipp:22
DriverStatus ReadFaultRegisterSelectiveClear(uint8_t ocp_mask, uint8_t hhf_mask, uint8_t olf_mask, uint8_t dpm_mask, FaultStatus &faults) const
[Advanced] Read FAULT register with per-type selective clear (MAX22200A)
Definition max22200.ipp:375
DriverStatus ConfigureChannelCdr(uint8_t channel, uint32_t hit_ma, uint32_t hold_ma, float hit_time_ms, SideMode side_mode=SideMode::LOW_SIDE, ChopFreq chop_freq=ChopFreq::FMAIN_DIV4, bool slew_rate_control_enabled=false, bool open_load_detection_enabled=false, bool plunger_movement_detection_enabled=false, bool hit_current_check_enabled=false)
Configure channel in real units (CDR mode)
Definition max22200.ipp:1150
DriverStatus SetDpmEnabledChannels(uint8_t channel_mask)
Definition max22200.ipp:428
DriverStatus GetHoldCurrentMa(uint8_t channel, uint32_t &ma) const
Get HOLD current in milliamps (CDR mode)
Definition max22200.ipp:860
DriverStatus GetHitDutyPercent(uint8_t channel, float &percent) const
Get HIT duty cycle in percent (VDR mode)
Definition max22200.ipp:994
DriverStatus EnableChannel(uint8_t channel)
Turn on a channel (set ONCHx = 1)
Definition max22200.ipp:263
DriverStatus GetHoldCurrentPercent(uint8_t channel, float &percent) const
Get HOLD current as percentage of IFS (CDR mode)
Definition max22200.ipp:900
DriverStatus SetHoldCurrentMa(uint8_t channel, uint32_t ma)
Set HOLD current in milliamps (CDR mode)
Definition max22200.ipp:781
DriverStatus ConfigureChannel(uint8_t channel, const ChannelConfig &config)
Configure a channel (write full 32-bit CFG_CHx register)
Definition max22200.ipp:188
DriverStatus GetHitTimeMs(uint8_t channel, float &ms) const
Get HIT time in milliseconds.
Definition max22200.ipp:1128
void SetStateChangeCallback(StateChangeCallback callback, void *user_data)
Definition max22200.ipp:567
DriverStatus GetHitCurrentPercent(uint8_t channel, float &percent) const
Get HIT current as percentage of IFS (CDR mode)
Definition max22200.ipp:878
DriverStatus SetHitCurrentPercent(uint8_t channel, float percent)
Set HIT current as percentage of IFS (CDR mode)
Definition max22200.ipp:812
DriverStatus SetHitTimeMs(uint8_t channel, float ms)
Set HIT time in milliseconds.
Definition max22200.ipp:1100
DriverStatus Initialize()
Initialize the driver per datasheet flowchart (Figure 6)
Definition max22200.ipp:47
DriverStatus ReadFaultRegister(FaultStatus &faults) const
Read per-channel fault register (FAULT)
Definition max22200.ipp:346
DriverStatus ClearFaultFlags()
Clear fault flags by reading STATUS register.
Definition max22200.ipp:399
DriverStatus SetAllChannelsEnabled(bool enable)
Set all channels on or off at once (convenience when toggling from a variable)
Definition max22200.ipp:297
DriverStatus ConfigureChannelVdr(uint8_t channel, float hit_duty_percent, float hold_duty_percent, float hit_time_ms, SideMode side_mode=SideMode::LOW_SIDE, ChopFreq chop_freq=ChopFreq::FMAIN_DIV4, bool slew_rate_control_enabled=false, bool open_load_detection_enabled=false, bool plunger_movement_detection_enabled=false, bool hit_current_check_enabled=false)
Configure channel in real units (VDR mode)
Definition max22200.ipp:1186
uint8_t GetLastFaultByte() const
Definition max22200.ipp:537
DriverStatus EnableAllChannels()
Turn on all channels.
Definition max22200.ipp:287
DriverStatus ReadStatus(StatusConfig &status) const
Read the full 32-bit STATUS register.
Definition max22200.ipp:163
constexpr uint8_t build(uint8_t bank, bool write, bool mode8=false)
Definition max22200_registers.hpp:172
constexpr uint8_t STATUS
Status register (32-bit) — channel on/off, HW config, faults, ACTIVE.
Definition max22200_registers.hpp:95
constexpr uint8_t FAULT
Fault register (32-bit, read-only) — per-channel fault flags.
Definition max22200_registers.hpp:104
constexpr uint8_t CFG_DPM
DPM configuration register (32-bit) — global DPM algorithm settings.
Definition max22200_registers.hpp:105
constexpr uint8_t FAULT_BYTE_COMER
Fault byte value returned on SDO when COMER is set (per datasheet Figure 6)
Definition max22200_registers.hpp:251
Definition max22200.ipp:15
@ VDR
Voltage Drive Regulation (VDRnCDR = 1) — low-side or high-side.
@ CDR
Current Drive Regulation (VDRnCDR = 0) — low-side only.
std::array< ChannelConfig, NUM_CHANNELS_ > ChannelConfigArray
Array type for channel configurations.
Definition max22200_types.hpp:970
SideMode
High-side / Low-side selection (HSnLS bit in CFG_CHx[6])
Definition max22200_types.hpp:123
DriverStatus
Driver status enumeration.
Definition max22200_types.hpp:923
@ INITIALIZATION_ERROR
Initialization failed.
@ COMMUNICATION_ERROR
SPI communication error.
@ OK
Operation successful.
@ INVALID_PARAMETER
Invalid parameter provided.
FullBridgeState
Full-bridge state for a channel pair (datasheet Table 7)
Definition max22200_types.hpp:913
@ 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 to GND)
@ HiZ
ONCHx=0, ONCHy=0 — high impedance.
uint32_t getChopFreqKhz(bool master_clock_80khz, ChopFreq cf)
Get chopping frequency in kHz for conversion (FREQM + FREQ_CFG)
Definition max22200_types.hpp:224
constexpr uint32_t MAX_SPI_FREQ_STANDALONE_
Maximum SPI clock frequency without daisy chaining (Hz)
Definition max22200_registers.hpp:70
constexpr uint8_t getChannelCfgBank(uint8_t channel)
Definition max22200_registers.hpp:535
GpioSignal
Abstract signal level for control pins.
Definition max22200_spi_interface.hpp:85
@ ACTIVE
Pin function is asserted.
ChopFreq
Chopping frequency setting (FREQ_CFG bits in CFG_CHx[5:4])
Definition max22200_types.hpp:211
@ 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.
@ 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.
void(*)(uint8_t channel, ChannelState old_state, ChannelState new_state, void *user_data) StateChangeCallback
Callback function type for channel state changes.
Definition max22200_types.hpp:981
constexpr uint8_t NUM_CHANNELS_
Number of channels on the MAX22200.
Definition max22200_registers.hpp:60
float getMaxHitTimeMs(bool master_clock_80khz, ChopFreq cf)
Maximum representable HIT time in ms for raw values 1–254 (255 = continuous).
Definition max22200_types.hpp:271
void(*)(uint8_t channel, FaultType fault_type, void *user_data) FaultCallback
Callback function type for fault events.
Definition max22200_types.hpp:975
@ FAULT
Fault status output (active-low, open-drain)
@ CMD
Command mode select (HIGH = SPI register, LOW = direct drive)
@ ENABLE
Output enable (active-high on the physical pin)
Board/scale configuration for unit-based APIs.
Definition max22200_types.hpp:1010
uint32_t full_scale_current_ma
Full-scale current in mA (from RREF: IFS = KFS×1000/RREF)
Definition max22200_types.hpp:1011
uint32_t max_current_ma
Max current limit in mA (0 = no limit, applies to all channels)
Definition max22200_types.hpp:1012
uint8_t max_duty_percent
Max duty limit in percent (0 = no limit, applies to VDR mode)
Definition max22200_types.hpp:1013
Channel configuration structure.
Definition max22200_types.hpp:360
DPM (Detection of Plunger Movement) algorithm configuration.
Definition max22200_types.hpp:882
Driver statistics structure.
Definition max22200_types.hpp:1082
uint32_t total_transfers
Definition max22200_types.hpp:1083
uint32_t failed_transfers
Definition max22200_types.hpp:1084
Duty cycle limits (δMIN, δMAX) for a given configuration.
Definition max22200_types.hpp:1057
Per-channel fault information from FAULT register (0x09)
Definition max22200_types.hpp:805
STATUS register structure.
Definition max22200_types.hpp:634
bool master_clock_80khz
Master clock base (false=100kHz, true=80kHz); affects fCHOP.
Definition max22200_types.hpp:648
uint8_t channels_on_mask
Definition max22200_types.hpp:636
bool active
Global enable (0=low-power, 1=normal); set to 1 during init.
Definition max22200_types.hpp:657