From 362a7cdf758e3c0c27f9d670a3600a81b9adef92 Mon Sep 17 00:00:00 2001 From: Joseph Coffland Date: Fri, 31 Aug 2018 15:19:01 -0700 Subject: [PATCH] Small fix for max current --- src/avr/src/drv8711.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/avr/src/drv8711.c b/src/avr/src/drv8711.c index 69e0a66..ef996e1 100644 --- a/src/avr/src/drv8711.c +++ b/src/avr/src/drv8711.c @@ -104,24 +104,26 @@ static void _current_set(current_t *c, float current) { float torque_over_gain = current * CURRENT_SENSE_RESISTOR / CURRENT_SENSE_REF; float gain = 0; - if (torque_over_gain < 1.0 / 40) { + if (torque_over_gain <= 1.0 / 40) { c->isgain = DRV8711_CTRL_ISGAIN_40; gain = 40; - } else if (torque_over_gain < 1.0 / 20) { + } else if (torque_over_gain <= 1.0 / 20) { c->isgain = DRV8711_CTRL_ISGAIN_20; gain = 20; - } else if (torque_over_gain < 1.0 / 10) { + } else if (torque_over_gain <= 1.0 / 10) { c->isgain = DRV8711_CTRL_ISGAIN_10; gain = 10; - } else if (torque_over_gain < 1.0 / 5) { + } else { + // Max configurable current is 11A + if (1.0 / 5 < torque_over_gain) torque_over_gain = 1.0 / 5; c->isgain = DRV8711_CTRL_ISGAIN_5; gain = 5; } - c->torque = round(torque_over_gain * gain * 256); + c->torque = round(torque_over_gain * gain * 255); } -- 2.27.0