summaryrefslogtreecommitdiff
path: root/device-functions.c
diff options
context:
space:
mode:
Diffstat (limited to 'device-functions.c')
-rw-r--r--device-functions.c74
1 files changed, 44 insertions, 30 deletions
diff --git a/device-functions.c b/device-functions.c
index 40ed3b8..333d9cb 100644
--- a/device-functions.c
+++ b/device-functions.c
@@ -233,6 +233,7 @@ void set_dac(int dac, int word)
/* allows dacs to be disabled (using dac=-1, for example) */
if ((dac >= 0) && (dac < max_dacs)) {
globals.Registers.parallel_DAC_reg[dac]=word;
+ g_print_debug(": set dac %d to %d\n\r",dac,word);
}
}
@@ -278,8 +279,6 @@ int Set_Amplitude(int check_possible_only,int pol_override,int override_on,int w
}
}
- g_print_debug ("ch %d, ampl %e\n\r",channel,new_ampl);
-
/* keep "-0" in negative area, to avoid using zeroed positive data */
if ( new_ampl<=smallest_allowed_number
&& new_ampl>=-smallest_allowed_number
@@ -360,7 +359,6 @@ int Set_Amplitude(int check_possible_only,int pol_override,int override_on,int w
}
if (globals.Flash.distort_enabled[channel]) {
- printf ("distort %d\n",word_out_aux);
set_dac(globals.Flash.distort_dac[channel],word_out_aux);
}
@@ -449,7 +447,7 @@ int Set_Amplitude(int check_possible_only,int pol_override,int override_on,int w
globals.Flags.force_output_fully_off=YES;
}
- g_print_debug("chan %d, ampl range %d, word %d, pol %d\n",channel,relay_range,word_out,actual_pol);
+ g_print_debug("chan %d, ampl %e, range %d, word %d\n", channel, new_ampl, relay_range, word_out);
globals.Changes.update_amp=YES;
@@ -593,6 +591,15 @@ int Set_Pw(int check_possible_only,int word_override,int range_override,int chan
Set_Use_Vctrl_PW_Range(channel,TRUE);
+ // AVP-2CHX units use the trigger signal PW to control the +/- relative
+ // delay of the second channel. Therefore, do not use the fix_pw_dac_val
+ // value from above. Instead, the CH2 delay function controls the
+ // pulse width of the trigger signal. Obscure!
+ if (globals.Flash.min_delay[1] >= 0.0) {
+ set_dac(4,word_out);
+ set_shiftreg_bits(SR_3, POS_0, SEVEN_BITS, cap_range_control);
+ }
+
} else {
Set_Use_Vctrl_PW_Range(channel,FALSE);
@@ -608,14 +615,14 @@ int Set_Pw(int check_possible_only,int word_override,int range_override,int chan
} else {
cap_range_control = 1 << (relay_range-2);
}
+
+ set_dac(4,word_out);
+ set_shiftreg_bits(SR_3, POS_0, SEVEN_BITS, cap_range_control);
}
+ } else {
+ set_dac(4,word_out);
+ set_shiftreg_bits(SR_3, POS_0, SEVEN_BITS, cap_range_control);
}
-
- /* set fine controls */
- set_dac(4,word_out);
-
- /* set ranges */
- set_shiftreg_bits(SR_3, POS_0, SEVEN_BITS, cap_range_control);
}
if (channel==1) {
@@ -645,7 +652,7 @@ int Set_Pw(int check_possible_only,int word_override,int range_override,int chan
globals.ChannelState[channel].pw=set_pw;
Set_Update_Chans();
- g_print_debug("pw range %d, word %d\n",relay_range,word_out);
+ g_print_debug("chan %d, pw %e, range %d, word %d\n", channel, set_pw, relay_range, word_out);
if (!called_from_set_ampl) {
Set_Amplitude(0,0,0,0,0,0,0,channel,globals.ChannelState[channel].amplitude,1);
@@ -824,7 +831,7 @@ int Set_frequency(int check_possible_only,int word_override,int range_override,i
set_shiftreg_bits(SR_2, POS_0, SEVEN_BITS, cap_range_control);
}
- g_print_debug("freq range %d, word %d\n",relay_range,word_out);
+ g_print_debug("chan %d, freq %e, range %d, word %d\n", channel, set_freq, relay_range, word_out);
globals.ChannelState[channel].frequency=set_freq;
@@ -921,13 +928,10 @@ int Set_Delay(int check_possible_only,int word_override,int range_override,int c
return HardwareError;
}
- g_print_debug("set delay %e, actual %e\n",set_delay,setting);
-
/* set the amplitude controls now. */
int status;
if ((status=Set_VI_Control(pwl_delay_values,channel,setting,&point_found,
&relay_range,&dummy,&UseNegData,&entry,&word_out,&actual_pol,NULL))) {
- g_print_debug("delay set status: %d",status);
return status;
}
}
@@ -950,13 +954,15 @@ int Set_Delay(int check_possible_only,int word_override,int range_override,int c
if (channel==0) {
set_dac(globals.Flash.delay_dac[channel],word_out);
set_shiftreg_bits(SR_2, POS_8, SEVEN_BITS, cap_range_control);
- }
-
- if (channel==1) {
+ } else if ((channel==1) && (globals.Flash.min_delay[channel] >= 0.0)) {
control_pcb107(globals.Flash.I2C_port_for_CH2_delay,globals.Flash.delay_dac[channel],word_out,relay_range);
+ } else if ((channel==1) && (globals.Flash.min_delay[channel] < 0.0)) {
+ // for obscure AVP-2CHX units, where trigger PW controls the delay of CH2
+ set_dac(4,word_out);
+ set_shiftreg_bits(SR_3, POS_0, SEVEN_BITS, cap_range_control);
}
- g_print_debug("delay range %d, word %d\n",relay_range,word_out);
+ g_print_debug("chan %d, delay %e nominal, %e actual, range %d, word %d\n", channel, set_delay, setting, relay_range, word_out);
globals.ChannelState[channel].delay=set_delay;
Set_Update_Chans();
@@ -1693,6 +1699,7 @@ int Set_Update_Chans(void)
}
+ g_print_debug ("\n\r");
return OK;
}
@@ -2667,7 +2674,11 @@ static int linear_interpolation (int x1, int x2, float y1, float y2, float y_nee
return -1;
}
- return (int) ( (y_need - y1) / (y2 - y1) * (float) (x2 - x1) ) + x1;
+ int solved = (int) ( (y_need - y1) / (y2 - y1) * (float) (x2 - x1) ) + x1;
+
+ g_print_debug (": linear interpolation: x1 %d y1 %e, x2 %d y2 %e, need %e, solved %d\n\r", x1, y1, x2, y2, y_need, solved);
+
+ return solved;
}
@@ -2687,7 +2698,9 @@ static int inverse_interpolation (int x1, int x2, float y1, float y2, float y_ne
int solved = (int) (A + (B / y_need));
- return (int) solved;
+ g_print_debug (": inverse interpolation: x1 %d y1 %e, x2 %d y2 %e, need %e, solved %d - A=%e, B=%e\n\r", x1, y1, x2, y2, y_need, solved, A, B);
+
+ return solved;
}
@@ -3115,6 +3128,7 @@ int Set_VI_Control(int parameter,int channel,float new_ampl,int *point_found,int
if (*word_out<0 && reciprocal_relationship) {
*point_found=0;
use_range=-1;
+ float range_start;
tweaked_use_ampl = use_ampl;
@@ -3127,13 +3141,15 @@ int Set_VI_Control(int parameter,int channel,float new_ampl,int *point_found,int
index=true_channel*max_ranges*max_polarity*max_points
+(range_i)*max_polarity*max_points
+(*UseNegData)*max_points;
- if (pwl[index]>smallest_allowed_number && pwl[index]<tweaked_use_ampl) {
+
+ range_start = pwl[index];
+ if ((fabs(range_start) > smallest_allowed_number) && (range_start < tweaked_use_ampl)) {
use_range=range_i;
}
}
if (use_range<0) {
- return HardwareError;
+ return NoHardwareRangeFoundError;
}
for (entry_i=max_points-2; (entry_i>=0) && (!*point_found); --entry_i) {
@@ -3157,13 +3173,13 @@ int Set_VI_Control(int parameter,int channel,float new_ampl,int *point_found,int
if (*word_out<0) {
*word_out=0;
- return HardwareError;
+ return HardwareWordError;
}
/* check for 12 or 13 bit overflow */
if (*word_out>dac_max) {
*word_out=dac_max; /* just to prevent wandering bits */
- return HardwareError;
+ return HardwareWordError;
}
return OK;
@@ -4676,9 +4692,9 @@ void Main_update_shift_registers()
bus_setpin(out_CLOCK_LINE, 1);
bus_setpin(out_STROBE_LINE, 0);
- g_print_debug ("\n\r-----------\n\r");
+// g_print_debug ("\n\r-----------\n\r");
for (i=(num_out_SRs-1); i>=0; --i) {
- g_print_debug ("SR %d = %lx hex\n\r",i,globals.Registers.shift_reg_out[i]);
+// g_print_debug ("SR %d = %lx hex\n\r",i,globals.Registers.shift_reg_out[i]);
switch (i) {
case 0:
case 1:
@@ -4901,10 +4917,8 @@ static void set_shiftreg_bits(int shiftreg, int start_at_bit, int numbits, int v
long shift_value = (value & used_bits) << start_at_bit;
long masked_reg = globals.Registers.shift_reg_out[shiftreg] & mask;
-// printf ("shiftreg %d, start_at_bit %d, numbits %d, value %x\n",shiftreg,start_at_bit,numbits,value);
-// printf (" in %lx\n", globals.Registers.shift_reg_out[shiftreg]);
+ g_print_debug(": shiftreg %d, start_at_bit %d, numbits %d, value %x\n",shiftreg,start_at_bit,numbits,value);
globals.Registers.shift_reg_out[shiftreg] = masked_reg | shift_value;
-// printf ("out %lx\n", globals.Registers.shift_reg_out[shiftreg]);
}