From 9d2cdd1c490e41df56e29adc16442869394c6603 Mon Sep 17 00:00:00 2001 From: Ben Wheeler Date: Tue, 30 Apr 2024 15:59:21 +0100 Subject: [PATCH 1/3] Fix timers for initial conversions in start() --- src/HX711_ADC.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/HX711_ADC.cpp b/src/HX711_ADC.cpp index 26021c2..33ab418 100644 --- a/src/HX711_ADC.cpp +++ b/src/HX711_ADC.cpp @@ -47,8 +47,9 @@ void HX711_ADC::begin(uint8_t gain) void HX711_ADC::start(unsigned long t) { t += 400; + unsigned long startTime = millis(); lastDoutLowTime = millis(); - while(millis() < t) + while(millis() < startTime + t) { update(); yield(); @@ -63,8 +64,9 @@ void HX711_ADC::start(unsigned long t) void HX711_ADC::start(unsigned long t, bool dotare) { t += 400; + unsigned long startTime = millis(); lastDoutLowTime = millis(); - while(millis() < t) + while(millis() < startTime + t) { update(); yield(); From a9df820defb94bde8bc2f0c63e508d7964f50c2e Mon Sep 17 00:00:00 2001 From: Ben Wheeler Date: Mon, 8 Jul 2024 10:06:26 +0100 Subject: [PATCH 2/3] Set SCK_DELAY to 1 as it's claimed this is better for the ESP32. It's not entirely clear whether it helps but it certainly doesn't hurt. --- src/config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.h b/src/config.h index 1ca410a..7210dc3 100644 --- a/src/config.h +++ b/src/config.h @@ -36,7 +36,7 @@ Note that you can also overide (reducing) the number of samples in use at any ti //microsecond delay after writing sck pin high or low. This delay could be required for faster mcu's. //So far the only mcu reported to need this delay is the ESP32 (issue #35), both the Arduino Due and ESP8266 seems to run fine without it. //Change the value to '1' to enable the delay. -#define SCK_DELAY 0 //default value: 0 +#define SCK_DELAY 1 //default value: 0 //if you have some other time consuming (>60μs) interrupt routines that trigger while the sck pin is high, this could unintentionally set the HX711 into "power down" mode //if required you can change the value to '1' to disable interrupts when writing to the sck pin. From e2ec49f3b7630cc09d8daa9409e540ea3c18a92b Mon Sep 17 00:00:00 2001 From: Ben Wheeler Date: Tue, 6 Aug 2024 19:38:56 +0100 Subject: [PATCH 3/3] Disable interrupts during data reads. The HX711 library does this, so it seems like a good idea. --- src/config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.h b/src/config.h index 7210dc3..a8f7af3 100644 --- a/src/config.h +++ b/src/config.h @@ -40,6 +40,6 @@ Note that you can also overide (reducing) the number of samples in use at any ti //if you have some other time consuming (>60μs) interrupt routines that trigger while the sck pin is high, this could unintentionally set the HX711 into "power down" mode //if required you can change the value to '1' to disable interrupts when writing to the sck pin. -#define SCK_DISABLE_INTERRUPTS 0 //default value: 0 +#define SCK_DISABLE_INTERRUPTS 1 //default value: 0 #endif