diff options
-rw-r--r-- | device-functions.c | 26 | ||||
-rw-r--r-- | flash.c | 1 | ||||
-rw-r--r-- | globals.h | 4 |
3 files changed, 26 insertions, 5 deletions
diff --git a/device-functions.c b/device-functions.c index 9f3a086..b6df2af 100644 --- a/device-functions.c +++ b/device-functions.c @@ -65,11 +65,27 @@ static float get_bounded_float (float val_in, float default_val) { // limits returned value within +/- 1 order of magnitude - if (val_in > 10.0 * default_val) { + if (val_in > (10.0 * default_val)) { return default_val; } - if (val_in < default_val / 10.0) { + if (val_in < (default_val / 10.0)) { + return default_val; + } + + return val_in; +} + + +static int get_bounded_int (int val_in, int default_val) +{ + // limits returned value within +/- 1 order of magnitude + + if (val_in > (10 * default_val)) { + return default_val; + } + + if (val_in < (default_val / 10)) { return default_val; } @@ -81,7 +97,7 @@ static float get_float_with_min (float val_in, float default_val) { // limits returned value within +2 / -0 order of magnitude - if (val_in > 100.0 * default_val) { + if (val_in > (100.0 * default_val)) { return default_val; } @@ -3916,7 +3932,9 @@ int go_cal(CalStruct *caldata) caldata->max_change = 0.0; caldata->avg_change = 0.0; - min_val = 40e-6; + min_val = get_bounded_int (globals.Flash.self_cal_min_count, SELF_CAL_MIN_COUNT) / + get_bounded_float (globals.Flash.self_cal_ref_freq, SELF_CAL_REF_FREQ); + if (caldata->cal_type == pwl_period_values) { max_val = 4.0 / globals.Flash.min_freq[caldata->channel]; chk_val = 0.25 / globals.Flash.max_freq[caldata->channel]; @@ -518,6 +518,7 @@ static void initFlashValues(FlashStruct *mem) mem->prf_limiter=1; mem->self_cal_ref_freq = SELF_CAL_REF_FREQ; + mem->self_cal_min_count = SELF_CAL_MIN_COUNT; mem->pcb116c_mon=1; /* more recent ADC, different reading code */ mem->warn_even_if_output_off=0; @@ -231,6 +231,7 @@ // hardware default values #define DEFAULT_OUTPUT_ON_DELAY 0.8 // needs at least 800 ms, due to soft-on circuit #define SELF_CAL_REF_FREQ 1e7 // 10 MHz +#define SELF_CAL_MIN_COUNT 400 // 1 in 400 // menu stuff #define Main_Menu_On 0 @@ -465,8 +466,9 @@ typedef struct { char prf_limiter; /* 243 */ float self_cal_ref_freq; /* 244 */ + short self_cal_min_count; /* 248 */ - char spare_padding[8]; /* 248 - padding between common and per-channel sections of the */ + char spare_padding[6]; /* 250 - padding between common and per-channel sections of the */ /* flash eeprom. Adjust size if variables added to common section, */ /* so that per-channel section starts at 256 */ |