aboutsummaryrefslogtreecommitdiff
path: root/hw/thefreeman/lin16dac/hwdef.h
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/lin16dac/hwdef.h
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/lin16dac/hwdef.h')
-rw-r--r--hw/thefreeman/lin16dac/hwdef.h33
1 files changed, 11 insertions, 22 deletions
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
}