summaryrefslogtreecommitdiff
path: root/device-functions.c
diff options
context:
space:
mode:
authorMike <mjc@avtechpulse.com>2000-01-01 01:01:52 +0900
committerMike <mjc@avtechpulse.com>2000-01-01 01:01:52 +0900
commite609cd52d421c1a1b8e4a98cd7820209e5bbd481 (patch)
treee530df6d693bfcba95fb80897a76d6af6b5a9894 /device-functions.c
parent53d1703cafbddaebaf9a87ce008f1d7cfbce2841 (diff)
Sleep time is now fraction of max based on DAC changeINSTRUMENT_6_4_33
Diffstat (limited to 'device-functions.c')
-rw-r--r--device-functions.c51
1 files changed, 37 insertions, 14 deletions
diff --git a/device-functions.c b/device-functions.c
index f5878ae..e787dec 100644
--- a/device-functions.c
+++ b/device-functions.c
@@ -228,15 +228,27 @@ void Main_Rst (void)
void set_dac(int dac, int word)
{
+ int i;
+
+ float dac_percent_change;
+ dac_percent_change = 0.0;
+
+ g_print_debug(": setting dac %d to %d\n\r",dac,word);
+
/* allows dacs to be disabled (using dac=-1, for example) */
if ((dac >= 0) && (dac < max_dacs)) {
+ for (i = 0; i < max_channels; i++) {
+ // signal a trigger sleep if the output is on, and this is an amplitude DAC
+ if ((dac == globals.Flash.ampl_DAC[i]) && (globals.ChannelState[i].output_state==output_on)) {
- // TODO: is this one of the ampl DACs?
- // If so, calculate |%change| in DAC and multiply by settling time max.
- // Then, see if it is larger than any previously calculated settling times (other chans).
- // Reset settling time at end of main update.
+ dac_percent_change = fabs (((float)word-(float)globals.Registers.parallel_DAC_reg[dac]) / (float)dac_max);
+ g_print_debug("ampl dac, %d vs %d old, %e fractional change,\n\r",word,globals.Registers.parallel_DAC_reg[dac],dac_percent_change);
+
+ globals.Timers.trigger_sleep_time = dac_percent_change * globals.Flash.hv_full_chargeup_time;
+ g_print_debug(" so dac %d requires %e settling time\n\r",dac,globals.Timers.trigger_sleep_time);
+ }
+ }
globals.Registers.parallel_DAC_reg[dac]=word;
- g_print_debug(": set dac %d to %d\n\r",dac,word);
}
}
@@ -457,10 +469,8 @@ int Set_Amplitude(int check_possible_only,int pol_override,int override_on,int w
debug_new_parameter (channel, parameter, requested_ampl);
globals.Changes.update_amp = YES;
- if (globals.ChannelState[channel].amplitude != new_ampl) {
- globals.ChannelState[channel].amplitude = new_ampl;
- globals.Flags.need_ampl_settling_time = YES;
- }
+ globals.ChannelState[channel].amplitude = new_ampl;
+
Set_Update_Chans();
if (pwl_struct[parameter][channel].range!=old_range) {
@@ -1182,8 +1192,19 @@ int Set_Output_State(int channel,int mode)
bus_setpin(OUTPUT_RELAY, 1); /* turn output on */
bus_setpin(PW_ENABLE, 1); /* enable PW circuit */
- gulong sleep_us = get_float_with_min (globals.Flash.output_on_delay, DEFAULT_OUTPUT_ON_DELAY) * 1e6;
- g_usleep (sleep_us); /* wait for extended-off circuit to work */
+ // hold output off for usually 0.8 seconds after output on
+ globals.Timers.trigger_sleep_time = get_float_with_min (globals.Flash.output_on_delay, DEFAULT_OUTPUT_ON_DELAY);
+
+ // check charge-up time, as fraction of maximum, based on ampl DAC word
+ float dac_percent_change = fabs (((float)globals.Registers.parallel_DAC_reg[globals.Flash.ampl_DAC[channel]]) / (float)dac_max);
+ g_print_debug("at output on, ampl dac %e fractional change,\n\r",dac_percent_change);
+
+ float charge_up_sleep_time = dac_percent_change * globals.Flash.hv_full_chargeup_time;
+ g_print_debug(" so min %e settling time\n\r",charge_up_sleep_time);
+
+ // select large of two sleeps
+ globals.Timers.trigger_sleep_time = MAX(charge_up_sleep_time, globals.Timers.trigger_sleep_time);
+ g_print_debug(" final output on sleep: %e\n\r",globals.Timers.trigger_sleep_time);
globals.Timers.last_activity_at[channel] = sec_timer();
} else {
@@ -4677,6 +4698,8 @@ void Main_update_shift_registers()
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
g_static_mutex_lock (&mutex);
+ g_print_debug("Main_update_shift_registers(), requested sleep %e\n\r", globals.Timers.trigger_sleep_time);
+
/* send MSB first, LSB last */
/* send highest # SR first */
@@ -4774,8 +4797,8 @@ void Main_update_shift_registers()
}
/* amplitude settling time after a change */
- if (globals.Flags.need_ampl_settling_time == YES) {
- sleep_us = MAX(sleep_us, 1e6 * globals.Flash.amplitude_settling_time);
+ if (globals.Timers.trigger_sleep_time > 0.0) {
+ sleep_us = MAX(sleep_us, 1e6 * globals.Timers.trigger_sleep_time);
}
/* limit to 5 seconds */
@@ -4805,7 +4828,7 @@ void Main_update_shift_registers()
// reset update sensors
globals.Changes.update_os = 0;
globals.Changes.update_amp = 0;
- globals.Flags.need_ampl_settling_time = 0;
+ globals.Timers.trigger_sleep_time = 0.0;
globals.Changes.update_zout = 0;
globals.Changes.update_load = 0;