From 7d09466da0552c17b9968fa92d8ede534abfbbb6 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Tue, 6 Aug 2019 20:17:09 -0600 Subject: un-hardcoded 255 as the highest PWM level, and used a "PWM_TOP" value instead (should make gradual adjustments work better on devices with more than 8 bits of PWM resolution) --- spaghetti-monster/fsm-ramping.c | 4 ++-- spaghetti-monster/fsm-ramping.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index 52a7246..7bee07e 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -146,13 +146,13 @@ void gradual_tick() { gt --; // convert 1-based number to 0-based - uint8_t target; + PWM_DATATYPE target; #if PWM_CHANNELS >= 1 target = PWM_GET(pwm1_levels, gt); if ((gt < actual_level) // special case for FET-only turbo && (PWM1_LVL == 0) // (bypass adjustment period for first step) - && (target == 255)) PWM1_LVL = 255; + && (target == PWM_TOP)) PWM1_LVL = PWM_TOP; else if (PWM1_LVL < target) PWM1_LVL ++; else if (PWM1_LVL > target) PWM1_LVL --; #endif diff --git a/spaghetti-monster/fsm-ramping.h b/spaghetti-monster/fsm-ramping.h index 24c19c0..c650e21 100644 --- a/spaghetti-monster/fsm-ramping.h +++ b/spaghetti-monster/fsm-ramping.h @@ -41,12 +41,15 @@ void gradual_tick(); // auto-detect the data type for PWM tables #ifndef PWM_BITS #define PWM_BITS 8 +#define PWM_TOP 255 #endif #if PWM_BITS <= 8 #define PWM_DATATYPE uint8_t +#define PWM_TOP 255 #define PWM_GET(x,y) pgm_read_byte(x+y) #else #define PWM_DATATYPE uint16_t +#define PWM_TOP 1023 // 10 bits by default // pointer plus 2*y bytes //#define PWM_GET(x,y) pgm_read_word(x+(2*y)) // nope, the compiler was already doing the math correctly -- cgit v1.2.3