aboutsummaryrefslogtreecommitdiff
path: root/arch/attiny1616.c
diff options
context:
space:
mode:
authorSelene ToyKeeper2023-11-24 06:29:56 -0700
committerSelene ToyKeeper2023-11-24 06:29:56 -0700
commit8c237206aba74f9096d85f90209ac6b7dc238b1b (patch)
tree529b22b5dec28bdab1029016dde9d85d80039c57 /arch/attiny1616.c
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 'arch/attiny1616.c')
-rw-r--r--arch/attiny1616.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/arch/attiny1616.c b/arch/attiny1616.c
index 330c809..2770d06 100644
--- a/arch/attiny1616.c
+++ b/arch/attiny1616.c
@@ -29,8 +29,7 @@ inline void clock_prescale_set(uint8_t n) {
inline void mcu_set_admux_therm() {
// put the ADC in temperature mode
// attiny1616 datasheet section 30.3.2.6
- VREF.CTRLA = (VREF.CTRLA & (~VREF_ADC0REFSEL_gm))
- | VREF_ADC0REFSEL_1V1_gc; // Set Vbg ref to 1.1V
+ mcu_set_adc0_vref(VREF_ADC0REFSEL_1V1_gc); // Set Vbg ref to 1.1V
ADC0.MUXPOS = ADC_MUXPOS_TEMPSENSE_gc; // read temperature
ADC0.CTRLB = ADC_SAMPNUM_ACC4_gc; // 10-bit result + 4x oversampling
ADC0.CTRLC = ADC_SAMPCAP_bm
@@ -46,8 +45,7 @@ inline void mcu_set_admux_voltage() {
ADC0.CTRLD |= ADC_INITDLY_DLY16_gc;
#ifdef USE_VOLTAGE_DIVIDER // measure an arbitrary pin
// result = resolution * Vdiv / 1.1V
- VREF.CTRLA = (VREF.CTRLA & (~VREF_ADC0REFSEL_gm))
- | VREF_ADC0REFSEL_1V1_gc; // Set Vbg ref to 1.1V
+ mcu_set_adc0_vref(VREF_ADC0REFSEL_1V1_gc); // Set Vbg ref to 1.1V
ADC0.MUXPOS = ADMUX_VOLTAGE_DIVIDER; // read the requested ADC pin
ADC0.CTRLB = ADC_SAMPNUM_ACC4_gc; // 12-bit result, 4x oversampling
ADC0.CTRLC = ADC_SAMPCAP_bm
@@ -55,8 +53,7 @@ inline void mcu_set_admux_voltage() {
| ADC_REFSEL_INTREF_gc; // Use internal ADC reference
#else // measure VDD pin
// result = resolution * 1.5V / Vbat
- VREF.CTRLA = (VREF.CTRLA & (~VREF_ADC0REFSEL_gm))
- | VREF_ADC0REFSEL_1V5_gc; // Set Vbg ref to 1.5V
+ mcu_set_adc0_vref(VREF_ADC0REFSEL_1V5_gc); // Set Vbg ref to 1.5V
ADC0.MUXPOS = ADC_MUXPOS_INTREF_gc; // read internal reference
ADC0.CTRLB = ADC_SAMPNUM_ACC4_gc; // 12-bit result, 4x oversampling
ADC0.CTRLC = ADC_SAMPCAP_bm