From bcaf2686d9f0570dfbc508ddcac95ee55d501f48 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sun, 29 Oct 2023 13:05:38 -0600 Subject: converted noctigon-dm11-boost to use PWM+DSM, and recalibrated timing for delays + smooth steps Anduril has gradually gotten faster over the years, apparently, so it needed longer delays to get accurate-ish timing for beacon and other modes. Adding DSM also changes the timing perceptibly, so I made it possible to calibrate the delay fudge factor on a per-build basis. --- hwdef-noctigon-dm11-boost.h | 60 +++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 21 deletions(-) (limited to 'hwdef-noctigon-dm11-boost.h') diff --git a/hwdef-noctigon-dm11-boost.h b/hwdef-noctigon-dm11-boost.h index 4453bc7..d56a5f5 100644 --- a/hwdef-noctigon-dm11-boost.h +++ b/hwdef-noctigon-dm11-boost.h @@ -31,7 +31,7 @@ * * Main LED power uses one pin to turn the Opamp on/off, * and one pin to control Opamp power level. - * Linear brightness control uses the power level pin, with dynamic PWM. + * Regulated brightness control uses the power level pin, with PWM+DSM. * The on/off pin is only used to turn the main LED on and off, * not to change brightness. */ @@ -62,35 +62,46 @@ enum CHANNEL_MODES { //#define CHANNEL_MODE_ARGS 0,0,0,0,0,0,0,0 -#define PWM_CHANNELS 1 // old, remove this +#define PWM_CHANNELS 1 // old, remove this -#define PWM_BITS 16 // dynamic 16-bit, but never goes over 255 -#define PWM_GET PWM_GET8 -#define PWM_DATATYPE uint16_t // is used for PWM_TOPS (which goes way over 255) -#define PWM_DATATYPE2 uint16_t // only needs 32-bit if ramp values go over 255 -#define PWM1_DATATYPE uint8_t // regulated ramp +#define PWM_BITS 16 // 0 to 32640 (0 to 255 PWM + 0 to 127 DSM) at constant kHz +#define PWM_GET PWM_GET16 +#define PWM_DATATYPE uint16_t +#define PWM_DATATYPE2 uint32_t // only needs 32-bit if ramp values go over 255 +#define PWM1_DATATYPE uint16_t // 15-bit PWM+DSM ramp #define PWM_TOP ICR1 // holds the TOP value for variable-resolution PWM -#define PWM_TOP_INIT 255 // highest value used in top half of ramp -#define PWM_CNT TCNT1 // for dynamic PWM, reset phase +#define PWM_TOP_INIT 255 +#define PWM_CNT TCNT1 // for checking / resetting phase +// (max is (255 << 7), because it's 8-bit PWM plus 7 bits of DSM) +#define DSM_TOP (255<<7) // 15-bit resolution leaves 1 bit for carry + +// timer interrupt for DSM +#define DSM_vect TIMER1_OVF_vect +#define DSM_INTCTRL TIMSK +#define DSM_OVF_bm (1<