diff options
| author | Selene ToyKeeper | 2023-11-24 06:29:56 -0700 |
|---|---|---|
| committer | Selene ToyKeeper | 2023-11-24 06:29:56 -0700 |
| commit | 8c237206aba74f9096d85f90209ac6b7dc238b1b (patch) | |
| tree | 529b22b5dec28bdab1029016dde9d85d80039c57 /hw/thefreeman/lin16dac | |
| parent | avr32dd20-devkit: make the defaults a bit more dev friendly (diff) | |
| download | anduril-8c237206aba74f9096d85f90209ac6b7dc238b1b.tar.gz anduril-8c237206aba74f9096d85f90209ac6b7dc238b1b.tar.bz2 anduril-8c237206aba74f9096d85f90209ac6b7dc238b1b.zip | |
more ADC / DAC / MCU progress...
- fixed t1616 Vref values getting clobbered sometimes,
wrapped setting those in a #define'd function for ease and consistency
- moved some DAC definitions from hw/ to arch/ to reduce repetition
- fixed thefreeman's other builds
- switched from PWM_TOPS to PWM2_LEVELS (I'm trying to phase out _TOPS)
Diffstat (limited to 'hw/thefreeman/lin16dac')
| -rw-r--r-- | hw/thefreeman/lin16dac/anduril.h | 22 | ||||
| -rw-r--r-- | hw/thefreeman/lin16dac/hwdef.c | 15 | ||||
| -rw-r--r-- | hw/thefreeman/lin16dac/hwdef.h | 33 |
3 files changed, 31 insertions, 39 deletions
diff --git a/hw/thefreeman/lin16dac/anduril.h b/hw/thefreeman/lin16dac/anduril.h index 8ca8b9f..8f9d6e4 100644 --- a/hw/thefreeman/lin16dac/anduril.h +++ b/hw/thefreeman/lin16dac/anduril.h @@ -3,7 +3,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later #pragma once -#include "thefreeman/lin16dac/hwdef.h" +#define HWDEF_H thefreeman/lin16dac/hwdef.h // the button lights up #define USE_INDICATOR_LED @@ -24,15 +24,17 @@ // PWM1: DAC Data // FIXME: ramp stalls with 8 duplicate levels in a row // (maybe use 1.1V Vref during that part of the ramp?) -#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 -// PWM Tops: VREF selector (0.55V=16,1.1V=17, 2.5V=18, 4.3V=19, 1.5V=20) -#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 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 +// PWM2: VREF selector (0.55V=16,1.1V=17, 2.5V=18, 4.3V=19, 1.5V=20) +#define PWM2_LEVELS \ + V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05, \ + V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25, \ + V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05,V05, \ + V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25 #define MAX_1x7135 34 #define HDR_ENABLE_LEVEL_MIN 35 // bottom level of top half of the ramp diff --git a/hw/thefreeman/lin16dac/hwdef.c b/hw/thefreeman/lin16dac/hwdef.c index 191444e..89700d7 100644 --- a/hw/thefreeman/lin16dac/hwdef.c +++ b/hw/thefreeman/lin16dac/hwdef.c @@ -22,7 +22,7 @@ Channel channels[] = { void set_level_zero() { DAC_LVL = 0; // DAC off - DAC_VREF = V055; // low Vref + mcu_set_dac_vref(V055); // low Vref HDR_ENABLE_PORT &= ~(1 << HDR_ENABLE_PIN); // HDR off // prevent post-off flash @@ -50,8 +50,8 @@ void set_level_main(uint8_t level) { OPAMP_ENABLE_PORT |= (1 << OPAMP_ENABLE_PIN); // pre-load ramp data so it can be assigned faster later - PWM_DATATYPE dac_lvl = PWM_GET(pwm1_levels, level); - PWM_DATATYPE dac_vref = PWM_GET(pwm_tops, level); + PWM1_DATATYPE dac_lvl = PWM1_GET(level); + PWM2_DATATYPE dac_vref = PWM2_GET(level); // enable HDR on top half of ramp if (level >= (HDR_ENABLE_LEVEL_MIN-1)) @@ -69,7 +69,8 @@ void set_level_main(uint8_t level) { // set these in successive clock cycles to avoid getting out of sync // (minimizes ramp bumps when changing gears) DAC_LVL = dac_lvl; - DAC_VREF = dac_vref; + mcu_set_dac_vref(dac_vref); + } bool gradual_tick_main(uint8_t gt) { @@ -77,11 +78,11 @@ bool gradual_tick_main(uint8_t gt) { // otherwise, simply jump to the next ramp level // and let set_level() handle any gear changes - PWM_DATATYPE dac_next = PWM_GET(pwm1_levels, gt); - PWM_DATATYPE vref_next = PWM_GET(pwm_tops, gt); + PWM1_DATATYPE dac_next = PWM1_GET(gt); + PWM2_DATATYPE vref_next = PWM2_GET(gt); // different gear = full adjustment - if (vref_next != DAC_VREF) return true; // let parent set_level() for us + if (vref_next != (DAC_VREF & VREF_DAC0REFSEL_gm)) return true; // let parent set_level() for us // same gear = small adjustment GRADUAL_ADJUST_SIMPLE(dac_next, DAC_LVL); diff --git a/hw/thefreeman/lin16dac/hwdef.h b/hw/thefreeman/lin16dac/hwdef.h index dc4377a..a68d9c2 100644 --- a/hw/thefreeman/lin16dac/hwdef.h +++ b/hw/thefreeman/lin16dac/hwdef.h @@ -32,24 +32,16 @@ enum CHANNEL_MODES { #define CHANNEL_MODES_ENABLED 0b0000000000000001 -#define PWM_CHANNELS 1 // old, remove this - #define PWM_BITS 8 // 8-bit DAC -#define PWM_GET PWM_GET8 #define PWM_DATATYPE uint8_t #define PWM_DATATYPE2 uint16_t // only needs 32-bit if ramp values go over 255 #define PWM1_DATATYPE uint8_t // main LED ramp +#define PWM1_GET(l) PWM_GET8(pwm1_levels, l) +#define PWM2_DATATYPE uint8_t // DAC Vref table +#define PWM2_GET(l) PWM_GET8(pwm2_levels, l) // main LED outputs -#define DAC_LVL DAC0.DATA // 0 to 255, for 0V to Vref -#define DAC_VREF VREF.CTRLA // 0.55V or 2.5V -#define PWM_TOP_INIT 255 // highest value used in top half of ramp (unused?) -// Vref values -#define V055 16 -#define V11 17 -#define V25 18 -#define V43 19 -#define V15 20 +// (DAC_LVL + DAC_VREF + Vref values are defined in arch/*.h) // Opamp enable // For turning on and off the op-amp @@ -84,11 +76,9 @@ enum CHANNEL_MODES { inline void hwdef_setup() { - // set up the system clock to run at 10 MHz instead of the default 3.33 MHz - // (it'll get underclocked to 2.5 MHz later) - // TODO: maybe run even slower? - _PROTECTED_WRITE( CLKCTRL.MCLKCTRLB, - CLKCTRL_PDIV_2X_gc | CLKCTRL_PEN_bm ); + // TODO: for this DAC controlled-light, try to decrease the clock speed + // to reduce overall system power + mcu_clock_speed(); VPORTA.DIR = PIN6_bm // DAC | PIN7_bm; // Opamp @@ -121,11 +111,10 @@ inline void hwdef_setup() { // 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 - // also VREF_DAC0REFSEL_0V55_gc and VREF_DAC0REFSEL_1V1_gc and VREF_DAC0REFSEL_2V5_gc - VREF.CTRLA |= VREF_DAC0REFSEL_2V5_gc; - VREF.CTRLB |= VREF_DAC0REFEN_bm; - DAC0.CTRLA = DAC_ENABLE_bm | DAC_OUTEN_bm; - DAC0.DATA = 255; // set the output voltage + mcu_set_dac_vref(V05); // boot at lowest Vref setting + VREF.CTRLB |= VREF_DAC0REFEN_bm; // enable DAC Vref + DAC0.CTRLA = DAC_ENABLE_bm | DAC_OUTEN_bm; // enable DAC + DAC_LVL = 0; // turn off output at boot } |
