fixed_t adc_to_volt(uint16_t adc, calibrate_t *cal) { uint32_t tmp; tmp = adc * cal->a; if (tmp > cal->b) tmp -= cal->b; else tmp = 0; return fixed_round(tmp); }
void temp_handler(void) { temp_samples[sample++] = make_fixed(raw_temp); if (sample == N_SAMPLES) { fixed_t t = make_fixed(0); for (uint8_t i = 0; i < N_SAMPLES; i++) { t = fixed_add(t, temp_samples[i]); } temp = fixed_round(fixed_div(fixed_div(t, N_SAMPLES), 4)); set_number(0, temp, relay_on); sample = 0; } }