aboutsummaryrefslogtreecommitdiff
path: root/hw/thefreeman/boost21-mp3431-hdr-dac-argb
diff options
context:
space:
mode:
authorSelene ToyKeeper2023-11-24 06:29:56 -0700
committerSelene ToyKeeper2023-11-24 06:29:56 -0700
commit8c237206aba74f9096d85f90209ac6b7dc238b1b (patch)
tree529b22b5dec28bdab1029016dde9d85d80039c57 /hw/thefreeman/boost21-mp3431-hdr-dac-argb
parentavr32dd20-devkit: make the defaults a bit more dev friendly (diff)
downloadanduril-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/boost21-mp3431-hdr-dac-argb')
-rw-r--r--hw/thefreeman/boost21-mp3431-hdr-dac-argb/anduril.h24
-rw-r--r--hw/thefreeman/boost21-mp3431-hdr-dac-argb/hwdef.c14
-rw-r--r--hw/thefreeman/boost21-mp3431-hdr-dac-argb/hwdef.h34
3 files changed, 31 insertions, 41 deletions
diff --git a/hw/thefreeman/boost21-mp3431-hdr-dac-argb/anduril.h b/hw/thefreeman/boost21-mp3431-hdr-dac-argb/anduril.h
index a6a111c..8319d13 100644
--- a/hw/thefreeman/boost21-mp3431-hdr-dac-argb/anduril.h
+++ b/hw/thefreeman/boost21-mp3431-hdr-dac-argb/anduril.h
@@ -3,7 +3,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
-#include "thefreeman/boost21-mp3431-hdr-dac-argb/hwdef.h"
+#define HWDEF_H thefreeman/boost21-mp3431-hdr-dac-argb/hwdef.h
// HPRsense : 1.7+0.3+5 = 7mR (DMN22M5UFG+trace resistance+5mR)
// Vsense=42.46mV, R1= 191k
@@ -19,15 +19,17 @@
// - high 0.55V
// - high 2.5V
// PWM1: DAC Data
-#define PWM1_LEVELS 2, 3, 4, 5, 7, 9, 11, 13, 16, 19, 23, 28, 33, 39, 45, 53, 61, 71, 81, 93,106,121,137,155,175,196,220,246, \
- 60, 67, 74, 82, 91,100,110,121,133,146,159,174,190,207,224,244, \
- 8, 9, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 23, 24, 26, 27, 29, 31, 33, 35, 37, 40, 42, 45, 47, 50, 53, 56, 59, 62, 66, 69, 73, 77, 81, 85, 90, 94, 99,104,109,114,120,126,132,138,144,151,158,165,173,180,188,196,205,214,223,232,242,252, \
- 57, 60, 62, 65, 67, 70, 73, 76, 78, 82, 85, 88, 91, 95, 98,102,105,109,113,117,121,126,130,135,139,144,149,154,159,164,170,175,181,187,193,199,206,212,219,225,232,240,247,255
-// PWM Tops: VREF selector (0.55V=16,1.1V=17, 2.5V=18, 4.3V=19, 1.5V=20)
-#define PWM_TOPS 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, \
- 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,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25
+#define PWM1_LEVELS \
+ 2, 3, 4, 5, 7, 9, 11, 13, 16, 19, 23, 28, 33, 39, 45, 53, 61, 71, 81, 93,106,121,137,155,175,196,220,246, \
+ 60, 67, 74, 82, 91,100,110,121,133,146,159,174,190,207,224,244, \
+ 8, 9, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 23, 24, 26, 27, 29, 31, 33, 35, 37, 40, 42, 45, 47, 50, 53, 56, 59, 62, 66, 69, 73, 77, 81, 85, 90, 94, 99,104,109,114,120,126,132,138,144,151,158,165,173,180,188,196,205,214,223,232,242,252, \
+ 57, 60, 62, 65, 67, 70, 73, 76, 78, 82, 85, 88, 91, 95, 98,102,105,109,113,117,121,126,130,135,139,144,149,154,159,164,170,175,181,187,193,199,206,212,219,225,232,240,247,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,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, \
+ 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,V25,V25,V25,V25,V25,V25,V25,V25,V25,V25
#define MAX_1x7135 44
#define DEFAULT_LEVEL 44
@@ -71,7 +73,7 @@
//#define SIMPLE_UI_ACTIVE 0 // advanced UI by default
// allow Aux Config and Strobe Modes in Simple UI
-#define USE_EXTENDED_SIMPLE_UI
+//#define USE_EXTENDED_SIMPLE_UI
// Allow 3C in Simple UI for switching between smooth and stepped ramping
#define USE_SIMPLE_UI_RAMPING_TOGGLE
diff --git a/hw/thefreeman/boost21-mp3431-hdr-dac-argb/hwdef.c b/hw/thefreeman/boost21-mp3431-hdr-dac-argb/hwdef.c
index 97f5fc9..573ec2f 100644
--- a/hw/thefreeman/boost21-mp3431-hdr-dac-argb/hwdef.c
+++ b/hw/thefreeman/boost21-mp3431-hdr-dac-argb/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
@@ -49,8 +49,8 @@ void set_level_main(uint8_t level) {
BST_ENABLE_PORT |= (1 << BST_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))
@@ -61,7 +61,7 @@ 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);
if (noflash) {
// wait for flash prevention to finish
@@ -75,11 +75,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/boost21-mp3431-hdr-dac-argb/hwdef.h b/hw/thefreeman/boost21-mp3431-hdr-dac-argb/hwdef.h
index d030516..d83aa46 100644
--- a/hw/thefreeman/boost21-mp3431-hdr-dac-argb/hwdef.h
+++ b/hw/thefreeman/boost21-mp3431-hdr-dac-argb/hwdef.h
@@ -57,26 +57,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
-// (1.1V ADC + variable DAC)
-#define V05 V055
-#define V055 (VREF_ADC0REFSEL_1V1_gc|VREF_DAC0REFSEL_0V55_gc)
-#define V11 (VREF_ADC0REFSEL_1V1_gc|VREF_DAC0REFSEL_1V1_gc)
-#define V25 (VREF_ADC0REFSEL_1V1_gc|VREF_DAC0REFSEL_2V5_gc)
-#define V43 (VREF_ADC0REFSEL_1V1_gc|VREF_DAC0REFSEL_4V34_gc)
-#define V15 (VREF_ADC0REFSEL_1V1_gc|VREF_DAC0REFSEL_1V5_gc)
+// (DAC_LVL + DAC_VREF + Vref values are defined in arch/*.h)
// BST enable
#define BST_ENABLE_PIN PIN0_bp
@@ -125,10 +115,9 @@ enum CHANNEL_MODES {
inline void hwdef_setup() {
- // TODO: for this DAC controlled-light, try to decrease the clock speed or use the ULP
- // set up the system clock to run at 10 MHz to match other attiny1616 lights
- _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
VPORTB.DIR = PIN1_bm // R
@@ -165,11 +154,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
}
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.