From 1fe9cd085b8e2c476434b80bbb8a6004dc42e14a Mon Sep 17 00:00:00 2001 From: Mike Date: Sat, 1 Jan 2000 00:14:30 +0900 Subject: calculate freq-based limits and errors in all modes, not just internal trigger mode --- error_utils.c | 338 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 161 insertions(+), 177 deletions(-) diff --git a/error_utils.c b/error_utils.c index 54073d5..5985442 100644 --- a/error_utils.c +++ b/error_utils.c @@ -837,122 +837,117 @@ int Error_check(ChannelStruct ChannelStateToTest[max_channels]) } - if (ChannelStateToTest[i].trigger_source==source_internal) { + /* --- check minimum frequency --- */ + globals.Constraints.err_min_freq[i]=globals.Flash.min_freq[i]; - /* --- check minimum frequency --- */ - globals.Constraints.err_min_freq[i]=globals.Flash.min_freq[i]; - - if (ChannelStateToTest[i].frequency<(0.999*globals.Constraints.err_min_freq[i])) { - report_error=freq_lower_limit; - } - /* ------------------------------- */ + if (ChannelStateToTest[i].frequency<(0.999*globals.Constraints.err_min_freq[i])) { + report_error=freq_lower_limit; + } + /* ------------------------------- */ - /* --- check maximum frequency --- */ - globals.Constraints.err_max_freq[i]=globals.Flash.max_freq[i]; + /* --- check maximum frequency --- */ + globals.Constraints.err_max_freq[i]=globals.Flash.max_freq[i]; - if (ChannelStateToTest[i].frequency>(1.001*globals.Constraints.err_max_freq[i])) { - report_error=freq_upper_limit; - } + if (ChannelStateToTest[i].frequency>(1.001*globals.Constraints.err_max_freq[i])) { + report_error=freq_upper_limit; + } - if ( (globals.Flash.max_freq_for_high_ot[i] > 0.0) && - (fabs(ChannelStateToTest[i].offset) > globals.Flash.high_ot[i])) { + if ( (globals.Flash.max_freq_for_high_ot[i] > 0.0) && + (fabs(ChannelStateToTest[i].offset) > globals.Flash.high_ot[i])) { - temp = globals.Flash.max_freq_for_high_ot[i]; - if (temp(1.001*globals.Constraints.err_max_freq[i])) { - report_error=PRF_limited_by_offset; - } - } + temp = globals.Flash.max_freq_for_high_ot[i]; + if (temp(1.001*globals.Constraints.err_max_freq[i])) { + report_error=PRF_limited_by_offset; + } + } + } + if (fabs(ChannelStateToTest[i].delay)>1.0e-15) { + temp=0.95/fabs(ChannelStateToTest[i].delay); + if (temp(1.001*globals.Constraints.err_max_freq[i])) { + report_error=Delay_Exceeds_95Period; + } } + } - if (fabs(ChannelStateToTest[i].delay)>1.0e-15) { - temp=0.95/fabs(ChannelStateToTest[i].delay); - if (temp(1.001*globals.Constraints.err_max_freq[i])) { - report_error=Delay_Exceeds_95Period; - } + if (globals.Flash.min_pw[i] > 0.0) { + temp=1/ChannelStateToTest[i].pw; + if (temp(1.001*globals.Constraints.err_max_freq[i])) { + report_error=PW_Exceeds_Period; } } - if (globals.Flash.min_pw[i] > 0.0) { - temp=1/ChannelStateToTest[i].pw; + if ( (ChannelStateToTest[i].burst_count>1) + && (globals.Flash.max_burst_count[i]>1) + && !globals.Flash.burst_func[i]) { + temp=1/(ChannelStateToTest[i].burst_count * (ChannelStateToTest[i].pw+ChannelStateToTest[i].burst_time)); if (temp(1.001*globals.Constraints.err_max_freq[i])) { - report_error=PW_Exceeds_Period; + report_error=Burst_Exceeds_Period; } } + } - if ( (ChannelStateToTest[i].burst_count>1) - && (globals.Flash.max_burst_count[i]>1) - && !globals.Flash.burst_func[i]) { - temp=1/(ChannelStateToTest[i].burst_count * (ChannelStateToTest[i].pw+ChannelStateToTest[i].burst_time)); - if (temp(1.001*globals.Constraints.err_max_freq[i])) { - report_error=Burst_Exceeds_Period; - } - } + temp=(1/ChannelStateToTest[i].pw)*(ampl_fixed_max_duty/duty_scale); + if (temp(1.001*globals.Constraints.err_max_freq[i])) { + report_error=duty_cycle_upper_limit; } + } - temp=(1/ChannelStateToTest[i].pw)*(ampl_fixed_max_duty/duty_scale); + if (ChannelStateToTest[i].double_pulse==double_on) { + // pulse sep must be less than one half-period + temp = 0.5 / ChannelStateToTest[i].delay; if (temp(1.001*globals.Constraints.err_max_freq[i])) { - report_error=duty_cycle_upper_limit; - } - } - - if (ChannelStateToTest[i].double_pulse==double_on) { - // pulse sep must be less than one half-period - temp = 0.5 / ChannelStateToTest[i].delay; - if (temp(1.001*globals.Constraints.err_max_freq[i])) { - report_error=Double_Separation_Too_Large; - } + report_error=Double_Separation_Too_Large; } } + } - if ((globals.Flash.max_avg_ampl[i]) > 0.0 && (fabs(ChannelStateToTest[i].amplitude)) > 0.0) { - temp=100.0 * globals.Flash.max_avg_ampl[i] / - (fabs(ChannelStateToTest[i].amplitude) * ChannelStateToTest[i].pw * duty_scale); - if (temp(1.001*globals.Constraints.err_max_freq[i])) { - report_error=Average_Amplitude_Too_High; - } + if ((globals.Flash.max_avg_ampl[i]) > 0.0 && (fabs(ChannelStateToTest[i].amplitude)) > 0.0) { + temp=100.0 * globals.Flash.max_avg_ampl[i] / + (fabs(ChannelStateToTest[i].amplitude) * ChannelStateToTest[i].pw * duty_scale); + if (temp(1.001*globals.Constraints.err_max_freq[i])) { + report_error=Average_Amplitude_Too_High; } } + } - if ((globals.Flash.hvps_avg_curr_limit[i] > 0.0) && (fabs(ChannelStateToTest[i].amplitude) > 0.0) && (ChannelStateToTest[i].pw > 0.0)) { - temp=(100.0 / duty_scale) * globals.Flash.hvps_avg_curr_limit[i] * ChannelStateToTest[i].load_type / - (fabs(ChannelStateToTest[i].amplitude) * ChannelStateToTest[i].pw); - if (temp(1.001*globals.Constraints.err_max_freq[i])) { - report_error=HVPS_Current_Too_High; - } + if ((globals.Flash.hvps_avg_curr_limit[i] > 0.0) && (fabs(ChannelStateToTest[i].amplitude) > 0.0) && (ChannelStateToTest[i].pw > 0.0)) { + temp=(100.0 / duty_scale) * globals.Flash.hvps_avg_curr_limit[i] * ChannelStateToTest[i].load_type / + (fabs(ChannelStateToTest[i].amplitude) * ChannelStateToTest[i].pw); + if (temp(1.001*globals.Constraints.err_max_freq[i])) { + report_error=HVPS_Current_Too_High; } } + } - if (globals.Flash.max_avg_power[i] > 0.0) { - temp = (globals.Flash.max_avg_power[i] * ChannelStateToTest[i].load_type) / (ChannelStateToTest[i].amplitude * ChannelStateToTest[i].amplitude * ChannelStateToTest[i].pw); - if (temp < globals.Constraints.err_max_freq[i]) { - globals.Constraints.err_max_freq[i] = temp; - if (ChannelStateToTest[i].frequency>(1.001*globals.Constraints.err_max_freq[i])) { - report_error=average_power_limit; - } + if (globals.Flash.max_avg_power[i] > 0.0) { + temp = (globals.Flash.max_avg_power[i] * ChannelStateToTest[i].load_type) / (ChannelStateToTest[i].amplitude * ChannelStateToTest[i].amplitude * ChannelStateToTest[i].pw); + if (temp < globals.Constraints.err_max_freq[i]) { + globals.Constraints.err_max_freq[i] = temp; + if (ChannelStateToTest[i].frequency>(1.001*globals.Constraints.err_max_freq[i])) { + report_error=average_power_limit; } } - } - - /* ------------------------------- */ } + /* ------------------------------- */ + /* --- check minimum pulse width --- */ globals.Constraints.err_min_pw[i]=globals.Flash.min_pw[i]; @@ -1001,78 +996,74 @@ int Error_check(ChannelStruct ChannelStateToTest[max_channels]) } } - if (ChannelStateToTest[i].trigger_source==source_internal) { + temp=(1/ChannelStateToTest[i].frequency) - globals.Flash.dead_time[i]; + if (temp(1.001*globals.Constraints.err_max_pw[i])) { + report_error=Dead_Time_Error; + } + } - temp=(1/ChannelStateToTest[i].frequency) - globals.Flash.dead_time[i]; - if (temp(1.001*globals.Constraints.err_max_pw[i])) { - report_error=Dead_Time_Error; - } + temp=1/ChannelStateToTest[i].frequency; + if (temp(1.001*globals.Constraints.err_max_pw[i])) { + report_error=PW_Exceeds_Period; } + } - temp=1/ChannelStateToTest[i].frequency; + if ( (ChannelStateToTest[i].burst_count>1) + && (globals.Flash.max_burst_count[i]>1) + && !globals.Flash.burst_func[i]) { + temp=(1/ChannelStateToTest[i].frequency)/ChannelStateToTest[i].burst_count - ChannelStateToTest[i].burst_time; if (temp(1.001*globals.Constraints.err_max_pw[i])) { - report_error=PW_Exceeds_Period; + report_error=Burst_Exceeds_Period; } } + } - if ( (ChannelStateToTest[i].burst_count>1) - && (globals.Flash.max_burst_count[i]>1) - && !globals.Flash.burst_func[i]) { - temp=(1/ChannelStateToTest[i].frequency)/ChannelStateToTest[i].burst_count - ChannelStateToTest[i].burst_time; - if (temp(1.001*globals.Constraints.err_max_pw[i])) { - report_error=Burst_Exceeds_Period; - } - } + temp=(1/ChannelStateToTest[i].frequency)*(ampl_fixed_max_duty/duty_scale); + if (temp(1.001*globals.Constraints.err_max_pw[i])) { + report_error=duty_cycle_upper_limit; } + } - temp=(1/ChannelStateToTest[i].frequency)*(ampl_fixed_max_duty/duty_scale); + if ((globals.Flash.max_avg_ampl[i]) > 0.0 && (fabs(ChannelStateToTest[i].amplitude)) > 0.0) { + temp=100.0 * globals.Flash.max_avg_ampl[i] / + (fabs(ChannelStateToTest[i].amplitude) * ChannelStateToTest[i].frequency * duty_scale); if (temp(1.001*globals.Constraints.err_max_pw[i])) { - report_error=duty_cycle_upper_limit; - } - } - - if ((globals.Flash.max_avg_ampl[i]) > 0.0 && (fabs(ChannelStateToTest[i].amplitude)) > 0.0) { - temp=100.0 * globals.Flash.max_avg_ampl[i] / - (fabs(ChannelStateToTest[i].amplitude) * ChannelStateToTest[i].frequency * duty_scale); - if (temp(1.001*globals.Constraints.err_max_pw[i])) { - report_error=Average_Amplitude_Too_High; - } + report_error=Average_Amplitude_Too_High; } } + } - if ((globals.Flash.hvps_avg_curr_limit[i] > 0.0) && (fabs(ChannelStateToTest[i].amplitude) > 0.0) && (ChannelStateToTest[i].frequency > 0.0)) { - temp=(100.0 / duty_scale) * globals.Flash.hvps_avg_curr_limit[i] * ChannelStateToTest[i].load_type / - (fabs(ChannelStateToTest[i].amplitude) * ChannelStateToTest[i].frequency); - if (temp(1.001*globals.Constraints.err_max_pw[i])) { - report_error=HVPS_Current_Too_High; - } + if ((globals.Flash.hvps_avg_curr_limit[i] > 0.0) && (fabs(ChannelStateToTest[i].amplitude) > 0.0) && (ChannelStateToTest[i].frequency > 0.0)) { + temp=(100.0 / duty_scale) * globals.Flash.hvps_avg_curr_limit[i] * ChannelStateToTest[i].load_type / + (fabs(ChannelStateToTest[i].amplitude) * ChannelStateToTest[i].frequency); + if (temp(1.001*globals.Constraints.err_max_pw[i])) { + report_error=HVPS_Current_Too_High; } } + } - - if (globals.Flash.max_avg_power[i] > 0.0) { - temp = globals.Flash.max_avg_power[i] * ChannelStateToTest[i].load_type / (ChannelStateToTest[i].amplitude * ChannelStateToTest[i].amplitude * ChannelStateToTest[i].frequency); - if (temp < globals.Constraints.err_max_pw[i]) { - globals.Constraints.err_max_pw[i] = temp; - if (ChannelStateToTest[i].pw>(1.001*globals.Constraints.err_max_pw[i])) { - report_error=average_power_limit; - } + if (globals.Flash.max_avg_power[i] > 0.0) { + temp = globals.Flash.max_avg_power[i] * ChannelStateToTest[i].load_type / (ChannelStateToTest[i].amplitude * ChannelStateToTest[i].amplitude * ChannelStateToTest[i].frequency); + if (temp < globals.Constraints.err_max_pw[i]) { + globals.Constraints.err_max_pw[i] = temp; + if (ChannelStateToTest[i].pw>(1.001*globals.Constraints.err_max_pw[i])) { + report_error=average_power_limit; } } - } + /* ------------------------------- */ /* --- check minimum delay ------- */ @@ -1096,14 +1087,12 @@ int Error_check(ChannelStruct ChannelStateToTest[max_channels]) report_error=delay_lower_limit; } - if (ChannelStateToTest[i].trigger_source==source_internal) { - temp=-0.95/ChannelStateToTest[i].frequency; - if (temp>globals.Constraints.err_min_delay[i]) { - globals.Constraints.err_min_delay[i]=temp; - if ( (globals.Constraints.err_min_delay[i]>=0.0 && ChannelStateToTest[i].delay<(0.999*globals.Constraints.err_min_delay[i])) - || (globals.Constraints.err_min_delay[i]<0.0 && ChannelStateToTest[i].delay<(1.001*globals.Constraints.err_min_delay[i])) ) { - report_error=Delay_Exceeds_95Period; - } + temp=-0.95/ChannelStateToTest[i].frequency; + if (temp>globals.Constraints.err_min_delay[i]) { + globals.Constraints.err_min_delay[i]=temp; + if ( (globals.Constraints.err_min_delay[i]>=0.0 && ChannelStateToTest[i].delay<(0.999*globals.Constraints.err_min_delay[i])) + || (globals.Constraints.err_min_delay[i]<0.0 && ChannelStateToTest[i].delay<(1.001*globals.Constraints.err_min_delay[i])) ) { + report_error=Delay_Exceeds_95Period; } } @@ -1136,25 +1125,23 @@ int Error_check(ChannelStruct ChannelStateToTest[max_channels]) report_error=delay_upper_limit; } - if (ChannelStateToTest[i].trigger_source==source_internal) { - temp=0.95/ChannelStateToTest[i].frequency; + temp=0.95/ChannelStateToTest[i].frequency; + if (temp=0.0 && ChannelStateToTest[i].delay>(1.001*globals.Constraints.err_max_delay[i])) + || (globals.Constraints.err_max_delay[i]<0.0 && ChannelStateToTest[i].delay>(0.999*globals.Constraints.err_max_delay[i])) ) { + report_error=Delay_Exceeds_95Period; + } + } + + if (ChannelStateToTest[i].double_pulse==double_on) { + // one half-period + temp = 0.5 / ChannelStateToTest[i].frequency; if (temp=0.0 && ChannelStateToTest[i].delay>(1.001*globals.Constraints.err_max_delay[i])) || (globals.Constraints.err_max_delay[i]<0.0 && ChannelStateToTest[i].delay>(0.999*globals.Constraints.err_max_delay[i])) ) { - report_error=Delay_Exceeds_95Period; - } - } - - if (ChannelStateToTest[i].double_pulse==double_on) { - // one half-period - temp = 0.5 / ChannelStateToTest[i].frequency; - if (temp=0.0 && ChannelStateToTest[i].delay>(1.001*globals.Constraints.err_max_delay[i])) - || (globals.Constraints.err_max_delay[i]<0.0 && ChannelStateToTest[i].delay>(0.999*globals.Constraints.err_max_delay[i])) ) { - report_error=Double_Separation_Too_Large; - } + report_error=Double_Separation_Too_Large; } } } @@ -1231,6 +1218,7 @@ int Error_check(ChannelStruct ChannelStateToTest[max_channels]) } temp = sqrt(globals.Flash.max_peak_power[i] * ChannelStateToTest[i].load_type); + // FIXME? if ((temp > 0.0) && (temp < globals.Constraints.err_max_ampl[i])) { globals.Constraints.err_max_ampl[i] = temp; if (-temp > globals.Constraints.err_min_ampl[i]) { @@ -1242,22 +1230,20 @@ int Error_check(ChannelStruct ChannelStateToTest[max_channels]) } } - if (ChannelStateToTest[i].trigger_source==source_internal) { - if (globals.Flash.max_avg_power[i] > 0.0) { - temp = sqrt(globals.Flash.max_avg_power[i] * ChannelStateToTest[i].load_type / (ChannelStateToTest[i].pw * ChannelStateToTest[i].frequency)); - // temp is positive at this point - if (temp < globals.Constraints.err_max_ampl[i]) { - globals.Constraints.err_max_ampl[i]=temp; - if (ChannelStateToTest[i].amplitude>(1.001*globals.Constraints.err_max_ampl[i])) { - report_error=average_power_limit; - } + if (globals.Flash.max_avg_power[i] > 0.0) { + temp = sqrt(globals.Flash.max_avg_power[i] * ChannelStateToTest[i].load_type / (ChannelStateToTest[i].pw * ChannelStateToTest[i].frequency)); + // temp is positive at this point + if (temp < globals.Constraints.err_max_ampl[i]) { + globals.Constraints.err_max_ampl[i]=temp; + if (ChannelStateToTest[i].amplitude>(1.001*globals.Constraints.err_max_ampl[i])) { + report_error=average_power_limit; } - temp = temp * -1.0; // check negative possibility - if (temp > globals.Constraints.err_min_ampl[i]) { - globals.Constraints.err_min_ampl[i]=temp; - if (ChannelStateToTest[i].amplitude<(1.001*globals.Constraints.err_min_ampl[i])) { - report_error=average_power_limit; - } + } + temp = temp * -1.0; // check negative possibility + if (temp > globals.Constraints.err_min_ampl[i]) { + globals.Constraints.err_min_ampl[i]=temp; + if (ChannelStateToTest[i].amplitude<(1.001*globals.Constraints.err_min_ampl[i])) { + report_error=average_power_limit; } } } @@ -1563,7 +1549,7 @@ int Error_check(ChannelStruct ChannelStateToTest[max_channels]) if (globals.Flash.switchable_load[i]) { globals.Constraints.err_min_load_type[i]=globals.Flash.low_load_type[i]; - if ((ChannelStateToTest[i].trigger_source==source_internal) && (duty_cycle > max_duty_this_ampl)) { + if (duty_cycle > max_duty_this_ampl) { globals.Constraints.err_min_load_type[i] *= duty_cycle / max_duty_this_ampl; } if (ChannelStateToTest[i].load_type<(0.999*globals.Constraints.err_min_load_type[i])) { @@ -1601,14 +1587,12 @@ int Error_check(ChannelStruct ChannelStateToTest[max_channels]) } } - if (ChannelStateToTest[i].trigger_source==source_internal) { - if (globals.Flash.max_avg_power[i] > 0.0) { - temp = (ChannelStateToTest[i].amplitude * ChannelStateToTest[i].amplitude * ChannelStateToTest[i].pw * ChannelStateToTest[i].frequency) / globals.Flash.max_avg_power[i]; - if (temp > globals.Constraints.err_min_load_type[i]) { - globals.Constraints.err_min_load_type[i] = temp; - if (ChannelStateToTest[i].load_type<(0.999*globals.Constraints.err_min_load_type[i])) { - report_error=average_power_limit; - } + if (globals.Flash.max_avg_power[i] > 0.0) { + temp = (ChannelStateToTest[i].amplitude * ChannelStateToTest[i].amplitude * ChannelStateToTest[i].pw * ChannelStateToTest[i].frequency) / globals.Flash.max_avg_power[i]; + if (temp > globals.Constraints.err_min_load_type[i]) { + globals.Constraints.err_min_load_type[i] = temp; + if (ChannelStateToTest[i].load_type<(0.999*globals.Constraints.err_min_load_type[i])) { + report_error=average_power_limit; } } } -- cgit