From 597b3457588dc8fb308b579846e686ef31477105 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Fri, 24 Sep 2021 05:18:42 -0600 Subject: copied Noctigon K1 -> MD11 to start defining a new light --- hwdef-Noctigon_MD11.h | 134 ++++++++++++++++++++++++++ spaghetti-monster/anduril/cfg-noctigon-md11.h | 61 ++++++++++++ 2 files changed, 195 insertions(+) create mode 100644 hwdef-Noctigon_MD11.h create mode 100644 spaghetti-monster/anduril/cfg-noctigon-md11.h diff --git a/hwdef-Noctigon_MD11.h b/hwdef-Noctigon_MD11.h new file mode 100644 index 0000000..4c0ce05 --- /dev/null +++ b/hwdef-Noctigon_MD11.h @@ -0,0 +1,134 @@ +#ifndef HWDEF_NOCTIGON_K1_H +#define HWDEF_NOCTIGON_K1_H + +/* Noctigon K1 driver layout (attiny1634) + * (originally known as Emisar D1S V2) + * + * Pin / Name / Function + * 1 PA6 (none) (PWM1B) (reserved for DD drivers) + * 2 PA5 R: red aux LED (PWM0B) + * 3 PA4 G: green aux LED + * 4 PA3 B: blue aux LED + * 5 PA2 (none) (reserved for L: button LED (on some models)) + * 6 PA1 (none) + * 7 PA0 (none) + * 8 GND GND + * 9 VCC VCC + * 10 PC5 (none) + * 11 PC4 (none) + * 12 PC3 RESET + * 13 PC2 (none) + * 14 PC1 SCK + * 15 PC0 (none) PWM0A + * 16 PB3 main LED PWM (PWM1A) + * 17 PB2 MISO + * 18 PB1 MOSI / battery voltage (ADC6) + * 19 PB0 Opamp power + * 20 PA7 e-switch (PCINT7) + * ADC12 thermal sensor + * + * Main LED power uses one pin to turn the Opamp on/off, + * and one pin to control Opamp power level. + * All brightness control uses the power level pin, with 4 kHz 10-bit PWM. + * The on/off pin is only used to turn the main LED on and off, + * not to change brightness. + */ + +#ifdef ATTINY +#undef ATTINY +#endif +#define ATTINY 1634 +#include + +#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 +#define SWITCH_PCIE PCIE0 // PCIE0 is for PCINT[7:0] +#define SWITCH_PCMSK PCMSK0 // PCMSK0 is for PCINT[7:0] +#define SWITCH_PORT PINA // PINA or PINB or PINC + +#define PWM1_PIN PB3 // pin 16, Opamp reference +#define PWM1_LVL OCR1A // OCR1A is the output compare register for PB3 + +#define LED_ENABLE_PIN PB0 // pin 19, Opamp power +#define LED_ENABLE_PORT PORTB // control port for PB0 + + +#define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is flattened +#define VOLTAGE_PIN PB1 // Pin 18 / PB1 / ADC6 +// pin to ADC mappings are in DS table 19-4 +#define VOLTAGE_ADC ADC6D // digital input disable pin for PB1 +// DIDR0/DIDR1 mappings are in DS section 19.13.5, 19.13.6 +#define VOLTAGE_ADC_DIDR DIDR1 // DIDR channel for ADC6D +// DS tables 19-3, 19-4 +// Bit 7 6 5 4 3 2 1 0 +// REFS1 REFS0 REFEN ADC0EN MUX3 MUX2 MUX1 MUX0 +// MUX[3:0] = 0, 1, 1, 0 for ADC6 / PB1 +// divided by ... +// REFS[1:0] = 1, 0 for internal 1.1V reference +// other bits reserved +#define ADMUX_VOLTAGE_DIVIDER 0b10000110 +#define ADC_PRSCL 0x07 // clk/128 + +// Raw ADC readings at 4.4V and 2.2V +// calibrate the voltage readout here +// estimated / calculated values are: +// (voltage - D1) * (R2/(R2+R1) * 256 / 1.1) +// D1, R1, R2 = 0, 330, 100 +#ifndef ADC_44 +//#define ADC_44 981 // raw value at 4.40V +#define ADC_44 967 // manually tweaked so 4.16V will blink out 4.2 +#endif +#ifndef ADC_22 +//#define ADC_22 489 // raw value at 2.20V +#define ADC_22 482 // manually tweaked so 4.16V will blink out 4.2 +#endif + +// this light has aux LEDs under the optic +#define AUXLED_R_PIN PA5 // pin 2 +#define AUXLED_G_PIN PA4 // pin 3 +#define AUXLED_B_PIN PA3 // pin 4 +#define AUXLED_RGB_PORT PORTA // PORTA or PORTB or PORTC +#define AUXLED_RGB_DDR DDRA // DDRA or DDRB or DDRC +#define AUXLED_RGB_PUE PUEA // PUEA or PUEB or PUEC + +// with so many pins, doing this all with #ifdefs gets awkward... +// ... so just hardcode it in each hwdef file instead +inline void hwdef_setup() { + // enable output ports + // Opamp level and Opamp on/off + DDRB = (1 << PWM1_PIN) + | (1 << LED_ENABLE_PIN); + // aux R/G/B + DDRA = (1 << AUXLED_R_PIN) + | (1 << AUXLED_G_PIN) + | (1 << AUXLED_B_PIN) + ; + + // configure PWM + // Setup PWM. F_pwm = F_clkio / 2 / N / TOP, where N = prescale factor, TOP = top of counter + // pre-scale for timer: N = 1 + // WGM1[3:0]: 0,0,1,1: PWM, Phase Correct, 10-bit (DS table 12-5) + // CS1[2:0]: 0,0,1: clk/1 (No prescaling) (DS table 12-6) + // COM1A[1:0]: 1,0: PWM OC1A in the normal direction (DS table 12-4) + // COM1B[1:0]: 0,0: PWM OC1B disabled (DS table 12-4) + TCCR1A = (1< -#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 PWM_CHANNELS 2 // override this for the no-FET version +#define PWM_BITS 16 // data type needs 16 bits, not 8 +#define PWM_TOP 255 // highest value used in top half of ramp +#define USE_DYN_PWM // dynamic frequency and speed #define SWITCH_PIN PA7 // pin 20 #define SWITCH_PCINT PCINT7 // pin 20 pin change interrupt @@ -52,6 +54,13 @@ #define PWM1_PIN PB3 // pin 16, Opamp reference #define PWM1_LVL OCR1A // OCR1A is the output compare register for PB3 +#define PWM1_CNT TCNT1 // for dynamic PWM, reset phase + +#define PWM2_PIN PA6 // pin 1, DD FET PWM +#define PWM2_LVL OCR1B // OCR1B is the output compare register for PA6 + +// PWM parameters of both channels are tied together because they share a counter +#define PWM1_TOP ICR1 // holds the TOP value for for variable-resolution PWM #define LED_ENABLE_PIN PB0 // pin 19, Opamp power #define LED_ENABLE_PORT PORTB // control port for PB0 @@ -76,7 +85,7 @@ // Raw ADC readings at 4.4V and 2.2V // calibrate the voltage readout here // estimated / calculated values are: -// (voltage - D1) * (R2/(R2+R1) * 256 / 1.1) +// (voltage - D1) * (R2/(R2+R1) * 1024 / 1.1) // D1, R1, R2 = 0, 330, 100 #ifndef ADC_44 //#define ADC_44 981 // raw value at 4.40V @@ -107,8 +116,9 @@ inline void hwdef_setup() { // Opamp level and Opamp on/off DDRB = (1 << PWM1_PIN) | (1 << LED_ENABLE_PIN); - // aux R/G/B - DDRA = (1 << AUXLED_R_PIN) + // DD FET PWM, aux R/G/B, button LED + DDRA = (1 << PWM2_PIN) + | (1 << AUXLED_R_PIN) | (1 << AUXLED_G_PIN) | (1 << AUXLED_B_PIN) | (1 << BUTTON_LED_PIN) @@ -117,18 +127,21 @@ inline void hwdef_setup() { // configure PWM // Setup PWM. F_pwm = F_clkio / 2 / N / TOP, where N = prescale factor, TOP = top of counter // pre-scale for timer: N = 1 - // WGM1[3:0]: 0,0,1,1: PWM, Phase Correct, 10-bit (DS table 12-5) + // WGM1[3:0]: 1,0,1,0: PWM, Phase Correct, adjustable (DS table 12-5) // CS1[2:0]: 0,0,1: clk/1 (No prescaling) (DS table 12-6) // COM1A[1:0]: 1,0: PWM OC1A in the normal direction (DS table 12-4) - // COM1B[1:0]: 0,0: PWM OC1B disabled (DS table 12-4) - TCCR1A = (1< end of dynamic PWM range + diff --git a/spaghetti-monster/anduril/cfg-noctigon-md11.h b/spaghetti-monster/anduril/cfg-noctigon-md11.h index ea768af..130e05c 100644 --- a/spaghetti-monster/anduril/cfg-noctigon-md11.h +++ b/spaghetti-monster/anduril/cfg-noctigon-md11.h @@ -48,10 +48,11 @@ #define SIMPLE_UI_STEPS 5 // make candle mode wobble more -#define CANDLE_AMPLITUDE 32 +#define CANDLE_AMPLITUDE 30 // stop panicking at ~70% power or ~600 lm #define THERM_FASTER_LEVEL 130 +#define MIN_THERM_STEPDOWN 66 // must be > end of dynamic PWM range //#define THERM_RESPONSE_MAGNITUDE 32 // smaller adjustments, this host changes temperature slowly //#define THERM_NEXT_WARNING_THRESHOLD 32 // more error tolerance before adjusting @@ -64,8 +65,8 @@ // the power regulator is a bit slow, so push it harder for a quick response from off #define DEFAULT_JUMP_START_LEVEL 21 -//#define BLINK_BRIGHTNESS DEFAULT_LEVEL -//#define BLINK_ONCE_TIME 12 +#define BLINK_BRIGHTNESS DEFAULT_LEVEL +#define BLINK_ONCE_TIME 12 // can't reset the normal way because power is connected before the button #define USE_SOFT_FACTORY_RESET -- cgit v1.2.3 From 16de2bade47b0e11495e06bfdb702dc346f8c5bc Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Mon, 4 Oct 2021 02:54:48 -0600 Subject: added early initial attempt at a boost/12V/6V version of the MD11 (had to guess about some hardware details, unsure if correct) --- hwdef-Noctigon_MD11-12V.h | 162 ++++++++++++++++++++++ spaghetti-monster/anduril/cfg-noctigon-md11-12v.h | 70 ++++++++++ 2 files changed, 232 insertions(+) create mode 100644 hwdef-Noctigon_MD11-12V.h create mode 100644 spaghetti-monster/anduril/cfg-noctigon-md11-12v.h diff --git a/hwdef-Noctigon_MD11-12V.h b/hwdef-Noctigon_MD11-12V.h new file mode 100644 index 0000000..909cdbd --- /dev/null +++ b/hwdef-Noctigon_MD11-12V.h @@ -0,0 +1,162 @@ +#ifndef HWDEF_NOCTIGON_MD11_12V_H +#define HWDEF_NOCTIGON_MD11_12V_H + +/* Noctigon MD11 (12V) driver layout (attiny1634) + * (based on Noctigon K1) + * + * Pin / Name / Function + * 1 PA6 (none) (PWM1B) (reserved for DD drivers) + * 2 PA5 R: red aux LED (PWM0B) + * 3 PA4 G: green aux LED + * 4 PA3 B: blue aux LED + * 5 PA2 L: button LED + * 6 PA1 (none) + * 7 PA0 (none) + * 8 GND GND + * 9 VCC VCC + * 10 PC5 (none) + * 11 PC4 (none) + * 12 PC3 RESET + * 13 PC2 (none) + * 14 PC1 SCK + * 15 PC0 boost PMIC enable (PWM0A not used) + * 16 PB3 main LED PWM (PWM1A) + * 17 PB2 MISO / e-switch? (PCINT10) + * 18 PB1 MOSI / battery voltage (ADC6) + * 19 PB0 Opamp power + * 20 PA7 e-switch? (PCINT7) + * ADC12 thermal sensor + * + * 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. + * The on/off pin is only used to turn the main LED on and off, + * not to change brightness. + */ + +#ifdef ATTINY +#undef ATTINY +#endif +#define ATTINY 1634 +#include + +#define PWM_CHANNELS 1 // can't use DD FET on boost drivers +#define PWM_BITS 16 // data type needs 16 bits, not 8 +#define PWM_TOP 255 // highest value used in top half of ramp +#define USE_DYN_PWM // dynamic frequency and speed + +//#define SWITCH_PIN PB2 // pin 17 +//#define SWITCH_PCINT PCINT10 // pin 17 pin change interrupt +//#define SWITCH_PCIE PCIE1 // PCIE1 is for PCINT[11:8] +//#define SWITCH_PCMSK PCMSK1 // PCMSK1 is for PCINT[11:8] +//#define SWITCH_PORT PINB // PINA or PINB or PINC +//#define PCINT_vect PCINT1_vect // ISR for PCINT[11:8] + +#define SWITCH_PIN PA7 // pin 20 +#define SWITCH_PCINT PCINT7 // pin 20 pin change interrupt +#define SWITCH_PCIE PCIE0 // PCIE0 is for PCINT[7:0] +#define SWITCH_PCMSK PCMSK0 // PCMSK0 is for PCINT[7:0] +#define SWITCH_PORT PINA // PINA or PINB or PINC + +#define PWM1_PIN PB3 // pin 16, Opamp reference +#define PWM1_LVL OCR1A // OCR1A is the output compare register for PB3 +#define PWM1_CNT TCNT1 // for dynamic PWM, reset phase + +// PWM parameters of both channels are tied together because they share a counter +#define PWM1_TOP ICR1 // holds the TOP value for for variable-resolution PWM + +#define LED_ENABLE_PIN PB0 // pin 19, Opamp power +#define LED_ENABLE_PORT PORTB // control port for PB0 + +#define LED2_ENABLE_PIN PC0 // pin 15, boost PMIC enable +#define LED2_ENABLE_PORT PORTC // control port for PC0 + + +#define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is flattened +#define VOLTAGE_PIN PB1 // Pin 18 / PB1 / ADC6 +// pin to ADC mappings are in DS table 19-4 +#define VOLTAGE_ADC ADC6D // digital input disable pin for PB1 +// DIDR0/DIDR1 mappings are in DS section 19.13.5, 19.13.6 +#define VOLTAGE_ADC_DIDR DIDR1 // DIDR channel for ADC6D +// DS tables 19-3, 19-4 +// Bit 7 6 5 4 3 2 1 0 +// REFS1 REFS0 REFEN ADC0EN MUX3 MUX2 MUX1 MUX0 +// MUX[3:0] = 0, 1, 1, 0 for ADC6 / PB1 +// divided by ... +// REFS[1:0] = 1, 0 for internal 1.1V reference +// other bits reserved +#define ADMUX_VOLTAGE_DIVIDER 0b10000110 +#define ADC_PRSCL 0x07 // clk/128 + +// Raw ADC readings at 4.4V and 2.2V +// calibrate the voltage readout here +// estimated / calculated values are: +// (voltage - D1) * (R2/(R2+R1) * 1024 / 1.1) +// D1, R1, R2 = 0, 330, 100 +#ifndef ADC_44 +//#define ADC_44 981 // raw value at 4.40V +#define ADC_44 967 // manually tweaked so 4.16V will blink out 4.2 +#endif +#ifndef ADC_22 +//#define ADC_22 489 // raw value at 2.20V +#define ADC_22 482 // manually tweaked so 4.16V will blink out 4.2 +#endif + +// this light has aux LEDs under the optic +#define AUXLED_R_PIN PA5 // pin 2 +#define AUXLED_G_PIN PA4 // pin 3 +#define AUXLED_B_PIN PA3 // pin 4 +#define AUXLED_RGB_PORT PORTA // PORTA or PORTB or PORTC +#define AUXLED_RGB_DDR DDRA // DDRA or DDRB or DDRC +#define AUXLED_RGB_PUE PUEA // PUEA or PUEB or PUEC + +#define BUTTON_LED_PIN PA2 // pin 5 +#define BUTTON_LED_PORT PORTA // for all "PA" pins +#define BUTTON_LED_DDR DDRA // for all "PA" pins +#define BUTTON_LED_PUE PUEA // for all "PA" pins + +// with so many pins, doing this all with #ifdefs gets awkward... +// ... so just hardcode it in each hwdef file instead +inline void hwdef_setup() { + // enable output ports + // boost PMIC on/off + DDRC = (1 << LED2_ENABLE_PIN); + // Opamp level and Opamp on/off + DDRB = (1 << PWM1_PIN) + | (1 << LED_ENABLE_PIN); + // aux R/G/B, button LED + DDRA = (1 << AUXLED_R_PIN) + | (1 << AUXLED_G_PIN) + | (1 << AUXLED_B_PIN) + | (1 << BUTTON_LED_PIN) + ; + + // configure PWM + // Setup PWM. F_pwm = F_clkio / 2 / N / TOP, where N = prescale factor, TOP = top of counter + // pre-scale for timer: N = 1 + // WGM1[3:0]: 1,0,1,0: PWM, Phase Correct, adjustable (DS table 12-5) + // CS1[2:0]: 0,0,1: clk/1 (No prescaling) (DS table 12-6) + // COM1A[1:0]: 1,0: PWM OC1A in the normal direction (DS table 12-4) + // COM1B[1:0]: 0,0: PWM OC1B disabled (DS table 12-4) + TCCR1A = (1< end of dynamic PWM range + +//#define THERM_RESPONSE_MAGNITUDE 32 // smaller adjustments, this host changes temperature slowly +//#define THERM_NEXT_WARNING_THRESHOLD 32 // more error tolerance before adjusting + +// slow down party strobe; this driver can't pulse for 1ms or less +#define PARTY_STROBE_ONTIME 4 + +#define THERM_CAL_OFFSET 5 + +// the power regulator is a bit slow, so push it harder for a quick response from off +#define DEFAULT_JUMP_START_LEVEL 21 +#define BLINK_BRIGHTNESS DEFAULT_LEVEL +#define BLINK_ONCE_TIME 12 + +// added for convenience +#define USE_SOFT_FACTORY_RESET -- cgit v1.2.3 From 05e4a4f94af32d18388e13c1be7ef40174ba749e Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Tue, 12 Oct 2021 16:39:00 -0600 Subject: renamed MD11 -> DM11 because Hank changed the product name --- hwdef-Noctigon_DM11-12V.h | 162 +++++++++++++++++++++ hwdef-Noctigon_DM11.h | 162 +++++++++++++++++++++ hwdef-Noctigon_MD11-12V.h | 162 --------------------- hwdef-Noctigon_MD11.h | 162 --------------------- spaghetti-monster/anduril/cfg-noctigon-dm11-12v.h | 70 +++++++++ .../anduril/cfg-noctigon-dm11-nofet.h | 42 ++++++ spaghetti-monster/anduril/cfg-noctigon-dm11.h | 72 +++++++++ spaghetti-monster/anduril/cfg-noctigon-md11-12v.h | 70 --------- .../anduril/cfg-noctigon-md11-nofet.h | 42 ------ spaghetti-monster/anduril/cfg-noctigon-md11.h | 72 --------- 10 files changed, 508 insertions(+), 508 deletions(-) create mode 100644 hwdef-Noctigon_DM11-12V.h create mode 100644 hwdef-Noctigon_DM11.h delete mode 100644 hwdef-Noctigon_MD11-12V.h delete mode 100644 hwdef-Noctigon_MD11.h create mode 100644 spaghetti-monster/anduril/cfg-noctigon-dm11-12v.h create mode 100644 spaghetti-monster/anduril/cfg-noctigon-dm11-nofet.h create mode 100644 spaghetti-monster/anduril/cfg-noctigon-dm11.h delete mode 100644 spaghetti-monster/anduril/cfg-noctigon-md11-12v.h delete mode 100644 spaghetti-monster/anduril/cfg-noctigon-md11-nofet.h delete mode 100644 spaghetti-monster/anduril/cfg-noctigon-md11.h diff --git a/hwdef-Noctigon_DM11-12V.h b/hwdef-Noctigon_DM11-12V.h new file mode 100644 index 0000000..bd24768 --- /dev/null +++ b/hwdef-Noctigon_DM11-12V.h @@ -0,0 +1,162 @@ +#ifndef HWDEF_NOCTIGON_DM11_12V_H +#define HWDEF_NOCTIGON_DM11_12V_H + +/* Noctigon DM11 (12V) driver layout (attiny1634) + * (based on Noctigon K1) + * + * Pin / Name / Function + * 1 PA6 (none) (PWM1B) (reserved for DD drivers) + * 2 PA5 R: red aux LED (PWM0B) + * 3 PA4 G: green aux LED + * 4 PA3 B: blue aux LED + * 5 PA2 L: button LED + * 6 PA1 (none) + * 7 PA0 (none) + * 8 GND GND + * 9 VCC VCC + * 10 PC5 (none) + * 11 PC4 (none) + * 12 PC3 RESET + * 13 PC2 (none) + * 14 PC1 SCK + * 15 PC0 boost PMIC enable (PWM0A not used) + * 16 PB3 main LED PWM (PWM1A) + * 17 PB2 MISO / e-switch? (PCINT10) + * 18 PB1 MOSI / battery voltage (ADC6) + * 19 PB0 Opamp power + * 20 PA7 e-switch? (PCINT7) + * ADC12 thermal sensor + * + * 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. + * The on/off pin is only used to turn the main LED on and off, + * not to change brightness. + */ + +#ifdef ATTINY +#undef ATTINY +#endif +#define ATTINY 1634 +#include + +#define PWM_CHANNELS 1 // can't use DD FET on boost drivers +#define PWM_BITS 16 // data type needs 16 bits, not 8 +#define PWM_TOP 255 // highest value used in top half of ramp +#define USE_DYN_PWM // dynamic frequency and speed + +//#define SWITCH_PIN PB2 // pin 17 +//#define SWITCH_PCINT PCINT10 // pin 17 pin change interrupt +//#define SWITCH_PCIE PCIE1 // PCIE1 is for PCINT[11:8] +//#define SWITCH_PCMSK PCMSK1 // PCMSK1 is for PCINT[11:8] +//#define SWITCH_PORT PINB // PINA or PINB or PINC +//#define PCINT_vect PCINT1_vect // ISR for PCINT[11:8] + +#define SWITCH_PIN PA7 // pin 20 +#define SWITCH_PCINT PCINT7 // pin 20 pin change interrupt +#define SWITCH_PCIE PCIE0 // PCIE0 is for PCINT[7:0] +#define SWITCH_PCMSK PCMSK0 // PCMSK0 is for PCINT[7:0] +#define SWITCH_PORT PINA // PINA or PINB or PINC + +#define PWM1_PIN PB3 // pin 16, Opamp reference +#define PWM1_LVL OCR1A // OCR1A is the output compare register for PB3 +#define PWM1_CNT TCNT1 // for dynamic PWM, reset phase + +// PWM parameters of both channels are tied together because they share a counter +#define PWM1_TOP ICR1 // holds the TOP value for for variable-resolution PWM + +#define LED_ENABLE_PIN PB0 // pin 19, Opamp power +#define LED_ENABLE_PORT PORTB // control port for PB0 + +#define LED2_ENABLE_PIN PC0 // pin 15, boost PMIC enable +#define LED2_ENABLE_PORT PORTC // control port for PC0 + + +#define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is flattened +#define VOLTAGE_PIN PB1 // Pin 18 / PB1 / ADC6 +// pin to ADC mappings are in DS table 19-4 +#define VOLTAGE_ADC ADC6D // digital input disable pin for PB1 +// DIDR0/DIDR1 mappings are in DS section 19.13.5, 19.13.6 +#define VOLTAGE_ADC_DIDR DIDR1 // DIDR channel for ADC6D +// DS tables 19-3, 19-4 +// Bit 7 6 5 4 3 2 1 0 +// REFS1 REFS0 REFEN ADC0EN MUX3 MUX2 MUX1 MUX0 +// MUX[3:0] = 0, 1, 1, 0 for ADC6 / PB1 +// divided by ... +// REFS[1:0] = 1, 0 for internal 1.1V reference +// other bits reserved +#define ADMUX_VOLTAGE_DIVIDER 0b10000110 +#define ADC_PRSCL 0x07 // clk/128 + +// Raw ADC readings at 4.4V and 2.2V +// calibrate the voltage readout here +// estimated / calculated values are: +// (voltage - D1) * (R2/(R2+R1) * 1024 / 1.1) +// D1, R1, R2 = 0, 330, 100 +#ifndef ADC_44 +//#define ADC_44 981 // raw value at 4.40V +#define ADC_44 967 // manually tweaked so 4.16V will blink out 4.2 +#endif +#ifndef ADC_22 +//#define ADC_22 489 // raw value at 2.20V +#define ADC_22 482 // manually tweaked so 4.16V will blink out 4.2 +#endif + +// this light has aux LEDs under the optic +#define AUXLED_R_PIN PA5 // pin 2 +#define AUXLED_G_PIN PA4 // pin 3 +#define AUXLED_B_PIN PA3 // pin 4 +#define AUXLED_RGB_PORT PORTA // PORTA or PORTB or PORTC +#define AUXLED_RGB_DDR DDRA // DDRA or DDRB or DDRC +#define AUXLED_RGB_PUE PUEA // PUEA or PUEB or PUEC + +#define BUTTON_LED_PIN PA2 // pin 5 +#define BUTTON_LED_PORT PORTA // for all "PA" pins +#define BUTTON_LED_DDR DDRA // for all "PA" pins +#define BUTTON_LED_PUE PUEA // for all "PA" pins + +// with so many pins, doing this all with #ifdefs gets awkward... +// ... so just hardcode it in each hwdef file instead +inline void hwdef_setup() { + // enable output ports + // boost PMIC on/off + DDRC = (1 << LED2_ENABLE_PIN); + // Opamp level and Opamp on/off + DDRB = (1 << PWM1_PIN) + | (1 << LED_ENABLE_PIN); + // aux R/G/B, button LED + DDRA = (1 << AUXLED_R_PIN) + | (1 << AUXLED_G_PIN) + | (1 << AUXLED_B_PIN) + | (1 << BUTTON_LED_PIN) + ; + + // configure PWM + // Setup PWM. F_pwm = F_clkio / 2 / N / TOP, where N = prescale factor, TOP = top of counter + // pre-scale for timer: N = 1 + // WGM1[3:0]: 1,0,1,0: PWM, Phase Correct, adjustable (DS table 12-5) + // CS1[2:0]: 0,0,1: clk/1 (No prescaling) (DS table 12-6) + // COM1A[1:0]: 1,0: PWM OC1A in the normal direction (DS table 12-4) + // COM1B[1:0]: 0,0: PWM OC1B disabled (DS table 12-4) + TCCR1A = (1< + +#define PWM_CHANNELS 2 // override this for the no-FET version +#define PWM_BITS 16 // data type needs 16 bits, not 8 +#define PWM_TOP 255 // highest value used in top half of ramp +#define USE_DYN_PWM // dynamic frequency and speed + +//#define SWITCH_PIN PB2 // pin 17 +//#define SWITCH_PCINT PCINT10 // pin 17 pin change interrupt +//#define SWITCH_PCIE PCIE1 // PCIE1 is for PCINT[11:8] +//#define SWITCH_PCMSK PCMSK1 // PCMSK1 is for PCINT[11:8] +//#define SWITCH_PORT PINB // PINA or PINB or PINC +//#define PCINT_vect PCINT1_vect // ISR for PCINT[11:8] + +#define SWITCH_PIN PA7 // pin 20 +#define SWITCH_PCINT PCINT7 // pin 20 pin change interrupt +#define SWITCH_PCIE PCIE0 // PCIE0 is for PCINT[7:0] +#define SWITCH_PCMSK PCMSK0 // PCMSK0 is for PCINT[7:0] +#define SWITCH_PORT PINA // PINA or PINB or PINC + +#define PWM1_PIN PB3 // pin 16, Opamp reference +#define PWM1_LVL OCR1A // OCR1A is the output compare register for PB3 +#define PWM1_CNT TCNT1 // for dynamic PWM, reset phase + +#define PWM2_PIN PA6 // pin 1, DD FET PWM +#define PWM2_LVL OCR1B // OCR1B is the output compare register for PA6 + +// PWM parameters of both channels are tied together because they share a counter +#define PWM1_TOP ICR1 // holds the TOP value for for variable-resolution PWM + +#define LED_ENABLE_PIN PB0 // pin 19, Opamp power +#define LED_ENABLE_PORT PORTB // control port for PB0 + + +#define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is flattened +#define VOLTAGE_PIN PB1 // Pin 18 / PB1 / ADC6 +// pin to ADC mappings are in DS table 19-4 +#define VOLTAGE_ADC ADC6D // digital input disable pin for PB1 +// DIDR0/DIDR1 mappings are in DS section 19.13.5, 19.13.6 +#define VOLTAGE_ADC_DIDR DIDR1 // DIDR channel for ADC6D +// DS tables 19-3, 19-4 +// Bit 7 6 5 4 3 2 1 0 +// REFS1 REFS0 REFEN ADC0EN MUX3 MUX2 MUX1 MUX0 +// MUX[3:0] = 0, 1, 1, 0 for ADC6 / PB1 +// divided by ... +// REFS[1:0] = 1, 0 for internal 1.1V reference +// other bits reserved +#define ADMUX_VOLTAGE_DIVIDER 0b10000110 +#define ADC_PRSCL 0x07 // clk/128 + +// Raw ADC readings at 4.4V and 2.2V +// calibrate the voltage readout here +// estimated / calculated values are: +// (voltage - D1) * (R2/(R2+R1) * 1024 / 1.1) +// D1, R1, R2 = 0, 330, 100 +#ifndef ADC_44 +//#define ADC_44 981 // raw value at 4.40V +#define ADC_44 967 // manually tweaked so 4.16V will blink out 4.2 +#endif +#ifndef ADC_22 +//#define ADC_22 489 // raw value at 2.20V +#define ADC_22 482 // manually tweaked so 4.16V will blink out 4.2 +#endif + +// this light has aux LEDs under the optic +#define AUXLED_R_PIN PA5 // pin 2 +#define AUXLED_G_PIN PA4 // pin 3 +#define AUXLED_B_PIN PA3 // pin 4 +#define AUXLED_RGB_PORT PORTA // PORTA or PORTB or PORTC +#define AUXLED_RGB_DDR DDRA // DDRA or DDRB or DDRC +#define AUXLED_RGB_PUE PUEA // PUEA or PUEB or PUEC + +#define BUTTON_LED_PIN PA2 // pin 5 +#define BUTTON_LED_PORT PORTA // for all "PA" pins +#define BUTTON_LED_DDR DDRA // for all "PA" pins +#define BUTTON_LED_PUE PUEA // for all "PA" pins + +// with so many pins, doing this all with #ifdefs gets awkward... +// ... so just hardcode it in each hwdef file instead +inline void hwdef_setup() { + // enable output ports + // Opamp level and Opamp on/off + DDRB = (1 << PWM1_PIN) + | (1 << LED_ENABLE_PIN); + // DD FET PWM, aux R/G/B, button LED + DDRA = (1 << PWM2_PIN) + | (1 << AUXLED_R_PIN) + | (1 << AUXLED_G_PIN) + | (1 << AUXLED_B_PIN) + | (1 << BUTTON_LED_PIN) + ; + + // configure PWM + // Setup PWM. F_pwm = F_clkio / 2 / N / TOP, where N = prescale factor, TOP = top of counter + // pre-scale for timer: N = 1 + // WGM1[3:0]: 1,0,1,0: PWM, Phase Correct, adjustable (DS table 12-5) + // CS1[2:0]: 0,0,1: clk/1 (No prescaling) (DS table 12-6) + // COM1A[1:0]: 1,0: PWM OC1A in the normal direction (DS table 12-4) + // COM1B[1:0]: 1,0: PWM OC1B in the normal direction (DS table 12-4) + TCCR1A = (1< - -#define PWM_CHANNELS 1 // can't use DD FET on boost drivers -#define PWM_BITS 16 // data type needs 16 bits, not 8 -#define PWM_TOP 255 // highest value used in top half of ramp -#define USE_DYN_PWM // dynamic frequency and speed - -//#define SWITCH_PIN PB2 // pin 17 -//#define SWITCH_PCINT PCINT10 // pin 17 pin change interrupt -//#define SWITCH_PCIE PCIE1 // PCIE1 is for PCINT[11:8] -//#define SWITCH_PCMSK PCMSK1 // PCMSK1 is for PCINT[11:8] -//#define SWITCH_PORT PINB // PINA or PINB or PINC -//#define PCINT_vect PCINT1_vect // ISR for PCINT[11:8] - -#define SWITCH_PIN PA7 // pin 20 -#define SWITCH_PCINT PCINT7 // pin 20 pin change interrupt -#define SWITCH_PCIE PCIE0 // PCIE0 is for PCINT[7:0] -#define SWITCH_PCMSK PCMSK0 // PCMSK0 is for PCINT[7:0] -#define SWITCH_PORT PINA // PINA or PINB or PINC - -#define PWM1_PIN PB3 // pin 16, Opamp reference -#define PWM1_LVL OCR1A // OCR1A is the output compare register for PB3 -#define PWM1_CNT TCNT1 // for dynamic PWM, reset phase - -// PWM parameters of both channels are tied together because they share a counter -#define PWM1_TOP ICR1 // holds the TOP value for for variable-resolution PWM - -#define LED_ENABLE_PIN PB0 // pin 19, Opamp power -#define LED_ENABLE_PORT PORTB // control port for PB0 - -#define LED2_ENABLE_PIN PC0 // pin 15, boost PMIC enable -#define LED2_ENABLE_PORT PORTC // control port for PC0 - - -#define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is flattened -#define VOLTAGE_PIN PB1 // Pin 18 / PB1 / ADC6 -// pin to ADC mappings are in DS table 19-4 -#define VOLTAGE_ADC ADC6D // digital input disable pin for PB1 -// DIDR0/DIDR1 mappings are in DS section 19.13.5, 19.13.6 -#define VOLTAGE_ADC_DIDR DIDR1 // DIDR channel for ADC6D -// DS tables 19-3, 19-4 -// Bit 7 6 5 4 3 2 1 0 -// REFS1 REFS0 REFEN ADC0EN MUX3 MUX2 MUX1 MUX0 -// MUX[3:0] = 0, 1, 1, 0 for ADC6 / PB1 -// divided by ... -// REFS[1:0] = 1, 0 for internal 1.1V reference -// other bits reserved -#define ADMUX_VOLTAGE_DIVIDER 0b10000110 -#define ADC_PRSCL 0x07 // clk/128 - -// Raw ADC readings at 4.4V and 2.2V -// calibrate the voltage readout here -// estimated / calculated values are: -// (voltage - D1) * (R2/(R2+R1) * 1024 / 1.1) -// D1, R1, R2 = 0, 330, 100 -#ifndef ADC_44 -//#define ADC_44 981 // raw value at 4.40V -#define ADC_44 967 // manually tweaked so 4.16V will blink out 4.2 -#endif -#ifndef ADC_22 -//#define ADC_22 489 // raw value at 2.20V -#define ADC_22 482 // manually tweaked so 4.16V will blink out 4.2 -#endif - -// this light has aux LEDs under the optic -#define AUXLED_R_PIN PA5 // pin 2 -#define AUXLED_G_PIN PA4 // pin 3 -#define AUXLED_B_PIN PA3 // pin 4 -#define AUXLED_RGB_PORT PORTA // PORTA or PORTB or PORTC -#define AUXLED_RGB_DDR DDRA // DDRA or DDRB or DDRC -#define AUXLED_RGB_PUE PUEA // PUEA or PUEB or PUEC - -#define BUTTON_LED_PIN PA2 // pin 5 -#define BUTTON_LED_PORT PORTA // for all "PA" pins -#define BUTTON_LED_DDR DDRA // for all "PA" pins -#define BUTTON_LED_PUE PUEA // for all "PA" pins - -// with so many pins, doing this all with #ifdefs gets awkward... -// ... so just hardcode it in each hwdef file instead -inline void hwdef_setup() { - // enable output ports - // boost PMIC on/off - DDRC = (1 << LED2_ENABLE_PIN); - // Opamp level and Opamp on/off - DDRB = (1 << PWM1_PIN) - | (1 << LED_ENABLE_PIN); - // aux R/G/B, button LED - DDRA = (1 << AUXLED_R_PIN) - | (1 << AUXLED_G_PIN) - | (1 << AUXLED_B_PIN) - | (1 << BUTTON_LED_PIN) - ; - - // configure PWM - // Setup PWM. F_pwm = F_clkio / 2 / N / TOP, where N = prescale factor, TOP = top of counter - // pre-scale for timer: N = 1 - // WGM1[3:0]: 1,0,1,0: PWM, Phase Correct, adjustable (DS table 12-5) - // CS1[2:0]: 0,0,1: clk/1 (No prescaling) (DS table 12-6) - // COM1A[1:0]: 1,0: PWM OC1A in the normal direction (DS table 12-4) - // COM1B[1:0]: 0,0: PWM OC1B disabled (DS table 12-4) - TCCR1A = (1< - -#define PWM_CHANNELS 2 // override this for the no-FET version -#define PWM_BITS 16 // data type needs 16 bits, not 8 -#define PWM_TOP 255 // highest value used in top half of ramp -#define USE_DYN_PWM // dynamic frequency and speed - -//#define SWITCH_PIN PB2 // pin 17 -//#define SWITCH_PCINT PCINT10 // pin 17 pin change interrupt -//#define SWITCH_PCIE PCIE1 // PCIE1 is for PCINT[11:8] -//#define SWITCH_PCMSK PCMSK1 // PCMSK1 is for PCINT[11:8] -//#define SWITCH_PORT PINB // PINA or PINB or PINC -//#define PCINT_vect PCINT1_vect // ISR for PCINT[11:8] - -#define SWITCH_PIN PA7 // pin 20 -#define SWITCH_PCINT PCINT7 // pin 20 pin change interrupt -#define SWITCH_PCIE PCIE0 // PCIE0 is for PCINT[7:0] -#define SWITCH_PCMSK PCMSK0 // PCMSK0 is for PCINT[7:0] -#define SWITCH_PORT PINA // PINA or PINB or PINC - -#define PWM1_PIN PB3 // pin 16, Opamp reference -#define PWM1_LVL OCR1A // OCR1A is the output compare register for PB3 -#define PWM1_CNT TCNT1 // for dynamic PWM, reset phase - -#define PWM2_PIN PA6 // pin 1, DD FET PWM -#define PWM2_LVL OCR1B // OCR1B is the output compare register for PA6 - -// PWM parameters of both channels are tied together because they share a counter -#define PWM1_TOP ICR1 // holds the TOP value for for variable-resolution PWM - -#define LED_ENABLE_PIN PB0 // pin 19, Opamp power -#define LED_ENABLE_PORT PORTB // control port for PB0 - - -#define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is flattened -#define VOLTAGE_PIN PB1 // Pin 18 / PB1 / ADC6 -// pin to ADC mappings are in DS table 19-4 -#define VOLTAGE_ADC ADC6D // digital input disable pin for PB1 -// DIDR0/DIDR1 mappings are in DS section 19.13.5, 19.13.6 -#define VOLTAGE_ADC_DIDR DIDR1 // DIDR channel for ADC6D -// DS tables 19-3, 19-4 -// Bit 7 6 5 4 3 2 1 0 -// REFS1 REFS0 REFEN ADC0EN MUX3 MUX2 MUX1 MUX0 -// MUX[3:0] = 0, 1, 1, 0 for ADC6 / PB1 -// divided by ... -// REFS[1:0] = 1, 0 for internal 1.1V reference -// other bits reserved -#define ADMUX_VOLTAGE_DIVIDER 0b10000110 -#define ADC_PRSCL 0x07 // clk/128 - -// Raw ADC readings at 4.4V and 2.2V -// calibrate the voltage readout here -// estimated / calculated values are: -// (voltage - D1) * (R2/(R2+R1) * 1024 / 1.1) -// D1, R1, R2 = 0, 330, 100 -#ifndef ADC_44 -//#define ADC_44 981 // raw value at 4.40V -#define ADC_44 967 // manually tweaked so 4.16V will blink out 4.2 -#endif -#ifndef ADC_22 -//#define ADC_22 489 // raw value at 2.20V -#define ADC_22 482 // manually tweaked so 4.16V will blink out 4.2 -#endif - -// this light has aux LEDs under the optic -#define AUXLED_R_PIN PA5 // pin 2 -#define AUXLED_G_PIN PA4 // pin 3 -#define AUXLED_B_PIN PA3 // pin 4 -#define AUXLED_RGB_PORT PORTA // PORTA or PORTB or PORTC -#define AUXLED_RGB_DDR DDRA // DDRA or DDRB or DDRC -#define AUXLED_RGB_PUE PUEA // PUEA or PUEB or PUEC - -#define BUTTON_LED_PIN PA2 // pin 5 -#define BUTTON_LED_PORT PORTA // for all "PA" pins -#define BUTTON_LED_DDR DDRA // for all "PA" pins -#define BUTTON_LED_PUE PUEA // for all "PA" pins - -// with so many pins, doing this all with #ifdefs gets awkward... -// ... so just hardcode it in each hwdef file instead -inline void hwdef_setup() { - // enable output ports - // Opamp level and Opamp on/off - DDRB = (1 << PWM1_PIN) - | (1 << LED_ENABLE_PIN); - // DD FET PWM, aux R/G/B, button LED - DDRA = (1 << PWM2_PIN) - | (1 << AUXLED_R_PIN) - | (1 << AUXLED_G_PIN) - | (1 << AUXLED_B_PIN) - | (1 << BUTTON_LED_PIN) - ; - - // configure PWM - // Setup PWM. F_pwm = F_clkio / 2 / N / TOP, where N = prescale factor, TOP = top of counter - // pre-scale for timer: N = 1 - // WGM1[3:0]: 1,0,1,0: PWM, Phase Correct, adjustable (DS table 12-5) - // CS1[2:0]: 0,0,1: clk/1 (No prescaling) (DS table 12-6) - // COM1A[1:0]: 1,0: PWM OC1A in the normal direction (DS table 12-4) - // COM1B[1:0]: 1,0: PWM OC1B in the normal direction (DS table 12-4) - TCCR1A = (1< end of dynamic PWM range + +//#define THERM_RESPONSE_MAGNITUDE 32 // smaller adjustments, this host changes temperature slowly +//#define THERM_NEXT_WARNING_THRESHOLD 32 // more error tolerance before adjusting + +// slow down party strobe; this driver can't pulse for 1ms or less +#define PARTY_STROBE_ONTIME 4 + +#define THERM_CAL_OFFSET 5 + +// the power regulator is a bit slow, so push it harder for a quick response from off +#define DEFAULT_JUMP_START_LEVEL 21 +#define BLINK_BRIGHTNESS DEFAULT_LEVEL +#define BLINK_ONCE_TIME 12 + +// added for convenience +#define USE_SOFT_FACTORY_RESET diff --git a/spaghetti-monster/anduril/cfg-noctigon-dm11-nofet.h b/spaghetti-monster/anduril/cfg-noctigon-dm11-nofet.h new file mode 100644 index 0000000..a1249b1 --- /dev/null +++ b/spaghetti-monster/anduril/cfg-noctigon-dm11-nofet.h @@ -0,0 +1,42 @@ +// Noctigon DM11-noFET config options for Anduril +#include "cfg-noctigon-dm11.h" +#undef MODEL_NUMBER +#define MODEL_NUMBER "0272" +// ATTINY: 1634 + +// turn off the DD FET +#undef PWM_CHANNELS +#define PWM_CHANNELS 1 + +// level_calc.py 5.01 1 149 7135 1 0.3 1740 --pwm dyn:78:16384:255 +#undef PWM1_LEVELS +#define PWM1_LEVELS 0,1,1,1,2,3,3,4,5,6,7,8,9,10,11,13,14,16,17,19,21,23,25,27,29,31,34,36,39,42,44,47,50,53,57,60,63,67,70,74,77,81,85,88,92,96,99,103,107,110,113,117,120,123,126,128,130,133,134,136,137,137,137,137,136,135,133,130,126,122,117,111,104,96,87,76,65,52,38,22,23,25,26,27,28,29,30,32,33,34,36,37,39,40,42,43,45,47,49,51,53,55,57,59,61,63,66,68,70,73,76,78,81,84,87,90,93,96,99,103,106,110,113,117,121,125,129,133,137,142,146,151,155,160,165,170,175,181,186,192,197,203,209,215,222,228,234,241,248,255 +#undef PWM2_LEVELS +#undef PWM_TOPS +#define PWM_TOPS 16383,16383,12404,8140,11462,14700,11041,12947,13795,14111,14124,13946,13641,13248,12791,13418,12808,13057,12385,12428,12358,12209,12000,11746,11459,11147,11158,10793,10708,10576,10173,9998,9800,9585,9527,9278,9023,8901,8634,8486,8216,8053,7881,7615,7440,7261,7009,6832,6656,6422,6196,6031,5819,5615,5419,5190,4973,4803,4571,4386,4179,3955,3745,3549,3340,3145,2940,2729,2513,2312,2109,1903,1697,1491,1286,1070,871,662,459,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255 +#undef DEFAULT_LEVEL +#define DEFAULT_LEVEL 50 +#undef MAX_1x7135 +#define MAX_1x7135 150 + +// make candle mode wobble more +#ifdef CANDLE_AMPLITUDE +#undef CANDLE_AMPLITUDE +#endif +#define CANDLE_AMPLITUDE 35 + + +// slow down party strobe; this driver can't pulse for 1ms or less +// (only needed on no-FET build) +#define PARTY_STROBE_ONTIME 2 + +// jump start a bit higher than base driver +#undef DEFAULT_JUMP_START_LEVEL +#define DEFAULT_JUMP_START_LEVEL 25 + +// stop panicking at ~70% power or ~600 lm +#undef THERM_FASTER_LEVEL +#define THERM_FASTER_LEVEL 130 +#undef MIN_THERM_STEPDOWN +#define MIN_THERM_STEPDOWN 80 // must be > end of dynamic PWM range + diff --git a/spaghetti-monster/anduril/cfg-noctigon-dm11.h b/spaghetti-monster/anduril/cfg-noctigon-dm11.h new file mode 100644 index 0000000..89d2fe6 --- /dev/null +++ b/spaghetti-monster/anduril/cfg-noctigon-dm11.h @@ -0,0 +1,72 @@ +// Noctigon DM11 config options for Anduril +#define MODEL_NUMBER "0271" +#include "hwdef-Noctigon_DM11.h" +#include "hank-cfg.h" +// ATTINY: 1634 + +// this light has three aux LED channels: R, G, B +#define USE_AUX_RGB_LEDS +// ... and a single LED in the button +#define USE_BUTTON_LED +// don't use aux LEDs while main LED is on +#ifdef USE_INDICATOR_LED_WHILE_RAMPING +#undef USE_INDICATOR_LED_WHILE_RAMPING +#endif + + +// power channels: +// - linear: 5A? +// - FET: DD +#define RAMP_LENGTH 150 +#define USE_DYN_PWM +// maxreg at 130, dynamic PWM: level_calc.py 5.01 2 149 7135 1 0.3 1740 FET 1 10 3190 --pwm dyn:64:16384:255 +// (plus one extra level at the beginning for moon) +#define PWM1_LEVELS 0,1,1,2,2,3,4,5,6,7,8,9,11,12,14,16,17,19,22,24,26,29,31,34,37,40,43,46,49,53,56,60,63,67,71,74,78,82,86,89,93,96,99,103,105,108,110,112,114,115,116,116,115,114,112,109,106,101,95,89,81,71,60,48,34,19,20,21,22,23,24,26,27,28,30,31,32,34,36,37,39,41,43,45,47,49,51,53,56,58,61,63,66,69,72,75,78,81,84,88,91,95,99,103,107,111,115,119,124,129,133,138,143,149,154,159,165,171,177,183,189,196,203,210,217,224,231,239,247,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0 +#define PWM2_LEVELS 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,20,30,41,52,63,75,87,99,112,125,138,151,165,179,194,208,224,239,255 +#define PWM_TOPS 16383,16383,11750,14690,9183,12439,13615,13955,13877,13560,13093,12529,13291,12513,12756,12769,11893,11747,12085,11725,11329,11316,10851,10713,10518,10282,10016,9729,9428,9298,8971,8794,8459,8257,8043,7715,7497,7275,7052,6753,6538,6260,5994,5798,5501,5271,5006,4758,4525,4268,4030,3775,3508,3263,3010,2752,2517,2256,1998,1763,1512,1249,994,749,497,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255 + +#define MAX_1x7135 130 +#define DEFAULT_LEVEL 50 +#define HALFSPEED_LEVEL 12 +#define QUARTERSPEED_LEVEL 4 + +// don't blink halfway up +#ifdef BLINK_AT_RAMP_MIDDLE +#undef BLINK_AT_RAMP_MIDDLE +#endif + +#define RAMP_SMOOTH_FLOOR 10 // low levels may be unreliable +#define RAMP_SMOOTH_CEIL 130 +// 10, 30, [50], 70, 90, 110, 130 +#define RAMP_DISCRETE_FLOOR 10 +#define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL +#define RAMP_DISCRETE_STEPS 7 + +// safe limit ~75% power +#define SIMPLE_UI_FLOOR RAMP_DISCRETE_FLOOR +#define SIMPLE_UI_CEIL RAMP_DISCRETE_CEIL +#define SIMPLE_UI_STEPS 5 + +// make candle mode wobble more +#define CANDLE_AMPLITUDE 30 + +// stop panicking at ~70% power or ~600 lm +#define THERM_FASTER_LEVEL 130 +#define MIN_THERM_STEPDOWN 66 // must be > end of dynamic PWM range + +//#define THERM_RESPONSE_MAGNITUDE 32 // smaller adjustments, this host changes temperature slowly +//#define THERM_NEXT_WARNING_THRESHOLD 32 // more error tolerance before adjusting + +// slow down party strobe; this driver can't pulse for 1ms or less +// (only needed on no-FET build) +//#define PARTY_STROBE_ONTIME 2 + +#define THERM_CAL_OFFSET 5 + +// the power regulator is a bit slow, so push it harder for a quick response from off +#define DEFAULT_JUMP_START_LEVEL 21 +#define BLINK_BRIGHTNESS DEFAULT_LEVEL +#define BLINK_ONCE_TIME 12 + +// can't reset the normal way because power is connected before the button +#define USE_SOFT_FACTORY_RESET diff --git a/spaghetti-monster/anduril/cfg-noctigon-md11-12v.h b/spaghetti-monster/anduril/cfg-noctigon-md11-12v.h deleted file mode 100644 index 1c90ab1..0000000 --- a/spaghetti-monster/anduril/cfg-noctigon-md11-12v.h +++ /dev/null @@ -1,70 +0,0 @@ -// Noctigon MD11 (12V) config options for Anduril -#define MODEL_NUMBER "0273" -#include "hwdef-Noctigon_MD11-12V.h" -#include "hank-cfg.h" -// ATTINY: 1634 - -// this light has three aux LED channels: R, G, B -#define USE_AUX_RGB_LEDS -// ... and a single LED in the button -#define USE_BUTTON_LED -// don't use aux LEDs while main LED is on -#ifdef USE_INDICATOR_LED_WHILE_RAMPING -#undef USE_INDICATOR_LED_WHILE_RAMPING -#endif - - -// power channels: -// - linear: 5A? -// - DD FET: none (can't do DD on a boost driver) -#define RAMP_LENGTH 150 -#define USE_DYN_PWM - -// level_calc.py 5.01 1 149 7135 1 0.3 1740 --pwm dyn:78:16384:255 -#define PWM1_LEVELS 0,1,1,1,2,3,3,4,5,6,7,8,9,10,11,13,14,16,17,19,21,23,25,27,29,31,34,36,39,42,44,47,50,53,57,60,63,67,70,74,77,81,85,88,92,96,99,103,107,110,113,117,120,123,126,128,130,133,134,136,137,137,137,137,136,135,133,130,126,122,117,111,104,96,87,76,65,52,38,22,23,25,26,27,28,29,30,32,33,34,36,37,39,40,42,43,45,47,49,51,53,55,57,59,61,63,66,68,70,73,76,78,81,84,87,90,93,96,99,103,106,110,113,117,121,125,129,133,137,142,146,151,155,160,165,170,175,181,186,192,197,203,209,215,222,228,234,241,248,255 -#define PWM_TOPS 16383,16383,12404,8140,11462,14700,11041,12947,13795,14111,14124,13946,13641,13248,12791,13418,12808,13057,12385,12428,12358,12209,12000,11746,11459,11147,11158,10793,10708,10576,10173,9998,9800,9585,9527,9278,9023,8901,8634,8486,8216,8053,7881,7615,7440,7261,7009,6832,6656,6422,6196,6031,5819,5615,5419,5190,4973,4803,4571,4386,4179,3955,3745,3549,3340,3145,2940,2729,2513,2312,2109,1903,1697,1491,1286,1070,871,662,459,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255 -#define DEFAULT_LEVEL 50 -#define MAX_1x7135 150 - -#define HALFSPEED_LEVEL 12 -#define QUARTERSPEED_LEVEL 4 - -// don't blink halfway up -#ifdef BLINK_AT_RAMP_MIDDLE -#undef BLINK_AT_RAMP_MIDDLE -#endif - -#define RAMP_SMOOTH_FLOOR 10 // low levels may be unreliable -#define RAMP_SMOOTH_CEIL 130 -// 10, 30, [50], 70, 90, 110, 130 -#define RAMP_DISCRETE_FLOOR 10 -#define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL -#define RAMP_DISCRETE_STEPS 7 - -// safe limit ~75% power -#define SIMPLE_UI_FLOOR RAMP_DISCRETE_FLOOR -#define SIMPLE_UI_CEIL RAMP_DISCRETE_CEIL -#define SIMPLE_UI_STEPS 5 - -// make candle mode wobble more -#define CANDLE_AMPLITUDE 30 - -// stop panicking at ~70% power or ~600 lm -#define THERM_FASTER_LEVEL 130 -#define MIN_THERM_STEPDOWN 80 // must be > end of dynamic PWM range - -//#define THERM_RESPONSE_MAGNITUDE 32 // smaller adjustments, this host changes temperature slowly -//#define THERM_NEXT_WARNING_THRESHOLD 32 // more error tolerance before adjusting - -// slow down party strobe; this driver can't pulse for 1ms or less -#define PARTY_STROBE_ONTIME 4 - -#define THERM_CAL_OFFSET 5 - -// the power regulator is a bit slow, so push it harder for a quick response from off -#define DEFAULT_JUMP_START_LEVEL 21 -#define BLINK_BRIGHTNESS DEFAULT_LEVEL -#define BLINK_ONCE_TIME 12 - -// added for convenience -#define USE_SOFT_FACTORY_RESET diff --git a/spaghetti-monster/anduril/cfg-noctigon-md11-nofet.h b/spaghetti-monster/anduril/cfg-noctigon-md11-nofet.h deleted file mode 100644 index 0efe85f..0000000 --- a/spaghetti-monster/anduril/cfg-noctigon-md11-nofet.h +++ /dev/null @@ -1,42 +0,0 @@ -// Noctigon MD11-noFET config options for Anduril -#include "cfg-noctigon-md11.h" -#undef MODEL_NUMBER -#define MODEL_NUMBER "0272" -// ATTINY: 1634 - -// turn off the DD FET -#undef PWM_CHANNELS -#define PWM_CHANNELS 1 - -// level_calc.py 5.01 1 149 7135 1 0.3 1740 --pwm dyn:78:16384:255 -#undef PWM1_LEVELS -#define PWM1_LEVELS 0,1,1,1,2,3,3,4,5,6,7,8,9,10,11,13,14,16,17,19,21,23,25,27,29,31,34,36,39,42,44,47,50,53,57,60,63,67,70,74,77,81,85,88,92,96,99,103,107,110,113,117,120,123,126,128,130,133,134,136,137,137,137,137,136,135,133,130,126,122,117,111,104,96,87,76,65,52,38,22,23,25,26,27,28,29,30,32,33,34,36,37,39,40,42,43,45,47,49,51,53,55,57,59,61,63,66,68,70,73,76,78,81,84,87,90,93,96,99,103,106,110,113,117,121,125,129,133,137,142,146,151,155,160,165,170,175,181,186,192,197,203,209,215,222,228,234,241,248,255 -#undef PWM2_LEVELS -#undef PWM_TOPS -#define PWM_TOPS 16383,16383,12404,8140,11462,14700,11041,12947,13795,14111,14124,13946,13641,13248,12791,13418,12808,13057,12385,12428,12358,12209,12000,11746,11459,11147,11158,10793,10708,10576,10173,9998,9800,9585,9527,9278,9023,8901,8634,8486,8216,8053,7881,7615,7440,7261,7009,6832,6656,6422,6196,6031,5819,5615,5419,5190,4973,4803,4571,4386,4179,3955,3745,3549,3340,3145,2940,2729,2513,2312,2109,1903,1697,1491,1286,1070,871,662,459,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255 -#undef DEFAULT_LEVEL -#define DEFAULT_LEVEL 50 -#undef MAX_1x7135 -#define MAX_1x7135 150 - -// make candle mode wobble more -#ifdef CANDLE_AMPLITUDE -#undef CANDLE_AMPLITUDE -#endif -#define CANDLE_AMPLITUDE 35 - - -// slow down party strobe; this driver can't pulse for 1ms or less -// (only needed on no-FET build) -#define PARTY_STROBE_ONTIME 2 - -// jump start a bit higher than base driver -#undef DEFAULT_JUMP_START_LEVEL -#define DEFAULT_JUMP_START_LEVEL 25 - -// stop panicking at ~70% power or ~600 lm -#undef THERM_FASTER_LEVEL -#define THERM_FASTER_LEVEL 130 -#undef MIN_THERM_STEPDOWN -#define MIN_THERM_STEPDOWN 80 // must be > end of dynamic PWM range - diff --git a/spaghetti-monster/anduril/cfg-noctigon-md11.h b/spaghetti-monster/anduril/cfg-noctigon-md11.h deleted file mode 100644 index 130e05c..0000000 --- a/spaghetti-monster/anduril/cfg-noctigon-md11.h +++ /dev/null @@ -1,72 +0,0 @@ -// Noctigon MD11 config options for Anduril -#define MODEL_NUMBER "0271" -#include "hwdef-Noctigon_MD11.h" -#include "hank-cfg.h" -// ATTINY: 1634 - -// this light has three aux LED channels: R, G, B -#define USE_AUX_RGB_LEDS -// ... and a single LED in the button -#define USE_BUTTON_LED -// don't use aux LEDs while main LED is on -#ifdef USE_INDICATOR_LED_WHILE_RAMPING -#undef USE_INDICATOR_LED_WHILE_RAMPING -#endif - - -// power channels: -// - linear: 5A? -// - FET: DD -#define RAMP_LENGTH 150 -#define USE_DYN_PWM -// maxreg at 130, dynamic PWM: level_calc.py 5.01 2 149 7135 1 0.3 1740 FET 1 10 3190 --pwm dyn:64:16384:255 -// (plus one extra level at the beginning for moon) -#define PWM1_LEVELS 0,1,1,2,2,3,4,5,6,7,8,9,11,12,14,16,17,19,22,24,26,29,31,34,37,40,43,46,49,53,56,60,63,67,71,74,78,82,86,89,93,96,99,103,105,108,110,112,114,115,116,116,115,114,112,109,106,101,95,89,81,71,60,48,34,19,20,21,22,23,24,26,27,28,30,31,32,34,36,37,39,41,43,45,47,49,51,53,56,58,61,63,66,69,72,75,78,81,84,88,91,95,99,103,107,111,115,119,124,129,133,138,143,149,154,159,165,171,177,183,189,196,203,210,217,224,231,239,247,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0 -#define PWM2_LEVELS 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,20,30,41,52,63,75,87,99,112,125,138,151,165,179,194,208,224,239,255 -#define PWM_TOPS 16383,16383,11750,14690,9183,12439,13615,13955,13877,13560,13093,12529,13291,12513,12756,12769,11893,11747,12085,11725,11329,11316,10851,10713,10518,10282,10016,9729,9428,9298,8971,8794,8459,8257,8043,7715,7497,7275,7052,6753,6538,6260,5994,5798,5501,5271,5006,4758,4525,4268,4030,3775,3508,3263,3010,2752,2517,2256,1998,1763,1512,1249,994,749,497,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255 - -#define MAX_1x7135 130 -#define DEFAULT_LEVEL 50 -#define HALFSPEED_LEVEL 12 -#define QUARTERSPEED_LEVEL 4 - -// don't blink halfway up -#ifdef BLINK_AT_RAMP_MIDDLE -#undef BLINK_AT_RAMP_MIDDLE -#endif - -#define RAMP_SMOOTH_FLOOR 10 // low levels may be unreliable -#define RAMP_SMOOTH_CEIL 130 -// 10, 30, [50], 70, 90, 110, 130 -#define RAMP_DISCRETE_FLOOR 10 -#define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL -#define RAMP_DISCRETE_STEPS 7 - -// safe limit ~75% power -#define SIMPLE_UI_FLOOR RAMP_DISCRETE_FLOOR -#define SIMPLE_UI_CEIL RAMP_DISCRETE_CEIL -#define SIMPLE_UI_STEPS 5 - -// make candle mode wobble more -#define CANDLE_AMPLITUDE 30 - -// stop panicking at ~70% power or ~600 lm -#define THERM_FASTER_LEVEL 130 -#define MIN_THERM_STEPDOWN 66 // must be > end of dynamic PWM range - -//#define THERM_RESPONSE_MAGNITUDE 32 // smaller adjustments, this host changes temperature slowly -//#define THERM_NEXT_WARNING_THRESHOLD 32 // more error tolerance before adjusting - -// slow down party strobe; this driver can't pulse for 1ms or less -// (only needed on no-FET build) -//#define PARTY_STROBE_ONTIME 2 - -#define THERM_CAL_OFFSET 5 - -// the power regulator is a bit slow, so push it harder for a quick response from off -#define DEFAULT_JUMP_START_LEVEL 21 -#define BLINK_BRIGHTNESS DEFAULT_LEVEL -#define BLINK_ONCE_TIME 12 - -// can't reset the normal way because power is connected before the button -#define USE_SOFT_FACTORY_RESET -- cgit v1.2.3 From 4b4353ade4c026c196e2b6edacbb0dc437e3ddda Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sun, 31 Oct 2021 02:35:49 -0600 Subject: added "200%" turbo on tint-ramping lights: D4S and LT1 Normal ramp from 0% to 100% power on levels 1 to 130, then 101% to 200% power at levels 131 to 150 using both channels at maximum for turbo. When either channel would go over 100%, the extra spills over to the other channel. --- hwdef-BLF_LT1.h | 4 +-- spaghetti-monster/anduril/cfg-blf-lantern.h | 24 +++++++++------ .../anduril/cfg-emisar-d4sv2-tintramp.h | 13 +++++---- spaghetti-monster/fsm-ramping.c | 33 ++++++++++++++++++--- spaghetti-monster/fsm-ramping.h | 34 +++++++++++----------- 5 files changed, 71 insertions(+), 37 deletions(-) diff --git a/hwdef-BLF_LT1.h b/hwdef-BLF_LT1.h index d0c2821..16e1c90 100644 --- a/hwdef-BLF_LT1.h +++ b/hwdef-BLF_LT1.h @@ -14,7 +14,7 @@ #include #define PWM_CHANNELS 1 // 1 virtual channel (1 for main LEDs + 1 for 2nd LEDs) -#define PWM_BITS 8 // 0 to 255 at 15.6 kHz +#define PWM_BITS 9 // 0 to 255 at 15.6 kHz, but goes to 510 for "200%" turbo #define PWM_TOP 255 // dynamic PWM with tint ramping (not supported on attiny85) @@ -25,7 +25,7 @@ // it out to a soft brightness value, in order to handle tint ramping // (this allows smooth thermal regulation to work, and makes things // otherwise simpler and easier) -uint8_t PWM1_LVL; +uint16_t PWM1_LVL; #define PWM1_PIN PB0 // pin 5, warm tint PWM #define TINT1_LVL OCR0A // OCR0A is the output compare register for PB0 diff --git a/spaghetti-monster/anduril/cfg-blf-lantern.h b/spaghetti-monster/anduril/cfg-blf-lantern.h index 48ed1f7..edbdca4 100644 --- a/spaghetti-monster/anduril/cfg-blf-lantern.h +++ b/spaghetti-monster/anduril/cfg-blf-lantern.h @@ -19,15 +19,20 @@ // (0 = 100% brightness, 64 = 200% brightness) //#define TINT_RAMPING_CORRECTION 26 // prototype, 140% #define TINT_RAMPING_CORRECTION 10 // production model, 115% +//#define TINT_RAMPING_CORRECTION 0 // none #ifdef RAMP_LENGTH #undef RAMP_LENGTH #endif -// level_calc.py 1 150 7135 1 30 800 +// 1-130: 0 to 100% power +// level_calc.py 3.0 1 130 7135 1 30 800 --pwm 255 +// 131-150: 101% to 200% power +// level_calc.py 8.69 1 150 7135 1 1 1600 --pwm 510 #define RAMP_LENGTH 150 -#define PWM1_LEVELS 1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,11,11,12,13,13,14,15,15,16,17,18,18,19,20,21,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,43,44,45,46,48,49,50,51,53,54,56,57,58,60,61,63,64,66,67,69,70,72,74,75,77,79,80,82,84,85,87,89,91,93,95,97,98,100,102,104,106,108,111,113,115,117,119,121,124,126,128,130,133,135,137,140,142,145,147,150,152,155,157,160,163,165,168,171,173,176,179,182,185,188,190,193,196,199,202,205,209,212,215,218,221,224,228,231,234,238,241,245,248,251,255 -#define MAX_1x7135 65 +#define PWM1_LEVELS 1,1,2,2,3,3,4,5,5,6,6,7,8,8,9,10,10,11,12,12,13,14,15,16,17,17,18,19,20,21,22,23,24,25,26,27,28,29,31,32,33,34,35,37,38,39,40,42,43,45,46,47,49,50,52,54,55,57,58,60,62,63,65,67,69,70,72,74,76,78,80,82,84,86,88,90,92,95,97,99,101,104,106,108,111,113,115,118,121,123,126,128,131,134,136,139,142,145,148,150,153,156,159,162,166,169,172,175,178,181,185,188,191,195,198,202,205,209,213,216,220,224,227,231,235,239,243,247,251,255,264,274,284,294,305,316,327,339,351,363,376,389,403,417,431,446,461,477,493,510 +#define MAX_1x7135 130 +#define DEFAULT_LEVEL 70 #define HALFSPEED_LEVEL 14 #define QUARTERSPEED_LEVEL 5 @@ -40,7 +45,7 @@ // set floor and ceiling as far apart as possible // because this lantern isn't overpowered #define RAMP_SMOOTH_FLOOR 1 -#define RAMP_SMOOTH_CEIL 150 +#define RAMP_SMOOTH_CEIL 130 #define RAMP_DISCRETE_FLOOR 10 #define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL #define RAMP_DISCRETE_STEPS 5 @@ -59,14 +64,15 @@ #undef USE_THERMAL_REGULATION #endif -// don't blink while ramping -#ifdef BLINK_AT_RAMP_MIDDLE -#undef BLINK_AT_RAMP_MIDDLE -#endif +// don't blink at floor #ifdef BLINK_AT_RAMP_FLOOR #undef BLINK_AT_RAMP_FLOOR #endif -// except the top... blink at the top +// blink at 100% power +#ifndef BLINK_AT_RAMP_MIDDLE +#define BLINK_AT_RAMP_MIDDLE +#endif +// blink again at the 200% power / ceil / turbo #ifndef BLINK_AT_RAMP_CEIL #define BLINK_AT_RAMP_CEIL #endif diff --git a/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h b/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h index c170645..bc710c2 100644 --- a/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h +++ b/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h @@ -28,10 +28,13 @@ // 2nd LEDs // output: unknown, 2000 lm? #define RAMP_LENGTH 150 -// level_calc.py 5.01 1 150 7135 1 0.2 2000 --pwm dyn:74:16383:511 // abstract ramp (power is split between both sets of LEDs) -#define PWM1_LEVELS 1,1,1,2,2,2,3,4,4,5,6,6,7,8,9,10,12,13,14,16,17,19,20,22,24,26,28,30,32,35,37,40,42,45,47,50,53,56,59,62,65,68,71,74,77,80,83,86,89,91,94,96,98,100,102,104,105,106,107,107,107,106,105,103,101,98,94,90,84,78,71,63,54,44,33,35,37,38,40,42,44,46,48,50,53,55,57,60,63,65,68,71,74,77,80,83,87,90,94,98,102,106,110,114,118,123,128,132,137,142,148,153,159,164,170,176,183,189,196,202,209,216,224,231,239,247,255,263,272,281,290,299,309,318,328,339,349,360,371,382,394,406,418,430,443,456,469,483,497,511 -#define PWM_TOPS 16383,13673,10738,15435,11908,8123,12779,14756,12240,13447,14013,11907,12263,12351,12261,12048,12926,12464,11972,12278,11704,11789,11180,11134,11013,10837,10620,10371,10100,10113,9793,9718,9376,9248,8898,8738,8560,8369,8168,7961,7749,7535,7321,7107,6895,6686,6480,6278,6080,5823,5639,5403,5178,4965,4763,4570,4346,4134,3936,3714,3507,3283,3074,2853,2648,2433,2211,2006,1776,1564,1351,1137,924,714,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511 +// 1-130: 0 to 100% power +// level_calc.py 5.01 1 130 7135 2 0.2 2000 --pwm dyn:64:16383:511 +// 131 to 150: 101% to 200% power +// level_calc.py 6.44 1 150 7135 1 0.2 2000 --pwm dyn:74:16383:1022 +#define PWM1_LEVELS 2,2,2,3,3,4,4,5,6,7,8,9,10,11,13,14,16,17,19,21,23,25,28,30,33,35,38,41,44,47,50,54,57,60,64,67,71,74,78,81,84,88,91,94,97,99,101,103,105,106,107,107,107,106,105,102,99,95,90,84,77,68,58,47,34,36,38,40,42,44,47,49,52,54,57,60,63,66,69,73,76,80,83,87,91,96,100,104,109,114,119,124,130,135,141,147,153,160,166,173,180,187,195,203,211,219,228,236,245,255,264,274,285,295,306,317,329,340,353,365,378,391,405,419,433,448,463,479,495,511,530,550,570,591,612,634,657,680,705,730,755,782,809,837,865,895,925,957,989,1022 +#define PWM_TOPS 16383,13234,9781,13826,9593,13434,9973,12021,12900,13193,13150,12899,12508,12023,12666,11982,12181,11422,11393,11247,11018,10731,10826,10434,10365,9927,9767,9565,9332,9076,8806,8693,8395,8096,7928,7626,7439,7143,6948,6665,6393,6203,5946,5700,5465,5187,4926,4681,4451,4195,3957,3700,3463,3213,2983,2718,2476,2231,1986,1742,1501,1245,997,756,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511 #define DEFAULT_LEVEL 70 #define MAX_1x7135 150 #define HALFSPEED_LEVEL 10 @@ -54,8 +57,8 @@ #define SIMPLE_UI_STEPS 5 // stop panicking at ~1500 lm -#define THERM_FASTER_LEVEL 140 -#define MIN_THERM_STEPDOWN 75 // should be above highest dyn_pwm level +#define THERM_FASTER_LEVEL 130 +#define MIN_THERM_STEPDOWN 65 // should be above highest dyn_pwm level // use the brightest setting for strobe #define STROBE_BRIGHTNESS MAX_LEVEL diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index 05c2e0e..ee72cd7 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -293,8 +293,14 @@ void update_tint() { // calculate actual PWM levels based on a single-channel ramp // and a global tint value //PWM_DATATYPE brightness = PWM_GET(pwm1_levels, level); - PWM_DATATYPE brightness = PWM1_LVL; - PWM_DATATYPE warm_PWM, cool_PWM; + uint16_t brightness = PWM1_LVL; + uint16_t warm_PWM, cool_PWM; + #ifdef USE_DYN_PWM + uint16_t top = PWM1_TOP; + //uint16_t top = PWM_GET(pwm_tops, actual_level-1); + #else + const uint16_t top = PWM_TOP; + #endif // auto-tint modes uint8_t mytint; @@ -311,18 +317,37 @@ void update_tint() { // stretch 1-254 to fit 0-255 range (hits every value except 98 and 198) else { mytint = (tint * 100 / 99) - 1; } - // middle tints sag, so correct for that effect PWM_DATATYPE2 base_PWM = brightness; - // correction is only necessary when PWM is fast #if defined(TINT_RAMPING_CORRECTION) && (TINT_RAMPING_CORRECTION > 0) + // middle tints sag, so correct for that effect + // by adding extra power which peaks at the middle tint + // (correction is only necessary when PWM is fast) if (level > HALFSPEED_LEVEL) { base_PWM = brightness + ((((PWM_DATATYPE2)brightness) * TINT_RAMPING_CORRECTION / 64) * triangle_wave(mytint) / 255); } + // fade the triangle wave out when above 100% power, + // so it won't go over 200% + if (brightness > top) { + base_PWM -= 2 * ( + ((brightness - top) * TINT_RAMPING_CORRECTION / 64) + * triangle_wave(mytint) / 255 + ); + } + // guarantee no more than 200% power + if (base_PWM > (top << 1)) { base_PWM = top << 1; } #endif cool_PWM = (((PWM_DATATYPE2)mytint * (PWM_DATATYPE2)base_PWM) + 127) / 255; warm_PWM = base_PWM - cool_PWM; + // when running at > 100% power, spill extra over to other channel + if (cool_PWM > top) { + warm_PWM += (cool_PWM - top); + cool_PWM = top; + } else if (warm_PWM > top) { + cool_PWM += (warm_PWM - top); + warm_PWM = top; + } TINT1_LVL = warm_PWM; TINT2_LVL = cool_PWM; diff --git a/spaghetti-monster/fsm-ramping.h b/spaghetti-monster/fsm-ramping.h index c1f6064..de090c2 100644 --- a/spaghetti-monster/fsm-ramping.h +++ b/spaghetti-monster/fsm-ramping.h @@ -48,26 +48,26 @@ void update_tint(); // auto-detect the data type for PWM tables #ifndef PWM_BITS -#define PWM_BITS 8 -#define PWM_TOP 255 + #define PWM_BITS 8 + #define PWM_TOP 255 #endif #if PWM_BITS <= 8 -#define PWM_DATATYPE uint8_t -#define PWM_DATATYPE2 uint16_t -#define PWM_TOP 255 -#define PWM_GET(x,y) pgm_read_byte(x+y) + #define PWM_DATATYPE uint8_t + #define PWM_DATATYPE2 uint16_t + #define PWM_TOP 255 + #define PWM_GET(x,y) pgm_read_byte(x+y) #else -#define PWM_DATATYPE uint16_t -#ifndef PWM_DATATYPE2 -#define PWM_DATATYPE2 uint32_t -#endif -#ifndef PWM_TOP -#define PWM_TOP 1023 // 10 bits by default -#endif -// 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 -#define PWM_GET(x,y) pgm_read_word(x+y) + #define PWM_DATATYPE uint16_t + #ifndef PWM_DATATYPE2 + #define PWM_DATATYPE2 uint32_t + #endif + #ifndef PWM_TOP + #define PWM_TOP 1023 // 10 bits by default + #endif + // 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 + #define PWM_GET(x,y) pgm_read_word(x+y) #endif // use UI-defined ramp tables if they exist -- cgit v1.2.3 From c890237f5ed6fba2f200cba23cff5622818a9ad0 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sun, 31 Oct 2021 02:51:38 -0600 Subject: fixed flicker on inactive tint ramp channel during ramping --- spaghetti-monster/fsm-ramping.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index ee72cd7..49e173f 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -102,6 +102,7 @@ void set_level(uint8_t level) { #endif } else { // enable the power channel, if relevant + #ifndef USE_TINT_RAMPING // update_tint handles this better #ifdef LED_ENABLE_PIN #ifndef LED_ENABLE_PIN_LEVEL_MIN LED_ENABLE_PORT |= (1 << LED_ENABLE_PIN); @@ -117,6 +118,7 @@ void set_level(uint8_t level) { #ifdef LED2_ENABLE_PIN LED2_ENABLE_PORT |= (1 << LED2_ENABLE_PIN); #endif + #endif // ifndef USE_TINT_RAMPING // PWM array index = level - 1 level --; @@ -354,11 +356,15 @@ void update_tint() { // disable the power channel, if relevant #ifdef LED_ENABLE_PIN - if (! warm_PWM) + if (warm_PWM) + LED_ENABLE_PORT |= (1 << LED_ENABLE_PIN); + else LED_ENABLE_PORT &= ~(1 << LED_ENABLE_PIN); #endif #ifdef LED2_ENABLE_PIN - if (! cool_PWM) + if (cool_PWM) + LED2_ENABLE_PORT |= (1 << LED2_ENABLE_PIN); + else LED2_ENABLE_PORT &= ~(1 << LED2_ENABLE_PIN); #endif } -- cgit v1.2.3 From f782cad5199d322815fdf4e1faa61aae5945bad8 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sun, 31 Oct 2021 03:19:13 -0600 Subject: made d4sv2-tintramp-fet work the same as no-fet version, but with added FET from ramp step 141 to 150 (0 to 100% power from 1 to 130, 101% to 200% from 131 to 150, and +DD FET from 141 to 150) also calibrated candle mode a bit better --- .../anduril/cfg-emisar-d4sv2-tintramp-fet.h | 24 ++++++++++++++-------- .../anduril/cfg-emisar-d4sv2-tintramp.h | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp-fet.h b/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp-fet.h index 3c638a7..657e25d 100644 --- a/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp-fet.h +++ b/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp-fet.h @@ -14,22 +14,30 @@ // 2nd LEDs // output: unknown, 2000 lm? #define RAMP_LENGTH 150 +///// copy non-FET ramp, but add FET to the top 10 levels from 141 to 150 +/* old // level_calc.py 5.01 1 140 7135 1 0.2 2000 --pwm dyn:69:16383:511 // plus a FET segment -// level_calc.py 2 1 10 7135 5 50.0 3000 --pwm 255 // abstract ramp (power is split between both sets of LEDs) +// level_calc.py 2 1 10 7135 5 50.0 3000 --pwm 255 // append: ,500,482,456,420,374,318,252,178,94,0 -#undef PWM1_LEVELS -#define PWM1_LEVELS 1,1,1,2,2,3,3,4,5,5,6,7,8,9,10,12,13,14,16,18,19,21,23,25,27,30,32,35,37,40,43,45,48,51,54,58,61,64,67,70,74,77,80,83,86,89,92,95,97,99,101,103,105,106,106,107,106,106,104,102,100,96,92,87,81,73,65,56,45,33,35,37,39,41,43,45,47,49,52,54,57,59,62,65,68,71,74,78,81,85,89,92,96,100,105,109,114,118,123,128,133,139,144,150,156,162,168,175,181,188,195,202,210,217,225,233,242,250,259,268,278,287,297,307,318,328,339,351,362,374,386,399,412,425,438,452,466,481,496,511,500,482,456,420,374,318,252,178,94,0 +*/ +/* also old +// level_calc.py 3 1 11 7135 511 2000 5000 --pwm 1022 +// append: 549,589,633,679,728,780,836,894,957,1022 +//#undef PWM1_LEVELS +//#define PWM1_LEVELS 1,1,1,2,2,3,3,4,5,5,6,7,8,9,10,12,13,14,16,18,19,21,23,25,27,30,32,35,37,40,43,45,48,51,54,58,61,64,67,70,74,77,80,83,86,89,92,95,97,99,101,103,105,106,106,107,106,106,104,102,100,96,92,87,81,73,65,56,45,33,35,37,39,41,43,45,47,49,52,54,57,59,62,65,68,71,74,78,81,85,89,92,96,100,105,109,114,118,123,128,133,139,144,150,156,162,168,175,181,188,195,202,210,217,225,233,242,250,259,268,278,287,297,307,318,328,339,351,362,374,386,399,412,425,438,452,466,481,496,511,549,589,633,679,728,780,836,894,957,1022 // append: ,511,511,511,511,511,511,511,511,511,511 -#undef PWM_TOPS -#define PWM_TOPS 16383,13469,10296,14694,10845,14620,11496,13507,14400,11954,12507,12676,12605,12376,12036,12805,12240,11650,11882,11933,11243,11155,10988,10763,10497,10569,10223,10164,9781,9646,9475,9071,8870,8652,8422,8330,8077,7823,7569,7318,7169,6919,6676,6439,6209,5986,5770,5561,5305,5063,4834,4618,4413,4180,3925,3723,3468,3264,3016,2787,2576,2333,2111,1885,1658,1412,1189,968,734,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511 +//#undef PWM_TOPS +//#define PWM_TOPS 16383,13469,10296,14694,10845,14620,11496,13507,14400,11954,12507,12676,12605,12376,12036,12805,12240,11650,11882,11933,11243,11155,10988,10763,10497,10569,10223,10164,9781,9646,9475,9071,8870,8652,8422,8330,8077,7823,7569,7318,7169,6919,6676,6439,6209,5986,5770,5561,5305,5063,4834,4618,4413,4180,3925,3723,3468,3264,3016,2787,2576,2333,2111,1885,1658,1412,1189,968,734,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511 +*/ + // prepend: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, #define PWM2_LEVELS 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,14,27,45,68,96,129,166,208,255 #undef DEFAULT_LEVEL #define DEFAULT_LEVEL 70 #undef MAX_1x7135 -#define MAX_1x7135 140 +#define MAX_1x7135 130 #undef RAMP_SMOOTH_FLOOR #define RAMP_SMOOTH_FLOOR 10 // level 1 is unreliable (?) @@ -53,9 +61,9 @@ // stop panicking at ~2000 lm #undef THERM_FASTER_LEVEL -#define THERM_FASTER_LEVEL 140 +#define THERM_FASTER_LEVEL 130 #undef MIN_THERM_STEPDOWN -#define MIN_THERM_STEPDOWN 70 // should be above highest dyn_pwm level +#define MIN_THERM_STEPDOWN 65 // should be above highest dyn_pwm level // speed up party strobe; the FET is really fast #undef PARTY_STROBE_ONTIME diff --git a/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h b/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h index bc710c2..3e54dca 100644 --- a/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h +++ b/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h @@ -66,7 +66,7 @@ #define PARTY_STROBE_ONTIME 2 // the default of 26 looks a bit flat, so increase it -#define CANDLE_AMPLITUDE 40 +#define CANDLE_AMPLITUDE 33 // the power regulator is a bit slow, so push it harder for a quick response from off #define DEFAULT_JUMP_START_LEVEL 21 -- cgit v1.2.3 From 03ccd35ea79cba1e8647d02dd79e44eac2a6568d Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sun, 31 Oct 2021 03:41:10 -0600 Subject: documented number entry 1H action (add 10) in UI table --- spaghetti-monster/anduril/anduril-manual.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/spaghetti-monster/anduril/anduril-manual.txt b/spaghetti-monster/anduril/anduril-manual.txt index 009e95e..34ae1bb 100644 --- a/spaghetti-monster/anduril/anduril-manual.txt +++ b/spaghetti-monster/anduril/anduril-manual.txt @@ -819,3 +819,4 @@ Config menus Full Hold Skip current item with no changes Config menus Full Release Configure current item Number entry Full Click Add 1 to value for current item +Number entry Full Hold Add 10 to value for current item -- cgit v1.2.3 From ccacc3931e1dd3e27483c930b40326c968f1e91e Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Wed, 3 Nov 2021 02:42:12 -0600 Subject: added KR4-tintramp build (is basically identical to D4Sv2-tintramp, but with the switch on a different pin, and no button LED) --- hwdef-Emisar_D4Sv2-tintramp.h | 3 +- hwdef-Noctigon_KR4-tintramp.h | 49 ++++++++++++++++++++++ .../anduril/cfg-noctigon-kr4-tintramp.h | 12 ++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 hwdef-Noctigon_KR4-tintramp.h create mode 100644 spaghetti-monster/anduril/cfg-noctigon-kr4-tintramp.h diff --git a/hwdef-Emisar_D4Sv2-tintramp.h b/hwdef-Emisar_D4Sv2-tintramp.h index 76f6097..3291c8b 100644 --- a/hwdef-Emisar_D4Sv2-tintramp.h +++ b/hwdef-Emisar_D4Sv2-tintramp.h @@ -52,6 +52,7 @@ #define SWITCH_PCIE PCIE0 // PCIE1 is for PCINT[7:0] #define SWITCH_PCMSK PCMSK0 // PCMSK1 is for PCINT[7:0] #define SWITCH_PORT PINA // PINA or PINB or PINC +#define SWITCH_PUE PUEA // pullup group A #define PCINT_vect PCINT0_vect // ISR for PCINT[7:0] // usually PWM1_LVL would be a hardware register, but we need to abstract @@ -173,7 +174,7 @@ inline void hwdef_setup() { PWM1_TOP = PWM_TOP; // set up e-switch - PUEA = (1 << SWITCH_PIN); // pull-up for e-switch + SWITCH_PUE = (1 << SWITCH_PIN); // pull-up for e-switch SWITCH_PCMSK = (1 << SWITCH_PCINT); // enable pin change interrupt } diff --git a/hwdef-Noctigon_KR4-tintramp.h b/hwdef-Noctigon_KR4-tintramp.h new file mode 100644 index 0000000..9857431 --- /dev/null +++ b/hwdef-Noctigon_KR4-tintramp.h @@ -0,0 +1,49 @@ +#ifndef HWDEF_KR4_TINTRAMP_H +#define HWDEF_KR4_TINTRAMP_H + +/* Noctigon KR4 w/ tint ramping + * (same driver as D4Sv2-tintramp, but with the switch on a different pin) + * + * Pin / Name / Function + * 1 PA6 2nd LED PWM (linear) (PWM1B) + * 2 PA5 R: red aux LED (PWM0B) + * 3 PA4 G: green aux LED + * 4 PA3 B: blue aux LED + * 5 PA2 button LED + * 6 PA1 Opamp 2 enable (2nd LEDs) + * 7 PA0 Opamp 1 enable (main LEDs) + * 8 GND GND + * 9 VCC VCC + * 10 PC5 (none) + * 11 PC4 (none) + * 12 PC3 RESET + * 13 PC2 (none) + * 14 PC1 SCK + * 15 PC0 main LED PWM (FET) (PWM0A) (unused on some models because tint ramping) + * 16 PB3 main LED PWM (linear) (PWM1A) + * 17 PB2 MISO / e-switch (PCINT10) + * 18 PB1 MOSI / battery voltage (ADC6) + * 19 PB0 (none) + * 20 PA7 (none) + * ADC12 thermal sensor + */ + +#include "hwdef-Emisar_D4Sv2-tintramp.h" + +// move the switch to a different pin +#undef SWITCH_PIN +#undef SWITCH_PCINT +#undef SWITCH_PCIE +#undef SWITCH_PCMSK +#undef SWITCH_PORT +#undef SWITCH_PUE +#undef PCINT_vect +#define SWITCH_PIN PB2 // pin 17 +#define SWITCH_PCINT PCINT10 // pin 17 pin change interrupt +#define SWITCH_PCIE PCIE1 // PCIE1 is for PCINT[11:8] +#define SWITCH_PCMSK PCMSK1 // PCMSK1 is for PCINT[11:8] +#define SWITCH_PORT PINB // PINA or PINB or PINC +#define SWITCH_PUE PUEB // pullup group B +#define PCINT_vect PCINT1_vect // ISR for PCINT[11:8] + +#endif diff --git a/spaghetti-monster/anduril/cfg-noctigon-kr4-tintramp.h b/spaghetti-monster/anduril/cfg-noctigon-kr4-tintramp.h new file mode 100644 index 0000000..f19744d --- /dev/null +++ b/spaghetti-monster/anduril/cfg-noctigon-kr4-tintramp.h @@ -0,0 +1,12 @@ +// Noctigon KR4 tint-ramping config options for Anduril +// (basically the same as Emisar D4S V2 tint-ramping, +// but switch on a different pin, and no lighted button) +// ATTINY: 1634 +#include "hwdef-Noctigon_KR4-tintramp.h" +#include "cfg-emisar-d4sv2-tintramp.h" +#undef MODEL_NUMBER +#define MODEL_NUMBER "0215" + +// the button doesn't light up +#undef USE_BUTTON_LED + -- cgit v1.2.3 From efd3f3ebdb0898d79e44d984cedd4c0409902e25 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Wed, 3 Nov 2021 04:16:05 -0600 Subject: added runtime config to choose tint-ramping or tint-toggle (Off->9H option 1, 0=smooth, 1=toggle) --- spaghetti-monster/anduril/anduril-manual.txt | 10 ++++++ spaghetti-monster/anduril/load-save-config-fsm.h | 1 + spaghetti-monster/anduril/load-save-config.c | 2 ++ spaghetti-monster/anduril/ramp-mode-fsm.h | 2 +- spaghetti-monster/anduril/ramp-mode.c | 7 ++-- spaghetti-monster/anduril/ramp-mode.h | 10 ++++++ spaghetti-monster/anduril/tint-ramping.c | 46 +++++++++--------------- spaghetti-monster/anduril/tint-ramping.h | 8 +++++ 8 files changed, 54 insertions(+), 32 deletions(-) diff --git a/spaghetti-monster/anduril/anduril-manual.txt b/spaghetti-monster/anduril/anduril-manual.txt index 34ae1bb..8d6ad75 100644 --- a/spaghetti-monster/anduril/anduril-manual.txt +++ b/spaghetti-monster/anduril/anduril-manual.txt @@ -692,6 +692,11 @@ Misc Config Menu Some models may have an extra config menu for settings which don't fit anywhere else. These settings are, in order: + - Tint ramp style: + + 0 = smooth (blend channels in any proportion) + 1 = toggle (only one channel active at a time) + - Jump Start level: Some lights are prone to starting up slowly at low levels, so they @@ -728,6 +733,11 @@ be warm white while dim, or cool white while bright. Or vice-versa. To access this, ramp to the end of the tint range, then keep holding until the light blinks a second time. +The misc config menu also has a setting to choose a tint ramp style. +This can be smooth, allowing the user to smoothly blend both channels in +whatever ratio they desire... or it can be "tint toggle" style, where +only one channel is active at a time. + UI Reference Table ------------------ diff --git a/spaghetti-monster/anduril/load-save-config-fsm.h b/spaghetti-monster/anduril/load-save-config-fsm.h index 894c344..ba3c69b 100644 --- a/spaghetti-monster/anduril/load-save-config-fsm.h +++ b/spaghetti-monster/anduril/load-save-config-fsm.h @@ -60,6 +60,7 @@ typedef enum { #endif #ifdef USE_TINT_RAMPING tint_e, + tint_style_e, #endif #ifdef USE_JUMP_START jump_start_level_e, diff --git a/spaghetti-monster/anduril/load-save-config.c b/spaghetti-monster/anduril/load-save-config.c index ee451ac..4987def 100644 --- a/spaghetti-monster/anduril/load-save-config.c +++ b/spaghetti-monster/anduril/load-save-config.c @@ -62,6 +62,7 @@ void load_config() { #endif #ifdef USE_TINT_RAMPING tint = eeprom[tint_e]; + tint_style = eeprom[tint_style_e]; #endif #ifdef USE_JUMP_START jump_start_level = eeprom[jump_start_level_e], @@ -140,6 +141,7 @@ void save_config() { #endif #ifdef USE_TINT_RAMPING eeprom[tint_e] = tint; + eeprom[tint_style_e] = tint_style; #endif #ifdef USE_JUMP_START eeprom[jump_start_level_e] = jump_start_level, diff --git a/spaghetti-monster/anduril/ramp-mode-fsm.h b/spaghetti-monster/anduril/ramp-mode-fsm.h index 7f67d1e..1a062e9 100644 --- a/spaghetti-monster/anduril/ramp-mode-fsm.h +++ b/spaghetti-monster/anduril/ramp-mode-fsm.h @@ -47,7 +47,7 @@ #endif // include an extra config mode for random stuff which doesn't fit elsewhere -#if defined(USE_JUMP_START) +#if defined(USE_TINT_RAMPING) || defined(USE_JUMP_START) #define USE_GLOBALS_CONFIG #endif diff --git a/spaghetti-monster/anduril/ramp-mode.c b/spaghetti-monster/anduril/ramp-mode.c index 6d85480..851f5a4 100644 --- a/spaghetti-monster/anduril/ramp-mode.c +++ b/spaghetti-monster/anduril/ramp-mode.c @@ -551,14 +551,17 @@ uint8_t ramp_extras_config_state(Event event, uint16_t arg) { #ifdef USE_GLOBALS_CONFIG void globals_config_save(uint8_t step, uint8_t value) { if (0) {} + #ifdef USE_TINT_RAMPING + else if (step == 1+tint_style_config_step) { tint_style = value; } + #endif #ifdef USE_JUMP_START - else { jump_start_level = value; } + else if (step == 1+jump_start_config_step) { jump_start_level = value; } #endif } uint8_t globals_config_state(Event event, uint16_t arg) { // TODO: set number of steps based on how many configurable options - return config_state_base(event, arg, 1, globals_config_save); + return config_state_base(event, arg, globals_config_num_steps, globals_config_save); } #endif diff --git a/spaghetti-monster/anduril/ramp-mode.h b/spaghetti-monster/anduril/ramp-mode.h index bba6d96..93756ab 100644 --- a/spaghetti-monster/anduril/ramp-mode.h +++ b/spaghetti-monster/anduril/ramp-mode.h @@ -224,6 +224,16 @@ uint8_t ramp_stepss[] = { uint8_t ramp_discrete_step_size; // don't set this #ifdef USE_GLOBALS_CONFIG +typedef enum { + #ifdef USE_TINT_RAMPING + tint_style_config_step, + #endif + #ifdef USE_JUMP_START + jump_start_config_step, + #endif + globals_config_num_steps +} globals_config_steps_e; + void globals_config_save(uint8_t step, uint8_t value); uint8_t globals_config_state(Event event, uint16_t arg); #endif diff --git a/spaghetti-monster/anduril/tint-ramping.c b/spaghetti-monster/anduril/tint-ramping.c index aa9b1f6..6cc0616 100644 --- a/spaghetti-monster/anduril/tint-ramping.c +++ b/spaghetti-monster/anduril/tint-ramping.c @@ -22,31 +22,6 @@ #include "tint-ramping.h" -#ifdef TINT_RAMP_TOGGLE_ONLY - -uint8_t tint_ramping_state(Event event, uint16_t arg) { - // click, click, hold: change the tint - if (event == EV_click3_hold) { - // toggle once on first frame; ignore other frames - if (! arg) { - tint = !tint; - set_level(actual_level); - //blink_once(); // unnecessary, and kind of annoying on moon - } - return EVENT_HANDLED; - } - - // click, click, hold, release: save config - else if (event == EV_click3_hold_release) { - // remember tint after battery change - save_config(); - return EVENT_HANDLED; - } - - return EVENT_NOT_HANDLED; -} - -#else // no TINT_RAMP_TOGGLE_ONLY uint8_t tint_ramping_state(Event event, uint16_t arg) { static int8_t tint_ramp_direction = 1; @@ -61,6 +36,21 @@ uint8_t tint_ramping_state(Event event, uint16_t arg) { // click, click, hold: change the tint if (event == EV_click3_hold) { + ///// tint-toggle mode + // toggle once on first frame; ignore other frames + if (tint_style) { + // only respond on first frame + if (arg) return EVENT_NOT_HANDLED; + + // force tint to be 1 or 254 + if (tint != 254) { tint = 1; } + // invert between 1 and 254 + tint = tint ^ 0xFF; + set_level(actual_level); + return EVENT_HANDLED; + } + + ///// smooth tint-ramp mode // reset at beginning of movement if (! arg) { active = 1; // first frame means this is for us @@ -98,8 +88,8 @@ uint8_t tint_ramping_state(Event event, uint16_t arg) { active = 0; // ignore next hold if it wasn't meant for us // reverse tint_ramp_direction = -tint_ramp_direction; - if (tint == 0) tint_ramp_direction = 1; - else if (tint == 255) tint_ramp_direction = -1; + if (tint <= 1) tint_ramp_direction = 1; + else if (tint >= 254) tint_ramp_direction = -1; // remember tint after battery change save_config(); return EVENT_HANDLED; @@ -108,8 +98,6 @@ uint8_t tint_ramping_state(Event event, uint16_t arg) { return EVENT_NOT_HANDLED; } -#endif // ifdef TINT_RAMP_TOGGLE_ONLY - #endif diff --git a/spaghetti-monster/anduril/tint-ramping.h b/spaghetti-monster/anduril/tint-ramping.h index e482999..1c5e22a 100644 --- a/spaghetti-monster/anduril/tint-ramping.h +++ b/spaghetti-monster/anduril/tint-ramping.h @@ -20,6 +20,14 @@ #ifndef TINT_RAMPING_H #define TINT_RAMPING_H +// 0: smooth tint ramp +// 1: toggle tint only between two extremes +#ifdef TINT_RAMP_TOGGLE_ONLY +uint8_t tint_style = 1; +#else +uint8_t tint_style = 0; +#endif + #ifdef USE_MANUAL_MEMORY uint8_t manual_memory_tint; #endif -- cgit v1.2.3 From c33100dcfbaee04e6992191defa3bf1e6be80b1e Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Wed, 3 Nov 2021 04:46:56 -0600 Subject: reset tint while changing tint ramp style --- spaghetti-monster/anduril/ramp-mode.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spaghetti-monster/anduril/ramp-mode.c b/spaghetti-monster/anduril/ramp-mode.c index 851f5a4..93b936a 100644 --- a/spaghetti-monster/anduril/ramp-mode.c +++ b/spaghetti-monster/anduril/ramp-mode.c @@ -552,7 +552,11 @@ uint8_t ramp_extras_config_state(Event event, uint16_t arg) { void globals_config_save(uint8_t step, uint8_t value) { if (0) {} #ifdef USE_TINT_RAMPING - else if (step == 1+tint_style_config_step) { tint_style = value; } + else if (step == 1+tint_style_config_step) { + tint_style = !(!(value)); + // set tint to middle or edge depending on style being smooth or toggle + tint = tint_style ? 1 : 127; + } #endif #ifdef USE_JUMP_START else if (step == 1+jump_start_config_step) { jump_start_level = value; } -- cgit v1.2.3 From c3f547d5edfbca0ed78190d9d8b8f3609baebb5f Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Wed, 3 Nov 2021 20:33:01 -0600 Subject: fixed KR4-tintramp build (switch wasn't working) and added it to MODELS --- hwdef-Emisar_D4Sv2-tintramp.h | 2 ++ hwdef-Noctigon_KR4-tintramp.h | 13 +++++-------- spaghetti-monster/anduril/MODELS | 1 + 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/hwdef-Emisar_D4Sv2-tintramp.h b/hwdef-Emisar_D4Sv2-tintramp.h index 3291c8b..90545f4 100644 --- a/hwdef-Emisar_D4Sv2-tintramp.h +++ b/hwdef-Emisar_D4Sv2-tintramp.h @@ -47,6 +47,7 @@ #define USE_DYN_PWM // dynamic frequency and speed #define PWM_DATATYPE2 uint32_t // only needs 32-bit if ramp values go over 255 +#ifndef SWITCH_PIN #define SWITCH_PIN PA7 // pin 20 #define SWITCH_PCINT PCINT7 // pin 20 pin change interrupt #define SWITCH_PCIE PCIE0 // PCIE1 is for PCINT[7:0] @@ -54,6 +55,7 @@ #define SWITCH_PORT PINA // PINA or PINB or PINC #define SWITCH_PUE PUEA // pullup group A #define PCINT_vect PCINT0_vect // ISR for PCINT[7:0] +#endif // usually PWM1_LVL would be a hardware register, but we need to abstract // it out to a soft brightness value, in order to handle tint ramping diff --git a/hwdef-Noctigon_KR4-tintramp.h b/hwdef-Noctigon_KR4-tintramp.h index 9857431..3bd57fe 100644 --- a/hwdef-Noctigon_KR4-tintramp.h +++ b/hwdef-Noctigon_KR4-tintramp.h @@ -28,16 +28,10 @@ * ADC12 thermal sensor */ -#include "hwdef-Emisar_D4Sv2-tintramp.h" +#define ATTINY 1634 +#include // move the switch to a different pin -#undef SWITCH_PIN -#undef SWITCH_PCINT -#undef SWITCH_PCIE -#undef SWITCH_PCMSK -#undef SWITCH_PORT -#undef SWITCH_PUE -#undef PCINT_vect #define SWITCH_PIN PB2 // pin 17 #define SWITCH_PCINT PCINT10 // pin 17 pin change interrupt #define SWITCH_PCIE PCIE1 // PCIE1 is for PCINT[11:8] @@ -46,4 +40,7 @@ #define SWITCH_PUE PUEB // pullup group B #define PCINT_vect PCINT1_vect // ISR for PCINT[11:8] +// the rest of the config is the same as D4Sv2-tintramp +#include "hwdef-Emisar_D4Sv2-tintramp.h" + #endif diff --git a/spaghetti-monster/anduril/MODELS b/spaghetti-monster/anduril/MODELS index ca9da30..a125f53 100644 --- a/spaghetti-monster/anduril/MODELS +++ b/spaghetti-monster/anduril/MODELS @@ -20,6 +20,7 @@ Model Name MCU 0212 noctigon-kr4-nofet attiny1634 0213 noctigon-kr4-219 attiny1634 0214 noctigon-kr4-219b attiny1634 +0215 noctigon-kr4-tintramp attiny1634 0251 noctigon-k1 attiny1634 0252 noctigon-k1-sbt90 attiny1634 0253 noctigon-k1-12v attiny1634 -- cgit v1.2.3 From 3ab0110af192cf7746dadbcf5966bd125b49860f Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sat, 6 Nov 2021 02:20:34 -0600 Subject: greatly smoothed out SP10 ramp, and configured defaults also fixed random ramp stuttering, by adding phase-reset register to hwdef (though it still has a brief stutter sometimes while ramping down across the channel boundary, at least it always seems to be smooth while going up now) --- hwdef-Sofirn_SP10-Pro.h | 1 + spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h | 40 +++++++++++++++---------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/hwdef-Sofirn_SP10-Pro.h b/hwdef-Sofirn_SP10-Pro.h index 5ed716d..3cd405c 100644 --- a/hwdef-Sofirn_SP10-Pro.h +++ b/hwdef-Sofirn_SP10-Pro.h @@ -38,6 +38,7 @@ PA1 : Boost Enable #ifndef PWM1_PIN #define PWM1_PIN PB5 #define PWM1_LVL TCA0.SINGLE.CMP2 // PB5 is Alternate MUX for TCA Compare 2 +#define PWM1_CNT TCA0.SINGLE.CNT // for resetting phase after each TOP adjustment #endif // Big channel diff --git a/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h b/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h index 2dc0def..51f189e 100644 --- a/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h +++ b/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h @@ -7,29 +7,33 @@ #define USE_DYNAMIC_UNDERCLOCKING -// PWM generated by: level_calc_dyn.py ninth 1 147 7135 1 1 800 --pwm dyn:64:1024:255 -// and then three steps manually added to the front for the low channel (low channel PWM created manually) +// 1....15: level_calc.py 3.01 1 15 7135 1 0.1 2 --pwm dyn:15:64:64 +// 16..150: level_calc.py 5.01 1 135 7135 1 2 800 --pwm dyn:49:4096:255 #define RAMP_LENGTH 150 #define USE_DYN_PWM -#define PWM1_LEVELS 2,12,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 -#define PWM2_LEVELS 0,0,0,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4,5,5,5,5,6,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,9,10,10,10,10,10,11,11,11,11,11,11,11,11,12,12,13,13,14,15,15,16,16,17,18,19,19,20,21,22,23,24,25,26,27,28,29,31,32,33,34,36,37,39,40,42,44,45,47,49,51,53,55,57,59,61,64,66,69,71,74,77,79,82,85,89,92,95,99,102,106,110,114,118,122,126,131,135,140,145,150,155,161,166,172,178,184,190,196,203,210,217,224,231,239,247,255 -#define PWM_TOPS 64,64,64,1024,966,909,851,792,733,674,614,554,493,883,815,747,679,611,543,474,816,762,709,655,602,549,745,700,655,610,566,522,652,613,575,537,625,591,557,523,491,555,525,496,467,514,487,461,436,470,447,424,402,381,406,387,367,349,332,350,334,318,303,288,275,262,250,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255 +#define _PWM1_LEVELS_ 1,2,4,6,9,12,15,19,23,28,34,41,48,55,64 +#define _PWM1_TOPS_ 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64 +#define _PWM2_LEVELS_ 1,1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,19,20,21,22,23,24,25,26,27,28,29,30,31,31,32,32,33,33,33,33,33,33,32,31,30,29,28,26,24,22,19,17,14,15,15,16,17,18,18,19,20,21,22,23,24,25,26,27,28,29,30,31,33,34,35,37,38,39,41,42,44,46,47,49,51,53,55,57,59,61,63,65,67,70,72,74,77,79,82,85,88,90,93,96,99,103,106,109,113,116,120,123,127,131,135,139,143,147,151,156,160,165,170,175,180,185,190,195,201,206,212,218,223,230,236,242,248,255 +#define _PWM2_TOPS_ 4096,2212,2316,2863,3070,3145,3154,3127,3080,3019,3284,3176,3071,2968,2869,2773,2680,2745,2647,2554,2464,2379,2297,2219,2144,2072,2004,1938,1875,1813,1698,1646,1545,1499,1411,1329,1253,1182,1116,1022,936,857,784,717,630,550,477,389,329,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255 +#define PWM1_LEVELS _PWM1_LEVELS_,_PWM2_TOPS_ +#define PWM2_LEVELS 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,_PWM2_LEVELS_ +#define PWM_TOPS _PWM1_TOPS_,_PWM2_TOPS_ -//#define PWM1_LEVELS 255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 -//#define PWM2_LEVELS 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,5,5,5,5,6,6,6,7,7,7,8,8,8,9,9,10,10,10,11,11,12,12,13,14,14,15,16,16,17,18,18,19,20,21,22,23,24,25,26,27,28,29,30,31,33,34,35,37,38,40,41,43,45,46,48,50,52,54,56,58,60,63,65,67,70,73,75,78,81,84,87,90,93,97,100,104,107,111,115,119,123,128,132,137,141,146,151,156,162,167,173,179,185,191,197,204,210,217,224,232,239,247,255 +#define MAX_1x7135 15 +#define HALFSPEED_LEVEL 15 +#define QUARTERSPEED_LEVEL 5 +#define DEFAULT_LEVEL 75 -#define MAX_1x7135 80 -#define HALFSPEED_LEVEL 3 -#define QUARTERSPEED_LEVEL 3 - -#define RAMP_SMOOTH_FLOOR 3 -#define RAMP_SMOOTH_CEIL 120 -#define RAMP_DISCRETE_FLOOR RAMP_SMOOTH_FLOOR +#define RAMP_SMOOTH_FLOOR 1 +#define RAMP_SMOOTH_CEIL 150 +// 1 25 50 [75] 100 125 150 +#define RAMP_DISCRETE_FLOOR 1 #define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL #define RAMP_DISCRETE_STEPS 7 // at Sofirn's request, use max (150) for the Simple UI ceiling -#define SIMPLE_UI_FLOOR RAMP_DISCRETE_FLOOR +// 15 48 [82] 116 150 +#define SIMPLE_UI_FLOOR MAX_1x7135 #define SIMPLE_UI_CEIL 150 #define SIMPLE_UI_STEPS 5 @@ -46,7 +50,7 @@ // stop panicking at ~30% power #define THERM_FASTER_LEVEL 105 -#define MIN_THERM_STEPDOWN 66 // must be > end of dynamic PWM range +#define MIN_THERM_STEPDOWN 65 // must be > end of dynamic PWM range // slow down party strobe; this driver can't pulse for too short a time #define PARTY_STROBE_ONTIME 8 @@ -56,3 +60,7 @@ // enable 2 click turbo (replaces USE_2C_MAX_TURBO) #define DEFAULT_2C_STYLE 1 + +// enable factory reset on 13H without loosening tailcap +#define USE_SOFT_FACTORY_RESET + -- cgit v1.2.3 From 02521ee8094ff79ff5e927856008c4fa153be6eb Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sat, 6 Nov 2021 02:30:08 -0600 Subject: reduced SP10 downward ramp flicker even more (reduced PWM_TOP minimum timing window to 32 cpu cycles, to allow TOP value of 64 to work better) --- spaghetti-monster/fsm-ramping.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index 49e173f..abbfbde 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -146,8 +146,8 @@ void set_level(uint8_t level) { // the timing of changing the TOP value (section 12.8.4)) // (but don't wait when turning on from zero, because // it'll reset the phase below anyway) - // to be safe, allow at least 64 cycles to update TOP - while(prev_level && (PWM1_CNT > (top - 64))) {} + // to be safe, allow at least 32 cycles to update TOP + while(prev_level && (PWM1_CNT > (top - 32))) {} #endif // pulse frequency modulation, a.k.a. dynamic PWM PWM1_TOP = top; @@ -155,13 +155,13 @@ void set_level(uint8_t level) { // repeat for other channels if necessary #ifdef PMW2_TOP #ifdef PWM2_CNT - while(prev_level && (PWM2_CNT > (top - 64))) {} + while(prev_level && (PWM2_CNT > (top - 32))) {} #endif PWM2_TOP = top; #endif #ifdef PMW3_TOP #ifdef PWM3_CNT - while(prev_level && (PWM3_CNT > (top - 64))) {} + while(prev_level && (PWM3_CNT > (top - 32))) {} #endif PWM3_TOP = top; #endif -- cgit v1.2.3 From ed168e69904ab6e843c1e088a47d8d543a6dd43d Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sat, 6 Nov 2021 02:31:10 -0600 Subject: reduced SP10 firefly/moon power usage slightly, by keeping CPU underclocked more until ch2 activates --- spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h b/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h index 51f189e..293c84d 100644 --- a/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h +++ b/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h @@ -21,7 +21,7 @@ #define MAX_1x7135 15 #define HALFSPEED_LEVEL 15 -#define QUARTERSPEED_LEVEL 5 +#define QUARTERSPEED_LEVEL 15 #define DEFAULT_LEVEL 75 #define RAMP_SMOOTH_FLOOR 1 -- cgit v1.2.3 From 817462cc70188af8d3c07c1006d79d54e3882c42 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Fri, 12 Nov 2021 03:13:10 -0700 Subject: fine-tuned DM11-12V build a bit based on actual measurements --- spaghetti-monster/anduril/cfg-noctigon-dm11-12v.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/spaghetti-monster/anduril/cfg-noctigon-dm11-12v.h b/spaghetti-monster/anduril/cfg-noctigon-dm11-12v.h index 27af461..03961e0 100644 --- a/spaghetti-monster/anduril/cfg-noctigon-dm11-12v.h +++ b/spaghetti-monster/anduril/cfg-noctigon-dm11-12v.h @@ -21,9 +21,10 @@ #define USE_DYN_PWM // level_calc.py 5.01 1 149 7135 1 0.3 1740 --pwm dyn:78:16384:255 +// (plus a 0 at the beginning for moon) #define PWM1_LEVELS 0,1,1,1,2,3,3,4,5,6,7,8,9,10,11,13,14,16,17,19,21,23,25,27,29,31,34,36,39,42,44,47,50,53,57,60,63,67,70,74,77,81,85,88,92,96,99,103,107,110,113,117,120,123,126,128,130,133,134,136,137,137,137,137,136,135,133,130,126,122,117,111,104,96,87,76,65,52,38,22,23,25,26,27,28,29,30,32,33,34,36,37,39,40,42,43,45,47,49,51,53,55,57,59,61,63,66,68,70,73,76,78,81,84,87,90,93,96,99,103,106,110,113,117,121,125,129,133,137,142,146,151,155,160,165,170,175,181,186,192,197,203,209,215,222,228,234,241,248,255 #define PWM_TOPS 16383,16383,12404,8140,11462,14700,11041,12947,13795,14111,14124,13946,13641,13248,12791,13418,12808,13057,12385,12428,12358,12209,12000,11746,11459,11147,11158,10793,10708,10576,10173,9998,9800,9585,9527,9278,9023,8901,8634,8486,8216,8053,7881,7615,7440,7261,7009,6832,6656,6422,6196,6031,5819,5615,5419,5190,4973,4803,4571,4386,4179,3955,3745,3549,3340,3145,2940,2729,2513,2312,2109,1903,1697,1491,1286,1070,871,662,459,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255 -#define DEFAULT_LEVEL 50 +#define DEFAULT_LEVEL 70 #define MAX_1x7135 150 #define HALFSPEED_LEVEL 12 @@ -36,7 +37,8 @@ #define RAMP_SMOOTH_FLOOR 10 // low levels may be unreliable #define RAMP_SMOOTH_CEIL 130 -// 10, 30, [50], 70, 90, 110, 130 +// 10, 30, 50, [70], 90, 110, 130 +// Nichia B35 model: (0.56), 1.4, 8.4, 34.5, [102], 250, 500, 860, (1300) lm #define RAMP_DISCRETE_FLOOR 10 #define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL #define RAMP_DISCRETE_STEPS 7 @@ -56,14 +58,16 @@ //#define THERM_RESPONSE_MAGNITUDE 32 // smaller adjustments, this host changes temperature slowly //#define THERM_NEXT_WARNING_THRESHOLD 32 // more error tolerance before adjusting -// slow down party strobe; this driver can't pulse for 1ms or less -#define PARTY_STROBE_ONTIME 4 +// slow down party strobe; this driver can't pulse for 2ms or less +#define PARTY_STROBE_ONTIME 3 #define THERM_CAL_OFFSET 5 -// the power regulator is a bit slow, so push it harder for a quick response from off -#define DEFAULT_JUMP_START_LEVEL 21 -#define BLINK_BRIGHTNESS DEFAULT_LEVEL +// the power regulator seems to "jump start" the LEDs all on its own, +// so the firmware doesn't have to +// (and unfortunately the power regulator jumps it a bit too hard) +#define DEFAULT_JUMP_START_LEVEL 1 +#define BLINK_BRIGHTNESS 50 #define BLINK_ONCE_TIME 12 // added for convenience -- cgit v1.2.3 From 13dd432134110138106ea2bf3b5605cd37e23ebc Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Fri, 12 Nov 2021 03:16:00 -0700 Subject: added DM11 to MODELS file --- spaghetti-monster/anduril/MODELS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spaghetti-monster/anduril/MODELS b/spaghetti-monster/anduril/MODELS index a125f53..79a6a4a 100644 --- a/spaghetti-monster/anduril/MODELS +++ b/spaghetti-monster/anduril/MODELS @@ -30,6 +30,9 @@ Model Name MCU 0265 noctigon-k9.3-tintramp-nofet attiny1634 0266 noctigon-k9.3-tintramp-fet attiny1634 0267 noctigon-k9.3-tintramp-219 attiny1634 +0271 noctigon-dm11 attiny1634 +0272 noctigon-dm11-nofet attiny1634 +0273 noctigon-dm11-12v attiny1634 0311 fw3a attiny85 0312 fw3a-219 attiny85 0313 fw3a-nofet attiny85 -- cgit v1.2.3 From 6a6d9e59cd950b07112c9801933461162e43e1cb Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Fri, 12 Nov 2021 03:26:20 -0700 Subject: a bit more fine-tuning for DM11 --- spaghetti-monster/anduril/cfg-noctigon-dm11-12v.h | 4 ++-- spaghetti-monster/anduril/cfg-noctigon-dm11-nofet.h | 4 ++-- spaghetti-monster/anduril/cfg-noctigon-dm11.h | 9 +++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/spaghetti-monster/anduril/cfg-noctigon-dm11-12v.h b/spaghetti-monster/anduril/cfg-noctigon-dm11-12v.h index 03961e0..3e7c1d3 100644 --- a/spaghetti-monster/anduril/cfg-noctigon-dm11-12v.h +++ b/spaghetti-monster/anduril/cfg-noctigon-dm11-12v.h @@ -24,9 +24,9 @@ // (plus a 0 at the beginning for moon) #define PWM1_LEVELS 0,1,1,1,2,3,3,4,5,6,7,8,9,10,11,13,14,16,17,19,21,23,25,27,29,31,34,36,39,42,44,47,50,53,57,60,63,67,70,74,77,81,85,88,92,96,99,103,107,110,113,117,120,123,126,128,130,133,134,136,137,137,137,137,136,135,133,130,126,122,117,111,104,96,87,76,65,52,38,22,23,25,26,27,28,29,30,32,33,34,36,37,39,40,42,43,45,47,49,51,53,55,57,59,61,63,66,68,70,73,76,78,81,84,87,90,93,96,99,103,106,110,113,117,121,125,129,133,137,142,146,151,155,160,165,170,175,181,186,192,197,203,209,215,222,228,234,241,248,255 #define PWM_TOPS 16383,16383,12404,8140,11462,14700,11041,12947,13795,14111,14124,13946,13641,13248,12791,13418,12808,13057,12385,12428,12358,12209,12000,11746,11459,11147,11158,10793,10708,10576,10173,9998,9800,9585,9527,9278,9023,8901,8634,8486,8216,8053,7881,7615,7440,7261,7009,6832,6656,6422,6196,6031,5819,5615,5419,5190,4973,4803,4571,4386,4179,3955,3745,3549,3340,3145,2940,2729,2513,2312,2109,1903,1697,1491,1286,1070,871,662,459,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255 + #define DEFAULT_LEVEL 70 #define MAX_1x7135 150 - #define HALFSPEED_LEVEL 12 #define QUARTERSPEED_LEVEL 4 @@ -49,7 +49,7 @@ #define SIMPLE_UI_STEPS 5 // make candle mode wobble more -#define CANDLE_AMPLITUDE 30 +#define CANDLE_AMPLITUDE 33 // stop panicking at ~70% power or ~600 lm #define THERM_FASTER_LEVEL 130 diff --git a/spaghetti-monster/anduril/cfg-noctigon-dm11-nofet.h b/spaghetti-monster/anduril/cfg-noctigon-dm11-nofet.h index a1249b1..5a828d6 100644 --- a/spaghetti-monster/anduril/cfg-noctigon-dm11-nofet.h +++ b/spaghetti-monster/anduril/cfg-noctigon-dm11-nofet.h @@ -15,7 +15,7 @@ #undef PWM_TOPS #define PWM_TOPS 16383,16383,12404,8140,11462,14700,11041,12947,13795,14111,14124,13946,13641,13248,12791,13418,12808,13057,12385,12428,12358,12209,12000,11746,11459,11147,11158,10793,10708,10576,10173,9998,9800,9585,9527,9278,9023,8901,8634,8486,8216,8053,7881,7615,7440,7261,7009,6832,6656,6422,6196,6031,5819,5615,5419,5190,4973,4803,4571,4386,4179,3955,3745,3549,3340,3145,2940,2729,2513,2312,2109,1903,1697,1491,1286,1070,871,662,459,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255 #undef DEFAULT_LEVEL -#define DEFAULT_LEVEL 50 +#define DEFAULT_LEVEL 70 #undef MAX_1x7135 #define MAX_1x7135 150 @@ -23,7 +23,7 @@ #ifdef CANDLE_AMPLITUDE #undef CANDLE_AMPLITUDE #endif -#define CANDLE_AMPLITUDE 35 +#define CANDLE_AMPLITUDE 33 // slow down party strobe; this driver can't pulse for 1ms or less diff --git a/spaghetti-monster/anduril/cfg-noctigon-dm11.h b/spaghetti-monster/anduril/cfg-noctigon-dm11.h index 89d2fe6..794ae2b 100644 --- a/spaghetti-monster/anduril/cfg-noctigon-dm11.h +++ b/spaghetti-monster/anduril/cfg-noctigon-dm11.h @@ -19,14 +19,15 @@ // - FET: DD #define RAMP_LENGTH 150 #define USE_DYN_PWM + // maxreg at 130, dynamic PWM: level_calc.py 5.01 2 149 7135 1 0.3 1740 FET 1 10 3190 --pwm dyn:64:16384:255 // (plus one extra level at the beginning for moon) #define PWM1_LEVELS 0,1,1,2,2,3,4,5,6,7,8,9,11,12,14,16,17,19,22,24,26,29,31,34,37,40,43,46,49,53,56,60,63,67,71,74,78,82,86,89,93,96,99,103,105,108,110,112,114,115,116,116,115,114,112,109,106,101,95,89,81,71,60,48,34,19,20,21,22,23,24,26,27,28,30,31,32,34,36,37,39,41,43,45,47,49,51,53,56,58,61,63,66,69,72,75,78,81,84,88,91,95,99,103,107,111,115,119,124,129,133,138,143,149,154,159,165,171,177,183,189,196,203,210,217,224,231,239,247,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0 #define PWM2_LEVELS 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,20,30,41,52,63,75,87,99,112,125,138,151,165,179,194,208,224,239,255 #define PWM_TOPS 16383,16383,11750,14690,9183,12439,13615,13955,13877,13560,13093,12529,13291,12513,12756,12769,11893,11747,12085,11725,11329,11316,10851,10713,10518,10282,10016,9729,9428,9298,8971,8794,8459,8257,8043,7715,7497,7275,7052,6753,6538,6260,5994,5798,5501,5271,5006,4758,4525,4268,4030,3775,3508,3263,3010,2752,2517,2256,1998,1763,1512,1249,994,749,497,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255 +#define DEFAULT_LEVEL 70 #define MAX_1x7135 130 -#define DEFAULT_LEVEL 50 #define HALFSPEED_LEVEL 12 #define QUARTERSPEED_LEVEL 4 @@ -37,7 +38,7 @@ #define RAMP_SMOOTH_FLOOR 10 // low levels may be unreliable #define RAMP_SMOOTH_CEIL 130 -// 10, 30, [50], 70, 90, 110, 130 +// 10, 30, 50, [70], 90, 110, 130 #define RAMP_DISCRETE_FLOOR 10 #define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL #define RAMP_DISCRETE_STEPS 7 @@ -65,8 +66,8 @@ // the power regulator is a bit slow, so push it harder for a quick response from off #define DEFAULT_JUMP_START_LEVEL 21 -#define BLINK_BRIGHTNESS DEFAULT_LEVEL +#define BLINK_BRIGHTNESS 50 #define BLINK_ONCE_TIME 12 -// can't reset the normal way because power is connected before the button +// added for convenience #define USE_SOFT_FACTORY_RESET -- cgit v1.2.3 From 56fed712d41b0f5f19e91d84c802a3a6079e771c Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sat, 13 Nov 2021 05:06:17 -0700 Subject: increased SP10 PWM speed as much as possible without making ramp bumpy, and made party strobe pulses much faster Reduced max PWM TOP to 3072, because 2048 wasn't enough and 4096 was more than necessary. Also, Ch1 lumens / 256 / ch2 lumens = 6, so 256 * 6 * 2 is the lowest value which allows ch1 to start at half of ch2's power. I tried 1536 initially, but it made the ramp visibly malformed at the channel boundary. However, 3072 seems about right. Implemented a non-linear PWM_TOP ramp-down in level_calc, to allow it to converge faster and reduce the number of levels with visible pulses. Added an option to keep the regulator chips on between strobe pulses, by keeping the LEDs at moon instead of turning completely off. This allows the SP10 party strobe to use much shorter, more consistent pulses. --- bin/level_calc.py | 8 +++++++- spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h | 9 +++++---- spaghetti-monster/anduril/strobe-modes.c | 2 +- spaghetti-monster/anduril/strobe-modes.h | 7 +++++++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/bin/level_calc.py b/bin/level_calc.py index 2998b44..60416db 100755 --- a/bin/level_calc.py +++ b/bin/level_calc.py @@ -65,10 +65,16 @@ def main(args): dpwm_steps = int(parts[1]) dpwn_max = int(parts[2]) dpwn_min = int(parts[3]) + dpwm_shape = 'linear' + if parts[4]: + dpwm_shape = float(parts[4]) max_pwms = [dpwn_min] * answers.num_levels for i in range(dpwm_steps): span = dpwn_max - dpwn_min - x = dpwn_min + (span * (float(dpwm_steps - i) / dpwm_steps)) + if dpwm_shape == 'linear': + x = dpwn_min + (span * (float(dpwm_steps - i) / dpwm_steps)) + else: # variable curve + x = dpwn_min + (span * ((float(dpwm_steps - i) / dpwm_steps) ** dpwm_shape)) max_pwms[i] = int(x) max_pwm = dpwn_min diff --git a/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h b/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h index 293c84d..5507440 100644 --- a/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h +++ b/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h @@ -8,13 +8,13 @@ #define USE_DYNAMIC_UNDERCLOCKING // 1....15: level_calc.py 3.01 1 15 7135 1 0.1 2 --pwm dyn:15:64:64 -// 16..150: level_calc.py 5.01 1 135 7135 1 2 800 --pwm dyn:49:4096:255 +// 16..150: level_calc.py 5.01 1 135 7135 1 2 800 --pwm dyn:49:3072:255:3.0 #define RAMP_LENGTH 150 #define USE_DYN_PWM #define _PWM1_LEVELS_ 1,2,4,6,9,12,15,19,23,28,34,41,48,55,64 #define _PWM1_TOPS_ 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64 -#define _PWM2_LEVELS_ 1,1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,19,20,21,22,23,24,25,26,27,28,29,30,31,31,32,32,33,33,33,33,33,33,32,31,30,29,28,26,24,22,19,17,14,15,15,16,17,18,18,19,20,21,22,23,24,25,26,27,28,29,30,31,33,34,35,37,38,39,41,42,44,46,47,49,51,53,55,57,59,61,63,65,67,70,72,74,77,79,82,85,88,90,93,96,99,103,106,109,113,116,120,123,127,131,135,139,143,147,151,156,160,165,170,175,180,185,190,195,201,206,212,218,223,230,236,242,248,255 -#define _PWM2_TOPS_ 4096,2212,2316,2863,3070,3145,3154,3127,3080,3019,3284,3176,3071,2968,2869,2773,2680,2745,2647,2554,2464,2379,2297,2219,2144,2072,2004,1938,1875,1813,1698,1646,1545,1499,1411,1329,1253,1182,1116,1022,936,857,784,717,630,550,477,389,329,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255 +#define _PWM2_LEVELS_ 1,1,2,2,3,3,4,4,5,5,6,6,6,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,9,9,9,10,10,10,11,11,12,13,13,14,15,15,16,17,18,18,19,20,21,22,23,24,25,26,27,28,29,30,31,33,34,35,37,38,39,41,42,44,46,47,49,51,53,55,57,59,61,63,65,67,70,72,74,77,79,82,85,88,90,93,96,99,103,106,109,113,116,120,123,127,131,135,139,143,147,151,156,160,165,170,175,180,185,190,195,201,206,212,218,223,230,236,242,248,255 +#define _PWM2_TOPS_ 3072,1960,2372,1476,2097,1572,1920,1570,1777,1524,1646,1454,1286,1369,1234,1115,1011,918,837,894,823,759,702,650,603,560,522,487,455,425,398,374,351,330,310,292,275,259,280,265,251,266,253,240,252,240,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255 #define PWM1_LEVELS _PWM1_LEVELS_,_PWM2_TOPS_ #define PWM2_LEVELS 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,_PWM2_LEVELS_ #define PWM_TOPS _PWM1_TOPS_,_PWM2_TOPS_ @@ -53,7 +53,8 @@ #define MIN_THERM_STEPDOWN 65 // must be > end of dynamic PWM range // slow down party strobe; this driver can't pulse for too short a time -#define PARTY_STROBE_ONTIME 8 +//#define PARTY_STROBE_ONTIME 8 +#define STROBE_OFF_LEVEL 1 // keep the regulator chip on between pulses // the default of 26 looks a bit flat, so increase it #define CANDLE_AMPLITUDE 50 diff --git a/spaghetti-monster/anduril/strobe-modes.c b/spaghetti-monster/anduril/strobe-modes.c index d5f12c0..e8d1dbb 100644 --- a/spaghetti-monster/anduril/strobe-modes.c +++ b/spaghetti-monster/anduril/strobe-modes.c @@ -215,7 +215,7 @@ inline void party_tactical_strobe_mode_iter(uint8_t st) { nice_delay_ms(del >> 1); } #endif - set_level(0); + set_level(STROBE_OFF_LEVEL); nice_delay_ms(del); // no return check necessary on final delay } #endif diff --git a/spaghetti-monster/anduril/strobe-modes.h b/spaghetti-monster/anduril/strobe-modes.h index e2389ba..c6cfb53 100644 --- a/spaghetti-monster/anduril/strobe-modes.h +++ b/spaghetti-monster/anduril/strobe-modes.h @@ -62,6 +62,13 @@ strobe_mode_te strobe_type = 0; #endif #endif +// some drivers need to keep the regulator chip on between pulses, +// so set this to 1 to keep the light on at moon mode between pulses, +// and thus keep the regulator powered up for the next flash +#ifndef STROBE_OFF_LEVEL +#define STROBE_OFF_LEVEL 0 +#endif + // party and tactical strobes #ifdef USE_STROBE_STATE uint8_t strobe_state(Event event, uint16_t arg); -- cgit v1.2.3 From d2a64b93ea7b5fb939fe632c018d3fc8b57970d5 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sat, 13 Nov 2021 05:18:23 -0700 Subject: enabled manual memory and timer by default; reset to ~6 lm (level 50/150) after being off for 10 minutes This sets the factory-reset default settings and affects Simple UI, so it will likely need confirmation from Sofirn. --- spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h b/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h index 5507440..bcfc80e 100644 --- a/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h +++ b/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h @@ -37,6 +37,12 @@ #define SIMPLE_UI_CEIL 150 #define SIMPLE_UI_STEPS 5 +// turn on at ~6 lm by default (level 50/150, or ramp step 2/5 or 3/7) +// (also sets lockout mode 2H to a useful level) +#define DEFAULT_MANUAL_MEMORY 50 +// reset to default after being off for 10 minutes +#define DEFAULT_MANUAL_MEMORY_TIMER 10 + // enable SOS in the blinkies group #define USE_SOS_MODE #define USE_SOS_MODE_IN_BLINKY_GROUP -- cgit v1.2.3 From 396fc623c7dce04fcd0a9afc9e777bb06b766a34 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sat, 13 Nov 2021 05:35:01 -0700 Subject: fixed SP10 ramp flickering properly, using double-buffered registers instead of my janky forced phase-reset workaround (gchart found the solution but couldn't reproduce the issue, so I tried his method and confirmed it seems to be fixed) --- hwdef-Sofirn_SP10-Pro.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hwdef-Sofirn_SP10-Pro.h b/hwdef-Sofirn_SP10-Pro.h index 3cd405c..bb10f2f 100644 --- a/hwdef-Sofirn_SP10-Pro.h +++ b/hwdef-Sofirn_SP10-Pro.h @@ -37,18 +37,19 @@ PA1 : Boost Enable // Small channel #ifndef PWM1_PIN #define PWM1_PIN PB5 -#define PWM1_LVL TCA0.SINGLE.CMP2 // PB5 is Alternate MUX for TCA Compare 2 -#define PWM1_CNT TCA0.SINGLE.CNT // for resetting phase after each TOP adjustment +#define PWM1_LVL TCA0.SINGLE.CMP2BUF // PB5 is Alternate MUX for TCA Compare 2 #endif // Big channel #ifndef PWM2_PIN #define PWM2_PIN PB0 -#define PWM2_LVL TCA0.SINGLE.CMP0 // PB0 is TCA Compare 0 +#define PWM2_LVL TCA0.SINGLE.CMP0BUF // PB0 is TCA Compare 0 #endif // PWM parameters of both channels are tied together because they share a counter -#define PWM1_TOP TCA0.SINGLE.PER // holds the TOP value for for variable-resolution PWM +#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 LED_ENABLE_PIN PIN1_bp #define LED_ENABLE_PORT PORTA_OUT -- cgit v1.2.3 From 3a8557dc1e514d4f04b2a6e0ef9da3bce1286c86 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Wed, 8 Dec 2021 12:49:44 -0700 Subject: fixed Ramp 3H with Anduril 2 style turbo (it was going to ceiling instead of full power) (also had to disable battcheck calibration on some large builds to make room) --- spaghetti-monster/anduril/cfg-ff-rot66.h | 6 ++++++ spaghetti-monster/anduril/cfg-mateminco-mf01-mini.h | 5 +++++ spaghetti-monster/anduril/ramp-mode.c | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/spaghetti-monster/anduril/cfg-ff-rot66.h b/spaghetti-monster/anduril/cfg-ff-rot66.h index 48541a7..03b74db 100644 --- a/spaghetti-monster/anduril/cfg-ff-rot66.h +++ b/spaghetti-monster/anduril/cfg-ff-rot66.h @@ -44,4 +44,10 @@ // too big, remove stuff to make room #undef USE_RAMP_AFTER_MOON_CONFIG #undef USE_RAMP_SPEED_CONFIG +#undef USE_VOLTAGE_CORRECTION //#undef USE_2C_STYLE_CONFIG +//#undef USE_TACTICAL_STROBE_MODE + +// reduce size a bit +#define NO_LOWPASS_WHILE_ASLEEP + diff --git a/spaghetti-monster/anduril/cfg-mateminco-mf01-mini.h b/spaghetti-monster/anduril/cfg-mateminco-mf01-mini.h index 86e8c26..09b684f 100644 --- a/spaghetti-monster/anduril/cfg-mateminco-mf01-mini.h +++ b/spaghetti-monster/anduril/cfg-mateminco-mf01-mini.h @@ -55,4 +55,9 @@ // too big, remove stuff to make room #undef USE_RAMP_AFTER_MOON_CONFIG #undef USE_RAMP_SPEED_CONFIG +#undef USE_VOLTAGE_CORRECTION //#undef USE_2C_STYLE_CONFIG + +// reduce size a bit +#define NO_LOWPASS_WHILE_ASLEEP + diff --git a/spaghetti-monster/anduril/ramp-mode.c b/spaghetti-monster/anduril/ramp-mode.c index 93b936a..8c49b11 100644 --- a/spaghetti-monster/anduril/ramp-mode.c +++ b/spaghetti-monster/anduril/ramp-mode.c @@ -396,7 +396,12 @@ uint8_t steady_state(Event event, uint16_t arg) { // 3H: momentary turbo (on lights with no tint ramping) else if (event == EV_click3_hold) { if (! arg) { // first frame only, to allow thermal regulation to work + #ifdef USE_2C_STYLE_CONFIG + uint8_t tl = style_2c ? MAX_LEVEL : turbo_level; + set_level_and_therm_target(tl); + #else set_level_and_therm_target(turbo_level); + #endif } return MISCHIEF_MANAGED; } -- cgit v1.2.3 From 3f6a9fe82d892a1fca198169a7d3ed7bba58f902 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Wed, 8 Dec 2021 15:31:00 -0700 Subject: added a compile option for USE_LOWPASS_WHILE_ASLEEP, but it doesn't actually fix the issue I was hoping it'd fix, so it's disabled by default (when the battery is right on a threshold between colors for aux LED "voltage" mode, it can bounce between colors until the cell isn't on the boundary any more... but a simple lowpass doesn't really help) (but I also didn't want to throw out the code, in case it's useful later as a reference for a more effective solution) --- spaghetti-monster/anduril/cfg-ff-rot66.h | 5 +++-- .../anduril/cfg-mateminco-mf01-mini.h | 4 +++- spaghetti-monster/anduril/config-default.h | 4 ++++ spaghetti-monster/fsm-adc.c | 22 ++++++++++++++++++++-- spaghetti-monster/fsm-standby.c | 2 ++ 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/spaghetti-monster/anduril/cfg-ff-rot66.h b/spaghetti-monster/anduril/cfg-ff-rot66.h index 03b74db..e2d5ff7 100644 --- a/spaghetti-monster/anduril/cfg-ff-rot66.h +++ b/spaghetti-monster/anduril/cfg-ff-rot66.h @@ -49,5 +49,6 @@ //#undef USE_TACTICAL_STROBE_MODE // reduce size a bit -#define NO_LOWPASS_WHILE_ASLEEP - +#ifdef USE_LOWPASS_WHILE_ASLEEP +#undef USE_LOWPASS_WHILE_ASLEEP +#endif diff --git a/spaghetti-monster/anduril/cfg-mateminco-mf01-mini.h b/spaghetti-monster/anduril/cfg-mateminco-mf01-mini.h index 09b684f..b5c3b12 100644 --- a/spaghetti-monster/anduril/cfg-mateminco-mf01-mini.h +++ b/spaghetti-monster/anduril/cfg-mateminco-mf01-mini.h @@ -59,5 +59,7 @@ //#undef USE_2C_STYLE_CONFIG // reduce size a bit -#define NO_LOWPASS_WHILE_ASLEEP +#ifdef USE_LOWPASS_WHILE_ASLEEP +#undef USE_LOWPASS_WHILE_ASLEEP +#endif diff --git a/spaghetti-monster/anduril/config-default.h b/spaghetti-monster/anduril/config-default.h index 406e98b..77b5c6b 100644 --- a/spaghetti-monster/anduril/config-default.h +++ b/spaghetti-monster/anduril/config-default.h @@ -189,5 +189,9 @@ // (defined here so config files can override it) #define USE_DYNAMIC_UNDERCLOCKING +// if the aux LEDs oscillate between "full battery" and "empty battery" +// while in "voltage" mode, enable this to reduce the amplitude of +// those oscillations +//#define USE_LOWPASS_WHILE_ASLEEP #endif diff --git a/spaghetti-monster/fsm-adc.c b/spaghetti-monster/fsm-adc.c index 975d12e..c5401ea 100644 --- a/spaghetti-monster/fsm-adc.c +++ b/spaghetti-monster/fsm-adc.c @@ -306,10 +306,28 @@ static inline void ADC_voltage_handler() { uint16_t measurement; // latest ADC value - if (adc_reset) { // while asleep, or just after waking, don't lowpass + if (adc_reset) { // just after waking, don't lowpass measurement = adc_raw[0]; - adc_smooth[0] = measurement; // no lowpass while asleep + adc_smooth[0] = measurement; // no lowpass, just use the latest value } + #ifdef USE_LOWPASS_WHILE_ASLEEP + else if (go_to_standby) { // weaker lowpass while asleep + // occasionally the aux LED color can oscillate during standby, + // while using "voltage" mode ... so try to reduce the oscillation + uint16_t m = adc_raw[0]; + uint16_t v = adc_smooth[0]; + #if 0 + // fixed-rate lowpass, slow, more stable but takes longer to settle + if (m < v) { v -= 64; } + if (m > v) { v += 64; } + #else + // weighted lowpass, faster but less stable + v = (m>>1) + (v>>1); + #endif + adc_smooth[0] = v; + measurement = v; + } + #endif else measurement = adc_smooth[0]; // values stair-step between intervals of 64, with random variations diff --git a/spaghetti-monster/fsm-standby.c b/spaghetti-monster/fsm-standby.c index c450bca..0ae6a2f 100644 --- a/spaghetti-monster/fsm-standby.c +++ b/spaghetti-monster/fsm-standby.c @@ -73,7 +73,9 @@ void sleep_until_eswitch_pressed() go_to_standby = 0; } if (irq_adc) { // ADC done measuring + #ifndef USE_LOWPASS_WHILE_ASLEEP adc_reset = 1; // don't lowpass while asleep + #endif adc_deferred_enable = 1; adc_deferred(); //ADC_off(); // takes care of itself -- cgit v1.2.3 From 752b7d7c91acad00a2ae988909133d10bbdc9cf1 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Wed, 8 Dec 2021 15:36:58 -0700 Subject: enabled SOS mode on lights which have enough room for it --- spaghetti-monster/anduril/cfg-ff-rot66.h | 1 + spaghetti-monster/anduril/cfg-mateminco-mf01-mini.h | 1 + spaghetti-monster/anduril/config-default.h | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/spaghetti-monster/anduril/cfg-ff-rot66.h b/spaghetti-monster/anduril/cfg-ff-rot66.h index e2d5ff7..481808a 100644 --- a/spaghetti-monster/anduril/cfg-ff-rot66.h +++ b/spaghetti-monster/anduril/cfg-ff-rot66.h @@ -42,6 +42,7 @@ #undef BLINK_AT_RAMP_CEIL // too big, remove stuff to make room +#undef USE_SOS_MODE #undef USE_RAMP_AFTER_MOON_CONFIG #undef USE_RAMP_SPEED_CONFIG #undef USE_VOLTAGE_CORRECTION diff --git a/spaghetti-monster/anduril/cfg-mateminco-mf01-mini.h b/spaghetti-monster/anduril/cfg-mateminco-mf01-mini.h index b5c3b12..83b2614 100644 --- a/spaghetti-monster/anduril/cfg-mateminco-mf01-mini.h +++ b/spaghetti-monster/anduril/cfg-mateminco-mf01-mini.h @@ -53,6 +53,7 @@ // too big, remove stuff to make room +#undef USE_SOS_MODE #undef USE_RAMP_AFTER_MOON_CONFIG #undef USE_RAMP_SPEED_CONFIG #undef USE_VOLTAGE_CORRECTION diff --git a/spaghetti-monster/anduril/config-default.h b/spaghetti-monster/anduril/config-default.h index 77b5c6b..0e70347 100644 --- a/spaghetti-monster/anduril/config-default.h +++ b/spaghetti-monster/anduril/config-default.h @@ -166,9 +166,9 @@ // (these replace the fun strobe group, // so don't enable them at the same time as any of the above strobes) //#define USE_POLICE_STROBE_MODE -//#define USE_SOS_MODE +#define USE_SOS_MODE //#define USE_SOS_MODE_IN_FF_GROUP // put SOS in the "boring strobes" mode -//#define USE_SOS_MODE_IN_BLINKY_GROUP // put SOS in the blinkies mode group +#define USE_SOS_MODE_IN_BLINKY_GROUP // put SOS in the blinkies mode group // enable a mode for locking the light for safe carry #define USE_LOCKOUT_MODE -- cgit v1.2.3 From b0d0d7f036f895e40451e8a923a109c7edd422c0 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Mon, 13 Dec 2021 15:19:19 -0700 Subject: Added "Lockout 3C -> Off", changed Lockout 4H blink (light) to a blip (dark), adjusted a couple builds which overflowed. --- spaghetti-monster/anduril/anduril-manual.txt | 4 ++++ spaghetti-monster/anduril/cfg-blf-gt-mini.h | 8 ++++++++ spaghetti-monster/anduril/cfg-blf-q8.h | 7 +++++++ spaghetti-monster/anduril/lockout-mode.c | 10 +++++++++- 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/spaghetti-monster/anduril/anduril-manual.txt b/spaghetti-monster/anduril/anduril-manual.txt index 8d6ad75..1873b8d 100644 --- a/spaghetti-monster/anduril/anduril-manual.txt +++ b/spaghetti-monster/anduril/anduril-manual.txt @@ -75,6 +75,7 @@ In Lockout mode with Simple UI, there are a few functions: - 1H: Momentary moon - 2H: Momentary low + - 3C: Unlock and turn off - 4C: Unlock and turn on - 4H: Unlock and turn on at low level - 5C: Unlock and turn on at high level @@ -296,6 +297,8 @@ To exit lockout mode, click 4 times. The light should blink briefly and then turn on at the memorized level. Or hold the final press to turn on at the floor level instead: + - 3C: Unlock and go to "Off" mode + - 4C: Go to ramp mode (memorized level). (uses manual mem level if there is one) @@ -788,6 +791,7 @@ Ramp Full 10H Ramp Extras config menu: Lockout Any 1C/1H Momentary moon (lowest floor) Lockout Any 2C/2H Momentary moon (highest floor, or manual mem level) +Lockout Any 3C Unlock (go to "Off" mode) Lockout Any 4C On (ramp mode, memorized level) Lockout Any 4H On (ramp mode, floor level) Lockout Any 5C On (ramp mode, ceiling level) diff --git a/spaghetti-monster/anduril/cfg-blf-gt-mini.h b/spaghetti-monster/anduril/cfg-blf-gt-mini.h index af16f2c..a647ea5 100644 --- a/spaghetti-monster/anduril/cfg-blf-gt-mini.h +++ b/spaghetti-monster/anduril/cfg-blf-gt-mini.h @@ -10,3 +10,11 @@ // the button is visible while main LEDs are on #define USE_INDICATOR_LED_WHILE_RAMPING +// too big, remove stuff to make room +#undef USE_SOS_MODE +//#undef USE_RAMP_AFTER_MOON_CONFIG +//#undef USE_RAMP_SPEED_CONFIG +//#undef USE_VOLTAGE_CORRECTION +//#undef USE_2C_STYLE_CONFIG +//#undef USE_TACTICAL_STROBE_MODE + diff --git a/spaghetti-monster/anduril/cfg-blf-q8.h b/spaghetti-monster/anduril/cfg-blf-q8.h index d4243ee..851d930 100644 --- a/spaghetti-monster/anduril/cfg-blf-q8.h +++ b/spaghetti-monster/anduril/cfg-blf-q8.h @@ -36,3 +36,10 @@ // stop panicking at ~75% power or ~3000 lm, this light has high thermal mass #define THERM_FASTER_LEVEL (RAMP_SIZE*9/10) // throttle back faster when high +// too big, remove stuff to make room +#undef USE_SOS_MODE +//#undef USE_RAMP_AFTER_MOON_CONFIG +//#undef USE_RAMP_SPEED_CONFIG +//#undef USE_VOLTAGE_CORRECTION +//#undef USE_2C_STYLE_CONFIG +//#undef USE_TACTICAL_STROBE_MODE diff --git a/spaghetti-monster/anduril/lockout-mode.c b/spaghetti-monster/anduril/lockout-mode.c index 8c83cff..e3e3fed 100644 --- a/spaghetti-monster/anduril/lockout-mode.c +++ b/spaghetti-monster/anduril/lockout-mode.c @@ -88,9 +88,16 @@ uint8_t lockout_state(Event event, uint16_t arg) { } #endif + // 3 clicks: exit and turn off + else if (event == EV_3clicks) { + blink_once(); + set_state(off_state, 0); + return MISCHIEF_MANAGED; + } // 4 clicks: exit and turn on else if (event == EV_4clicks) { #ifdef USE_MANUAL_MEMORY + // FIXME: memory timer is totally ignored if (manual_memory) set_state(steady_state, manual_memory); else @@ -100,7 +107,8 @@ uint8_t lockout_state(Event event, uint16_t arg) { } // 4 clicks, but hold last: exit and start at floor else if (event == EV_click4_hold) { - blink_once(); + //blink_once(); + blip(); // reset button sequence to avoid activating anything in ramp mode current_event = 0; // ... and back to ramp mode -- cgit v1.2.3 From 274b615fc35b0c6256fc647422e98f721a06e8ce Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Mon, 13 Dec 2021 15:54:30 -0700 Subject: fixed bug where tint-ramping could end up 1 brightness ramp step different than it started --- spaghetti-monster/anduril/tint-ramping.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spaghetti-monster/anduril/tint-ramping.c b/spaghetti-monster/anduril/tint-ramping.c index 6cc0616..d270d9d 100644 --- a/spaghetti-monster/anduril/tint-ramping.c +++ b/spaghetti-monster/anduril/tint-ramping.c @@ -22,7 +22,6 @@ #include "tint-ramping.h" - uint8_t tint_ramping_state(Event event, uint16_t arg) { static int8_t tint_ramp_direction = 1; static uint8_t prev_tint = 0; @@ -92,6 +91,9 @@ uint8_t tint_ramping_state(Event event, uint16_t arg) { else if (tint >= 254) tint_ramp_direction = -1; // remember tint after battery change save_config(); + // bug?: for some reason, brightness can seemingly change + // from 1/150 to 2/150 without this next line... not sure why + set_level(actual_level); return EVENT_HANDLED; } -- cgit v1.2.3 From 91c84394de6987ee93f9cf5fccffc84ebcb5d36b Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 24 Mar 2022 18:47:04 -0600 Subject: added Noctigon DM11-SBT90.2 build (which is mostly like the regular linear+FET build, but has the switch on a different pin for some reason) --- hwdef-Noctigon_DM11-SBT90.h | 154 +++++++++++++++++++++ hwdef-Noctigon_DM11.h | 13 +- .../anduril/cfg-noctigon-dm11-sbt90.h | 73 ++++++++++ 3 files changed, 229 insertions(+), 11 deletions(-) create mode 100644 hwdef-Noctigon_DM11-SBT90.h create mode 100644 spaghetti-monster/anduril/cfg-noctigon-dm11-sbt90.h diff --git a/hwdef-Noctigon_DM11-SBT90.h b/hwdef-Noctigon_DM11-SBT90.h new file mode 100644 index 0000000..64ebe05 --- /dev/null +++ b/hwdef-Noctigon_DM11-SBT90.h @@ -0,0 +1,154 @@ +#ifndef HWDEF_NOCTIGON_DM11SBT90_H +#define HWDEF_NOCTIGON_DM11SBT90_H + +/* Noctigon DM11-SBT90.2 driver layout (attiny1634) + * (based on Noctigon K1 and DM11) + * + * Pin / Name / Function + * 1 PA6 FET PWM (direct drive) (PWM1B) + * 2 PA5 R: red aux LED (PWM0B) + * 3 PA4 G: green aux LED + * 4 PA3 B: blue aux LED + * 5 PA2 L: button LED + * 6 PA1 (none) + * 7 PA0 (none) + * 8 GND GND + * 9 VCC VCC + * 10 PC5 (none) + * 11 PC4 (none) + * 12 PC3 RESET + * 13 PC2 (none) + * 14 PC1 SCK + * 15 PC0 (none) PWM0A + * 16 PB3 main LED PWM (PWM1A) + * 17 PB2 MISO / e-switch (PCINT10) + * 18 PB1 MOSI / battery voltage (ADC6) + * 19 PB0 Opamp power + * 20 PA7 (none) (PCINT7) + * ADC12 thermal sensor + * + * 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. + * The on/off pin is only used to turn the main LED on and off, + * not to change brightness. + * Also has a direct-drive FET for turbo. + */ + +#ifdef ATTINY +#undef ATTINY +#endif +#define ATTINY 1634 +#include + +#define PWM_CHANNELS 2 // override this for the no-FET version +#define PWM_BITS 16 // data type needs 16 bits, not 8 +#define PWM_TOP 255 // highest value used in top half of ramp +#define USE_DYN_PWM // dynamic frequency and speed + +#define SWITCH_PIN PB2 // pin 17 +#define SWITCH_PCINT PCINT10 // pin 17 pin change interrupt +#define SWITCH_PCIE PCIE1 // PCIE1 is for PCINT[11:8] +#define SWITCH_PCMSK PCMSK1 // PCMSK1 is for PCINT[11:8] +#define SWITCH_PORT PINB // PINA or PINB or PINC +#define PCINT_vect PCINT1_vect // ISR for PCINT[11:8] + +#define PWM1_PIN PB3 // pin 16, Opamp reference +#define PWM1_LVL OCR1A // OCR1A is the output compare register for PB3 +#define PWM1_CNT TCNT1 // for dynamic PWM, reset phase + +#define PWM2_PIN PA6 // pin 1, DD FET PWM +#define PWM2_LVL OCR1B // OCR1B is the output compare register for PA6 + +// PWM parameters of both channels are tied together because they share a counter +#define PWM1_TOP ICR1 // holds the TOP value for for variable-resolution PWM + +#define LED_ENABLE_PIN PB0 // pin 19, Opamp power +#define LED_ENABLE_PORT PORTB // control port for PB0 + + +#define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is flattened +#define VOLTAGE_PIN PB1 // Pin 18 / PB1 / ADC6 +// pin to ADC mappings are in DS table 19-4 +#define VOLTAGE_ADC ADC6D // digital input disable pin for PB1 +// DIDR0/DIDR1 mappings are in DS section 19.13.5, 19.13.6 +#define VOLTAGE_ADC_DIDR DIDR1 // DIDR channel for ADC6D +// DS tables 19-3, 19-4 +// Bit 7 6 5 4 3 2 1 0 +// REFS1 REFS0 REFEN ADC0EN MUX3 MUX2 MUX1 MUX0 +// MUX[3:0] = 0, 1, 1, 0 for ADC6 / PB1 +// divided by ... +// REFS[1:0] = 1, 0 for internal 1.1V reference +// other bits reserved +#define ADMUX_VOLTAGE_DIVIDER 0b10000110 +#define ADC_PRSCL 0x07 // clk/128 + +// Raw ADC readings at 4.4V and 2.2V +// calibrate the voltage readout here +// estimated / calculated values are: +// (voltage - D1) * (R2/(R2+R1) * 1024 / 1.1) +// D1, R1, R2 = 0, 330, 100 +#ifndef ADC_44 +//#define ADC_44 981 // raw value at 4.40V +#define ADC_44 967 // manually tweaked so 4.16V will blink out 4.2 +#endif +#ifndef ADC_22 +//#define ADC_22 489 // raw value at 2.20V +#define ADC_22 482 // manually tweaked so 4.16V will blink out 4.2 +#endif + +// this light has aux LEDs under the optic +#define AUXLED_R_PIN PA5 // pin 2 +#define AUXLED_G_PIN PA4 // pin 3 +#define AUXLED_B_PIN PA3 // pin 4 +#define AUXLED_RGB_PORT PORTA // PORTA or PORTB or PORTC +#define AUXLED_RGB_DDR DDRA // DDRA or DDRB or DDRC +#define AUXLED_RGB_PUE PUEA // PUEA or PUEB or PUEC + +#define BUTTON_LED_PIN PA2 // pin 5 +#define BUTTON_LED_PORT PORTA // for all "PA" pins +#define BUTTON_LED_DDR DDRA // for all "PA" pins +#define BUTTON_LED_PUE PUEA // for all "PA" pins + +// with so many pins, doing this all with #ifdefs gets awkward... +// ... so just hardcode it in each hwdef file instead +inline void hwdef_setup() { + // enable output ports + // Opamp level and Opamp on/off + DDRB = (1 << PWM1_PIN) + | (1 << LED_ENABLE_PIN); + // DD FET PWM, aux R/G/B, button LED + DDRA = (1 << PWM2_PIN) + | (1 << AUXLED_R_PIN) + | (1 << AUXLED_G_PIN) + | (1 << AUXLED_B_PIN) + | (1 << BUTTON_LED_PIN) + ; + + // configure PWM + // Setup PWM. F_pwm = F_clkio / 2 / N / TOP, where N = prescale factor, TOP = top of counter + // pre-scale for timer: N = 1 + // WGM1[3:0]: 1,0,1,0: PWM, Phase Correct, adjustable (DS table 12-5) + // CS1[2:0]: 0,0,1: clk/1 (No prescaling) (DS table 12-6) + // COM1A[1:0]: 1,0: PWM OC1A in the normal direction (DS table 12-4) + // COM1B[1:0]: 1,0: PWM OC1B in the normal direction (DS table 12-4) + TCCR1A = (1< end of dynamic PWM range + +//#define THERM_RESPONSE_MAGNITUDE 32 // smaller adjustments, this host changes temperature slowly +//#define THERM_NEXT_WARNING_THRESHOLD 32 // more error tolerance before adjusting + +// slow down party strobe; this driver can't pulse for 1ms or less +// (only needed on no-FET build) +//#define PARTY_STROBE_ONTIME 2 + +#define THERM_CAL_OFFSET 5 + +// the power regulator is a bit slow, so push it harder for a quick response from off +#define DEFAULT_JUMP_START_LEVEL 21 +#define BLINK_BRIGHTNESS 50 +#define BLINK_ONCE_TIME 12 + +// added for convenience +#define USE_SOFT_FACTORY_RESET -- cgit v1.2.3 From 4d9c1a13bcf572557a1c300e5938ffafc053368d Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Wed, 30 Mar 2022 01:20:36 -0600 Subject: added KR4-12V build, fixed model number for DM11-SBT90 build --- hwdef-Noctigon_KR4-12V.h | 154 +++++++++++++++++++++ spaghetti-monster/anduril/MODELS | 2 + .../anduril/cfg-noctigon-dm11-sbt90.h | 2 +- spaghetti-monster/anduril/cfg-noctigon-kr4-12v.h | 70 ++++++++++ 4 files changed, 227 insertions(+), 1 deletion(-) create mode 100644 hwdef-Noctigon_KR4-12V.h create mode 100644 spaghetti-monster/anduril/cfg-noctigon-kr4-12v.h diff --git a/hwdef-Noctigon_KR4-12V.h b/hwdef-Noctigon_KR4-12V.h new file mode 100644 index 0000000..20724a2 --- /dev/null +++ b/hwdef-Noctigon_KR4-12V.h @@ -0,0 +1,154 @@ +#ifndef HWDEF_NOCTIGON_KR4_12V_H +#define HWDEF_NOCTIGON_KR4_12V_H + +/* Noctigon KR4 (12V) driver layout (attiny1634) + * (based on Noctigon DM11-12V and KR4) + * + * Pin / Name / Function + * 1 PA6 (none) (PWM1B) (reserved for DD drivers) + * 2 PA5 R: red aux LED (PWM0B) + * 3 PA4 G: green aux LED + * 4 PA3 B: blue aux LED + * 5 PA2 L: button LED + * 6 PA1 (none) + * 7 PA0 (none) + * 8 GND GND + * 9 VCC VCC + * 10 PC5 (none) + * 11 PC4 (none) + * 12 PC3 RESET + * 13 PC2 (none) + * 14 PC1 SCK + * 15 PC0 boost PMIC enable (PWM0A not used) + * 16 PB3 main LED PWM (PWM1A) + * 17 PB2 MISO / e-switch (PCINT10) + * 18 PB1 MOSI / battery voltage (ADC6) + * 19 PB0 Opamp power + * 20 PA7 (none) (PCINT7) + * ADC12 thermal sensor + * + * 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. + * The on/off pin is only used to turn the main LED on and off, + * not to change brightness. + */ + +#ifdef ATTINY +#undef ATTINY +#endif +#define ATTINY 1634 +#include + +#define PWM_CHANNELS 1 // can't use DD FET on boost drivers +#define PWM_BITS 16 // data type needs 16 bits, not 8 +#define PWM_TOP 255 // highest value used in top half of ramp +#define USE_DYN_PWM // dynamic frequency and speed + +#define SWITCH_PIN PB2 // pin 17 +#define SWITCH_PCINT PCINT10 // pin 17 pin change interrupt +#define SWITCH_PCIE PCIE1 // PCIE1 is for PCINT[11:8] +#define SWITCH_PCMSK PCMSK1 // PCMSK1 is for PCINT[11:8] +#define SWITCH_PORT PINB // PINA or PINB or PINC +#define PCINT_vect PCINT1_vect // ISR for PCINT[11:8] + +#define PWM1_PIN PB3 // pin 16, Opamp reference +#define PWM1_LVL OCR1A // OCR1A is the output compare register for PB3 +#define PWM1_CNT TCNT1 // for dynamic PWM, reset phase + +// PWM parameters of both channels are tied together because they share a counter +#define PWM1_TOP ICR1 // holds the TOP value for for variable-resolution PWM + +#define LED_ENABLE_PIN PB0 // pin 19, Opamp power +#define LED_ENABLE_PORT PORTB // control port for PB0 + +#define LED2_ENABLE_PIN PC0 // pin 15, boost PMIC enable +#define LED2_ENABLE_PORT PORTC // control port for PC0 + + +#define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is flattened +#define VOLTAGE_PIN PB1 // Pin 18 / PB1 / ADC6 +// pin to ADC mappings are in DS table 19-4 +#define VOLTAGE_ADC ADC6D // digital input disable pin for PB1 +// DIDR0/DIDR1 mappings are in DS section 19.13.5, 19.13.6 +#define VOLTAGE_ADC_DIDR DIDR1 // DIDR channel for ADC6D +// DS tables 19-3, 19-4 +// Bit 7 6 5 4 3 2 1 0 +// REFS1 REFS0 REFEN ADC0EN MUX3 MUX2 MUX1 MUX0 +// MUX[3:0] = 0, 1, 1, 0 for ADC6 / PB1 +// divided by ... +// REFS[1:0] = 1, 0 for internal 1.1V reference +// other bits reserved +#define ADMUX_VOLTAGE_DIVIDER 0b10000110 +#define ADC_PRSCL 0x07 // clk/128 + +// Raw ADC readings at 4.4V and 2.2V +// calibrate the voltage readout here +// estimated / calculated values are: +// (voltage - D1) * (R2/(R2+R1) * 1024 / 1.1) +// D1, R1, R2 = 0, 330, 100 +#ifndef ADC_44 +//#define ADC_44 981 // raw value at 4.40V +#define ADC_44 967 // manually tweaked so 4.16V will blink out 4.2 +#endif +#ifndef ADC_22 +//#define ADC_22 489 // raw value at 2.20V +#define ADC_22 482 // manually tweaked so 4.16V will blink out 4.2 +#endif + +// this light has aux LEDs under the optic +#define AUXLED_R_PIN PA5 // pin 2 +#define AUXLED_G_PIN PA4 // pin 3 +#define AUXLED_B_PIN PA3 // pin 4 +#define AUXLED_RGB_PORT PORTA // PORTA or PORTB or PORTC +#define AUXLED_RGB_DDR DDRA // DDRA or DDRB or DDRC +#define AUXLED_RGB_PUE PUEA // PUEA or PUEB or PUEC + +#define BUTTON_LED_PIN PA2 // pin 5 +#define BUTTON_LED_PORT PORTA // for all "PA" pins +#define BUTTON_LED_DDR DDRA // for all "PA" pins +#define BUTTON_LED_PUE PUEA // for all "PA" pins + +// with so many pins, doing this all with #ifdefs gets awkward... +// ... so just hardcode it in each hwdef file instead +inline void hwdef_setup() { + // enable output ports + // boost PMIC on/off + DDRC = (1 << LED2_ENABLE_PIN); + // Opamp level and Opamp on/off + DDRB = (1 << PWM1_PIN) + | (1 << LED_ENABLE_PIN); + // aux R/G/B, button LED + DDRA = (1 << AUXLED_R_PIN) + | (1 << AUXLED_G_PIN) + | (1 << AUXLED_B_PIN) + | (1 << BUTTON_LED_PIN) + ; + + // configure PWM + // Setup PWM. F_pwm = F_clkio / 2 / N / TOP, where N = prescale factor, TOP = top of counter + // pre-scale for timer: N = 1 + // WGM1[3:0]: 1,0,1,0: PWM, Phase Correct, adjustable (DS table 12-5) + // CS1[2:0]: 0,0,1: clk/1 (No prescaling) (DS table 12-6) + // COM1A[1:0]: 1,0: PWM OC1A in the normal direction (DS table 12-4) + // COM1B[1:0]: 0,0: PWM OC1B disabled (DS table 12-4) + TCCR1A = (1< end of dynamic PWM range + +// slow down party strobe; this driver can't pulse for 2ms or less +#define PARTY_STROBE_ONTIME 3 + +#define THERM_CAL_OFFSET 5 + +// the power regulator seems to "jump start" the LEDs all on its own, +// so the firmware doesn't have to +// (and unfortunately the power regulator jumps it a bit too hard) +#define DEFAULT_JUMP_START_LEVEL 1 +#define BLINK_BRIGHTNESS 50 +#define BLINK_ONCE_TIME 12 + +// can't reset the normal way because power is connected before the button +#define USE_SOFT_FACTORY_RESET -- cgit v1.2.3 From 48ef5ed191f4942d0cc1a40d2b108426a0845519 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sat, 9 Apr 2022 02:37:59 -0600 Subject: k9.3 tint-toggle build is broken, generate a better fail error (until it's fixed) --- spaghetti-monster/anduril/cfg-noctigon-k9.3.c | 1 + spaghetti-monster/anduril/ramp-mode.h | 1 + 2 files changed, 2 insertions(+) diff --git a/spaghetti-monster/anduril/cfg-noctigon-k9.3.c b/spaghetti-monster/anduril/cfg-noctigon-k9.3.c index 5ce5c5a..d79c03f 100644 --- a/spaghetti-monster/anduril/cfg-noctigon-k9.3.c +++ b/spaghetti-monster/anduril/cfg-noctigon-k9.3.c @@ -1,3 +1,4 @@ +#error This build is broken. /* * K9.3 has unusual power channels, so it must override some of FSM's code. * There are two sets of LEDs: diff --git a/spaghetti-monster/anduril/ramp-mode.h b/spaghetti-monster/anduril/ramp-mode.h index 93756ab..ed76ed5 100644 --- a/spaghetti-monster/anduril/ramp-mode.h +++ b/spaghetti-monster/anduril/ramp-mode.h @@ -26,6 +26,7 @@ // thermal properties, if not defined per-driver #ifndef MIN_THERM_STEPDOWN +// TODO: Replace MAX_Xx7135 with MAX_CH1, MAX_CH2, MAX_REGULATED, etc #define MIN_THERM_STEPDOWN MAX_1x7135 // lowest value it'll step down to #endif #ifndef THERM_FASTER_LEVEL -- cgit v1.2.3 From 3d81483ef1948cd0b60917cae5e1845c5975a22d Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sat, 9 Apr 2022 07:07:47 -0600 Subject: revert spurious change to version.h (forgot to revert it after build test, before merge commit) --- spaghetti-monster/anduril/version.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spaghetti-monster/anduril/version.h b/spaghetti-monster/anduril/version.h index 6bd781e..8cf3c90 100644 --- a/spaghetti-monster/anduril/version.h +++ b/spaghetti-monster/anduril/version.h @@ -1 +1,4 @@ -#define VERSION_NUMBER "20220409" +// this file is replaced automatically by the build script +// set your own date here if you're not using the build script +// otherwise, default to first human contact with the moon +#define VERSION_NUMBER "19690720" -- cgit v1.2.3