From c63aba815f8a098a73e4db13d7c4338d25e7bbae Mon Sep 17 00:00:00 2001 From: Bexin3 <88098139+Bexin3@users.noreply.github.com> Date: Wed, 25 Jan 2023 20:39:43 +0000 Subject: [PATCH] Update ADCSetup.cpp --- src/ADCSetup.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ADCSetup.cpp b/src/ADCSetup.cpp index a08a1a1..3c8c222 100644 --- a/src/ADCSetup.cpp +++ b/src/ADCSetup.cpp @@ -14,7 +14,9 @@ void ADC0Setup(bool DacRef, int Res, int Samp, int ADCClk, int ADCDiv, int BaseV DACSetup(BaseV); //Setup DAC if needed }; -ADC0->CALIB.reg = ADC_CALIB_BIASCOMP(0x7) | ADC_CALIB_BIASREFBUF(0x7); + + ADC0->CALIB.reg = ADC_CALIB_BIASREFBUF(((*((uint32_t *) ADC0_FUSES_BIASREFBUF_ADDR) & ADC0_FUSES_BIASREFBUF_Msk) >> ADC0_FUSES_BIASREFBUF_Pos)) + | ADC_CALIB_BIASCOMP(((*((uint32_t *) ADC0_FUSES_BIASCOMP_ADDR) & ADC0_FUSES_BIASCOMP_Msk) >> ADC0_FUSES_BIASCOMP_Pos)); if (DacRef) { ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC1_Val; @@ -129,12 +131,14 @@ void ADC1Setup(bool DacRef, int Res, int Samp, int ADCClk, int ADCDiv, int BaseV DACSetup(BaseV); //Setup DAC if needed }; -ADC1->CALIB.reg = ADC_CALIB_BIASCOMP(0x7) | ADC_CALIB_BIASREFBUF(0x7); + + ADC1->CALIB.reg = ADC_CALIB_BIASREFBUF(((*((uint32_t *) ADC1_FUSES_BIASREFBUF_ADDR) & ADC1_FUSES_BIASREFBUF_Msk) >> ADC1_FUSES_BIASREFBUF_Pos)) + | ADC_CALIB_BIASCOMP(((*((uint32_t *) ADC1_FUSES_BIASCOMP_ADDR) & ADC1_FUSES_BIASCOMP_Msk) >> ADC1_FUSES_BIASCOMP_Pos)); if (DacRef) { - ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC1_Val; + ADC1->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC1_Val; } else { - ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC2_Val; + ADC1->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC2_Val; };