From b249c20b96b6c1f50c5a5df4658afa1ca7cfbb4c Mon Sep 17 00:00:00 2001 From: Gabriel Hart Date: Tue, 4 May 2021 10:27:44 -0500 Subject: Update 1-Series to use 10 MHz clock and Phase Correct PWM. Add PWM documentation. Also clear thermal offset on factory reset instead of setting it to 21*C. --- hwdef-BLF_Q8-T1616.h | 14 ++++++++++---- hwdef-Sofirn_SP10S.h | 14 ++++++++++---- hwdef-gchart-fet1-t1616.h | 17 ++++++++++------- spaghetti-monster/anduril/factory-reset.c | 4 ++++ spaghetti-monster/anduril/version.h | 5 +---- tk-attiny.h | 16 ++++++++-------- 6 files changed, 43 insertions(+), 27 deletions(-) diff --git a/hwdef-BLF_Q8-T1616.h b/hwdef-BLF_Q8-T1616.h index 2a0e6ff..d6ad760 100644 --- a/hwdef-BLF_Q8-T1616.h +++ b/hwdef-BLF_Q8-T1616.h @@ -61,8 +61,8 @@ Driver pinout: // ... so just hardcode it in each hwdef file instead inline void hwdef_setup() { - // set up the system clock to run at 5 MHz instead of the default 3.33 MHz - _PROTECTED_WRITE( CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_4X_gc | CLKCTRL_PEN_bm ); + // set up the system clock to run at 10 MHz instead of the default 3.33 MHz + _PROTECTED_WRITE( CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_2X_gc | CLKCTRL_PEN_bm ); //VPORTA.DIR = ...; VPORTB.DIR = PIN0_bm | PIN1_bm | PIN5_bm; // Outputs: Aux LED and PWMs @@ -91,8 +91,14 @@ inline void hwdef_setup() { PORTC.PIN3CTRL = PORT_PULLUPEN_bm; // set up the PWM - // TODO: add references to MCU documentation - TCA0.SINGLE.CTRLB = TCA_SINGLE_CMP0EN_bm | TCA_SINGLE_CMP1EN_bm | TCA_SINGLE_WGMODE_SINGLESLOPE_gc; + // https://ww1.microchip.com/downloads/en/DeviceDoc/ATtiny1614-16-17-DataSheet-DS40002204A.pdf + // PB0 is TCA0:WO0, use TCA_SINGLE_CMP0EN_bm + // PB1 is TCA0:WO1, use TCA_SINGLE_CMP1EN_bm + // PB2 is TCA0:WO2, use TCA_SINGLE_CMP2EN_bm + // For Fast (Single Slope) PWM use TCA_SINGLE_WGMODE_SINGLESLOPE_gc + // For Phase Correct (Dual Slope) PWM use TCA_SINGLE_WGMODE_DSBOTTOM_gc + // See the manual for other pins, clocks, configs, portmux, etc + TCA0.SINGLE.CTRLB = TCA_SINGLE_CMP0EN_bm | TCA_SINGLE_CMP1EN_bm | TCA_SINGLE_WGMODE_DSBOTTOM_gc; TCA0.SINGLE.PER = 255; TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV1_gc | TCA_SINGLE_ENABLE_bm; } diff --git a/hwdef-Sofirn_SP10S.h b/hwdef-Sofirn_SP10S.h index 0ee3332..5760037 100644 --- a/hwdef-Sofirn_SP10S.h +++ b/hwdef-Sofirn_SP10S.h @@ -83,8 +83,8 @@ ATTINY1616 Mapping: // ... so just hardcode it in each hwdef file instead inline void hwdef_setup() { - // set up the system clock to run at 5 MHz instead of the default 3.33 MHz - _PROTECTED_WRITE( CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_4X_gc | CLKCTRL_PEN_bm ); + // set up the system clock to run at 10 MHz instead of the default 3.33 MHz + _PROTECTED_WRITE( CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_2X_gc | CLKCTRL_PEN_bm ); VPORTA.DIR = PIN1_bm; // Boost enable pin VPORTB.DIR = PIN0_bm | PIN5_bm; // PWM pins as output @@ -113,9 +113,15 @@ inline void hwdef_setup() { PORTC.PIN3CTRL = PORT_PULLUPEN_bm; // set up the PWM - // TODO: add references to MCU documentation + // https://ww1.microchip.com/downloads/en/DeviceDoc/ATtiny1614-16-17-DataSheet-DS40002204A.pdf + // PB0 is TCA0:WO0, use TCA_SINGLE_CMP0EN_bm + // PB1 is TCA0:WO1, use TCA_SINGLE_CMP1EN_bm + // PB2 is TCA0:WO2, use TCA_SINGLE_CMP2EN_bm + // For Fast (Single Slope) PWM use TCA_SINGLE_WGMODE_SINGLESLOPE_gc + // For Phase Correct (Dual Slope) PWM use TCA_SINGLE_WGMODE_DSBOTTOM_gc + // See the manual for other pins, clocks, configs, portmux, etc PORTMUX.CTRLC = PORTMUX_TCA02_ALTERNATE_gc; // Use alternate pin for TCA0:WO2 - TCA0.SINGLE.CTRLB = TCA_SINGLE_CMP0EN_bm | TCA_SINGLE_CMP2EN_bm | TCA_SINGLE_WGMODE_SINGLESLOPE_gc; + TCA0.SINGLE.CTRLB = TCA_SINGLE_CMP0EN_bm | TCA_SINGLE_CMP2EN_bm | TCA_SINGLE_WGMODE_DSBOTTOM_gc; TCA0.SINGLE.PER = 255; TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV1_gc | TCA_SINGLE_ENABLE_bm; } diff --git a/hwdef-gchart-fet1-t1616.h b/hwdef-gchart-fet1-t1616.h index 365ecd7..2435b99 100644 --- a/hwdef-gchart-fet1-t1616.h +++ b/hwdef-gchart-fet1-t1616.h @@ -60,8 +60,8 @@ Read voltage from VCC pin, has diode with ~0.4v drop // ... so just hardcode it in each hwdef file instead inline void hwdef_setup() { - // set up the system clock to run at 5 MHz instead of the default 3.33 MHz - _PROTECTED_WRITE( CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_4X_gc | CLKCTRL_PEN_bm ); + // set up the system clock to run at 10 MHz instead of the default 3.33 MHz + _PROTECTED_WRITE( CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_2X_gc | CLKCTRL_PEN_bm ); //VPORTA.DIR = 0b00000010; VPORTB.DIR = PIN0_bm | PIN1_bm | PIN3_bm; @@ -90,11 +90,14 @@ inline void hwdef_setup() { PORTC.PIN3CTRL = PORT_PULLUPEN_bm; // set up the PWM - // TODO: add references to MCU documentation - // TODO: measure 5 MHz fast PWM vs 10 MHz phase-correct, to see if it - // still has issues at 0/255 and 255/255 like older models did - // (and maybe switch to phase-correct@10MHz) - TCA0.SINGLE.CTRLB = TCA_SINGLE_CMP0EN_bm | TCA_SINGLE_CMP1EN_bm | TCA_SINGLE_WGMODE_SINGLESLOPE_gc; + // https://ww1.microchip.com/downloads/en/DeviceDoc/ATtiny1614-16-17-DataSheet-DS40002204A.pdf + // PB0 is TCA0:WO0, use TCA_SINGLE_CMP0EN_bm + // PB1 is TCA0:WO1, use TCA_SINGLE_CMP1EN_bm + // PB2 is TCA0:WO2, use TCA_SINGLE_CMP2EN_bm + // For Fast (Single Slope) PWM use TCA_SINGLE_WGMODE_SINGLESLOPE_gc + // For Phase Correct (Dual Slope) PWM use TCA_SINGLE_WGMODE_DSBOTTOM_gc + // See the manual for other pins, clocks, configs, portmux, etc + TCA0.SINGLE.CTRLB = TCA_SINGLE_CMP0EN_bm | TCA_SINGLE_CMP1EN_bm | TCA_SINGLE_WGMODE_DSBOTTOM_gc; TCA0.SINGLE.PER = 255; TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV1_gc | TCA_SINGLE_ENABLE_bm; } diff --git a/spaghetti-monster/anduril/factory-reset.c b/spaghetti-monster/anduril/factory-reset.c index c327e65..f05b5eb 100644 --- a/spaghetti-monster/anduril/factory-reset.c +++ b/spaghetti-monster/anduril/factory-reset.c @@ -44,8 +44,12 @@ void factory_reset() { // explode, if button pressed long enough if (reset) { #ifdef USE_THERMAL_REGULATION + #ifdef AVRXMEGA3 // AVR 1-Series has factory calibrated thermal sensor, remove the offset + thermal_config_save(1,temperature - therm_cal_offset); // this will cancel out the offset + #else // auto-calibrate temperature... assume current temperature is 21 C thermal_config_save(1, 21); + #endif // AVRXMEGA3 #endif // save all settings to eeprom // (assuming they're all at default because we haven't loaded them yet) diff --git a/spaghetti-monster/anduril/version.h b/spaghetti-monster/anduril/version.h index 8cf3c90..dd9c703 100644 --- a/spaghetti-monster/anduril/version.h +++ b/spaghetti-monster/anduril/version.h @@ -1,4 +1 @@ -// 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" +#define VERSION_NUMBER "20210503" diff --git a/tk-attiny.h b/tk-attiny.h index ae70afd..110507b 100644 --- a/tk-attiny.h +++ b/tk-attiny.h @@ -73,7 +73,7 @@ //#define VOLTAGE_ADC_DIDR DIDR0 // set this in hwdef #elif (ATTINY == 412) || (ATTINY == 416) || (ATTINY == 417) || (ATTINY == 816) || (ATTINY == 817) || (ATTINY == 1616) || (ATTINY == 1617) || (ATTINY == 3216) || (ATTINY == 3217) #define AVRXMEGA3 - #define F_CPU 5000000UL + #define F_CPU 10000000UL #define BOGOMIPS (F_CPU/4000) #define EEPSIZE 128 #define DELAY_ZERO_TIME 1020 @@ -155,14 +155,14 @@ } typedef enum { - // Actual clock is 20 MHz, but assume that 5 MHz is the top speed and work from there + // Actual clock is 20 MHz, but assume that 10 MHz is the top speed and work from there // TODO: measure PWM speed and power use at 1.25/2.5/5/10 MHz, to determine which speeds are optimal - clock_div_1 = (CLKCTRL_PDIV_4X_gc | CLKCTRL_PEN_bm), // 5 MHz - clock_div_2 = (CLKCTRL_PDIV_8X_gc | CLKCTRL_PEN_bm), // 2.5 MHz - clock_div_4 = (CLKCTRL_PDIV_16X_gc | CLKCTRL_PEN_bm), // 1.25 MHz - clock_div_8 = (CLKCTRL_PDIV_32X_gc | CLKCTRL_PEN_bm), // 625 kHz - clock_div_16 = (CLKCTRL_PDIV_64X_gc | CLKCTRL_PEN_bm), // 312 kHz, max without changing to the 32 kHz ULP - clock_div_32 = (CLKCTRL_PDIV_64X_gc | CLKCTRL_PEN_bm), // 312 kHz + clock_div_1 = (CLKCTRL_PDIV_2X_gc | CLKCTRL_PEN_bm), // 10 MHz + clock_div_2 = (CLKCTRL_PDIV_4X_gc | CLKCTRL_PEN_bm), // 5 MHz + clock_div_4 = (CLKCTRL_PDIV_8X_gc | CLKCTRL_PEN_bm), // 2.5 MHz + clock_div_8 = (CLKCTRL_PDIV_16X_gc | CLKCTRL_PEN_bm), // 1.25 MHz + clock_div_16 = (CLKCTRL_PDIV_32X_gc | CLKCTRL_PEN_bm), // 625 kHz + clock_div_32 = (CLKCTRL_PDIV_64X_gc | CLKCTRL_PEN_bm), // 312 kHz, max without changing to the 32 kHz ULP clock_div_64 = (CLKCTRL_PDIV_64X_gc | CLKCTRL_PEN_bm), // 312 kHz clock_div_128 = (CLKCTRL_PDIV_64X_gc | CLKCTRL_PEN_bm), // 312 kHz clock_div_256 = (CLKCTRL_PDIV_64X_gc | CLKCTRL_PEN_bm) // 312 kHz -- cgit v1.2.3 From 9ec281181dc50a97ab90f0110bd37630c51f267d Mon Sep 17 00:00:00 2001 From: Gabriel Hart Date: Thu, 12 Aug 2021 11:05:49 -0500 Subject: Finalized SP10S and renamed to SP10 Pro. Updated Sofirn settings to include SOS. --- hwdef-Sofirn_SP10-Pro.h | 116 +++++++++++++++++++++ hwdef-Sofirn_SP10S.h | 130 ------------------------ spaghetti-monster/anduril/MODELS | 2 +- spaghetti-monster/anduril/cfg-blf-q8-t1616.h | 4 + spaghetti-monster/anduril/cfg-blf-q8.h | 4 + spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h | 44 ++++++++ spaghetti-monster/anduril/cfg-sofirn-sp10s.h | 40 -------- spaghetti-monster/anduril/version.h | 2 +- 8 files changed, 170 insertions(+), 172 deletions(-) create mode 100644 hwdef-Sofirn_SP10-Pro.h delete mode 100644 hwdef-Sofirn_SP10S.h create mode 100644 spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h delete mode 100644 spaghetti-monster/anduril/cfg-sofirn-sp10s.h diff --git a/hwdef-Sofirn_SP10-Pro.h b/hwdef-Sofirn_SP10-Pro.h new file mode 100644 index 0000000..e35728c --- /dev/null +++ b/hwdef-Sofirn_SP10-Pro.h @@ -0,0 +1,116 @@ +#ifndef HWDEF_SOFIRN_SP10_H +#define HWDEF_SOFIRN_SP10_H + +/* Sofirn SP10 Pro pinout + +ATTINY1616 Mapping: +PB5 : PWM small channel (TCA0 - WO2 Alternate MUX) +PB3 : eSwitch +PB0 : PWM big channel (TCA0 - WO0) +PB4 : Voltage divider (ADC0 - AIN9) +PA1 : Boost Enable + +*/ + + +#define LAYOUT_DEFINED + +#ifdef ATTINY +#undef ATTINY +#endif +#define ATTINY 1616 +#include + +#ifndef SWITCH_PIN +#define SWITCH_PIN 3 +#define SWITCH_PORT VPORTB.IN +#define SWITCH_ISC_REG PORTB.PIN3CTRL +#define SWITCH_VECT PORTB_PORT_vect +#define SWITCH_INTFLG VPORTB.INTFLAGS +#endif + +#define PWM_CHANNELS 2 + +// Small channel +#ifndef PWM1_PIN +#define PWM1_PIN PB5 +#define PWM1_LVL TCA0.SINGLE.CMP2 // 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 +#endif + +#define LED_ENABLE_PIN PIN1_bp +#define LED_ENABLE_PORT PORTA_OUT + +#define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is flattened +#define DUAL_VOLTAGE_FLOOR 20 // for AA/14500 boost drivers, don't indicate low voltage if below this level +#define DUAL_VOLTAGE_LOW_LOW 9 // the lower voltage range's danger zone 0.9 volts (NiMH) +#define ADMUX_VOLTAGE_DIVIDER ADC_MUXPOS_AIN9_gc // which ADC channel to read + +// 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) +// Resistors are 300,000 and 100,000 +#ifndef ADC_44 +#define ADC_44 1023 // raw value at 4.40V +#endif +#ifndef ADC_22 +#define ADC_22 512 // raw value at 2.20V +#endif + + + +// with so many pins, doing this all with #ifdefs gets awkward... +// ... so just hardcode it in each hwdef file instead +inline void hwdef_setup() { + + // set up the system clock to run at 10 MHz instead of the default 3.33 MHz + _PROTECTED_WRITE( CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_2X_gc | CLKCTRL_PEN_bm ); + + VPORTA.DIR = PIN1_bm; // Boost enable pin + VPORTB.DIR = PIN0_bm | PIN5_bm; // PWM pins as output + //VPORTC.DIR = ...; + + // enable pullups on the input pins to reduce power + PORTA.PIN0CTRL = PORT_PULLUPEN_bm; + //PORTA.PIN1CTRL = PORT_PULLUPEN_bm; // Boost enable pin + PORTA.PIN2CTRL = PORT_PULLUPEN_bm; + PORTA.PIN3CTRL = PORT_PULLUPEN_bm; + PORTA.PIN4CTRL = PORT_PULLUPEN_bm; + PORTA.PIN5CTRL = PORT_PULLUPEN_bm; + PORTA.PIN6CTRL = PORT_PULLUPEN_bm; + PORTA.PIN7CTRL = PORT_PULLUPEN_bm; + + //PORTB.PIN0CTRL = PORT_PULLUPEN_bm; // Big PWM channel + PORTB.PIN1CTRL = PORT_PULLUPEN_bm; + PORTB.PIN2CTRL = PORT_PULLUPEN_bm; + PORTB.PIN3CTRL = PORT_PULLUPEN_bm | PORT_ISC_BOTHEDGES_gc; // Switch + //PORTB.PIN4CTRL = PORT_PULLUPEN_bm; // Voltage divider + //PORTB.PIN5CTRL = PORT_PULLUPEN_bm; // Small PWM channel + + PORTC.PIN0CTRL = PORT_PULLUPEN_bm; + PORTC.PIN1CTRL = PORT_PULLUPEN_bm; + PORTC.PIN2CTRL = PORT_PULLUPEN_bm; + PORTC.PIN3CTRL = PORT_PULLUPEN_bm; + + // set up the PWM + // https://ww1.microchip.com/downloads/en/DeviceDoc/ATtiny1614-16-17-DataSheet-DS40002204A.pdf + // PB0 is TCA0:WO0, use TCA_SINGLE_CMP0EN_bm + // PB1 is TCA0:WO1, use TCA_SINGLE_CMP1EN_bm + // PB2 is TCA0:WO2, use TCA_SINGLE_CMP2EN_bm + // For Fast (Single Slope) PWM use TCA_SINGLE_WGMODE_SINGLESLOPE_gc + // For Phase Correct (Dual Slope) PWM use TCA_SINGLE_WGMODE_DSBOTTOM_gc + // See the manual for other pins, clocks, configs, portmux, etc + PORTMUX.CTRLC = PORTMUX_TCA02_ALTERNATE_gc; // Use alternate pin for TCA0:WO2 + TCA0.SINGLE.CTRLB = TCA_SINGLE_CMP0EN_bm | TCA_SINGLE_CMP2EN_bm | TCA_SINGLE_WGMODE_DSBOTTOM_gc; + TCA0.SINGLE.PER = 255; + TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV1_gc | TCA_SINGLE_ENABLE_bm; +} + + +#endif diff --git a/hwdef-Sofirn_SP10S.h b/hwdef-Sofirn_SP10S.h deleted file mode 100644 index 5760037..0000000 --- a/hwdef-Sofirn_SP10S.h +++ /dev/null @@ -1,130 +0,0 @@ -#ifndef HWDEF_SOFIRN_SP10S_H -#define HWDEF_SOFIRN_SP10S_H - -// TODO: rename to sofirn-sp10s-gchart? - -/* gChart's PIC12 to ATTINY1616 v1 adapter for the SP10S -https://oshpark.com/shared_projects/b4IZEGSy - -PIC12 Pinout: -1 - VDD -2 - No Connect -3 - Low Channel FET (series 4.7K Ohms) -4 - Switch -5 - High Channel FET (main PWM) -6 - Voltage Divider (300K:100K Ohms) -7 - Boost chip enable -8 - GND - -ATTINY1616 Mapping: -2 - PA5 : (no connect) -3 - PB5 : TCA0 - WO2 Alternate MUX -4 - PB3 : (switch) -5 - PB0 : TCA0 - WO0 -6 - PB4 : ADC0 - AIN9 -7 - PA1 : (boost enable) - -*/ - - -#define LAYOUT_DEFINED - -#ifdef ATTINY -#undef ATTINY -#endif -#define ATTINY 1616 -#include - -#ifndef SWITCH_PIN -#define SWITCH_PIN 3 -#define SWITCH_PORT VPORTB.IN -#define SWITCH_ISC_REG PORTB.PIN3CTRL -#define SWITCH_VECT PORTB_PORT_vect -#define SWITCH_INTFLG VPORTB.INTFLAGS -#endif - -#define PWM_CHANNELS 2 - -// Small channel -#ifndef PWM1_PIN -#define PWM1_PIN PB5 -#define PWM1_LVL TCA0.SINGLE.CMP2 // 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 -#endif - -#define LED_ENABLE_PIN PIN1_bp -#define LED_ENABLE_PORT PORTA_OUT - -#define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is flattened -#define DUAL_VOLTAGE_FLOOR 20 // for AA/14500 boost drivers, don't indicate low voltage if below this level -#define DUAL_VOLTAGE_LOW_LOW 07 // the lower voltage range's danger zone 0.7 volts -#define ADMUX_VOLTAGE_DIVIDER ADC_MUXPOS_AIN9_gc // which ADC channel to read - -// 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) -// Resistors are 300,000 and 100,000 -#ifndef ADC_44 -#define ADC_44 1023 // raw value at 4.40V -#endif -#ifndef ADC_22 -#define ADC_22 512 // raw value at 2.20V -#endif - - - -// with so many pins, doing this all with #ifdefs gets awkward... -// ... so just hardcode it in each hwdef file instead -inline void hwdef_setup() { - - // set up the system clock to run at 10 MHz instead of the default 3.33 MHz - _PROTECTED_WRITE( CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_2X_gc | CLKCTRL_PEN_bm ); - - VPORTA.DIR = PIN1_bm; // Boost enable pin - VPORTB.DIR = PIN0_bm | PIN5_bm; // PWM pins as output - //VPORTC.DIR = ...; - - // enable pullups on the input pins to reduce power - PORTA.PIN0CTRL = PORT_PULLUPEN_bm; - //PORTA.PIN1CTRL = PORT_PULLUPEN_bm; // Boost enable pin - PORTA.PIN2CTRL = PORT_PULLUPEN_bm; - PORTA.PIN3CTRL = PORT_PULLUPEN_bm; - PORTA.PIN4CTRL = PORT_PULLUPEN_bm; - PORTA.PIN5CTRL = PORT_PULLUPEN_bm; - PORTA.PIN6CTRL = PORT_PULLUPEN_bm; - PORTA.PIN7CTRL = PORT_PULLUPEN_bm; - - //PORTB.PIN0CTRL = PORT_PULLUPEN_bm; // Big PWM channel - PORTB.PIN1CTRL = PORT_PULLUPEN_bm; - PORTB.PIN2CTRL = PORT_PULLUPEN_bm; - PORTB.PIN3CTRL = PORT_PULLUPEN_bm | PORT_ISC_BOTHEDGES_gc; // Switch - //PORTB.PIN4CTRL = PORT_PULLUPEN_bm; // Voltage divider - //PORTB.PIN5CTRL = PORT_PULLUPEN_bm; // Small PWM channel - - //PORTC.PIN0CTRL = PORT_PULLUPEN_bm; connected to the ADC via airwire - PORTC.PIN1CTRL = PORT_PULLUPEN_bm; - PORTC.PIN2CTRL = PORT_PULLUPEN_bm; - PORTC.PIN3CTRL = PORT_PULLUPEN_bm; - - // set up the PWM - // https://ww1.microchip.com/downloads/en/DeviceDoc/ATtiny1614-16-17-DataSheet-DS40002204A.pdf - // PB0 is TCA0:WO0, use TCA_SINGLE_CMP0EN_bm - // PB1 is TCA0:WO1, use TCA_SINGLE_CMP1EN_bm - // PB2 is TCA0:WO2, use TCA_SINGLE_CMP2EN_bm - // For Fast (Single Slope) PWM use TCA_SINGLE_WGMODE_SINGLESLOPE_gc - // For Phase Correct (Dual Slope) PWM use TCA_SINGLE_WGMODE_DSBOTTOM_gc - // See the manual for other pins, clocks, configs, portmux, etc - PORTMUX.CTRLC = PORTMUX_TCA02_ALTERNATE_gc; // Use alternate pin for TCA0:WO2 - TCA0.SINGLE.CTRLB = TCA_SINGLE_CMP0EN_bm | TCA_SINGLE_CMP2EN_bm | TCA_SINGLE_WGMODE_DSBOTTOM_gc; - TCA0.SINGLE.PER = 255; - TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV1_gc | TCA_SINGLE_ENABLE_bm; -} - - -#endif diff --git a/spaghetti-monster/anduril/MODELS b/spaghetti-monster/anduril/MODELS index 13ce2e4..aa35833 100644 --- a/spaghetti-monster/anduril/MODELS +++ b/spaghetti-monster/anduril/MODELS @@ -41,7 +41,7 @@ Model numbers: 0614 sofirn-sp36-t1616 0621 blf-lantern 0622 blf-lantern-t1616 -0631 sofirn-sp10s +0631 sofirn-sp10-pro 1618 gchart-fet1-t1616 Duplicates: Missing: diff --git a/spaghetti-monster/anduril/cfg-blf-q8-t1616.h b/spaghetti-monster/anduril/cfg-blf-q8-t1616.h index fe01d07..340faa1 100644 --- a/spaghetti-monster/anduril/cfg-blf-q8-t1616.h +++ b/spaghetti-monster/anduril/cfg-blf-q8-t1616.h @@ -37,6 +37,10 @@ // also at Sofirn's request, enable 2 click turbo #define USE_2C_MAX_TURBO +// enable SOS in the blinkies group +#define USE_SOS_MODE +#define USE_SOS_MODE_IN_BLINKY_GROUP + // Allow 3C in Simple UI for switching between smooth and stepped ramping #define USE_SIMPLE_UI_RAMPING_TOGGLE diff --git a/spaghetti-monster/anduril/cfg-blf-q8.h b/spaghetti-monster/anduril/cfg-blf-q8.h index f1917ce..00bdd8a 100644 --- a/spaghetti-monster/anduril/cfg-blf-q8.h +++ b/spaghetti-monster/anduril/cfg-blf-q8.h @@ -36,6 +36,10 @@ // also at Sofirn's request, enable 2 click turbo #define USE_2C_MAX_TURBO +// enable SOS in the blinkies group +#define USE_SOS_MODE +#define USE_SOS_MODE_IN_BLINKY_GROUP + // Allow 3C in Simple UI for switching between smooth and stepped ramping #define USE_SIMPLE_UI_RAMPING_TOGGLE diff --git a/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h b/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h new file mode 100644 index 0000000..9072fdd --- /dev/null +++ b/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h @@ -0,0 +1,44 @@ +// Sofirn SP10 Pro config options for Anduril +#define MODEL_NUMBER "0631" +#include "hwdef-Sofirn_SP10-Pro.h" +// ATTINY: 1616 + +#undef BLINK_AT_RAMP_MIDDLE + +#define USE_DYNAMIC_UNDERCLOCKING + +#define RAMP_LENGTH 150 +#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,2,2,2,2,3,3,3,3,4,4,4,5,5,5,6,6,6,7,7,8,8,8,9,9,10,10,11,11,12,13,13,14,14,15,16,16,17,18,19,19,20,21,22,23,23,24,25,26,27,28,29,30,31,32,33,34,35,37,38,39,40,41,43,44,45,47,48,49,51,52,54,55,57,58,60,61,63,65,66,68,70,72,74,75,77,79,81,83,85,87,89,91,93,96,98,100,102,105,107,109,112,114,117,119,122,124,127,129,132,135,138,140,143,146,149,152,155,158,161,164,167,170,174,177,180,184,187,190,194,197,201,204,208,212,215,219,223,227,231,235,239,243,247,251,255 + +#define MAX_1x7135 13 +#define HALFSPEED_LEVEL 14 +#define QUARTERSPEED_LEVEL 6 + +#define RAMP_SMOOTH_FLOOR 1 +#define RAMP_SMOOTH_CEIL 120 +#define RAMP_DISCRETE_FLOOR RAMP_SMOOTH_FLOOR +#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 +#define SIMPLE_UI_CEIL 150 +#define SIMPLE_UI_STEPS 5 + +// also at Sofirn's request, enable 2 click turbo +#define USE_2C_MAX_TURBO + +// enable SOS in the blinkies group +#define USE_SOS_MODE +#define USE_SOS_MODE_IN_BLINKY_GROUP + +// Allow 3C in Simple UI for switching between smooth and stepped ramping +#define USE_SIMPLE_UI_RAMPING_TOGGLE + +// and finally, set the default ramp style to Stepped +#undef RAMP_STYLE +#define RAMP_STYLE 1 // 0 = smooth, 1 = stepped + +// stop panicking at ~30% power +#define THERM_FASTER_LEVEL 105 \ No newline at end of file diff --git a/spaghetti-monster/anduril/cfg-sofirn-sp10s.h b/spaghetti-monster/anduril/cfg-sofirn-sp10s.h deleted file mode 100644 index 350c0b5..0000000 --- a/spaghetti-monster/anduril/cfg-sofirn-sp10s.h +++ /dev/null @@ -1,40 +0,0 @@ -// gChart's custom SP10S driver config options for Anduril -#define MODEL_NUMBER "0631" -#include "hwdef-Sofirn_SP10S.h" -// ATTINY: 1616 - -#undef BLINK_AT_RAMP_MIDDLE - -#define USE_DYNAMIC_UNDERCLOCKING - -#define RAMP_LENGTH 150 -#define PWM1_LEVELS 20,30,41,54,69,87,106,128,152,179,209,242,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,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,1,1,1,1,1,1,2,2,2,2,3,3,3,4,4,4,5,5,5,6,6,7,7,8,8,9,9,10,10,11,12,12,13,14,14,15,16,17,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,33,34,35,36,38,39,41,42,43,45,46,48,50,51,53,55,56,58,60,62,64,66,68,70,72,74,76,78,80,83,85,87,90,92,94,97,99,102,105,107,110,113,116,119,121,124,127,130,133,137,140,143,146,150,153,156,160,164,167,171,174,178,182,186,190,194,198,202,206,210,214,219,223,227,232,236,241,246,250,255 - -#define MAX_1x7135 13 -#define HALFSPEED_LEVEL 14 -#define QUARTERSPEED_LEVEL 6 - -#define RAMP_SMOOTH_FLOOR 1 -#define RAMP_SMOOTH_CEIL 120 -#define RAMP_DISCRETE_FLOOR 10 -#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 -#define SIMPLE_UI_CEIL 150 -#define SIMPLE_UI_STEPS 5 - -// also at Sofirn's request, enable 2 click turbo -#define USE_2C_MAX_TURBO - -// Allow 3C in Simple UI for switching between smooth and stepped ramping -#define USE_SIMPLE_UI_RAMPING_TOGGLE - -// and finally, set the default ramp style to Stepped -#undef RAMP_STYLE -#define RAMP_STYLE 1 // 0 = smooth, 1 = stepped - -// stop panicking at ~30% power -#define THERM_FASTER_LEVEL 105 \ No newline at end of file diff --git a/spaghetti-monster/anduril/version.h b/spaghetti-monster/anduril/version.h index 088df3c..0646df5 100644 --- a/spaghetti-monster/anduril/version.h +++ b/spaghetti-monster/anduril/version.h @@ -1 +1 @@ -#define VERSION_NUMBER "20210514" +#define VERSION_NUMBER "20210812" -- cgit v1.2.3 From edb709b0354c1e802634af9eee4cf9a5cf285cb1 Mon Sep 17 00:00:00 2001 From: Gabriel Hart Date: Sun, 15 Aug 2021 14:21:50 -0500 Subject: Adjusted Sofirn SP10 ramp values --- spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h | 3 ++- spaghetti-monster/anduril/version.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h b/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h index 9072fdd..3e85aca 100644 --- a/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h +++ b/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h @@ -7,9 +7,10 @@ #define USE_DYNAMIC_UNDERCLOCKING +// PWM is mostly a "ninth" ramp from level_calc.py but with some extra lower values at the beginning of the ramp #define RAMP_LENGTH 150 #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,2,2,2,2,3,3,3,3,4,4,4,5,5,5,6,6,6,7,7,8,8,8,9,9,10,10,11,11,12,13,13,14,14,15,16,16,17,18,19,19,20,21,22,23,23,24,25,26,27,28,29,30,31,32,33,34,35,37,38,39,40,41,43,44,45,47,48,49,51,52,54,55,57,58,60,61,63,65,66,68,70,72,74,75,77,79,81,83,85,87,89,91,93,96,98,100,102,105,107,109,112,114,117,119,122,124,127,129,132,135,138,140,143,146,149,152,155,158,161,164,167,170,174,177,180,184,187,190,194,197,201,204,208,212,215,219,223,227,231,235,239,243,247,251,255 +#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 13 #define HALFSPEED_LEVEL 14 diff --git a/spaghetti-monster/anduril/version.h b/spaghetti-monster/anduril/version.h index 0646df5..d161ed5 100644 --- a/spaghetti-monster/anduril/version.h +++ b/spaghetti-monster/anduril/version.h @@ -1 +1 @@ -#define VERSION_NUMBER "20210812" +#define VERSION_NUMBER "20210814" -- cgit v1.2.3 From 43006f56c22a99f9635e28374a1a7ee7dbce0c7c Mon Sep 17 00:00:00 2001 From: Gabriel Hart Date: Sun, 15 Aug 2021 22:59:49 -0500 Subject: Adjusted more Sofirn SP10 config values (party strobe, candle amp, max_1x7135) --- spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h | 10 ++++++++-- spaghetti-monster/anduril/version.h | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h b/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h index 3e85aca..a0bea0a 100644 --- a/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h +++ b/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h @@ -12,7 +12,7 @@ #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 13 +#define MAX_1x7135 80 #define HALFSPEED_LEVEL 14 #define QUARTERSPEED_LEVEL 6 @@ -42,4 +42,10 @@ #define RAMP_STYLE 1 // 0 = smooth, 1 = stepped // stop panicking at ~30% power -#define THERM_FASTER_LEVEL 105 \ No newline at end of file +#define THERM_FASTER_LEVEL 105 + +// slow down party strobe; this driver can't pulse for too short a time +#define PARTY_STROBE_ONTIME 6 + +// the default of 26 looks a bit flat, so increase it +#define CANDLE_AMPLITUDE 40 \ No newline at end of file diff --git a/spaghetti-monster/anduril/version.h b/spaghetti-monster/anduril/version.h index d161ed5..f0c08a5 100644 --- a/spaghetti-monster/anduril/version.h +++ b/spaghetti-monster/anduril/version.h @@ -1 +1 @@ -#define VERSION_NUMBER "20210814" +#define VERSION_NUMBER "20210815" -- cgit v1.2.3 From 02d197fdf6d6294e3aeb392f427c5acc3a0c475d Mon Sep 17 00:00:00 2001 From: Gabriel Hart Date: Fri, 20 Aug 2021 09:48:04 -0500 Subject: from Tom E, support PB4 for any of the 3 PWM channels --- spaghetti-monster/fsm-main.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/spaghetti-monster/fsm-main.c b/spaghetti-monster/fsm-main.c index f3c319c..2015563 100644 --- a/spaghetti-monster/fsm-main.c +++ b/spaghetti-monster/fsm-main.c @@ -46,17 +46,28 @@ static inline void hw_setup() { DDRB |= (1 << PWM1_PIN); TCCR0B = 0x01; // pre-scaler for timer (1 => 1, 2 => 8, 3 => 64...) TCCR0A = PHASE; + #if (PWM1_PIN == PB4) // Second PWM counter is ... weird + TCCR1 = _BV (CS10); + GTCCR = _BV (COM1B1) | _BV (PWM1B); + OCR1C = 255; // Set ceiling value to maximum + #endif #endif #if PWM_CHANNELS >= 2 DDRB |= (1 << PWM2_PIN); + #if (PWM2_PIN == PB4) // Second PWM counter is ... weird + TCCR1 = _BV (CS10); + GTCCR = _BV (COM1B1) | _BV (PWM1B); + OCR1C = 255; // Set ceiling value to maximum + #endif #endif #if PWM_CHANNELS >= 3 - // Second PWM counter is ... weird DDRB |= (1 << PWM3_PIN); + #if (PWM3_PIN == PB4) // Second PWM counter is ... weird TCCR1 = _BV (CS10); GTCCR = _BV (COM1B1) | _BV (PWM1B); OCR1C = 255; // Set ceiling value to maximum #endif + #endif #if PWM_CHANNELS >= 4 // 4th PWM channel is ... not actually supported in hardware :( DDRB |= (1 << PWM4_PIN); -- cgit v1.2.3 From 51a8a455e613f61caa06a9c76a998724de7dca40 Mon Sep 17 00:00:00 2001 From: Gabriel Hart Date: Sun, 29 Aug 2021 14:37:22 -0500 Subject: Add 2C Turbo for BLF Lantern (LT1) --- spaghetti-monster/anduril/cfg-blf-lantern.h | 3 +++ spaghetti-monster/anduril/version.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/spaghetti-monster/anduril/cfg-blf-lantern.h b/spaghetti-monster/anduril/cfg-blf-lantern.h index 6e30d55..63f507d 100644 --- a/spaghetti-monster/anduril/cfg-blf-lantern.h +++ b/spaghetti-monster/anduril/cfg-blf-lantern.h @@ -62,6 +62,9 @@ #define SIMPLE_UI_CEIL RAMP_DISCRETE_CEIL #define SIMPLE_UI_STEPS RAMP_DISCRETE_STEPS +// also at Sofirn's request, enable 2 click turbo +#define USE_2C_MAX_TURBO + #define USE_SOS_MODE #define USE_SOS_MODE_IN_BLINKY_GROUP diff --git a/spaghetti-monster/anduril/version.h b/spaghetti-monster/anduril/version.h index f0c08a5..cb49013 100644 --- a/spaghetti-monster/anduril/version.h +++ b/spaghetti-monster/anduril/version.h @@ -1 +1 @@ -#define VERSION_NUMBER "20210815" +#define VERSION_NUMBER "20210825" -- cgit v1.2.3 From c32ae490226e7713492c78bea9168b250513a3a0 Mon Sep 17 00:00:00 2001 From: Gabriel Hart Date: Sun, 19 Sep 2021 14:22:43 -0500 Subject: SP10 Pro: use dynamic PWM, add hidden firefly, adjust candle amplitude, and tweak party strobe & LVP level --- hwdef-Sofirn_SP10-Pro.h | 10 +++++++-- spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h | 28 ++++++++++++++----------- spaghetti-monster/anduril/version.h | 2 +- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/hwdef-Sofirn_SP10-Pro.h b/hwdef-Sofirn_SP10-Pro.h index e35728c..4691d04 100644 --- a/hwdef-Sofirn_SP10-Pro.h +++ b/hwdef-Sofirn_SP10-Pro.h @@ -30,6 +30,9 @@ PA1 : Boost Enable #endif #define PWM_CHANNELS 2 +#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 // Small channel #ifndef PWM1_PIN @@ -43,12 +46,15 @@ PA1 : Boost Enable #define PWM2_LVL TCA0.SINGLE.CMP0 // 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 LED_ENABLE_PIN PIN1_bp #define LED_ENABLE_PORT PORTA_OUT #define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is flattened #define DUAL_VOLTAGE_FLOOR 20 // for AA/14500 boost drivers, don't indicate low voltage if below this level -#define DUAL_VOLTAGE_LOW_LOW 9 // the lower voltage range's danger zone 0.9 volts (NiMH) +#define DUAL_VOLTAGE_LOW_LOW 8 // the lower voltage range's danger zone 0.8 volts (NiMH) #define ADMUX_VOLTAGE_DIVIDER ADC_MUXPOS_AIN9_gc // which ADC channel to read // Raw ADC readings at 4.4V and 2.2V @@ -108,7 +114,7 @@ inline void hwdef_setup() { // See the manual for other pins, clocks, configs, portmux, etc PORTMUX.CTRLC = PORTMUX_TCA02_ALTERNATE_gc; // Use alternate pin for TCA0:WO2 TCA0.SINGLE.CTRLB = TCA_SINGLE_CMP0EN_bm | TCA_SINGLE_CMP2EN_bm | TCA_SINGLE_WGMODE_DSBOTTOM_gc; - TCA0.SINGLE.PER = 255; + PWM1_TOP = PWM_TOP; TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV1_gc | TCA_SINGLE_ENABLE_bm; } diff --git a/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h b/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h index 2d0ea7f..2dc0def 100644 --- a/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h +++ b/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h @@ -7,16 +7,22 @@ #define USE_DYNAMIC_UNDERCLOCKING -// PWM is mostly a "ninth" ramp from level_calc.py but with some extra lower values at the beginning of the ramp +// 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) #define RAMP_LENGTH 150 -#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 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 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 80 -#define HALFSPEED_LEVEL 14 -#define QUARTERSPEED_LEVEL 6 +#define HALFSPEED_LEVEL 3 +#define QUARTERSPEED_LEVEL 3 -#define RAMP_SMOOTH_FLOOR 1 +#define RAMP_SMOOTH_FLOOR 3 #define RAMP_SMOOTH_CEIL 120 #define RAMP_DISCRETE_FLOOR RAMP_SMOOTH_FLOOR #define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL @@ -27,9 +33,6 @@ #define SIMPLE_UI_CEIL 150 #define SIMPLE_UI_STEPS 5 -// also at Sofirn's request, enable 2 click turbo -#define USE_2C_MAX_TURBO - // enable SOS in the blinkies group #define USE_SOS_MODE #define USE_SOS_MODE_IN_BLINKY_GROUP @@ -43,12 +46,13 @@ // stop panicking at ~30% power #define THERM_FASTER_LEVEL 105 +#define MIN_THERM_STEPDOWN 66 // 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 6 +#define PARTY_STROBE_ONTIME 8 // the default of 26 looks a bit flat, so increase it -#define CANDLE_AMPLITUDE 40 +#define CANDLE_AMPLITUDE 50 -// enable 2 click turbo +// enable 2 click turbo (replaces USE_2C_MAX_TURBO) #define DEFAULT_2C_STYLE 1 diff --git a/spaghetti-monster/anduril/version.h b/spaghetti-monster/anduril/version.h index cb49013..82d6a9f 100644 --- a/spaghetti-monster/anduril/version.h +++ b/spaghetti-monster/anduril/version.h @@ -1 +1 @@ -#define VERSION_NUMBER "20210825" +#define VERSION_NUMBER "20210919" -- cgit v1.2.3 From e0c04a9d8a3947443e0303238234cbfc8da7718c Mon Sep 17 00:00:00 2001 From: Gabriel Hart Date: Mon, 20 Sep 2021 14:18:45 -0500 Subject: SP10 Pro: lower AA LVP to 0.7v --- hwdef-Sofirn_SP10-Pro.h | 2 +- spaghetti-monster/anduril/version.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hwdef-Sofirn_SP10-Pro.h b/hwdef-Sofirn_SP10-Pro.h index 4691d04..5ed716d 100644 --- a/hwdef-Sofirn_SP10-Pro.h +++ b/hwdef-Sofirn_SP10-Pro.h @@ -54,7 +54,7 @@ PA1 : Boost Enable #define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is flattened #define DUAL_VOLTAGE_FLOOR 20 // for AA/14500 boost drivers, don't indicate low voltage if below this level -#define DUAL_VOLTAGE_LOW_LOW 8 // the lower voltage range's danger zone 0.8 volts (NiMH) +#define DUAL_VOLTAGE_LOW_LOW 7 // the lower voltage range's danger zone 0.7 volts (NiMH) #define ADMUX_VOLTAGE_DIVIDER ADC_MUXPOS_AIN9_gc // which ADC channel to read // Raw ADC readings at 4.4V and 2.2V diff --git a/spaghetti-monster/anduril/version.h b/spaghetti-monster/anduril/version.h index 82d6a9f..0da142b 100644 --- a/spaghetti-monster/anduril/version.h +++ b/spaghetti-monster/anduril/version.h @@ -1 +1 @@ -#define VERSION_NUMBER "20210919" +#define VERSION_NUMBER "20210920" -- cgit v1.2.3 From 17027a533661d14082f6566848bfb9cd122d03c6 Mon Sep 17 00:00:00 2001 From: Gabriel Hart Date: Fri, 29 Oct 2021 12:32:30 -0500 Subject: Add thefreeman's DAC linear driver (beta); also update Sofirn bilds to use the new 2C_STYLE defines --- hwdef-thefreeman-lin16dac.h | 109 +++++++++++++++++++++ spaghetti-monster/anduril/cfg-blf-lantern.h | 4 +- spaghetti-monster/anduril/cfg-blf-q8-t1616.h | 4 +- spaghetti-monster/anduril/cfg-blf-q8.h | 4 +- .../anduril/cfg-thefreeman-lin16dac.h | 45 +++++++++ spaghetti-monster/anduril/version.h | 2 +- 6 files changed, 161 insertions(+), 7 deletions(-) create mode 100644 hwdef-thefreeman-lin16dac.h create mode 100644 spaghetti-monster/anduril/cfg-thefreeman-lin16dac.h diff --git a/hwdef-thefreeman-lin16dac.h b/hwdef-thefreeman-lin16dac.h new file mode 100644 index 0000000..0999c4c --- /dev/null +++ b/hwdef-thefreeman-lin16dac.h @@ -0,0 +1,109 @@ +#ifndef HWDEF_THEFREEMAN_LIN18_H +#define HWDEF_THEFREEMAN_LIN18_H + +/* thefreeman's Linear 16 driver using DAC control + +PA6 - DAC for LED brightness control +PA7 - Op-amp enable pin +PB5 - Aux LED +PB4 - Switch pin, internal pullup +PB3 - HDR control, set High to enable the high power channel, set Low for low power +Read voltage from VCC pin, has PFET so no drop + +*/ + + +#define LAYOUT_DEFINED + +#ifdef ATTINY +#undef ATTINY +#endif +#define ATTINY 1616 +#include + +#define PWM_CHANNELS 1 +#define USE_DYN_PWM // dynamic frequency and speed + +#ifndef SWITCH_PIN +#define SWITCH_PIN PIN4_bp +#define SWITCH_PORT VPORTB.IN +#define SWITCH_ISC_REG PORTB.PIN2CTRL +#define SWITCH_VECT PORTB_PORT_vect +#define SWITCH_INTFLG VPORTB.INTFLAGS +#endif + + +#define PWM1_LVL DAC0.DATA // use this for DAC voltage output + +// PWM parameters of both channels are tied together because they share a counter +#define PWM1_TOP VREF.CTRLA // holds the TOP value for for variable-resolution PWM + +// For enabling / disabling the HDR high-range channel +#define LED_ENABLE_PIN PIN3_bp +#define LED_ENABLE_PORT PORTB_OUT +#define LED_ENABLE_PIN_LEVEL_MIN 35 +#define LED_ENABLE_PIN_LEVEL_MAX 150 + +// For turning on and off the op-amp +#define LED2_ENABLE_PIN PIN7_bp +#define LED2_ENABLE_PORT PORTA_OUT + + +// average drop across diode on this hardware +#ifndef VOLTAGE_FUDGE_FACTOR +#define VOLTAGE_FUDGE_FACTOR 0 // using a PFET so no appreciable drop +#endif + +// lighted button +#ifndef AUXLED_PIN +#define AUXLED_PIN PIN5_bp +#define AUXLED_PORT PORTB +#endif + + +// with so many pins, doing this all with #ifdefs gets awkward... +// ... so just hardcode it in each hwdef file instead +inline void hwdef_setup() { + + // set up the system clock to run at 10 MHz instead of the default 3.33 MHz + // TODO: for this DAC controlled-light, try to decrease the clock speed or use the ULP + _PROTECTED_WRITE( CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_2X_gc | CLKCTRL_PEN_bm ); + + VPORTA.DIR = PIN6_bm | PIN7_bm; + VPORTB.DIR = PIN3_bm; + //VPORTC.DIR = 0b00000000; + + // enable pullups on the input pins to reduce power + PORTA.PIN0CTRL = PORT_PULLUPEN_bm; + PORTA.PIN1CTRL = PORT_PULLUPEN_bm; + PORTA.PIN2CTRL = PORT_PULLUPEN_bm; + PORTA.PIN3CTRL = PORT_PULLUPEN_bm; + PORTA.PIN4CTRL = PORT_PULLUPEN_bm; + PORTA.PIN5CTRL = PORT_PULLUPEN_bm; + //PORTA.PIN6CTRL = PORT_PULLUPEN_bm; // DAC ouput + //PORTA.PIN7CTRL = PORT_PULLUPEN_bm; // Op-amp enable pin + + PORTB.PIN0CTRL = PORT_PULLUPEN_bm; + PORTB.PIN1CTRL = PORT_PULLUPEN_bm; + PORTB.PIN2CTRL = PORT_PULLUPEN_bm; + //PORTB.PIN3CTRL = PORT_PULLUPEN_bm; // HDR channel selection + PORTB.PIN4CTRL = PORT_PULLUPEN_bm | PORT_ISC_BOTHEDGES_gc; // switch + //PORTB.PIN5CTRL = PORT_PULLUPEN_bm; // Aux LED + + PORTC.PIN0CTRL = PORT_PULLUPEN_bm; + PORTC.PIN1CTRL = PORT_PULLUPEN_bm; + PORTC.PIN2CTRL = PORT_PULLUPEN_bm; + PORTC.PIN3CTRL = PORT_PULLUPEN_bm; + + // set up the DAC + // https://ww1.microchip.com/downloads/en/DeviceDoc/ATtiny1614-16-17-DataSheet-DS40002204A.pdf + // DAC ranges from 0V to (255 * Vref) / 256 + VREF.CTRLA |= VREF_DAC0REFSEL_2V5_gc; // also VREF_DAC0REFSEL_0V55_gc and VREF_DAC0REFSEL_1V1_gc and VREF_DAC0REFSEL_2V5_gc + VREF.CTRLB |= VREF_DAC0REFEN_bm; + DAC0.CTRLA = DAC_ENABLE_bm | DAC_OUTEN_bm; + DAC0.DATA = 255; // set the output voltage + +} + + +#endif diff --git a/spaghetti-monster/anduril/cfg-blf-lantern.h b/spaghetti-monster/anduril/cfg-blf-lantern.h index ff28a98..a989ca4 100644 --- a/spaghetti-monster/anduril/cfg-blf-lantern.h +++ b/spaghetti-monster/anduril/cfg-blf-lantern.h @@ -53,8 +53,8 @@ #define SIMPLE_UI_CEIL RAMP_DISCRETE_CEIL #define SIMPLE_UI_STEPS RAMP_DISCRETE_STEPS -// also at Sofirn's request, enable 2 click turbo -#define USE_2C_MAX_TURBO +// also at Sofirn's request, enable 2 click turbo (Anduril 1 style) +#define DEFAULT_2C_STYLE 1 #define USE_SOS_MODE #define USE_SOS_MODE_IN_BLINKY_GROUP diff --git a/spaghetti-monster/anduril/cfg-blf-q8-t1616.h b/spaghetti-monster/anduril/cfg-blf-q8-t1616.h index 340faa1..30a3368 100644 --- a/spaghetti-monster/anduril/cfg-blf-q8-t1616.h +++ b/spaghetti-monster/anduril/cfg-blf-q8-t1616.h @@ -34,8 +34,8 @@ #define SIMPLE_UI_CEIL 150 #define SIMPLE_UI_STEPS 5 -// also at Sofirn's request, enable 2 click turbo -#define USE_2C_MAX_TURBO +// also at Sofirn's request, enable 2 click turbo (Anduril 1 style) +#define DEFAULT_2C_STYLE 1 // enable SOS in the blinkies group #define USE_SOS_MODE diff --git a/spaghetti-monster/anduril/cfg-blf-q8.h b/spaghetti-monster/anduril/cfg-blf-q8.h index 00bdd8a..6a5055c 100644 --- a/spaghetti-monster/anduril/cfg-blf-q8.h +++ b/spaghetti-monster/anduril/cfg-blf-q8.h @@ -33,8 +33,8 @@ #define SIMPLE_UI_CEIL 150 #define SIMPLE_UI_STEPS 5 -// also at Sofirn's request, enable 2 click turbo -#define USE_2C_MAX_TURBO +// also at Sofirn's request, enable 2 click turbo (Anduril 1 style) +#define DEFAULT_2C_STYLE 1 // enable SOS in the blinkies group #define USE_SOS_MODE diff --git a/spaghetti-monster/anduril/cfg-thefreeman-lin16dac.h b/spaghetti-monster/anduril/cfg-thefreeman-lin16dac.h new file mode 100644 index 0000000..64dcd8c --- /dev/null +++ b/spaghetti-monster/anduril/cfg-thefreeman-lin16dac.h @@ -0,0 +1,45 @@ +// thefreeman's Linear 16 driver using DAC control +#define MODEL_NUMBER "0000" // TBD +#include "hwdef-thefreeman-lin16dac.h" +// ATTINY: 1616 + +// the button lights up +#define USE_INDICATOR_LED +// the button is visible while main LEDs are on +#define USE_INDICATOR_LED_WHILE_RAMPING +// off mode: low (1) +// lockout: blinking (3) +#define INDICATOR_LED_DEFAULT_MODE ((3<<2) + 1) + +#undef BLINK_AT_RAMP_MIDDLE + +// We're abusing the Dynamic PWM functionality to set the VREF instead of PWM TOP. +// We don't want the Gradual functionality to mess with the PWM_TOP value. +#ifdef USE_SET_LEVEL_GRADUALLY +#undef USE_SET_LEVEL_GRADUALLY +#endif + +// level_calc.py ninth 2 150 7135 1 0.03 6.4 7135 1 6.3 1600 +#define RAMP_LENGTH 150 +#define USE_DYN_PWM + +// PWM1: DAC Data, PWM Tops: VREF selector +#define PWM1_LEVELS 25,25,33,41,41,50,58,66,75,83,92,108,117,133,150,167,192,209,234,58,64,71,80,90,99,110,121,134,149,163,180,198,218,241,1,1,1,1,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,5,5,6,6,7,7,8,8,9,10,11,11,12,13,14,15,16,18,19,20,22,23,25,26,28,30,32,34,36,39,41,44,47,50,53,56,59,63,67,71,75,79,84,89,94,100,105,112,118,124,131,139,146,154,163,172,181,191,201,212,223,234,246,57,60,63,66,69,73,76,80,84,88,93,97,102,107,112,117,123,129,135,141,147,154,161,169,176,184,193,201,210,220,229,239,250,255 +#define PWM_TOPS 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18 + +#define MAX_1x7135 34 +#define HALFSPEED_LEVEL 14 +#define QUARTERSPEED_LEVEL 6 + +#define RAMP_SMOOTH_FLOOR 1 +#define RAMP_SMOOTH_CEIL 120 +// 10, 28, 46, [65], 83, 101, 120 +#define RAMP_DISCRETE_FLOOR 10 +#define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL +#define RAMP_DISCRETE_STEPS 7 + +// stop panicking at ~30% power +#define THERM_FASTER_LEVEL 123 + +// enable 2 click turbo +#define DEFAULT_2C_STYLE 1 diff --git a/spaghetti-monster/anduril/version.h b/spaghetti-monster/anduril/version.h index 0da142b..7560ef2 100644 --- a/spaghetti-monster/anduril/version.h +++ b/spaghetti-monster/anduril/version.h @@ -1 +1 @@ -#define VERSION_NUMBER "20210920" +#define VERSION_NUMBER "20211029" -- 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 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