summaryrefslogtreecommitdiff
path: root/digital/mimot/src/dirty
diff options
context:
space:
mode:
Diffstat (limited to 'digital/mimot/src/dirty')
-rw-r--r--digital/mimot/src/dirty/pwm.h5
-rw-r--r--digital/mimot/src/dirty/pwm_ocr.avr.c8
-rw-r--r--digital/mimot/src/dirty/speed.c20
3 files changed, 22 insertions, 11 deletions
diff --git a/digital/mimot/src/dirty/pwm.h b/digital/mimot/src/dirty/pwm.h
index e48f66b9..32000bb7 100644
--- a/digital/mimot/src/dirty/pwm.h
+++ b/digital/mimot/src/dirty/pwm.h
@@ -25,8 +25,11 @@
*
* }}} */
+/** Offset to compensate for H-bridge dead zone at low PWM values. */
+#define PWM_OFFSET 0x40
+
/** Define the absolute maximum PWM value. */
-#define PWM_MAX 0x3ff
+#define PWM_MAX (0x3ff - PWM_OFFSET)
/** PWM control state. */
struct pwm_t
diff --git a/digital/mimot/src/dirty/pwm_ocr.avr.c b/digital/mimot/src/dirty/pwm_ocr.avr.c
index f10f37e7..804d7dcd 100644
--- a/digital/mimot/src/dirty/pwm_ocr.avr.c
+++ b/digital/mimot/src/dirty/pwm_ocr.avr.c
@@ -94,12 +94,12 @@ pwm_ocr_update (void)
IO_SET (PWM1_BRK_IO);
if (PWM_VALUE (PWM1) < 0)
{
- pwm1 = -PWM_VALUE (PWM1);
+ pwm1 = -PWM_VALUE (PWM1) + PWM_OFFSET;
}
else
{
dir_d |= _BV (PWM1_DIR);
- pwm1 = PWM_VALUE (PWM1);
+ pwm1 = PWM_VALUE (PWM1) + PWM_OFFSET;
}
}
# endif /* PWM1 */
@@ -115,12 +115,12 @@ pwm_ocr_update (void)
IO_SET (PWM2_BRK_IO);
if (PWM_VALUE (PWM2) < 0)
{
- pwm2 = -PWM_VALUE (PWM2);
+ pwm2 = -PWM_VALUE (PWM2) + PWM_OFFSET;
}
else
{
dir_d |= _BV (PWM2_DIR);
- pwm2 = PWM_VALUE (PWM2);
+ pwm2 = PWM_VALUE (PWM2) + PWM_OFFSET;
}
}
# endif /* PWM2 */
diff --git a/digital/mimot/src/dirty/speed.c b/digital/mimot/src/dirty/speed.c
index cd68fec2..8aa3d54b 100644
--- a/digital/mimot/src/dirty/speed.c
+++ b/digital/mimot/src/dirty/speed.c
@@ -52,13 +52,21 @@ speed_init (void)
static void
speed_update_by_speed (struct speed_t *speed)
{
- /* Update current speed. */
- if (UTILS_ABS (speed->cons - speed->cur) < speed->acc)
- speed->cur = speed->cons;
- else if (speed->cons > speed->cur)
- speed->cur += speed->acc;
+ /* Update current speed (be careful of overflow!). */
+ if (speed->cons > speed->cur)
+ {
+ if ((uint16_t) (speed->cons - speed->cur) < (uint16_t) speed->acc)
+ speed->cur = speed->cons;
+ else
+ speed->cur += speed->acc;
+ }
else
- speed->cur -= speed->acc;
+ {
+ if ((uint16_t) (speed->cur - speed->cons) < (uint16_t) speed->acc)
+ speed->cur = speed->cons;
+ else
+ speed->cur -= speed->acc;
+ }
}
/** Compute maximum allowed speed according to: distance left, maximum speed,