-
-
Save SammysHP/5fcd15901e1b901e378d47fefb52f7ed to your computer and use it in GitHub Desktop.
WIP Wurkkos TS10 dynamic PWM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Wurkkos TS10 config options for Anduril using the Attiny1616 | |
// Same pinout as BLF Q8 | |
#define MODEL_NUMBER "0000" | |
#include "hwdef-BLF_Q8-T1616-v2.h" | |
// ATTINY: 1616 | |
#define USE_INDICATOR_LED | |
#undef USE_INDICATOR_LED_WHILE_RAMPING | |
#define INDICATOR_LED_DEFAULT_MODE ((3<<2) + 1) | |
// level 1 by hand, for the rest | |
// level_calc.py 7.01 2 149 7135 3 0.5 125 FET 1 10 1200 --pwm dyn:63:2048:255 | |
#define RAMP_LENGTH 150 | |
#define USE_DYN_PWM | |
#define PWM1_LEVELS 1,3,3,4,5,6,7,8,9,10,12,13,14,16,17,19,20,22,24,25,27,29,31,33,35,37,40,42,44,47,49,52,54,57,59,62,64,67,70,72,75,77,80,82,85,87,89,91,93,95,96,98,99,100,100,101,100,100,99,97,95,93,90,86,82,87,91,96,100,106,111,116,122,128,134,141,147,155,162,169,177,186,194,203,213,222,232,243,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,3,4,6,7,9,11,12,14,16,18,20,22,24,27,29,31,34,37,39,42,45,48,51,54,57,61,64,68,72,75,79,83,88,92,97,101,106,111,116,121,126,132,138,144,150,156,162,169,176,183,190,197,205,213,221,229,237,246,255 | |
#define PWM_TOPS 2047,2047,1198,1322,1584,1676,1701,1691,1662,1622,1774,1703,1631,1692,1613,1639,1558,1564,1559,1478,1464,1444,1420,1392,1361,1329,1331,1293,1256,1246,1207,1192,1152,1133,1094,1074,1035,1013,991,954,932,897,875,842,820,790,760,731,704,678,646,622,593,566,534,510,478,452,423,393,364,338,310,280,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,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 90 | |
#define HALFSPEED_LEVEL 2 | |
#define QUARTERSPEED_LEVEL 2 | |
#define DEFAULT_LEVEL 65 | |
#define THERM_FASTER_LEVEL 130 | |
#define MIN_THERM_STEPDOWN 65 | |
#define RAMP_SMOOTH_FLOOR 1 | |
#define RAMP_SMOOTH_CEIL 130 | |
// 10 [50] 90 130 | |
#define RAMP_DISCRETE_FLOOR 10 | |
#define RAMP_DISCRETE_CEIL 130 | |
#define RAMP_DISCRETE_STEPS 4 | |
#define SIMPLE_UI_FLOOR RAMP_SMOOTH_FLOOR | |
#define SIMPLE_UI_CEIL RAMP_SMOOTH_CEIL | |
#define SIMPLE_UI_STEPS 7 | |
#define SIMPLE_UI_ACTIVE 0 | |
#define RAMP_STYLE 0 | |
#define DEFAULT_2C_STYLE 2 | |
#define USE_SOS_MODE | |
#define USE_SOS_MODE_IN_BLINKY_GROUP | |
#define USE_SIMPLE_UI_RAMPING_TOGGLE | |
#define USE_SOFT_FACTORY_RESET | |
#undef BLINK_AT_RAMP_MIDDLE | |
#undef BLINK_AT_RAMP_CEIL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef HWDEF_BLF_Q8_T1616_V2_H | |
#define HWDEF_BLF_Q8_T1616_V2_H | |
/* | |
* BLF Q8 driver layout using the Attiny1616 | |
* | |
* Driver pinout: | |
* eSwitch: PA5 | |
* Aux LED: PB5 | |
* PWM FET: PB0 (TCA0 WO0) | |
* PWM 1x7135: PB1 (TCA0 WO1) | |
* Voltage: VCC | |
*/ | |
#define LAYOUT_DEFINED | |
#ifdef ATTINY | |
#undef ATTINY | |
#endif | |
#define ATTINY 1616 | |
#include <avr/io.h> | |
#ifndef SWITCH_PIN | |
#define SWITCH_PIN PIN5_bp | |
#define SWITCH_PORT VPORTA.IN | |
#define SWITCH_ISC_REG PORTA.PIN2CTRL | |
#define SWITCH_VECT PORTA_PORT_vect | |
#define SWITCH_INTFLG VPORTA.INTFLAGS | |
#endif | |
#define PWM_CHANNELS 2 | |
#define PWM_BITS 16 | |
#define PWM_TOP 255 | |
#define USE_DYN_PWM | |
// 7135 channel | |
#ifndef PWM1_PIN | |
#define PWM1_PIN PB1 | |
#define PWM1_LVL TCA0.SINGLE.CMP1BUF | |
#endif | |
// FET channel | |
#ifndef PWM2_PIN | |
#define PWM2_PIN PB0 | |
#define PWM2_LVL TCA0.SINGLE.CMP0BUF | |
#endif | |
// PWM parameters of both channels are tied together because they share a counter | |
#define PWM1_TOP TCA0.SINGLE.PERBUF | |
#define PWM1_CNT TCA0.SINGLE.CNT | |
#define PWM1_PHASE_RESET_OFF | |
#define PWM1_PHASE_RESET_ON | |
// aux LED channel | |
#ifndef AUXLED_PIN | |
#define AUXLED_PIN PIN5_bp | |
#define AUXLED_PORT PORTB | |
#endif | |
// average drop across diode on this hardware | |
#ifndef VOLTAGE_FUDGE_FACTOR | |
#define VOLTAGE_FUDGE_FACTOR 5 | |
#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 = ...; | |
VPORTB.DIR = PIN0_bm | PIN1_bm | PIN5_bm; // Outputs: Aux LED and PWMs | |
//VPORTC.DIR = ...; | |
// enable pullups on the unused 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 | PORT_ISC_BOTHEDGES_gc; // eSwitch | |
PORTA.PIN6CTRL = PORT_PULLUPEN_bm; | |
PORTA.PIN7CTRL = PORT_PULLUPEN_bm; | |
//PORTB.PIN0CTRL = PORT_PULLUPEN_bm; // FET channel | |
//PORTB.PIN1CTRL = PORT_PULLUPEN_bm; // 7135 channel | |
PORTB.PIN2CTRL = PORT_PULLUPEN_bm; | |
PORTB.PIN3CTRL = PORT_PULLUPEN_bm; | |
PORTB.PIN4CTRL = PORT_PULLUPEN_bm; | |
//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 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 | |
TCA0.SINGLE.CTRLB = TCA_SINGLE_CMP0EN_bm | TCA_SINGLE_CMP1EN_bm | TCA_SINGLE_WGMODE_DSBOTTOM_gc; | |
PWM1_TOP = PWM_TOP; | |
TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV1_gc | TCA_SINGLE_ENABLE_bm; | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment