From 6cd9ece81e191556c31606581fdca3f6c78d096b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Niew=C3=B6hner?= Date: Fri, 16 Aug 2024 00:52:20 +0200 Subject: [PATCH] hwconf/*: disable DAC buffer to increase accuracy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to the STM32F4 datasheet, the ADC is equipped with a buffer for being able to drive external loads directly. This buffer negatively impacts accuracy, though. The offset can be as high as 0.2V. Thus, disable the buffer by setting the BOFFx flag. This was verified on a STM32 nucleo64 F446RE by reading the DAC voltage back via ADC and comparing results with and without BOFFx=1. The output voltage was verified (calibrated DMM BM789) to be correct with BOFFx=1. Reference: STM DS8626 STM32F40xxx Rev 9 - 5.3.25 DAC electrical characteristics - Figure 53. 12-bit buffered non-buffered DAC Signed-off-by: Michael Niewöhner --- hwconf/other/hw_uxv_sr.c | 2 +- hwconf/trampa/100_250_MKIII/hw_100_250_mkiii_core.c | 2 +- hwconf/trampa/rb/hw_rb_core.c | 2 +- hwconf/trampa/sparkf/hw_sparkf_core.c | 2 +- hwconf/trampa/str500/hw_str500_core.c | 2 +- hwconf/trampa/vesc6/hw_60_core.c | 2 +- hwconf/trampa/vesc_edu/hw_edu_core.c | 2 +- hwconf/trampa/vesc_gp/hw_gp_core.c | 2 +- hwconf/vesc/basic/hw_basic_core.c | 2 +- hwconf/vesc/str365/hw_str365_core.c | 4 ++-- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/hwconf/other/hw_uxv_sr.c b/hwconf/other/hw_uxv_sr.c index 097d0f89f..699db4306 100644 --- a/hwconf/other/hw_uxv_sr.c +++ b/hwconf/other/hw_uxv_sr.c @@ -265,7 +265,7 @@ THD_FUNCTION(dac_thread, arg) { chRegSetThreadName("DAC"); chThdSleepMilliseconds(3000); RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); - DAC->CR |= DAC_CR_EN2; + DAC->CR |= DAC_CR_EN2 | DAC_CR_BOFF2; //DAC->CR |= DAC_CR_BOFF2; diff --git a/hwconf/trampa/100_250_MKIII/hw_100_250_mkiii_core.c b/hwconf/trampa/100_250_MKIII/hw_100_250_mkiii_core.c index 19d3c156c..842df1734 100644 --- a/hwconf/trampa/100_250_MKIII/hw_100_250_mkiii_core.c +++ b/hwconf/trampa/100_250_MKIII/hw_100_250_mkiii_core.c @@ -118,7 +118,7 @@ void hw_init_gpio(void) { // DAC as voltage reference for shunt amps palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG); RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); - DAC->CR |= DAC_CR_EN1; + DAC->CR |= DAC_CR_EN1 | DAC_CR_BOFF1; DAC->DHR12R1 = 2047; } diff --git a/hwconf/trampa/rb/hw_rb_core.c b/hwconf/trampa/rb/hw_rb_core.c index e134ddb11..768ea2039 100644 --- a/hwconf/trampa/rb/hw_rb_core.c +++ b/hwconf/trampa/rb/hw_rb_core.c @@ -140,7 +140,7 @@ void hw_init_gpio(void) { // DAC as voltage reference for shunt amps palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG); RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); - DAC->CR |= DAC_CR_EN1; + DAC->CR |= DAC_CR_EN1 | DAC_CR_BOFF1; DAC->DHR12R1 = 2047; palSetPadMode(BRAKE_SW_GPIO, BRAKE_SW_PIN, PAL_MODE_INPUT); diff --git a/hwconf/trampa/sparkf/hw_sparkf_core.c b/hwconf/trampa/sparkf/hw_sparkf_core.c index 0663bf356..6575424ed 100644 --- a/hwconf/trampa/sparkf/hw_sparkf_core.c +++ b/hwconf/trampa/sparkf/hw_sparkf_core.c @@ -126,7 +126,7 @@ void hw_init_gpio(void) { // DAC as voltage reference for shunt amps palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG); RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); - DAC->CR |= DAC_CR_EN1; + DAC->CR |= DAC_CR_EN1 | DAC_CR_BOFF1; DAC->DHR12R1 = 2047; lispif_add_ext_load_callback(load_extensions); diff --git a/hwconf/trampa/str500/hw_str500_core.c b/hwconf/trampa/str500/hw_str500_core.c index 6bb494f8a..cf478ae08 100644 --- a/hwconf/trampa/str500/hw_str500_core.c +++ b/hwconf/trampa/str500/hw_str500_core.c @@ -119,7 +119,7 @@ void hw_init_gpio(void) { // DAC as voltage reference for shunt amps palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG); RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); - DAC->CR |= DAC_CR_EN1; + DAC->CR |= DAC_CR_EN1 | DAC_CR_BOFF1; DAC->DHR12R1 = 2047; } diff --git a/hwconf/trampa/vesc6/hw_60_core.c b/hwconf/trampa/vesc6/hw_60_core.c index edf58096f..12c03565f 100644 --- a/hwconf/trampa/vesc6/hw_60_core.c +++ b/hwconf/trampa/vesc6/hw_60_core.c @@ -149,7 +149,7 @@ void hw_init_gpio(void) { // DAC as voltage reference for shunt amps palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG); RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); - DAC->CR |= DAC_CR_EN1; + DAC->CR |= DAC_CR_EN1 | DAC_CR_BOFF1; DAC->DHR12R1 = 2047; #endif diff --git a/hwconf/trampa/vesc_edu/hw_edu_core.c b/hwconf/trampa/vesc_edu/hw_edu_core.c index 37f830a77..06c75db57 100644 --- a/hwconf/trampa/vesc_edu/hw_edu_core.c +++ b/hwconf/trampa/vesc_edu/hw_edu_core.c @@ -124,7 +124,7 @@ void hw_init_gpio(void) { // DAC as voltage reference for shunt amps palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG); RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); - DAC->CR |= DAC_CR_EN1; + DAC->CR |= DAC_CR_EN1 | DAC_CR_BOFF1; DAC->DHR12R1 = 2047; terminal_register_command_callback( diff --git a/hwconf/trampa/vesc_gp/hw_gp_core.c b/hwconf/trampa/vesc_gp/hw_gp_core.c index f01601f7b..3eb20db54 100644 --- a/hwconf/trampa/vesc_gp/hw_gp_core.c +++ b/hwconf/trampa/vesc_gp/hw_gp_core.c @@ -113,7 +113,7 @@ void hw_init_gpio(void) { // DAC as voltage reference for shunt amps palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG); RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); - DAC->CR |= DAC_CR_EN1; + DAC->CR |= DAC_CR_EN1 | DAC_CR_BOFF1; DAC->DHR12R1 = 2047; } diff --git a/hwconf/vesc/basic/hw_basic_core.c b/hwconf/vesc/basic/hw_basic_core.c index 5c2c334b3..d34c1ff21 100644 --- a/hwconf/vesc/basic/hw_basic_core.c +++ b/hwconf/vesc/basic/hw_basic_core.c @@ -157,7 +157,7 @@ void hw_init_gpio(void) { // DAC as voltage reference for shunt amps palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG); RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); - DAC->CR |= DAC_CR_EN1; + DAC->CR |= DAC_CR_EN1 | DAC_CR_BOFF1; DAC->DHR12R1 = 2047; palSetPadMode(OUT_1_GPIO, OUT_1_PIN, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); diff --git a/hwconf/vesc/str365/hw_str365_core.c b/hwconf/vesc/str365/hw_str365_core.c index f601f4363..9775682cb 100644 --- a/hwconf/vesc/str365/hw_str365_core.c +++ b/hwconf/vesc/str365/hw_str365_core.c @@ -175,12 +175,12 @@ void hw_init_gpio(void) { // DAC as voltage reference for shunt amps palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG); RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); - DAC->CR |= DAC_CR_EN1; + DAC->CR |= DAC_CR_EN1 | DAC_CR_BOFF1; DAC->DHR12R1 = 2047; // Regulator palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG); - DAC->CR |= DAC_CR_EN2; + DAC->CR |= DAC_CR_EN2 | DAC_CR_BOFF2; DAC->DHR12R2 = 4095; REG_OFF();