UUtzinger_DRV8704 0.1.0 Arduino library for the DRV8704 dual H-bridge gate driver

drv8704_types.h
Go to the documentation of this file.
1
6 #ifndef DRV8704_TYPES_H
7 #define DRV8704_TYPES_H
8
9 #include <stdint.h>
10
14 enum class SenseGain : uint8_t {
15 Gain5VperV = 0,
16 Gain10VperV,
17 Gain20VperV,
18 Gain40VperV
19 };
20
24 enum class DeadTime : uint8_t {
25 Ns410 = 0,
26 Ns460,
27 Ns670,
28 Ns880
29 };
30
34 enum class DecayMode : uint8_t {
35 Slow = 0,
36 Fast = 2,
37 Mixed = 3,
38 AutoMixed = 5
39 };
40
44 enum class OcpThreshold : uint8_t {
45 MilliVolts250 = 0,
46 MilliVolts500,
47 MilliVolts750,
48 MilliVolts1000
49 };
50
54 enum class OcpDeglitch : uint8_t {
55 Us1p05 = 0,
56 Us2p10,
57 Us4p20,
58 Us8p40
59 };
60
64 enum class GateDriveTime : uint8_t {
65 Ns263 = 0,
66 Ns525,
67 Ns1050,
68 Ns2100
69 };
70
74 enum class GateDriveSourceCurrent : uint8_t {
75 MilliAmps50 = 0,
76 MilliAmps100,
77 MilliAmps150,
78 MilliAmps200
79 };
80
84 enum class GateDriveSinkCurrent : uint8_t {
85 MilliAmps100 = 0,
86 MilliAmps200,
87 MilliAmps300,
88 MilliAmps400
89 };
90
94 enum class BridgeId : uint8_t {
95 A = 0,
96 B
97 };
98
102 enum class BridgeMode : uint8_t {
103 Coast = 0,
104 Forward,
105 Reverse,
106 Brake
107 };
108
112 enum class BridgeRuntimeState : uint8_t {
113 Coast = 0,
114 Brake,
115 CurrentDrive,
116 PwmDriveWithCurrentLimit
117 };
118
122 enum class Direction : uint8_t {
123 Forward = 0,
124 Reverse
125 };
126
130 enum class PwmBackendType : uint8_t {
131 None = 0,
132 GeneralAnalogWrite,
133 Esp32Ledc,
134 TeensyHardware,
135 StmHardware,
136 Unsupported
137 };
138
142 enum class CurrentModePreset : uint8_t {
143 Heater = 0,
144 ThermoelectricCooler,
145 MotorSmallInductance,
146 MotorMediumInductance,
147 MotorLargeInductance
148 };
149
153 enum class FaultBit : uint8_t {
154 Ots = 0,
155 Aocp,
156 Bocp,
157 Apdf,
158 Bpdf,
159 Uvlo
160 };
161
165 enum class RegisterAddress : uint8_t {
166 Ctrl = 0x00,
167 Torque = 0x01,
168 Off = 0x02,
169 Blank = 0x03,
170 Decay = 0x04,
171 Reserved = 0x05,
172 Drive = 0x06,
173 Status = 0x07
174 };
175
179 struct DRV8704Pins {
180 uint8_t csPin;
181 int8_t sleepPin;
182 int8_t resetPin;
183 int8_t faultPin;
184 int8_t ain1Pin;
185 int8_t ain2Pin;
186 int8_t bin1Pin;
187 int8_t bin2Pin;
188
189 DRV8704Pins()
190 : csPin(0),
191 sleepPin(-1),
192 resetPin(-1),
193 faultPin(-1),
194 ain1Pin(-1),
195 ain2Pin(-1),
196 bin1Pin(-1),
197 bin2Pin(-1) {}
198 };
199
203 struct GateDriveConfig {
204 OcpThreshold ocpThreshold;
205 OcpDeglitch ocpDeglitch;
206 GateDriveTime tDriveN;
207 GateDriveTime tDriveP;
208 GateDriveSinkCurrent iDriveN;
209 GateDriveSourceCurrent iDriveP;
210
211 GateDriveConfig()
212 : ocpThreshold(OcpThreshold::MilliVolts500),
213 ocpDeglitch(OcpDeglitch::Us2p10),
214 tDriveN(GateDriveTime::Ns1050),
215 tDriveP(GateDriveTime::Ns1050),
216 iDriveN(GateDriveSinkCurrent::MilliAmps400),
217 iDriveP(GateDriveSourceCurrent::MilliAmps200) {}
218 };
219
223 struct DRV8704Config {
224 bool enabled;
225 SenseGain senseGain;
226 DeadTime deadTime;
227 uint8_t torque;
228 uint8_t offTime;
229 uint8_t blankTime;
230 DecayMode decayMode;
231 uint8_t decayTime;
232 GateDriveConfig gateDrive;
233
234 DRV8704Config()
235 : enabled(true),
236 senseGain(SenseGain::Gain5VperV),
237 deadTime(DeadTime::Ns410),
238 torque(0xFF),
239 offTime(0x30),
240 blankTime(0x80),
241 decayMode(DecayMode::Slow),
242 decayTime(0x10) {}
243 };
244
248 struct DRV8704CurrentPresetConfig {
249 CurrentModePreset preset;
250 uint8_t offTime;
251 uint8_t blankTime;
252 DecayMode decayMode;
253 uint8_t decayTime;
254 DeadTime deadTime;
255
256 DRV8704CurrentPresetConfig()
257 : preset(CurrentModePreset::MotorMediumInductance),
258 offTime(0x30),
259 blankTime(0x80),
260 decayMode(DecayMode::Mixed),
261 decayTime(0x10),
262 deadTime(DeadTime::Ns460) {}
263 };
264
268 struct DRV8704BridgeState {
269 BridgeId bridge;
270 Direction direction;
271 BridgeRuntimeState runtimeState;
272 float speedPercent;
273
274 DRV8704BridgeState()
275 : bridge(BridgeId::A),
276 direction(Direction::Forward),
277 runtimeState(BridgeRuntimeState::Coast),
278 speedPercent(0.0f) {}
279 };
280
284 struct DRV8704CurrentLimitResult {
285 bool enabled;
286 bool valid;
287 float requestedCurrentLimitAmps;
288 float referenceShuntOhms;
289 float shuntOhmsA;
290 float shuntOhmsB;
291 SenseGain selectedGain;
292 uint8_t torqueDac;
293 float ampsPerTorqueCount;
294 float achievableMaxCurrentAmps;
295 float appliedCurrentLimitAmpsA;
296 float appliedCurrentLimitAmpsB;
297 CurrentModePreset preset;
298 uint32_t pwmFrequencyHz;
299
300 DRV8704CurrentLimitResult()
301 : enabled(false),
302 valid(false),
303 requestedCurrentLimitAmps(0.0f),
304 referenceShuntOhms(0.0f),
305 shuntOhmsA(0.0f),
306 shuntOhmsB(0.0f),
307 selectedGain(SenseGain::Gain5VperV),
308 torqueDac(0U),
309 ampsPerTorqueCount(0.0f),
310 achievableMaxCurrentAmps(0.0f),
311 appliedCurrentLimitAmpsA(0.0f),
312 appliedCurrentLimitAmpsB(0.0f),
313 preset(CurrentModePreset::MotorMediumInductance),
314 pwmFrequencyHz(0UL) {}
315 };
316
320 struct DRV8704PwmConfig {
321 uint32_t frequencyHz;
322 uint8_t preferredResolutionBits;
323
324 DRV8704PwmConfig()
325 : frequencyHz(20000UL),
326 preferredResolutionBits(8U) {}
327 };
328
332 struct DRV8704PwmCapability {
333 bool available;
334 PwmBackendType backendType;
335 uint32_t requestedFrequencyHz;
336 uint32_t achievedFrequencyHz;
337 uint8_t resolutionBits;
338 uint32_t dutySteps;
339 float smallestDutyIncrementPercent;
340
341 DRV8704PwmCapability()
342 : available(false),
343 backendType(PwmBackendType::None),
344 requestedFrequencyHz(0UL),
345 achievedFrequencyHz(0UL),
346 resolutionBits(0U),
347 dutySteps(0UL),
348 smallestDutyIncrementPercent(0.0f) {}
349 };
350
354 struct DRV8704Status {
355 uint16_t raw;
356 bool overTemperature;
357 bool overCurrentA;
358 bool overCurrentB;
359 bool predriverFaultA;
360 bool predriverFaultB;
361 bool undervoltage;
362
363 DRV8704Status()
364 : raw(0),
365 overTemperature(false),
366 overCurrentA(false),
367 overCurrentB(false),
368 predriverFaultA(false),
369 predriverFaultB(false),
370 undervoltage(false) {}
371 };
372
376 struct DRV8704HealthCheck {
377 bool spiOk;
378 bool initialized;
379 bool faultPinActive;
380 bool defaultsMatch;
381 bool writeReadbackOk;
382 uint8_t defaultMatches;
383 uint16_t statusRegister;
384 bool faultPresent;
385
386 DRV8704HealthCheck()
387 : spiOk(false),
388 initialized(false),
389 faultPinActive(false),
390 defaultsMatch(false),
391 writeReadbackOk(false),
392 defaultMatches(0),
393 statusRegister(0),
394 faultPresent(false) {}
395 };
396
397 #endif // DRV8704_TYPES_H
GateDriveSourceCurrent
GateDriveSourceCurrent
Supported source current values for the predriver.
Definition: drv8704_types.h:74
GateDriveSourceCurrent::MilliAmps50
@ MilliAmps50
GateDriveSourceCurrent::MilliAmps200
@ MilliAmps200
GateDriveSourceCurrent::MilliAmps100
@ MilliAmps100
GateDriveSourceCurrent::MilliAmps150
@ MilliAmps150
FaultBit
FaultBit
Selectable fault bits in the STATUS register.
Definition: drv8704_types.h:153
FaultBit::Ots
@ Ots
FaultBit::Bocp
@ Bocp
FaultBit::Aocp
@ Aocp
FaultBit::Bpdf
@ Bpdf
FaultBit::Apdf
@ Apdf
FaultBit::Uvlo
@ Uvlo
OcpDeglitch
OcpDeglitch
Supported OCP deglitch durations.
Definition: drv8704_types.h:54
OcpDeglitch::Us2p10
@ Us2p10
OcpDeglitch::Us8p40
@ Us8p40
OcpDeglitch::Us4p20
@ Us4p20
OcpDeglitch::Us1p05
@ Us1p05
Direction
Direction
High-level direction selector for current mode and PWM mode.
Definition: drv8704_types.h:122
BridgeRuntimeState
BridgeRuntimeState
High-level runtime state for one bridge.
Definition: drv8704_types.h:112
BridgeRuntimeState::CurrentDrive
@ CurrentDrive
BridgeRuntimeState::PwmDriveWithCurrentLimit
@ PwmDriveWithCurrentLimit
PwmBackendType
PwmBackendType
Supported platform PWM backend families.
Definition: drv8704_types.h:130
PwmBackendType::Esp32Ledc
@ Esp32Ledc
PwmBackendType::StmHardware
@ StmHardware
PwmBackendType::None
@ None
PwmBackendType::GeneralAnalogWrite
@ GeneralAnalogWrite
PwmBackendType::Unsupported
@ Unsupported
PwmBackendType::TeensyHardware
@ TeensyHardware
CurrentModePreset
CurrentModePreset
Predefined load presets for current-mode timing and decay behavior.
Definition: drv8704_types.h:142
CurrentModePreset::MotorSmallInductance
@ MotorSmallInductance
CurrentModePreset::MotorMediumInductance
@ MotorMediumInductance
CurrentModePreset::ThermoelectricCooler
@ ThermoelectricCooler
CurrentModePreset::MotorLargeInductance
@ MotorLargeInductance
CurrentModePreset::Heater
@ Heater
RegisterAddress
RegisterAddress
Supported register addresses.
Definition: drv8704_types.h:165
RegisterAddress::Torque
@ Torque
RegisterAddress::Ctrl
@ Ctrl
RegisterAddress::Decay
@ Decay
RegisterAddress::Reserved
@ Reserved
RegisterAddress::Off
@ Off
RegisterAddress::Blank
@ Blank
RegisterAddress::Status
@ Status
RegisterAddress::Drive
@ Drive
GateDriveTime
GateDriveTime
Supported gate-drive timing values.
Definition: drv8704_types.h:64
GateDriveTime::Ns2100
@ Ns2100
GateDriveTime::Ns263
@ Ns263
GateDriveTime::Ns1050
@ Ns1050
GateDriveTime::Ns525
@ Ns525
GateDriveSinkCurrent
GateDriveSinkCurrent
Supported sink current values for the predriver.
Definition: drv8704_types.h:84
GateDriveSinkCurrent::MilliAmps400
@ MilliAmps400
GateDriveSinkCurrent::MilliAmps300
@ MilliAmps300
DecayMode
DecayMode
Supported current-decay modes.
Definition: drv8704_types.h:34
DecayMode::Mixed
@ Mixed
DecayMode::AutoMixed
@ AutoMixed
DecayMode::Fast
@ Fast
DecayMode::Slow
@ Slow
OcpThreshold
OcpThreshold
Supported overcurrent thresholds.
Definition: drv8704_types.h:44
OcpThreshold::MilliVolts750
@ MilliVolts750
OcpThreshold::MilliVolts1000
@ MilliVolts1000
OcpThreshold::MilliVolts250
@ MilliVolts250
OcpThreshold::MilliVolts500
@ MilliVolts500
BridgeId
BridgeId
Bridge selector.
Definition: drv8704_types.h:94
BridgeId::A
@ A
BridgeId::B
@ B
DeadTime
DeadTime
Supported dead-time settings.
Definition: drv8704_types.h:24
DeadTime::Ns410
@ Ns410
DeadTime::Ns880
@ Ns880
DeadTime::Ns670
@ Ns670
DeadTime::Ns460
@ Ns460
SenseGain
SenseGain
Supported sense amplifier gain settings.
Definition: drv8704_types.h:14
SenseGain::Gain5VperV
@ Gain5VperV
SenseGain::Gain40VperV
@ Gain40VperV
SenseGain::Gain20VperV
@ Gain20VperV
SenseGain::Gain10VperV
@ Gain10VperV
BridgeMode
BridgeMode
Runtime bridge command.
Definition: drv8704_types.h:102
BridgeMode::Coast
@ Coast
BridgeMode::Forward
@ Forward
BridgeMode::Reverse
@ Reverse
BridgeMode::Brake
@ Brake
DRV8704BridgeState
Reported direction and runtime mode of one bridge.
Definition: drv8704_types.h:268
DRV8704BridgeState::bridge
BridgeId bridge
Definition: drv8704_types.h:269
DRV8704BridgeState::DRV8704BridgeState
DRV8704BridgeState()
Definition: drv8704_types.h:274
DRV8704BridgeState::runtimeState
BridgeRuntimeState runtimeState
Definition: drv8704_types.h:271
DRV8704BridgeState::direction
Direction direction
Definition: drv8704_types.h:270
DRV8704BridgeState::speedPercent
float speedPercent
Definition: drv8704_types.h:272
DRV8704Config
High-level DRV8704 configuration snapshot.
Definition: drv8704_types.h:223
DRV8704Config::offTime
uint8_t offTime
Definition: drv8704_types.h:228
DRV8704Config::torque
uint8_t torque
Definition: drv8704_types.h:227
DRV8704Config::enabled
bool enabled
Definition: drv8704_types.h:224
DRV8704Config::blankTime
uint8_t blankTime
Definition: drv8704_types.h:229
DRV8704Config::gateDrive
GateDriveConfig gateDrive
Definition: drv8704_types.h:232
DRV8704Config::senseGain
SenseGain senseGain
Definition: drv8704_types.h:225
DRV8704Config::decayMode
DecayMode decayMode
Definition: drv8704_types.h:230
DRV8704Config::deadTime
DeadTime deadTime
Definition: drv8704_types.h:226
DRV8704Config::decayTime
uint8_t decayTime
Definition: drv8704_types.h:231
DRV8704Config::DRV8704Config
DRV8704Config()
Definition: drv8704_types.h:234
DRV8704CurrentLimitResult
Derived chip-global current-limit settings and per-bridge consequences.
Definition: drv8704_types.h:284
DRV8704CurrentLimitResult::shuntOhmsB
float shuntOhmsB
Definition: drv8704_types.h:290
DRV8704CurrentLimitResult::valid
bool valid
Definition: drv8704_types.h:286
DRV8704CurrentLimitResult::referenceShuntOhms
float referenceShuntOhms
Definition: drv8704_types.h:288
DRV8704CurrentLimitResult::DRV8704CurrentLimitResult
DRV8704CurrentLimitResult()
Definition: drv8704_types.h:300
DRV8704CurrentLimitResult::pwmFrequencyHz
uint32_t pwmFrequencyHz
Definition: drv8704_types.h:298
DRV8704CurrentLimitResult::torqueDac
uint8_t torqueDac
Definition: drv8704_types.h:292
DRV8704CurrentLimitResult::enabled
bool enabled
Definition: drv8704_types.h:285
DRV8704CurrentLimitResult::shuntOhmsA
float shuntOhmsA
Definition: drv8704_types.h:289
DRV8704CurrentLimitResult::ampsPerTorqueCount
float ampsPerTorqueCount
Definition: drv8704_types.h:293
DRV8704CurrentLimitResult::appliedCurrentLimitAmpsB
float appliedCurrentLimitAmpsB
Definition: drv8704_types.h:296
DRV8704CurrentLimitResult::appliedCurrentLimitAmpsA
float appliedCurrentLimitAmpsA
Definition: drv8704_types.h:295
DRV8704CurrentLimitResult::preset
CurrentModePreset preset
Definition: drv8704_types.h:297
DRV8704CurrentLimitResult::achievableMaxCurrentAmps
float achievableMaxCurrentAmps
Definition: drv8704_types.h:294
DRV8704CurrentLimitResult::selectedGain
SenseGain selectedGain
Definition: drv8704_types.h:291
DRV8704CurrentLimitResult::requestedCurrentLimitAmps
float requestedCurrentLimitAmps
Definition: drv8704_types.h:287
DRV8704CurrentPresetConfig
Timing and decay recommendation associated with a current-mode preset.
Definition: drv8704_types.h:248
DRV8704CurrentPresetConfig::preset
CurrentModePreset preset
Definition: drv8704_types.h:249
DRV8704CurrentPresetConfig::offTime
uint8_t offTime
Definition: drv8704_types.h:250
DRV8704CurrentPresetConfig::decayTime
uint8_t decayTime
Definition: drv8704_types.h:253
DRV8704CurrentPresetConfig::deadTime
DeadTime deadTime
Definition: drv8704_types.h:254
DRV8704CurrentPresetConfig::DRV8704CurrentPresetConfig
DRV8704CurrentPresetConfig()
Definition: drv8704_types.h:256
DRV8704CurrentPresetConfig::decayMode
DecayMode decayMode
Definition: drv8704_types.h:252
DRV8704CurrentPresetConfig::blankTime
uint8_t blankTime
Definition: drv8704_types.h:251
DRV8704HealthCheck
Minimal transport/bring-up health result.
Definition: drv8704_types.h:376
DRV8704HealthCheck::faultPinActive
bool faultPinActive
Definition: drv8704_types.h:379
DRV8704HealthCheck::initialized
bool initialized
Definition: drv8704_types.h:378
DRV8704HealthCheck::writeReadbackOk
bool writeReadbackOk
Definition: drv8704_types.h:381
DRV8704HealthCheck::DRV8704HealthCheck
DRV8704HealthCheck()
Definition: drv8704_types.h:386
DRV8704HealthCheck::faultPresent
bool faultPresent
Definition: drv8704_types.h:384
DRV8704HealthCheck::defaultsMatch
bool defaultsMatch
Definition: drv8704_types.h:380
DRV8704HealthCheck::spiOk
bool spiOk
Definition: drv8704_types.h:377
DRV8704HealthCheck::defaultMatches
uint8_t defaultMatches
Definition: drv8704_types.h:382
DRV8704HealthCheck::statusRegister
uint16_t statusRegister
Definition: drv8704_types.h:383
DRV8704Pins
Pin assignment bundle for a DRV8704 instance.
Definition: drv8704_types.h:179
DRV8704Pins::ain2Pin
int8_t ain2Pin
Definition: drv8704_types.h:185
DRV8704Pins::DRV8704Pins
DRV8704Pins()
Definition: drv8704_types.h:189
DRV8704Pins::bin1Pin
int8_t bin1Pin
Definition: drv8704_types.h:186
DRV8704Pins::faultPin
int8_t faultPin
Definition: drv8704_types.h:183
DRV8704Pins::resetPin
int8_t resetPin
Definition: drv8704_types.h:182
DRV8704Pins::sleepPin
int8_t sleepPin
Definition: drv8704_types.h:181
DRV8704Pins::bin2Pin
int8_t bin2Pin
Definition: drv8704_types.h:187
DRV8704Pins::csPin
uint8_t csPin
Definition: drv8704_types.h:180
DRV8704Pins::ain1Pin
int8_t ain1Pin
Definition: drv8704_types.h:184
DRV8704PwmCapability
Resolved platform PWM capabilities for the active backend.
Definition: drv8704_types.h:332
DRV8704PwmCapability::dutySteps
uint32_t dutySteps
Definition: drv8704_types.h:338
DRV8704PwmCapability::backendType
PwmBackendType backendType
Definition: drv8704_types.h:334
DRV8704PwmCapability::requestedFrequencyHz
uint32_t requestedFrequencyHz
Definition: drv8704_types.h:335
DRV8704PwmCapability::resolutionBits
uint8_t resolutionBits
Definition: drv8704_types.h:337
DRV8704PwmCapability::smallestDutyIncrementPercent
float smallestDutyIncrementPercent
Definition: drv8704_types.h:339
DRV8704PwmCapability::available
bool available
Definition: drv8704_types.h:333
DRV8704PwmCapability::DRV8704PwmCapability
DRV8704PwmCapability()
Definition: drv8704_types.h:341
DRV8704PwmCapability::achievedFrequencyHz
uint32_t achievedFrequencyHz
Definition: drv8704_types.h:336
DRV8704PwmConfig
Requested PWM generator settings.
Definition: drv8704_types.h:320
DRV8704PwmConfig::DRV8704PwmConfig
DRV8704PwmConfig()
Definition: drv8704_types.h:324
DRV8704PwmConfig::frequencyHz
uint32_t frequencyHz
Definition: drv8704_types.h:321
DRV8704PwmConfig::preferredResolutionBits
uint8_t preferredResolutionBits
Definition: drv8704_types.h:322
DRV8704Status
Decoded device status and fault state.
Definition: drv8704_types.h:354
DRV8704Status::overCurrentB
bool overCurrentB
Definition: drv8704_types.h:358
DRV8704Status::predriverFaultB
bool predriverFaultB
Definition: drv8704_types.h:360
DRV8704Status::undervoltage
bool undervoltage
Definition: drv8704_types.h:361
DRV8704Status::overTemperature
bool overTemperature
Definition: drv8704_types.h:356
DRV8704Status::overCurrentA
bool overCurrentA
Definition: drv8704_types.h:357
DRV8704Status::raw
uint16_t raw
Definition: drv8704_types.h:355
DRV8704Status::DRV8704Status
DRV8704Status()
Definition: drv8704_types.h:363
DRV8704Status::predriverFaultA
bool predriverFaultA
Definition: drv8704_types.h:359
GateDriveConfig
Gate-drive configuration group.
Definition: drv8704_types.h:203
GateDriveConfig::iDriveP
GateDriveSourceCurrent iDriveP
Definition: drv8704_types.h:209
GateDriveConfig::ocpThreshold
OcpThreshold ocpThreshold
Definition: drv8704_types.h:204
GateDriveConfig::GateDriveConfig
GateDriveConfig()
Definition: drv8704_types.h:211
GateDriveConfig::ocpDeglitch
OcpDeglitch ocpDeglitch
Definition: drv8704_types.h:205
GateDriveConfig::iDriveN
GateDriveSinkCurrent iDriveN
Definition: drv8704_types.h:208
GateDriveConfig::tDriveP
GateDriveTime tDriveP
Definition: drv8704_types.h:207
GateDriveConfig::tDriveN
GateDriveTime tDriveN
Definition: drv8704_types.h:206