aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster/fsm-ramping.c
diff options
context:
space:
mode:
authorSelene ToyKeeper2021-08-12 05:32:51 -0600
committerSelene ToyKeeper2021-08-12 05:32:51 -0600
commit73b67cccbe050be9e7e7ea671ffbbdd1d6f14f61 (patch)
treef81c6bd9c835cf16d563c1b4436b6fe76c62e4c7 /spaghetti-monster/fsm-ramping.c
parentchanged Noctigon KR4 from fixed to dynamic PWM TOP value, for later use (diff)
downloadanduril-73b67cccbe050be9e7e7ea671ffbbdd1d6f14f61.tar.gz
anduril-73b67cccbe050be9e7e7ea671ffbbdd1d6f14f61.tar.bz2
anduril-73b67cccbe050be9e7e7ea671ffbbdd1d6f14f61.zip
got PFM / dynamic PWM actually working on Noctigon KR4
(and also added "jump start moon" to it) (and generally finished adding dynamic PWM support to FSM)
Diffstat (limited to 'spaghetti-monster/fsm-ramping.c')
-rw-r--r--spaghetti-monster/fsm-ramping.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c
index d6a14ef..503f90f 100644
--- a/spaghetti-monster/fsm-ramping.c
+++ b/spaghetti-monster/fsm-ramping.c
@@ -151,6 +151,32 @@ void set_level(uint8_t level) {
#endif
#endif // ifdef USE_TINT_RAMPING
+
+ #ifdef USE_DYN_PWM
+ // pulse frequency modulation, a.k.a. dynamic PWM
+ PWM1_TOP = PWM_GET(pwm_tops, level);
+ #ifdef PMW2_TOP
+ PWM2_TOP = PWM_GET(pwm_tops, level);
+ #endif
+ #ifdef PMW3_TOP
+ PWM3_TOP = PWM_GET(pwm_tops, level);
+ #endif
+
+ // reset the phase, to avoid random long pulses
+ // see attiny1634 reference manual page 103 for a warning about
+ // the timing of changing the TOP value (section 12.8.4)
+ // (we don't care about being phase-correct, so the brute-force
+ // approach can be used to reset it here)
+ #ifdef PWM1_CNT
+ PWM1_CNT = 0;
+ #endif
+ #ifdef PWM2_CNT
+ PWM2_CNT = 0;
+ #endif
+ #ifdef PWM3_CNT
+ PWM3_CNT = 0;
+ #endif
+ #endif
}
#endif // ifdef OVERRIDE_SET_LEVEL
#ifdef USE_DYNAMIC_UNDERCLOCKING