averaging
This commit is contained in:
parent
cb6ce36a1d
commit
671a9d4439
@ -56,6 +56,7 @@ measurement_input inputs[] = {
|
||||
static spinlock_t adc_res_mutex;
|
||||
volatile unsigned long conv_done_cpt = 0;
|
||||
volatile int meas_res[INPUTS_NUM];
|
||||
volatile int meas_nb[INPUTS_NUM];
|
||||
|
||||
char buff[64];
|
||||
|
||||
@ -80,7 +81,8 @@ static bool IRAM_ATTR on_conv_done(adc_continuous_handle_t handle, const adc_con
|
||||
adc_digi_output_data_t* res = (adc_digi_output_data_t*)edata->conv_frame_buffer;
|
||||
|
||||
int index = get_input_index_from_channel(res->type2.channel);
|
||||
meas_res[index] = res->type2.data;
|
||||
meas_res[index] += res->type2.data;
|
||||
meas_nb[index]++;
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -108,18 +110,22 @@ void app_main(void){
|
||||
ESP_LOGI(TAG, "RANGE : %d", r_ind);
|
||||
|
||||
int meas_res_buff[INPUTS_NUM];
|
||||
int meas_nb_buff[INPUTS_NUM];
|
||||
|
||||
portENTER_CRITICAL(&adc_res_mutex);
|
||||
for(int i = 0; i < INPUTS_NUM; i++){
|
||||
meas_res_buff[i] = meas_res[i];
|
||||
meas_res[i] = 0;
|
||||
|
||||
meas_nb_buff[i] = meas_nb[i];
|
||||
meas_nb[i] = 0;
|
||||
}
|
||||
portEXIT_CRITICAL(&adc_res_mutex);
|
||||
|
||||
for(int i = 0; i < INPUTS_NUM; i++){
|
||||
int mv;
|
||||
ESP_ERROR_CHECK(adc_cali_raw_to_voltage(adc_conv_h[i], meas_res_buff[i], &mv));
|
||||
ESP_LOGI(TAG, "IN %d : %d mV", i, meas_res_buff[i]);
|
||||
ESP_ERROR_CHECK(adc_cali_raw_to_voltage(adc_conv_h[i], meas_res_buff[i]/meas_nb_buff[i], &mv));
|
||||
ESP_LOGI(TAG, "IN %d : %d mV (%d / %d)", i, mv, meas_res_buff[i], meas_nb_buff[i]);
|
||||
}
|
||||
|
||||
//activate_range(ranges, r_ind, R100);
|
||||
|
Loading…
x
Reference in New Issue
Block a user