diff options
| author | Selene ToyKeeper | 2019-08-06 20:17:09 -0600 |
|---|---|---|
| committer | Selene ToyKeeper | 2019-08-06 20:17:09 -0600 |
| commit | 7d09466da0552c17b9968fa92d8ede534abfbbb6 (patch) | |
| tree | c490fd9de5f3704df54d368715b1c5284f58f638 | |
| parent | measured and adjusted D1S v2 ramp parameters (diff) | |
| download | anduril-7d09466da0552c17b9968fa92d8ede534abfbbb6.tar.gz anduril-7d09466da0552c17b9968fa92d8ede534abfbbb6.tar.bz2 anduril-7d09466da0552c17b9968fa92d8ede534abfbbb6.zip | |
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)
Diffstat (limited to '')
| -rw-r--r-- | hwdef-Emisar_D1Sv2.h | 1 | ||||
| -rw-r--r-- | spaghetti-monster/fsm-ramping.c | 4 | ||||
| -rw-r--r-- | spaghetti-monster/fsm-ramping.h | 3 |
3 files changed, 6 insertions, 2 deletions
diff --git a/hwdef-Emisar_D1Sv2.h b/hwdef-Emisar_D1Sv2.h index e1f8029..5912ea8 100644 --- a/hwdef-Emisar_D1Sv2.h +++ b/hwdef-Emisar_D1Sv2.h @@ -41,6 +41,7 @@ #define PWM_CHANNELS 1 #define PWM_BITS 10 // 0 to 1023 at 4 kHz, not 0 to 255 at 16 kHz +#define PWM_TOP 1023 #define SWITCH_PIN PA7 // pin 20 #define SWITCH_PCINT PCINT7 // pin 20 pin change interrupt 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 |
