From 81888eb26b1ba44b89b0307e4a37907eb4a547b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Wed, 28 Jan 2015 19:36:00 +0100 Subject: [PATCH] tune threshold and add weight interpretation --- firmware/main.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/firmware/main.c b/firmware/main.c index e31842a..1c44871 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -29,15 +29,11 @@ #include "main.h" // main definitions /* contants */ -// max measurement jitter for high and low value -#define JITTER_HIGH 8 -#define JITTER_LOW 3 +// max measurement jitter for high and low value 8/3 +#define JITTER_HIGH 11 +#define JITTER_LOW 5 // how many value have to be stable before showing output #define MEASUREMENT_STABLE 3 -// weight coefficient (timer 1 ticks/kg) -// proportionally decreasing for high, increasing for low -#define COEF_HIGH 41.78 -#define COEF_LOW 39.87 /* variables */ volatile uint8_t state_portD; // the state of port D @@ -204,21 +200,31 @@ int main(void) zero_high = measurement_high; zero_low = measurement_low; #ifdef DEBUG - printf("zero values high/low: %u/%u\n", zero_high, zero_low); + printf("zero values high low: %u %u\n", zero_high, zero_low); #endif - } else { // prinf measurement weight - double weight_high = (int16_t)(zero_high-measurement_high)/COEF_HIGH; - double weight_low = (int16_t)(measurement_low-zero_low)/COEF_LOW; - double weight = (weight_high+weight_low)/2; - printf("%d kg\n", zero_high-measurement_high); - printf("%.2f kg\n", weight); + count_high = count_low = 0; + } else { // print measurement weight +#ifdef DEBUG + printf("%u %u 0\n", zero_high, zero_low); + printf("%u %u t1\n", measurement_high, measurement_low); +#endif + + // the low measurement are linear and more stable + // normally it should not have a origin, but the linear estimation shows one and it works better + const double orig_low = -1.92285; + const double coef_low = 0.0258119; + double weight_low = (int16_t)(measurement_low-zero_low)*coef_low+orig_low; + if (weight_loworig_low*1.5) { + weight_low = 0; + } + printf("%.2f kg\n", weight_low); } count_high = count_low = 0; } /* display if scale switches off */ if (scale_old!=scale_on && !scale_on) { #ifdef DEBUG - printf(PSTR("scale stop\n")); + printf(PSTR("scale stop\n")); // actually measurement is finished and the on switch is released #endif scale_old = scale_on; // save new state }