Use average temperature over 16 samples
This commit is contained in:
parent
c2e823dfb5
commit
ebd47ee2c5
@ -63,6 +63,8 @@ struct input {
|
|||||||
enum logic btn[MAX_BTN];
|
enum logic btn[MAX_BTN];
|
||||||
} g_in;
|
} g_in;
|
||||||
|
|
||||||
|
#define MAX_SAMPLES 16
|
||||||
|
|
||||||
struct state {
|
struct state {
|
||||||
enum machine_state mstate;
|
enum machine_state mstate;
|
||||||
unsigned long brewing_t0;
|
unsigned long brewing_t0;
|
||||||
@ -70,8 +72,11 @@ struct state {
|
|||||||
unsigned long heating_t0;
|
unsigned long heating_t0;
|
||||||
unsigned long hot_t0;
|
unsigned long hot_t0;
|
||||||
|
|
||||||
|
int ntc_i; /* Next available place */
|
||||||
float ntc_R;
|
float ntc_R;
|
||||||
float ntc_T;
|
float ntc_last_T;
|
||||||
|
float ntc_array_T[MAX_SAMPLES];
|
||||||
|
float ntc_T; /* average */
|
||||||
|
|
||||||
struct btn btn[MAX_BTN];
|
struct btn btn[MAX_BTN];
|
||||||
enum buzz_state buzz_state;
|
enum buzz_state buzz_state;
|
||||||
@ -114,7 +119,16 @@ void do_input(struct input *input)
|
|||||||
void proc_ntc(struct state *state, const struct input *input)
|
void proc_ntc(struct state *state, const struct input *input)
|
||||||
{
|
{
|
||||||
state->ntc_R = ntc_resistance(input->ntc_V);
|
state->ntc_R = ntc_resistance(input->ntc_V);
|
||||||
state->ntc_T = ntc_temp(state->ntc_R);
|
state->ntc_last_T = ntc_temp(state->ntc_R);
|
||||||
|
state->ntc_array_T[state->ntc_i++] = state->ntc_last_T;
|
||||||
|
if (state->ntc_i >= MAX_SAMPLES)
|
||||||
|
state->ntc_i = 0;
|
||||||
|
|
||||||
|
float avg = 0;
|
||||||
|
for (int i = 0; i < MAX_SAMPLES; i++)
|
||||||
|
avg += state->ntc_array_T[i];
|
||||||
|
|
||||||
|
state->ntc_T = avg / MAX_SAMPLES;
|
||||||
}
|
}
|
||||||
|
|
||||||
void proc_buttons(struct state *state, const struct input *input)
|
void proc_buttons(struct state *state, const struct input *input)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user