diff options
author | Mike <mjc@avtechpulse.com> | 2000-01-01 01:22:35 +0900 |
---|---|---|
committer | Mike <mjc@avtechpulse.com> | 2000-01-01 01:22:35 +0900 |
commit | 608cc506418375737ba53d520fabf905c19ca672 (patch) | |
tree | dab454adf6f386531ff26bfcec286ee63c5c3ad8 /monitor.c | |
parent | 37097b33a4f0dbbf8d3b48d37416e6bec8b6b79e (diff) |
better monitor averaging (for AVO-8E3 S/N 13790) with auto-reset of average
Diffstat (limited to 'monitor.c')
-rw-r--r-- | monitor.c | 38 |
1 files changed, 27 insertions, 11 deletions
@@ -155,7 +155,7 @@ int I2C_Get_Monitor_Word(int channel) int I2C_Check_Monitors(void) { int monitor_word; - float step_size; + float new_val, avg_val, step_size; int channel; int ampl_range,point_found,UseNegData,entry,word_out,atten_range; @@ -198,16 +198,34 @@ int I2C_Check_Monitors(void) &l_range,&atten_range,&UseNegData,&entry,&word_out,&actual_pol,NULL); /* 5.0V is the full-scale voltage of the 12bit ADC */ - globals.ChannelState[channel].Curr_Mon_value=((((float) monitor_word)/4095.0) * 5.0) + new_val = ((((float) monitor_word)/4095.0) * 5.0) / globals.Flash.mon_vi_ratio[channel][ampl_range][use_neg_data]; - /* convert to even step size */ + /* averaging */ + for (i=CURR_MON_MAX_OLD_COUNTS-1;i>0;i--) { + globals.ChannelState[channel].old_mon_vals[i]=globals.ChannelState[channel].old_mon_vals[i-1]; + } + globals.ChannelState[channel].old_mon_vals[0] = new_val; + + if (globals.ChannelState[channel].num_mon_vals<CURR_MON_MAX_OLD_COUNTS) { + ++globals.ChannelState[channel].num_mon_vals; + } + + avg_val = 0.0; + for (i=0;i<globals.ChannelState[channel].num_mon_vals;i++) { + avg_val += globals.ChannelState[channel].old_mon_vals[i] / globals.ChannelState[channel].num_mon_vals; + } + step_size=globals.Flash.monitor_step[channel]; - globals.ChannelState[channel].Curr_Mon_value= - ((float) - ((long) (globals.ChannelState[channel].Curr_Mon_value/step_size)) - ) - * step_size; + + /* reset average if change is bigger than MAX_STEP_DEV_FROM_AVG steps */ + if (fabs((new_val-avg_val)/step_size) > MAX_STEP_DEV_FROM_AVG) { + globals.ChannelState[channel].num_mon_vals = 1; + avg_val = new_val; + } + + /* convert to even step size */ + globals.ChannelState[channel].Curr_Mon_value= ((float) ((long) (avg_val/step_size)) ) * step_size; /* AVO-8D2: check for duty cycle problems, as a function of measured amplitude */ if ( globals.Flash.hard_current_limit_enabled[channel] && @@ -230,9 +248,7 @@ int I2C_Check_Monitors(void) } else if (globals.MenuStatus.Type_Of_Menu==Main_Menu_On && !globals.MenuStatus.Error_Screen && !globals.MenuStatus.Nonstd_Display && - globals.ChannelState[channel].Curr_Mon_value!=globals.ChannelState[channel].displayed_mon_val && - (seconds_since_last > 0)) - /* only update display once a second */ + globals.ChannelState[channel].Curr_Mon_value!=globals.ChannelState[channel].displayed_mon_val) { ++update_display; } |