tune threshold and add weight interpretation
This commit is contained in:
parent
336d4e5bda
commit
81888eb26b
|
@ -29,15 +29,11 @@
|
||||||
#include "main.h" // main definitions
|
#include "main.h" // main definitions
|
||||||
|
|
||||||
/* contants */
|
/* contants */
|
||||||
// max measurement jitter for high and low value
|
// max measurement jitter for high and low value 8/3
|
||||||
#define JITTER_HIGH 8
|
#define JITTER_HIGH 11
|
||||||
#define JITTER_LOW 3
|
#define JITTER_LOW 5
|
||||||
// how many value have to be stable before showing output
|
// how many value have to be stable before showing output
|
||||||
#define MEASUREMENT_STABLE 3
|
#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 */
|
/* variables */
|
||||||
volatile uint8_t state_portD; // the state of port D
|
volatile uint8_t state_portD; // the state of port D
|
||||||
|
@ -204,21 +200,31 @@ int main(void)
|
||||||
zero_high = measurement_high;
|
zero_high = measurement_high;
|
||||||
zero_low = measurement_low;
|
zero_low = measurement_low;
|
||||||
#ifdef DEBUG
|
#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
|
#endif
|
||||||
} else { // prinf measurement weight
|
count_high = count_low = 0;
|
||||||
double weight_high = (int16_t)(zero_high-measurement_high)/COEF_HIGH;
|
} else { // print measurement weight
|
||||||
double weight_low = (int16_t)(measurement_low-zero_low)/COEF_LOW;
|
#ifdef DEBUG
|
||||||
double weight = (weight_high+weight_low)/2;
|
printf("%u %u 0\n", zero_high, zero_low);
|
||||||
printf("%d kg\n", zero_high-measurement_high);
|
printf("%u %u t1\n", measurement_high, measurement_low);
|
||||||
printf("%.2f kg\n", weight);
|
#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_low<orig_low*-1.5 && weight_low>orig_low*1.5) {
|
||||||
|
weight_low = 0;
|
||||||
|
}
|
||||||
|
printf("%.2f kg\n", weight_low);
|
||||||
}
|
}
|
||||||
count_high = count_low = 0;
|
count_high = count_low = 0;
|
||||||
}
|
}
|
||||||
/* display if scale switches off */
|
/* display if scale switches off */
|
||||||
if (scale_old!=scale_on && !scale_on) {
|
if (scale_old!=scale_on && !scale_on) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf(PSTR("scale stop\n"));
|
printf(PSTR("scale stop\n")); // actually measurement is finished and the on switch is released
|
||||||
#endif
|
#endif
|
||||||
scale_old = scale_on; // save new state
|
scale_old = scale_on; // save new state
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue