diff options
author | Mike <mjc@avtechpulse.com> | 2000-01-01 01:01:52 +0900 |
---|---|---|
committer | Mike <mjc@avtechpulse.com> | 2000-01-01 01:01:52 +0900 |
commit | e609cd52d421c1a1b8e4a98cd7820209e5bbd481 (patch) | |
tree | e530df6d693bfcba95fb80897a76d6af6b5a9894 | |
parent | 53d1703cafbddaebaf9a87ce008f1d7cfbce2841 (diff) |
Sleep time is now fraction of max based on DAC changeINSTRUMENT_6_4_33
-rw-r--r-- | device-functions.c | 51 | ||||
-rw-r--r-- | flash.c | 2 | ||||
-rw-r--r-- | globals.h | 4 |
3 files changed, 40 insertions, 17 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; @@ -895,7 +895,7 @@ static void initFlashValues(FlashStruct *mem) mem->relay_delay_in_sec=0.5; mem->extended_relay_delay_in_sec=0.5; - mem->amplitude_settling_time=0.3; + mem->hv_full_chargeup_time=0.9; strcpy(mem->aux_error_message,"PRF too high! Output disabled."); strcpy(mem->ot_error_message,"Over-heating problem. Output off."); @@ -712,7 +712,7 @@ typedef struct { char zout_relay_high_for_max[max_channels]; /* addr 8700 */ char load_type_dac[max_channels]; /* addr 8702 */ - float amplitude_settling_time; /* addr 8704 */ + float hv_full_chargeup_time; /* addr 8704 */ float sparex1; /* addr 8708 */ float sparex2[max_channels]; /* addr 8712 */ float rcl_sparex3[max_channels][max_stored_settings]; /* addr 8720 */ @@ -906,7 +906,6 @@ typedef struct { int do_check_settings; int flash_writes_suspended; int force_output_fully_off; - int need_ampl_settling_time; int attenuators_enabled; } FlagStruct; @@ -925,6 +924,7 @@ typedef struct { long last_activity_at[max_channels]; long normal_relay_bounce_time_in_milliseconds; long Relay_Switching_Delay_in_Milliseconds; + float trigger_sleep_time; } TimeStruct; |