summaryrefslogtreecommitdiff
path: root/device-functions.c
diff options
context:
space:
mode:
authorMichael J. Chudobiak <mjc@avtechpulse.com>2012-09-07 10:21:34 -0400
committerMichael J. Chudobiak <mjc@avtechpulse.com>2012-09-07 10:21:34 -0400
commitb9264ec05328aae8f29e56d945f5168848b89737 (patch)
treece9a7f0d6d7c14e9e942fc891a660e859532d74b /device-functions.c
parent61990ae8b79aca30745eca02b44e63c377504176 (diff)
first attempt at adding Main_update_shift_registers
Diffstat (limited to 'device-functions.c')
-rw-r--r--device-functions.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/device-functions.c b/device-functions.c
index 1b2a888..6a54241 100644
--- a/device-functions.c
+++ b/device-functions.c
@@ -4534,3 +4534,91 @@ void Set_Sav(int setting_num)
return;
}
+
+
+void Main_update_shift_registers()
+{
+ /* send MSB first, LSB last */
+ /* send highest # SR first */
+
+ int store_trigger_mode[max_channels];
+ int i,j,n; /* counters */
+ char data_out;
+ int temp_output_state[max_channels];
+
+ /* suppress triggering during relay switching */
+ if ( globals.Registers.last_relay_driver_settings[0]!=globals.Registers.shift_reg_out[2]
+ || globals.Registers.last_relay_driver_settings[1]!=globals.Registers.shift_reg_out[3]) {
+ start_gate_override ();
+ }
+
+
+ /* physically turn off output for amplitude range changes */
+ /* i.e., short output in 155's */
+ if (globals.Flags.force_output_fully_off==YES)
+ for (i=0; i<(globals.Flash.ChanKey_frequency?globals.Flash.channels:1); ++i) {
+ temp_output_state[i]=globals.ChannelState[i].output_state;
+ Set_Output_State(i,output_off);
+ g_usleep (1e3 * globals.Timers.normal_relay_bounce_time_in_milliseconds);
+ }
+
+ bus_setpin(out_CLOCK_LINE, 1);
+ bus_setpin(out_STROBE_LINE, 0);
+
+ for (i=(num_out_SRs-1); i>=0; --i) {
+ switch (i) {
+ case 0:
+ case 1:
+ n=8;
+ break;
+ case 2:
+ case 3:
+ n=20; /* 20 bit shift registers - UCN5812s */
+ break;
+ }
+
+ for (j=n-1; j>=0; --j) { /* send MSB first, LSB last */
+ bus_setpin(out_CLOCK_LINE, 0);
+ data_out = (char) (1 & (globals.Registers.shift_reg_out[i]>>j));
+ bus_setpin(out_DATA_LINE, data_out);
+ bus_setpin(out_CLOCK_LINE, 1);
+ }
+ }
+
+ bus_setpin(out_STROBE_LINE, 1); // latch the data
+ bus_setpin(out_STROBE_LINE, 0); // release latch
+
+ for (i=0; i<8; ++i) {
+ /* load the upper-nibble latch */
+ bus_writebyte ((uint8_t) (Octal_DACportCS_high), (uint8_t) (globals.Registers.parallel_DAC_reg[i] >> 8));
+
+ /* write lower byte (with address data), and force transfer of latched nibble */
+ bus_writebyte ((uint8_t) (Octal_DACportCS_low + i), (uint8_t) (globals.Registers.parallel_DAC_reg[i] & 255));
+ }
+
+ /* keep trigger suppressed for a time (normally 5ms) after a relay update */
+ if ( globals.Registers.last_relay_driver_settings[0]!=globals.Registers.shift_reg_out[2]
+ || globals.Registers.last_relay_driver_settings[1]!=globals.Registers.shift_reg_out[3]
+ || globals.Flags.force_output_fully_off==YES) {
+ g_usleep (1e3 * globals.Timers.Relay_Switching_Delay_in_Milliseconds);
+ }
+
+
+ /* restore output if required */
+ if (globals.Flags.force_output_fully_off==YES)
+ for (i=0; i<(globals.Flash.ChanKey_frequency?globals.Flash.channels:1); ++i) {
+ Set_Output_State(i,temp_output_state[i]);
+ g_usleep (1e3 * globals.Timers.normal_relay_bounce_time_in_milliseconds);
+ globals.Flags.force_output_fully_off=NO;
+ }
+
+ stop_gate_override ();
+
+ globals.Timers.Relay_Switching_Delay_in_Milliseconds=globals.Timers.normal_relay_bounce_time_in_milliseconds;
+ /* restore default delay */
+
+ /* save relay data for comparision next time */
+ globals.Registers.last_relay_driver_settings[0]=globals.Registers.shift_reg_out[2];
+ globals.Registers.last_relay_driver_settings[1]=globals.Registers.shift_reg_out[3];
+}
+