adccmds: Add support for min/max temperature check filtering

Extend the ADC out of range check so that it is possible to sample
multiple times before going into a shutdown state.  This reduces the
chance that measurement noise will cause an error.  In an actual over
temperature (or under temperature event) it is expected that the
sensor will consistently report the problem, so extra checks for an
additional second or two should not substantially increase risk.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-07-02 13:47:22 -04:00
parent 5b3444c060
commit 0dbfa915de
4 changed files with 25 additions and 9 deletions

View file

@ -15,6 +15,7 @@ struct analog_in {
uint32_t rest_time, sample_time, next_begin_time;
uint16_t value, min_value, max_value;
struct gpio_adc pin;
uint8_t invalid_count, range_check_count;
uint8_t state, sample_count;
};
@ -42,8 +43,15 @@ analog_in_event(struct timer *timer)
a->timer.waketime += a->sample_time;
return SF_RESCHEDULE;
}
if (a->value < a->min_value || a->value > a->max_value)
try_shutdown("ADC out of range");
if (likely(a->value >= a->min_value && a->value <= a->max_value)) {
a->invalid_count = 0;
} else {
a->invalid_count++;
if (a->invalid_count >= a->range_check_count) {
try_shutdown("ADC out of range");
a->invalid_count = 0;
}
}
sched_wake_task(&analog_wake);
a->next_begin_time += a->rest_time;
a->timer.waketime = a->next_begin_time;
@ -75,13 +83,14 @@ command_query_analog_in(uint32_t *args)
a->rest_time = args[4];
a->min_value = args[5];
a->max_value = args[6];
a->range_check_count = args[7];
if (! a->sample_count)
return;
sched_add_timer(&a->timer);
}
DECL_COMMAND(command_query_analog_in,
"query_analog_in oid=%c clock=%u sample_ticks=%u sample_count=%c"
" rest_ticks=%u min_value=%hu max_value=%hu");
" rest_ticks=%u min_value=%hu max_value=%hu range_check_count=%c");
void
analog_in_task(void)