Skip to content

Commit 85098e8

Browse files
committed
Fix setCurrentMilliamps36v8 and update version number to 1.1.1.
1 parent 138e362 commit 85098e8

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

HighPowerStepperDriver.h

+10-7
Original file line numberDiff line numberDiff line change
@@ -381,15 +381,18 @@ class HighPowerStepperDriver
381381
void setCurrentMilliamps36v4(uint16_t current)
382382
{
383383
if (current > 8000) { current = 8000; }
384-
setCurrentMilliamps36v8(current);
384+
385+
// The 36v4 is just like the 36v8, except Risense is twice as large, so
386+
// TORQUE/ISGAIN has to be doubled.
387+
setCurrentMilliamps36v8(current * 2);
385388
}
386389

387390
/// Sets the current limit for a High-Power Stepper Motor Driver 36v8.
388391
///
389392
/// The argument to this function should be the desired current limit in
390393
/// milliamps.
391394
///
392-
/// WARNING: The 36v4 can supply up to about 8 A per coil continuously;
395+
/// WARNING: The 36v8 can supply up to about 8 A per coil continuously;
393396
/// higher currents might be sustainable for short periods, but can eventually
394397
/// cause the MOSFETs to overheat, which could damage them. See the driver's
395398
/// product page for more information.
@@ -413,18 +416,18 @@ class HighPowerStepperDriver
413416
//
414417
// TORQUE = (256 * ISGAIN * Risense * Ifs) / 2.75 V
415418
//
416-
// The 36v4 and 36v8 have an Risense of 30 milliohms, and "current" is
419+
// The 36v8 has an Risense of 15 milliohms, and "current" is
417420
// in milliamps, so:
418421
//
419-
// TORQUE = (256 * ISGAIN * (30/1000) ohms * (current/1000) A) / 2.75 V
420-
// = (7680 * ISGAIN * current) / 2750000
421-
// = (768 * (ISGAIN/40) * current) / 6875
422+
// TORQUE = (256 * ISGAIN * (15/1000) ohms * (current/1000) A) / 2.75 V
423+
// = (3840 * ISGAIN * current) / 2750000
424+
// = (384 * (ISGAIN/40) * current) / 6875
422425
//
423426
// We want to pick the highest gain (5, 10, 20, or 40) that will not
424427
// overflow TORQUE (8 bits, 0xFF max), so we start with a gain of 40 and
425428
// calculate the TORQUE value needed.
426429
uint8_t isgainBits = 0b11;
427-
uint16_t torqueBits = ((uint32_t)768 * current) / 6875;
430+
uint16_t torqueBits = ((uint32_t)384 * current) / 6875;
428431

429432
// Halve the gain and TORQUE until the TORQUE value fits in 8 bits.
430433
while (torqueBits > 0xFF)

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ HighPowerStepperDriver class reference.
8686

8787
## Version history
8888

89+
* 1.1.1 (2024-12-09): Fix the `setCurrentMilliamps36v8` function, which was
90+
setting current limits 2x higher than intended.
8991
* 1.1.0 (2024-12-06): Added support for the [Pololu High-Power Stepper Motor Driver 36v8][hpsd-36v8].
9092
* 1.0.0 (2019-06-04): Original release.
9193

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=HighPowerStepperDriver
2-
version=1.1.0
2+
version=1.1.1
33
author=Pololu
44
maintainer=Pololu <[email protected]>
55
sentence=High-Power Stepper Motor Driver library for Arduino

0 commit comments

Comments
 (0)