From 7831fd9b343fd8c7ad638c5a1c1309ab5030c458 Mon Sep 17 00:00:00 2001 From: fruchti Date: Sat, 8 Apr 2023 21:42:18 +0200 Subject: [PATCH] Elevate lerp to 64 bits For long lines, the linear interpolation for the current position could overflow. This is the reason the length resolution is currently so small, which sets a limit on the minimum pen speed. This change introduces two 64-bit divisions, but allows for a larger length resolution and lower pen speeds. The runtime is still pretty minimal. --- stm32f103t8u6/build_number.txt | 2 +- stm32f103t8u6/src/pwm_output.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/stm32f103t8u6/build_number.txt b/stm32f103t8u6/build_number.txt index 55bd0ac..f59a90f 100644 --- a/stm32f103t8u6/build_number.txt +++ b/stm32f103t8u6/build_number.txt @@ -1 +1 @@ -333 +337 diff --git a/stm32f103t8u6/src/pwm_output.c b/stm32f103t8u6/src/pwm_output.c index 985bc69..6aa5898 100644 --- a/stm32f103t8u6/src/pwm_output.c +++ b/stm32f103t8u6/src/pwm_output.c @@ -197,11 +197,15 @@ void Output_Tick(void) Output_CurrentLinePosition += step_length; unsigned int remaining = Output_CurrentLineLength - Output_CurrentLinePosition; - position.x = (Output_CurrentLineEnd.x * Output_CurrentLinePosition - + Output_CurrentLineStart.x * remaining) + position.x = ((long long)Output_CurrentLineEnd.x + * Output_CurrentLinePosition + + (long long)Output_CurrentLineStart.x + * remaining) / Output_CurrentLineLength; - position.y = (Output_CurrentLineEnd.y * Output_CurrentLinePosition - + Output_CurrentLineStart.y * remaining) + position.y = ((long long)Output_CurrentLineEnd.y + * Output_CurrentLinePosition + + (long long)Output_CurrentLineStart.y + * remaining) / Output_CurrentLineLength; break; }