From 69ba26537260f77a6bfc2b49b6207062b618f49b Mon Sep 17 00:00:00 2001 From: Bexin3 <88098139+Bexin3@users.noreply.github.com> Date: Wed, 25 Jan 2023 20:18:05 +0000 Subject: [PATCH] Update ADCSetup.cpp --- src/ADCSetup.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/ADCSetup.cpp b/src/ADCSetup.cpp index a04758b..a08a1a1 100644 --- a/src/ADCSetup.cpp +++ b/src/ADCSetup.cpp @@ -7,16 +7,20 @@ int16_t anv = 0; void ADC0Setup(bool DacRef, int Res, int Samp, int ADCClk, int ADCDiv, int BaseV, bool Freerun, bool PreDiv) { -/* genericClockSetup(ADCClk, ADCDiv); //Sets up ADC clock and divides it + genericClockSetup(ADCClk, ADCDiv); //Sets up ADC clock and divides it AttachClock(ADCClk, 0x1E); if (DacRef) { DACSetup(BaseV); //Setup DAC if needed }; -*/ + ADC0->CALIB.reg = ADC_CALIB_BIASCOMP(0x7) | ADC_CALIB_BIASREFBUF(0x7); + if (DacRef) { ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC1_Val; + } else { + ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC2_Val; + }; @@ -118,16 +122,20 @@ return(anv); //Write it down void ADC1Setup(bool DacRef, int Res, int Samp, int ADCClk, int ADCDiv, int BaseV, bool Freerun, bool PreDiv) { -/* genericClockSetup(ADCClk, ADCDiv); //Sets up ADC clock and divides it + genericClockSetup(ADCClk, ADCDiv); //Sets up ADC clock and divides it AttachClock(ADCClk, 0x1E); if (DacRef) { DACSetup(BaseV); //Setup DAC if needed }; -*/ + ADC1->CALIB.reg = ADC_CALIB_BIASCOMP(0x7) | ADC_CALIB_BIASREFBUF(0x7); - ADC1->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC1_Val; + if (DacRef) { + ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC1_Val; + } else { + ADC0->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC2_Val; + };