summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael J. Chudobiak <mjc@avtechpulse.com>2013-04-02 15:07:27 -0400
committerMichael J. Chudobiak <mjc@avtechpulse.com>2013-04-02 15:07:27 -0400
commit5e5d1b450bd584c84b85b8c204a09fa899416ec3 (patch)
treef31525b577e872e38e717b562e00de9f7faa3d8f
parent1a9a1de2b2635e67998ad5a07ed0e4dbb5cbe474 (diff)
implemented basic attenuator range function (but not in cal funcs)
-rw-r--r--device-functions.c231
-rw-r--r--device-functions.h2
-rw-r--r--globals.h4
-rw-r--r--monitor.c4
4 files changed, 142 insertions, 99 deletions
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)<globals.Flash.ampl_zero_equiv[channel]) {
return NeedNonZeroAmpl;
@@ -1519,13 +1532,13 @@ int Set_Amp_Calib(int channel,float meas_ampl)
int Set_Mon_Calib(int channel,float meas_ampl)
{
float change_ratio;
- int point_found,relay_range,UseNegData,entry,word_out,actual_pol,eprom_loc;
+ int point_found,relay_range,UseNegData,entry,word_out,actual_pol,eprom_loc,atten_range;
/* 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].Curr_Mon_value)< (5.0 * globals.Flash.monitor_step[channel])) {
return NeedNonZeroAmpl;
@@ -2407,7 +2420,7 @@ int Set_VI_Del_Cal(int parameter,int channel,int calibration_point_number)
}
-int Set_VI_Control(int parameter,int channel,float new_ampl,int *point_found,int *relay_range,
+int Set_VI_Control(int parameter,int channel,float new_ampl,int *point_found,int *relay_range,int *atten_range,
int *UseNegData,int *entry,int *word_out,int *actual_pol)
{
float use_ampl,tweaked_use_ampl,fraction;
@@ -2682,75 +2695,101 @@ int Set_VI_Control(int parameter,int channel,float new_ampl,int *point_found,int
*point_found=*relay_range=*entry=0;
*word_out=-1;
- tweaked_use_ampl = use_ampl;
+ float use_atten = 1.0;
- for (range_i=starting_range; (range_i<max_ranges) && (!*point_found || top_range_only); ++range_i) { /* use non-all-zero ranges */
- /* apply pw ampl/pol tweaks */
- if (parameter == pwl_pw_values) {
- tweaked_use_ampl = use_ampl + globals.Flash.pw_range_pol_tweaks[channel][range_i][pw_polarity];
- }
+ for (*atten_range = max_attens; (*atten_range >= -1) && !(*point_found);) {
- for (entry_i=0; (entry_i<max_points-1) && (!*point_found || top_range_only); ++entry_i) {
- index=true_channel*max_ranges*max_polarity*max_points
- +(range_i)*max_polarity*max_points
- +(*UseNegData)*max_points
- +(entry_i);
+ (*atten_range)--;
- if ( (fabs(pwl_amp[index]-pwl_amp[index+1])>smallest_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_i<max_ranges) && (!*point_found || top_range_only); ++range_i) { /* use non-all-zero ranges */
+ /* apply pw ampl/pol tweaks */
+ if (parameter == pwl_pw_values) {
+ // tweak pw shifts
+ tweaked_use_ampl = use_ampl + globals.Flash.pw_range_pol_tweaks[channel][range_i][pw_polarity];
+ } else if (parameter == pwl_ampl_values) {
+ // compensate for attenuators
+ tweaked_use_ampl = use_ampl * use_atten;
+ } else {
+ // no tweaks
+ tweaked_use_ampl = use_ampl;
+ }
- if ((parameter==pwl_ampl_values) && globals.Flash.ampl_os_ranges_related[channel]) {
- for (i=0; i<points_in_range; i++) {
- if (max_os_in_range<globals.Flash.os_pwl_amp[channel][range_i][0][i]) {
- max_os_in_range=globals.Flash.os_pwl_amp[channel][range_i][0][i];
+ for (entry_i=0; (entry_i<max_points-1) && (!*point_found || top_range_only); ++entry_i) {
+ index=true_channel*max_ranges*max_polarity*max_points
+ +(range_i)*max_polarity*max_points
+ +(*UseNegData)*max_points
+ +(entry_i);
+
+ if ( (fabs(pwl_amp[index]-pwl_amp[index+1])>smallest_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; i<points_in_range; i++) {
+ if (max_os_in_range<globals.Flash.os_pwl_amp[channel][range_i][0][i]) {
+ max_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 (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].offset<min_os_in_range) || (globals.ChannelState[channel].offset>max_os_in_range)) {
+ *point_found=0; /* try higher range if can't satisfy os and ampl both in this range */
}
}
- if ((globals.ChannelState[channel].offset<min_os_in_range) || (globals.ChannelState[channel].offset>max_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; i<points_in_range; i++) {
- if (max_ampl_in_range<globals.Flash.ampl_pwl_amp[channel][range_i][*UseNegData][i]) {
- max_ampl_in_range=globals.Flash.ampl_pwl_amp[channel][range_i][*UseNegData][i];
+ if ((parameter==pwl_os_values) && globals.Flash.ampl_os_ranges_related[channel]) {
+ for (i=0; i<points_in_range; i++) {
+ if (max_ampl_in_range<globals.Flash.ampl_pwl_amp[channel][range_i][*UseNegData][i]) {
+ max_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 (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)<min_ampl_in_range) || (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)<min_ampl_in_range) || (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;
}
diff --git a/device-functions.h b/device-functions.h
index dc14abd..5199443 100644
--- a/device-functions.h
+++ b/device-functions.h
@@ -45,7 +45,7 @@ int Set_Dly_Shr_Cal(int channel,int calibration_point_number,float cal_point);
int Set_Cal_Nom(int channel,int calibration_point_number,int parameter, float *nom_val);
int Set_VI_Cal_Pnt(int parameter,int channel,int calibration_point_number,float cal_point);
int Set_VI_Del_Cal(int parameter,int channel,int calibration_point_number);
-int Set_VI_Control(int parameter,int channel,float new_ampl,int *point_found,int *relay_range,
+int Set_VI_Control(int parameter,int channel,float new_ampl,int *point_found,int *relay_range,int *atten_range,
int *UseNegData,int *entry,int *word_out,int *actual_pol);
int Set_VI_Add_Cal(int parameter,int channel,float cal_point);
int Get_VI_Num_Pnts(int parameter,int channel);
diff --git a/globals.h b/globals.h
index 52cf1fc..cfc17b5 100644
--- a/globals.h
+++ b/globals.h
@@ -702,6 +702,10 @@ typedef struct {
float attenuators[max_channels][max_attens]; // addr 10070
// smallest attenuators first
+ // value = magnitude of attenuation.
+ // for example, for 20 dB, use 10.0
+ // for 15 dB, use 5.62
+ // for 10 dB, use 3.16
char spare_end;
diff --git a/monitor.c b/monitor.c
index 7c50922..44751e2 100644
--- a/monitor.c
+++ b/monitor.c
@@ -157,7 +157,7 @@ int I2C_Check_Monitors(void)
int monitor_word;
float step_size;
int channel;
- int ampl_range,point_found,UseNegData,entry,word_out;
+ int ampl_range,point_found,UseNegData,entry,word_out,atten_range;
int update_display;
int use_neg_data;
@@ -195,7 +195,7 @@ int I2C_Check_Monitors(void)
/* determine current ampl_range */
Set_VI_Control(pwl_ampl_values,channel,globals.ChannelState[channel].amplitude,&point_found,
- &ampl_range,&UseNegData,&entry,&word_out,&actual_pol);
+ &ampl_range,&atten_range,&UseNegData,&entry,&word_out,&actual_pol);
/* 5.0V is the full-scale voltage of the 12bit ADC */
globals.ChannelState[channel].Curr_Mon_value=((((float) monitor_word)/4095.0) * 5.0)