From 5e5d1b450bd584c84b85b8c204a09fa899416ec3 Mon Sep 17 00:00:00 2001 From: "Michael J. Chudobiak" Date: Tue, 2 Apr 2013 15:07:27 -0400 Subject: implemented basic attenuator range function (but not in cal funcs) --- device-functions.c | 231 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 135 insertions(+), 96 deletions(-) (limited to 'device-functions.c') diff --git a/device-functions.c b/device-functions.c index a590830..2376e5a 100644 --- a/device-functions.c +++ b/device-functions.c @@ -192,7 +192,7 @@ int Set_Amplitude(int check_possible_only,int pol_override,int override_on,int w int switch_range_only,int channel,float new_ampl,int called_from_set_pw) { int word_out; /* what is sent to the DAC */ - int relay_range,old_range,old_actual_pol; /* selects relay range */ + int relay_range,atten_range,old_range,old_actual_pol; /* selects relay range */ int UseNegData; /* if polarity is negative and separate piece-wise linear data is available for neg */ int point_found; int entry; @@ -255,7 +255,7 @@ int Set_Amplitude(int check_possible_only,int pol_override,int override_on,int w /* determine the previous relay range */ Set_VI_Control(pwl_ampl_values,channel,globals.ChannelState[channel].amplitude,&point_found, - &old_range,&UseNegData,&entry,&word_out,&old_actual_pol); + &old_range,&atten_range,&UseNegData,&entry,&word_out,&old_actual_pol); } word_out = -1; @@ -272,7 +272,7 @@ int Set_Amplitude(int check_possible_only,int pol_override,int override_on,int w /* set the amplitude controls now. */ int status; if ((status=Set_VI_Control(pwl_ampl_values,channel,new_ampl,&point_found, - &relay_range,&UseNegData,&entry,&word_out,&actual_pol))) { + &relay_range,&atten_range,&UseNegData,&entry,&word_out,&actual_pol))) { return status; } } @@ -319,6 +319,19 @@ int Set_Amplitude(int check_possible_only,int pol_override,int override_on,int w set_shiftreg_bits(SR_3, POS_13, ONE_BIT, BIT_LOW); /* set O.POL line low to switch pol relay to -, normally */ } + // Are attenuators used? + if (globals.Flash.attenuators[channel][0] > 0.0) { + // deal with attenuator range - haven't done for CH2 yet + + // only implement one attenuator so far (range 0), out of possible max_attens (8!) + if (atten_range == 0) { + set_shiftreg_bits(SR_2, XTR_POS + 5, ONE_BIT, BIT_HIGH); + } else { + set_shiftreg_bits(SR_2, XTR_POS + 5, ONE_BIT, BIT_LOW); + } + } +printf ("\nAMPL %f, range %d, word %d, atten %d\n\n", new_ampl, relay_range, word_out, atten_range); + } else { if (!globals.Flash.ampl_ranges_for_ch2_only) { @@ -368,7 +381,7 @@ int Set_Pw(int check_possible_only,int word_override,int range_override,int chan { int word_out; /* what is sent to the DAC */ int cap_range_control; - int point_found,relay_range,UseNegData,entry; + int point_found,relay_range,dummy,UseNegData,entry; int status,actual_pol; /* abandon if high channel selected by user but not enabled by firmware */ @@ -404,7 +417,7 @@ int Set_Pw(int check_possible_only,int word_override,int range_override,int chan } else { /* set the pw controls now. */ if ((status=Set_VI_Control(pwl_pw_values,channel,set_pw,&point_found, - &relay_range,&UseNegData,&entry,&word_out,&actual_pol))) { + &relay_range,&dummy,&UseNegData,&entry,&word_out,&actual_pol))) { return status; } } @@ -492,7 +505,7 @@ int Set_Pw(int check_possible_only,int word_override,int range_override,int chan /* use CH2 calibration to do this */ if (globals.Flash.is_monocycle[0] && channel==0) { if ((status=Set_VI_Control(pwl_pw_values,1,set_pw,&point_found, - &relay_range,&UseNegData,&entry,&word_out,&actual_pol))) { + &relay_range,&dummy,&UseNegData,&entry,&word_out,&actual_pol))) { return status; } set_dac(globals.Flash.monocycle_dac[0],word_out); @@ -513,7 +526,7 @@ int Set_Offset(int check_possible_only,int override_on,int word_override,int ran { int word_out; /* what is sent to the DAC */ int point_found; - int entry,dummy1,dummy2,dummy3; + int entry,dummy0,dummy1,dummy2,dummy3; int actual_pol; int old_range,relay_range; @@ -541,7 +554,7 @@ int Set_Offset(int check_possible_only,int override_on,int word_override,int ran /* determine the previous relay range */ Set_VI_Control(pwl_os_values,channel,globals.ChannelState[channel].offset,&point_found, - &old_range,&dummy1,&dummy2,&word_out,&dummy3); + &old_range,&dummy0,&dummy1,&dummy2,&word_out,&dummy3); } if (override_on) { @@ -550,7 +563,7 @@ int Set_Offset(int check_possible_only,int override_on,int word_override,int ran } else { int status; if ((status=Set_VI_Control(pwl_os_values,channel,new_offset,&point_found, - &relay_range,&dummy2,&entry,&word_out,&actual_pol))) { + &relay_range,&dummy0,&dummy2,&entry,&word_out,&actual_pol))) { return status; } } @@ -595,7 +608,7 @@ int Set_Offset(int check_possible_only,int override_on,int word_override,int ran int Set_frequency(int check_possible_only,int word_override,int range_override,int channel,float set_freq) { float new_pw; - int point_found,relay_range,UseNegData,entry,actual_pol,old_range; + int point_found,relay_range,UseNegData,entry,actual_pol,old_range,dummy; int word_out; /* what is sent to the DAC */ /* abandon if high channel selected by user but not enabled by firmware */ @@ -626,7 +639,7 @@ int Set_frequency(int check_possible_only,int word_override,int range_override,i /* added Feb 23/05 */ /* determine the previous relay range */ Set_VI_Control(pwl_period_values,channel,1.0/globals.ChannelState[channel].frequency,&point_found, - &old_range,&UseNegData,&entry,&word_out,&actual_pol); + &old_range,&dummy,&UseNegData,&entry,&word_out,&actual_pol); } /* find appropriate range/fine settings from piece-wise linear data in flash memory */ @@ -637,7 +650,7 @@ int Set_frequency(int check_possible_only,int word_override,int range_override,i /* set the amplitude controls now. */ int status; if ((status=Set_VI_Control(pwl_period_values,channel,1.0/set_freq,&point_found, - &relay_range,&UseNegData,&entry,&word_out,&actual_pol))) { + &relay_range,&dummy,&UseNegData,&entry,&word_out,&actual_pol))) { return status; } } @@ -694,7 +707,7 @@ int Set_Delay(int check_possible_only,int word_override,int range_override,int c int word_out; /* what is sent to the DAC */ int cap_range_control; /* what is actually sent to shift register */ float setting; - int point_found,relay_range,UseNegData,entry,actual_pol; + int point_found,relay_range,UseNegData,entry,actual_pol,dummy; /* abandon if high channel selected by user but not enabled by firmware */ if (channel && !globals.Flash.ChanKey_delay) { @@ -743,7 +756,7 @@ int Set_Delay(int check_possible_only,int word_override,int range_override,int c /* set the amplitude controls now. */ int status; if ((status=Set_VI_Control(pwl_delay_values,channel,setting,&point_found, - &relay_range,&UseNegData,&entry,&word_out,&actual_pol))) { + &relay_range,&dummy,&UseNegData,&entry,&word_out,&actual_pol))) { return status; } } @@ -1475,14 +1488,14 @@ int Set_Amp_Calib(int channel,float meas_ampl) { float change_ratio; int i,status; - int point_found,relay_range,UseNegData,entry,word_out,actual_pol; + int point_found,relay_range,UseNegData,entry,word_out,actual_pol,atten_range; int eprom_loc; /* use for all channels */ /* get current range and polarity settings */ Set_VI_Control(pwl_ampl_values,channel,globals.ChannelState[channel].amplitude,&point_found, - &relay_range,&UseNegData,&entry,&word_out,&actual_pol); + &relay_range,&atten_range,&UseNegData,&entry,&word_out,&actual_pol); if (fabs(globals.ChannelState[channel].amplitude)= -1) && !(*point_found);) { - for (entry_i=0; (entry_ismallest_allowed_number) - && - ( ((tweaked_use_ampl>=pwl_amp[index]) && (tweaked_use_ampl<=pwl_amp[index+1])) - || - (decreasing_values_allowed && (tweaked_use_ampl<=pwl_amp[index]) && (tweaked_use_ampl>=pwl_amp[index+1])) /* for OS only */ - ) - ) { - *point_found=1; + if (*atten_range == -1) { + // no valid attenuators + use_atten = 1.0; + } else { + + if (parameter != pwl_ampl_values) { + continue; + } else if (globals.Flash.attenuators[channel][*atten_range] == 0.0) { + continue; + } else { + use_atten = globals.Flash.attenuators[channel][*atten_range]; + } + } + + for (range_i=starting_range; (range_ismallest_allowed_number) + && + ( ((tweaked_use_ampl>=pwl_amp[index]) && (tweaked_use_ampl<=pwl_amp[index+1])) + || + (decreasing_values_allowed && (tweaked_use_ampl<=pwl_amp[index]) && (tweaked_use_ampl>=pwl_amp[index+1])) /* for OS only */ + ) + ) { + *point_found=1; + + if ((parameter==pwl_ampl_values) && globals.Flash.ampl_os_ranges_related[channel]) { + for (i=0; iglobals.Flash.os_pwl_amp[channel][range_i][0][i]) { + min_os_in_range=globals.Flash.os_pwl_amp[channel][range_i][0][i]; + } } - if (min_os_in_range>globals.Flash.os_pwl_amp[channel][range_i][0][i]) { - min_os_in_range=globals.Flash.os_pwl_amp[channel][range_i][0][i]; + if ((globals.ChannelState[channel].offsetmax_os_in_range)) { + *point_found=0; /* try higher range if can't satisfy os and ampl both in this range */ } } - if ((globals.ChannelState[channel].offsetmax_os_in_range)) { - *point_found=0; /* try higher range if can't satisfy os and ampl both in this range */ - } - } - if ((parameter==pwl_os_values) && globals.Flash.ampl_os_ranges_related[channel]) { - for (i=0; iglobals.Flash.ampl_pwl_amp[channel][range_i][*UseNegData][i]) { + min_ampl_in_range=globals.Flash.ampl_pwl_amp[channel][range_i][*UseNegData][i]; + } } - if (min_ampl_in_range>globals.Flash.ampl_pwl_amp[channel][range_i][*UseNegData][i]) { - min_ampl_in_range=globals.Flash.ampl_pwl_amp[channel][range_i][*UseNegData][i]; + if ((fabs(globals.ChannelState[channel].amplitude)max_ampl_in_range)) { + *point_found=0; /* try higher range if can't satisfy os and ampl both in this range */ } } - if ((fabs(globals.ChannelState[channel].amplitude)max_ampl_in_range)) { - *point_found=0; /* try higher range if can't satisfy os and ampl both in this range */ - } - } - fraction = (tweaked_use_ampl-pwl_amp[index]) / (pwl_amp[index] - pwl_amp[index+1]); - *relay_range=range_i; - *entry=entry_i; + fraction = (tweaked_use_ampl-pwl_amp[index]) / (pwl_amp[index] - pwl_amp[index+1]); + *relay_range=range_i; + *entry=entry_i; - /* check for linear voltage-controlled PW */ - if ( (parameter==pwl_pw_values) - && globals.Flash.volt_ctrl_pw[channel] - && (pwl_vc[index] < pwl_vc[index+1])) { - reciprocal_relationship=NO; - } + /* check for linear voltage-controlled PW */ + if ( (parameter==pwl_pw_values) + && globals.Flash.volt_ctrl_pw[channel] + && (pwl_vc[index] < pwl_vc[index+1])) { + reciprocal_relationship=NO; + } - if (reciprocal_relationship) { - inverse_word_out = fraction * (1.0/((float) pwl_vc[index]) - 1.0/((float) pwl_vc[index+1])); - inverse_word_out+=1/((float) pwl_vc[index]); - *word_out=(int) (1.0/inverse_word_out); - } else { - *word_out = (int) ( fraction * (float) (pwl_vc[index] - pwl_vc[index+1]) ); - *word_out+=pwl_vc[index]; + if (reciprocal_relationship) { + inverse_word_out = fraction * (1.0/((float) pwl_vc[index]) - 1.0/((float) pwl_vc[index+1])); + inverse_word_out+=1/((float) pwl_vc[index]); + *word_out=(int) (1.0/inverse_word_out); + } else { + *word_out = (int) ( fraction * (float) (pwl_vc[index] - pwl_vc[index+1]) ); + *word_out+=pwl_vc[index]; + } } } } @@ -2825,7 +2864,7 @@ int Set_VI_Control(int parameter,int channel,float new_ampl,int *point_found,int int Set_VI_Add_Cal(int parameter,int channel,float cal_point) { - int point_found,range,polarity,entry,word_out,total; + int point_found,range,polarity,entry,word_out,total,atten_range; int i; float max_in_range; float least_integrated_error,integrated_error; @@ -2866,7 +2905,7 @@ int Set_VI_Add_Cal(int parameter,int channel,float cal_point) size_of_y_float=sizeof(globals.Flash.ampl_pwl_amp); Set_VI_Control(pwl_ampl_values,channel,globals.ChannelState[channel].amplitude,&point_found, - &range,&polarity,&entry,&word_out,&actual_pol); + &range,&atten_range,&polarity,&entry,&word_out,&actual_pol); old_val=globals.ChannelState[channel].amplitude; abs_cal_point=fabs(cal_point); /* ampl data is positive always */ @@ -2887,7 +2926,7 @@ int Set_VI_Add_Cal(int parameter,int channel,float cal_point) old_val=globals.ChannelState[channel].offset; Set_VI_Control(pwl_os_values,channel,old_val,&point_found, - &range,&polarity,&entry,&word_out,&actual_pol); + &range,&atten_range,&polarity,&entry,&word_out,&actual_pol); break; case pwl_pw_values: max_polarity=timing_polarities; @@ -2898,7 +2937,7 @@ int Set_VI_Add_Cal(int parameter,int channel,float cal_point) size_of_y_float=sizeof(globals.Flash.pw_pwl_time); old_val=globals.ChannelState[channel].pw; Set_VI_Control(pwl_pw_values,channel,old_val,&point_found, - &range,&polarity,&entry,&word_out,&actual_pol); + &range,&atten_range,&polarity,&entry,&word_out,&actual_pol); break; case pwl_delay_values: max_polarity=timing_polarities; @@ -2909,7 +2948,7 @@ int Set_VI_Add_Cal(int parameter,int channel,float cal_point) size_of_y_float=sizeof(globals.Flash.delay_pwl_time); old_val=globals.ChannelState[channel].delay; Set_VI_Control(pwl_delay_values,channel,old_val,&point_found, - &range,&polarity,&entry,&word_out,&actual_pol); + &range,&atten_range,&polarity,&entry,&word_out,&actual_pol); break; case pwl_period_values: max_polarity=timing_polarities; @@ -2920,7 +2959,7 @@ int Set_VI_Add_Cal(int parameter,int channel,float cal_point) size_of_y_float=sizeof(globals.Flash.period_pwl_time); old_val=1.0/globals.ChannelState[channel].frequency; Set_VI_Control(pwl_period_values,channel,old_val,&point_found, - &range,&polarity,&entry,&word_out,&actual_pol); + &range,&atten_range,&polarity,&entry,&word_out,&actual_pol); break; case pwl_burst_values: max_polarity=timing_polarities; @@ -2931,7 +2970,7 @@ int Set_VI_Add_Cal(int parameter,int channel,float cal_point) size_of_y_float=sizeof(globals.Flash.burst_pwl_time); old_val=globals.ChannelState[channel].burst_time; Set_VI_Control(pwl_burst_values,channel,old_val,&point_found, - &range,&polarity,&entry,&word_out,&actual_pol); + &range,&atten_range,&polarity,&entry,&word_out,&actual_pol); break; case pwl_rise_time_values: max_polarity=ampl_polarities; @@ -2942,7 +2981,7 @@ int Set_VI_Add_Cal(int parameter,int channel,float cal_point) size_of_y_float=sizeof(globals.Flash.rise_time_pwl_time); old_val=globals.ChannelState[channel].rise_time; Set_VI_Control(pwl_rise_time_values,channel,old_val,&point_found, - &range,&polarity,&entry,&word_out,&actual_pol); + &range,&atten_range,&polarity,&entry,&word_out,&actual_pol); break; case pwl_slew_values: max_polarity=timing_polarities; @@ -2953,7 +2992,7 @@ int Set_VI_Add_Cal(int parameter,int channel,float cal_point) size_of_y_float=sizeof(globals.Flash.slew_pwl_time); old_val=globals.ChannelState[channel].slew; Set_VI_Control(pwl_slew_values,channel,old_val,&point_found, - &range,&polarity,&entry,&word_out,&actual_pol); + &range,&atten_range,&polarity,&entry,&word_out,&actual_pol); break; case pwl_vcc1_values: max_polarity=1; @@ -2965,7 +3004,7 @@ int Set_VI_Add_Cal(int parameter,int channel,float cal_point) size_of_y_float=sizeof(globals.Flash.vcc1_pwl_amp); old_val=globals.ChannelState[true_channel].vcc1; Set_VI_Control(pwl_vcc1_values,channel,old_val,&point_found, - &range,&polarity,&entry,&word_out,&actual_pol); + &range,&atten_range,&polarity,&entry,&word_out,&actual_pol); break; case pwl_vcc2_values: max_polarity=1; @@ -2977,7 +3016,7 @@ int Set_VI_Add_Cal(int parameter,int channel,float cal_point) size_of_y_float=sizeof(globals.Flash.vcc2_pwl_amp); old_val=globals.ChannelState[true_channel].vcc2; Set_VI_Control(pwl_vcc2_values,channel,old_val,&point_found, - &range,&polarity,&entry,&word_out,&actual_pol); + &range,&atten_range,&polarity,&entry,&word_out,&actual_pol); break; case pwl_load_type_values: max_polarity=load_type_polarities; @@ -2988,7 +3027,7 @@ int Set_VI_Add_Cal(int parameter,int channel,float cal_point) size_of_y_float=sizeof(globals.Flash.load_type_pwl_time); old_val=globals.ChannelState[channel].load_type; Set_VI_Control(pwl_load_type_values,channel,old_val,&point_found, - &range,&polarity,&entry,&word_out,&actual_pol); + &range,&atten_range,&polarity,&entry,&word_out,&actual_pol); break; } @@ -3434,7 +3473,7 @@ int Set_Burst_Count(int channel,int count,float new_burst_time) int Set_Burst_Time(int check_possible_only,int word_override,int range_override,int channel,float new_burst_time) { int count_word_out; - int point_found,relay_range,UseNegData,entry,actual_pol,word_out; + int point_found,relay_range,UseNegData,entry,actual_pol,word_out,dummy; if (globals.Flash.max_burst_count[channel]<=1) { return Unrecognized; @@ -3467,7 +3506,7 @@ int Set_Burst_Time(int check_possible_only,int word_override,int range_override, } else { int status; if ((status=Set_VI_Control(pwl_burst_values,channel,new_burst_time,&point_found, - &relay_range,&UseNegData,&entry,&word_out,&actual_pol))) { + &relay_range,&dummy,&UseNegData,&entry,&word_out,&actual_pol))) { return status; } } @@ -3525,7 +3564,7 @@ int Set_Burst_Time(int check_possible_only,int word_override,int range_override, int Set_rise_time(int check_possible_only,int word_override,int range_override,int channel,float new_rise_time) { - int point_found,relay_range,UseNegData,entry,actual_pol,word_out; + int point_found,relay_range,UseNegData,entry,actual_pol,word_out,dummy; char range_control; if (globals.Flash.fixed_rise_time[channel]) { @@ -3556,7 +3595,7 @@ int Set_rise_time(int check_possible_only,int word_override,int range_override,i } else { int status; if ((status=Set_VI_Control(pwl_rise_time_values,channel,new_rise_time,&point_found, - &relay_range,&UseNegData,&entry,&word_out,&actual_pol))) { + &relay_range,&dummy,&UseNegData,&entry,&word_out,&actual_pol))) { return status; } } @@ -3700,7 +3739,7 @@ int Set_current_limit(int check_possible_only,int channel,float new_adj_current_ int Set_avrq_res(int check_possible_only,int word_override,int range_override,int channel,float new_res) { - int point_found,relay_range,UseNegData,entry,actual_pol,word_out; + int point_found,relay_range,UseNegData,entry,actual_pol,word_out,dummy; if (!globals.Flash.switchable_load[channel]) { return Unrecognized; @@ -3742,7 +3781,7 @@ int Set_avrq_res(int check_possible_only,int word_override,int range_override,in int status; if ((status=Set_VI_Control(pwl_load_type_values,channel,compensated_new_res,&point_found, - &relay_range,&UseNegData,&entry,&word_out,&actual_pol))) { + &relay_range,&dummy,&UseNegData,&entry,&word_out,&actual_pol))) { return status; } } @@ -3775,7 +3814,7 @@ int Set_avrq_res(int check_possible_only,int word_override,int range_override,in int Set_slew(int check_possible_only,int word_override,int range_override,int channel,float new_slew) { int check_valid; - int status,point_found,relay_range,UseNegData,entry,actual_pol,word_out; + int status,point_found,relay_range,UseNegData,entry,actual_pol,word_out,dummy; char range_control; if (!globals.Flash.curr_slew[channel]) { @@ -3805,7 +3844,7 @@ int Set_slew(int check_possible_only,int word_override,int range_override,int ch relay_range=range_override; } else { if ((status=Set_VI_Control(pwl_slew_values,channel,new_slew,&point_found, - &relay_range,&UseNegData,&entry,&word_out,&actual_pol))) { + &relay_range,&dummy,&UseNegData,&entry,&word_out,&actual_pol))) { return status; } } @@ -3852,7 +3891,7 @@ int Set_slew(int check_possible_only,int word_override,int range_override,int ch int Set_avrq_ampl(int check_possible_only,int word_override,int range_override,int channel,float new_avrq_ampl) { int check_valid; - int status,point_found,relay_range,UseNegData,entry,actual_pol,word_out; + int status,point_found,relay_range,UseNegData,entry,actual_pol,word_out,dummy; int true_channel; int use_pwl; @@ -3923,7 +3962,7 @@ int Set_avrq_ampl(int check_possible_only,int word_override,int range_override,i } if (use_pwl != pwl_vlogic_values) - if ((status=Set_VI_Control(use_pwl,channel,new_avrq_ampl,&point_found,&relay_range,&UseNegData,&entry,&word_out,&actual_pol))) { + if ((status=Set_VI_Control(use_pwl,channel,new_avrq_ampl,&point_found,&relay_range,&dummy,&UseNegData,&entry,&word_out,&actual_pol))) { return status; } -- cgit