From 8c237206aba74f9096d85f90209ac6b7dc238b1b Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Fri, 24 Nov 2023 06:29:56 -0700 Subject: 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) --- arch/attiny1616.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'arch/attiny1616.c') 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 -- cgit v1.2.3