aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSelene ToyKeeper2022-04-14 21:27:08 -0600
committerSelene ToyKeeper2022-04-14 21:27:08 -0600
commitad92203240b60d1f9a916f5f0625e701d6d4387a (patch)
tree8e254f4aa75233c8b8cd8daf80abcc2520d892f5
parentavrdude fails when .fuse section is included, so omit that when copying elf t... (diff)
downloadanduril-ad92203240b60d1f9a916f5f0625e701d6d4387a.tar.gz
anduril-ad92203240b60d1f9a916f5f0625e701d6d4387a.tar.bz2
anduril-ad92203240b60d1f9a916f5f0625e701d6d4387a.zip
sp10-pro: hard reset phase while turning off, fixes shutoff bug without a delay
(also, made phase hacks individually selectable)
-rw-r--r--hwdef-Sofirn_SP10-Pro.h7
-rw-r--r--spaghetti-monster/fsm-ramping.c25
2 files changed, 22 insertions, 10 deletions
diff --git a/hwdef-Sofirn_SP10-Pro.h b/hwdef-Sofirn_SP10-Pro.h
index eee2f72..d7c2081 100644
--- a/hwdef-Sofirn_SP10-Pro.h
+++ b/hwdef-Sofirn_SP10-Pro.h
@@ -49,11 +49,14 @@ PA1 : Boost Enable
// PWM parameters of both channels are tied together because they share a counter
#define PWM1_TOP TCA0.SINGLE.PERBUF // holds the TOP value for for variable-resolution PWM
// not necessary when double-buffered "BUF" registers are used
-//#define PWM1_CNT TCA0.SINGLE.CNT // for resetting phase after each TOP adjustment
+#define PWM1_CNT TCA0.SINGLE.CNT // for resetting phase after each TOP adjustment
+#define PWM1_PHASE_RESET_OFF // force reset while shutting off
+#define PWM1_PHASE_RESET_ON // force reset while turning on
+//#define PWM1_PHASE_SYNC // manual sync while changing level
#define LED_ENABLE_PIN PIN1_bp
#define LED_ENABLE_PORT PORTA_OUT
-#define LED_OFF_DELAY 4
+//#define LED_OFF_DELAY 4 // only needed when PWM1_PHASE_RESET_OFF not used
#define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is flattened
#define DUAL_VOLTAGE_FLOOR 21 // for AA/14500 boost drivers, don't indicate low voltage if below this level
diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c
index ade49b7..1667c00 100644
--- a/spaghetti-monster/fsm-ramping.c
+++ b/spaghetti-monster/fsm-ramping.c
@@ -70,7 +70,7 @@ void set_level(uint8_t level) {
set_level_override(level);
#else
- #ifdef PWM1_CNT
+ #if defined(PWM1_CNT) && defined(PWM1_PHASE_RESET_ON) || defined(PWM1_PHASE_SYNC)
static uint8_t prev_level = 0;
uint8_t api_level = level;
#endif
@@ -93,6 +93,15 @@ void set_level(uint8_t level) {
TINT1_LVL = 0;
TINT2_LVL = 0;
#endif
+ #if defined(PWM1_CNT) && defined(PWM1_PHASE_RESET_OFF)
+ PWM1_CNT = 0;
+ #endif
+ #if defined(PWM2_CNT) && defined(PWM2_PHASE_RESET_OFF)
+ PWM2_CNT = 0;
+ #endif
+ #if defined(PWM3_CNT) && defined(PWM3_PHASE_RESET_OFF)
+ PWM3_CNT = 0;
+ #endif
#ifdef LED_OFF_DELAY
// for drivers with a slow regulator chip (eg, boost converter),
// delay before turning off to prevent flashes
@@ -167,7 +176,7 @@ void set_level(uint8_t level) {
#ifdef USE_DYN_PWM
uint16_t top = PWM_GET(pwm_tops, level);
- #ifdef PWM1_CNT
+ #if defined(PWM1_CNT) && defined(PWM1_PHASE_SYNC)
// wait to ensure compare match won't be missed
// (causes visible flickering when missed, because the counter
// goes all the way to 65535 before returning)
@@ -183,27 +192,27 @@ void set_level(uint8_t level) {
// repeat for other channels if necessary
#ifdef PMW2_TOP
- #ifdef PWM2_CNT
+ #if defined(PWM2_CNT) && defined(PWM2_PHASE_SYNC)
while(prev_level && (PWM2_CNT > (top - 32))) {}
#endif
PWM2_TOP = top;
#endif
#ifdef PMW3_TOP
- #ifdef PWM3_CNT
+ #if defined(PWM3_CNT) && defined(PWM3_PHASE_SYNC)
while(prev_level && (PWM3_CNT > (top - 32))) {}
#endif
PWM3_TOP = top;
#endif
#endif // ifdef USE_DYN_PWM
- #ifdef PWM1_CNT
+ #if defined(PWM1_CNT) && defined(PWM1_PHASE_RESET_ON)
// force reset phase when turning on from zero
// (because otherwise the initial response is inconsistent)
if (! prev_level) {
PWM1_CNT = 0;
- #ifdef PWM2_CNT
+ #if defined(PWM2_CNT) && defined(PWM2_PHASE_RESET_ON)
PWM2_CNT = 0;
#endif
- #ifdef PWM3_CNT
+ #if defined(PWM3_CNT) && defined(PWM3_PHASE_RESET_ON)
PWM3_CNT = 0;
#endif
}
@@ -213,7 +222,7 @@ void set_level(uint8_t level) {
update_tint();
#endif
- #ifdef PWM1_CNT
+ #if defined(PWM1_CNT) && defined(PWM1_PHASE_RESET_ON) || defined(PWM1_PHASE_SYNC)
prev_level = api_level;
#endif
#endif // ifdef OVERRIDE_SET_LEVEL
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.