diff options
author | Michael J. Chudobiak <mjc@avtechpulse.com> | 2014-08-13 15:43:49 -0400 |
---|---|---|
committer | Michael J. Chudobiak <mjc@avtechpulse.com> | 2014-08-13 15:43:49 -0400 |
commit | 6959b9dadb91c32c2582afe0b4abaa040af53504 (patch) | |
tree | b105c8016878b8fd7b3dfc86e1bcbb3e80d28d5b | |
parent | 2691b7441d1a8cad7ccb23b766180d9f5176b567 (diff) |
first attempt at better AVRQ amplitude handling
-rw-r--r-- | device-functions.c | 73 | ||||
-rw-r--r-- | device-functions.h | 4 | ||||
-rw-r--r-- | error_utils.c | 12 | ||||
-rw-r--r-- | flash.c | 4 | ||||
-rw-r--r-- | globals.h | 11 | ||||
-rw-r--r-- | menus.c | 180 |
6 files changed, 233 insertions, 51 deletions
diff --git a/device-functions.c b/device-functions.c index 263758d..4bff9f5 100644 --- a/device-functions.c +++ b/device-functions.c @@ -89,11 +89,7 @@ void Main_Rst (void) globals.ChannelState[i].pw=0.0; } - if (globals.Flash.ampl_min_max_only[i] || (globals.Flash.min_ampl[i] > 0.0)) { - globals.ChannelState[i].amplitude = globals.Flash.min_ampl[i]; - } else { - globals.ChannelState[i].amplitude=0.0; - } + globals.ChannelState[i].amplitude = rst_fixed_ampl_point(i); globals.ChannelState[i].offset=0.0; globals.ChannelState[i].zout=globals.Flash.zout_min[i]; @@ -4930,3 +4926,70 @@ static void set_shiftreg_bits(int shiftreg, int start_at_bit, int numbits, int v // printf ("out %lx\n", globals.Registers.shift_reg_out[shiftreg]); } + +int number_of_fixed_ampl_points(int channel) +{ + int i, count; + count = 0; + + for (i=0; i<max_fixed_ampl_points; i++) { + if (fabs(globals.Flash.fixed_ampl_points[channel][i]) > 0.0) { + count = i+1; + } + } + + return count; +} + + +float rst_fixed_ampl_point (int channel) +{ + // smallest positive value, or zero + + int i, max, pos_count, neg_count; + pos_count = 0; + neg_count = 0; + + float smallest_pos, smallest_neg; + smallest_pos = 1e9; + smallest_neg = -1e9; + + max = number_of_fixed_ampl_points(channel); + + // any zeroes? + for (i=0; i<max; i++) { + if (globals.Flash.fixed_ampl_points[channel][i] >= 0.0 ) { + ++pos_count; + if (globals.Flash.fixed_ampl_points[channel][i] < smallest_pos) { + smallest_pos = globals.Flash.fixed_ampl_points[channel][i]; + } + } else if (globals.Flash.fixed_ampl_points[channel][i] < 0.0 ) { + ++neg_count; + if (globals.Flash.fixed_ampl_points[channel][i] > smallest_neg) { + smallest_neg = globals.Flash.fixed_ampl_points[channel][i]; + } + } + } + + if (pos_count > 0) { + return smallest_pos; + } else if (neg_count > 0) { + return smallest_neg; + } else { + return 0.0; + } +} + + +gboolean fixed_ampl_ok (int channel, float use_ampl) { + + int i,max; + max = number_of_fixed_ampl_points(channel); + + for (i=0; i<max; i++) { + if (fabs(use_ampl-globals.Flash.fixed_ampl_points[channel][i])<globals.Flash.ampl_zero_equiv[channel]) + return TRUE; + } + + return FALSE; +} diff --git a/device-functions.h b/device-functions.h index 5199443..9c33b81 100644 --- a/device-functions.h +++ b/device-functions.h @@ -75,4 +75,8 @@ int IO_Setup_RS232(int baud, char handshake, gboolean update_flash); int change_password (gchar *old_password, gchar *new_password); +int number_of_fixed_ampl_points(int channel); +float rst_fixed_ampl_point (int channel); +gboolean fixed_ampl_ok (int channel, float use_ampl); + #endif diff --git a/error_utils.c b/error_utils.c index 0a77019..603d072 100644 --- a/error_utils.c +++ b/error_utils.c @@ -20,6 +20,7 @@ END DESCRIPTION **********************************************************/ #include "error_utils.h" #include "menus.h" #include "gpib.h" +#include "device-functions.h" /*** EndHeader */ @@ -1095,16 +1096,11 @@ int Error_check(ChannelStruct ChannelStateToTest[max_channels]) /* --- check intermediate amplitude --- */ - if (globals.Flash.ampl_min_max_only[i]) - - if ( !(fabs(ChannelStateToTest[i].amplitude - globals.Flash.min_ampl[i] ) < globals.Flash.ampl_zero_equiv[i] ) - && - !(fabs(ChannelStateToTest[i].amplitude - globals.Flash.max_ampl[i]) < globals.Flash.ampl_zero_equiv[i] ) - ) - - { + if (number_of_fixed_ampl_points(i)>0) { + if (!fixed_ampl_ok (i, ChannelStateToTest[i].amplitude)) { report_error=amplitude_confined_values; } + } /* ------------------------------- */ @@ -817,6 +817,10 @@ static void initFlashValues(FlashStruct *mem) mem->max_freq_for_high_ot[i] = 0.0; mem->high_ot[i] = 0.0; + + for (j=0; j<max_fixed_ampl_points; j++) { + mem->fixed_ampl_points[i][j] = 0.0; + } } mem->relay_delay_in_sec=0.5; @@ -266,6 +266,10 @@ #define Submenu1_avrq 3400 +// must be equal! +#define Submenu_maximum_entries 10 +#define max_fixed_ampl_points 10 + long sec_timer (void); unsigned long long ms_timer (void); @@ -514,10 +518,9 @@ typedef struct { char switchable_load[max_channels]; char monitor_enabled[max_channels]; /* addr 1906 */ char use_pos_ampl_data_only[max_channels]; - char ampl_min_max_only[max_channels]; - - short zout_min[max_channels]; /* addr 1912 */ + char ampl_min_max_only[max_channels]; /* no longer used - use fixed_ampl_points instead */ + short zout_min[max_channels]; /* addr 1912 */ short os_pwl_Vc_norm4095[max_channels][os_ranges][os_polarities][points_in_range]; /* addr 1916 */ float os_pwl_amp[max_channels][os_ranges][os_polarities][points_in_range]; /* addr 2116 */ @@ -729,6 +732,8 @@ typedef struct { float max_freq_for_high_ot[max_channels]; /* addr 10154, for 1011-OT */ float high_ot[max_channels]; /* addr 10162, for 1011-OT */ + float fixed_ampl_points[max_channels][max_fixed_ampl_points]; /* addr 10170, for AVR-D2, AVRQ-4 */ + char flash_end; } FlashStruct; @@ -115,8 +115,6 @@ #define mode_exit_rs232 5600 #define mode_logic_ttl 5700 #define mode_logic_ecl 5800 -#define mode_amp_min 5900 -#define mode_amp_max 6000 #define mode_os_normal 6300 #define mode_os_eo 6400 #define mode_amp_amplify 6500 @@ -133,8 +131,10 @@ #define mode_57600 7700 #define mode_115200 7800 #define mode_pw_ew 7900 +#define mode_ampl_fixed_points 8000 -#define Submenu_maximum_entries 10 /* used to be 4, before scrolling lists were added */ + +#define Submenu_maximum_entries 10 /* what parameter to adjust */ #define Show_frequency 0 @@ -1350,16 +1350,16 @@ static void Submenu_Display(int change_selection) title = g_strdup ("Amplitude:"); } - - if (globals.ChannelState[channel].amp_mode==amp_mode_normal && !globals.Flash.ampl_min_max_only[channel]) { + if (number_of_fixed_ampl_points(channel)>0) { + int fixed_count; + Submenu_max_entry = number_of_fixed_ampl_points(channel) - 1; + for (fixed_count = 0; fixed_count < number_of_fixed_ampl_points(channel); ++fixed_count) { + Submenu_Structure[i] = mode_ampl_fixed_points + fixed_count; + } + } else if (globals.ChannelState[channel].amp_mode==amp_mode_normal) { Submenu_Numeric_Parameter=Show_amplitude+channel; } - if (globals.Flash.ampl_min_max_only[channel]) { - Submenu_max_entry=1; - Submenu_Structure[0]=mode_amp_min; - Submenu_Structure[1]=mode_amp_max; - } if (globals.Flash.ea_enabled[channel]) { ++Submenu_max_entry; Submenu_Structure[0]=mode_amp_normal; @@ -1638,6 +1638,14 @@ static void Submenu_Display(int change_selection) for (i=0; i<=Submenu_max_entry; ++i) { gchar *mode_name; + gchar *fixed_ampl_units; + float use_ampl; + + if (globals.Flash.voltage_enabled[channel]) { + fixed_ampl_units = g_strdup("V"); + } else { + fixed_ampl_units = g_strdup("A"); + } switch (Submenu_Structure[i]-channel) { case mode_freq_int: @@ -1895,28 +1903,84 @@ static void Submenu_Display(int change_selection) current_operating_mode=i; } break; - case mode_amp_min: - if (globals.Flash.voltage_enabled[channel]) { - String_Parameter_To_Text(globals.Flash.min_ampl[channel],2,"","V",&mode_name,YES,LCD_col_width); - } else { - String_Parameter_To_Text(globals.Flash.min_ampl[channel],2,"","A",&mode_name,YES,LCD_col_width); - } - if (fabs(globals.ChannelState[channel].amplitude-globals.Flash.min_ampl[channel])<globals.Flash.ampl_zero_equiv[channel]) { - current_operating_mode=i; - } - break; - case mode_amp_max: - if (globals.Flash.voltage_enabled[channel]) { - String_Parameter_To_Text(globals.Flash.max_ampl[channel],2,"","V",&mode_name,YES,LCD_col_width); - } else { - String_Parameter_To_Text(globals.Flash.max_ampl[channel],2,"","A",&mode_name,YES,LCD_col_width); - } - if (fabs(globals.ChannelState[channel].amplitude-globals.Flash.max_ampl[channel])<globals.Flash.ampl_zero_equiv[channel]) { + // hard-coded count of 10 - not ideal! + case mode_ampl_fixed_points + 0: + use_ampl = globals.Flash.fixed_ampl_points[channel][0]; + String_Parameter_To_Text(use_ampl,2,"",fixed_ampl_units,&mode_name,YES,LCD_col_width); + if (fabs(globals.ChannelState[channel].amplitude-use_ampl)<globals.Flash.ampl_zero_equiv[channel]) { + current_operating_mode=i; + } + break; + case mode_ampl_fixed_points + 1: + use_ampl = globals.Flash.fixed_ampl_points[channel][1]; + String_Parameter_To_Text(use_ampl,2,"",fixed_ampl_units,&mode_name,YES,LCD_col_width); + if (fabs(globals.ChannelState[channel].amplitude-use_ampl)<globals.Flash.ampl_zero_equiv[channel]) { + current_operating_mode=i; + } + break; + case mode_ampl_fixed_points + 2: + use_ampl = globals.Flash.fixed_ampl_points[channel][2]; + String_Parameter_To_Text(use_ampl,2,"",fixed_ampl_units,&mode_name,YES,LCD_col_width); + if (fabs(globals.ChannelState[channel].amplitude-use_ampl)<globals.Flash.ampl_zero_equiv[channel]) { + current_operating_mode=i; + } + break; + + case mode_ampl_fixed_points + 3: + use_ampl = globals.Flash.fixed_ampl_points[channel][3]; + String_Parameter_To_Text(use_ampl,2,"",fixed_ampl_units,&mode_name,YES,LCD_col_width); + if (fabs(globals.ChannelState[channel].amplitude-use_ampl)<globals.Flash.ampl_zero_equiv[channel]) { current_operating_mode=i; } break; + + case mode_ampl_fixed_points + 4: + use_ampl = globals.Flash.fixed_ampl_points[channel][4]; + String_Parameter_To_Text(use_ampl,2,"",fixed_ampl_units,&mode_name,YES,LCD_col_width); + if (fabs(globals.ChannelState[channel].amplitude-use_ampl)<globals.Flash.ampl_zero_equiv[channel]) { + current_operating_mode=i; + } + break; + case mode_ampl_fixed_points + 5: + use_ampl = globals.Flash.fixed_ampl_points[channel][5]; + String_Parameter_To_Text(use_ampl,2,"",fixed_ampl_units,&mode_name,YES,LCD_col_width); + if (fabs(globals.ChannelState[channel].amplitude-use_ampl)<globals.Flash.ampl_zero_equiv[channel]) { + current_operating_mode=i; + } + break; + case mode_ampl_fixed_points + 6: + use_ampl = globals.Flash.fixed_ampl_points[channel][6]; + String_Parameter_To_Text(use_ampl,2,"",fixed_ampl_units,&mode_name,YES,LCD_col_width); + if (fabs(globals.ChannelState[channel].amplitude-use_ampl)<globals.Flash.ampl_zero_equiv[channel]) { + current_operating_mode=i; + } + break; + case mode_ampl_fixed_points + 7: + use_ampl = globals.Flash.fixed_ampl_points[channel][7]; + String_Parameter_To_Text(use_ampl,2,"",fixed_ampl_units,&mode_name,YES,LCD_col_width); + if (fabs(globals.ChannelState[channel].amplitude-use_ampl)<globals.Flash.ampl_zero_equiv[channel]) { + current_operating_mode=i; + } + break; + case mode_ampl_fixed_points + 8: + use_ampl = globals.Flash.fixed_ampl_points[channel][8]; + String_Parameter_To_Text(use_ampl,2,"",fixed_ampl_units,&mode_name,YES,LCD_col_width); + if (fabs(globals.ChannelState[channel].amplitude-use_ampl)<globals.Flash.ampl_zero_equiv[channel]) { + current_operating_mode=i; + } + break; + case mode_ampl_fixed_points + 9: + use_ampl = globals.Flash.fixed_ampl_points[channel][9]; + String_Parameter_To_Text(use_ampl,2,"",fixed_ampl_units,&mode_name,YES,LCD_col_width); + if (fabs(globals.ChannelState[channel].amplitude-use_ampl)<globals.Flash.ampl_zero_equiv[channel]) { + current_operating_mode=i; + } + break; + + + case mode_1200: mode_name = g_strdup("1200 baud"); if (globals.Flash.baud==1200) { @@ -1984,6 +2048,8 @@ static void Submenu_Display(int change_selection) } g_ptr_array_add (gparray, (gpointer) mode_name); + + g_free (fixed_ampl_units); } /* If change_selection==NO, the submenu is being drawn from scratch. @@ -2625,7 +2691,7 @@ static void Submenu_Service_Encoder(int encoder_change) } } - if (globals.Flash.ampl_min_max_only[channel]) { /* not used for two-state amplitudes */ + if (number_of_fixed_ampl_points(channel)>0) { /* not used for fixed point amplitudes */ return; } @@ -3142,16 +3208,60 @@ static int Submenu_Implement_Changes(void) return error_num; } break; - case mode_amp_min: - if (error_num=Set_Amplitude(0,0,0,0,0,0,channel,globals.Flash.min_ampl[channel],0)) { - return error_num; - } - break; - case mode_amp_max: - if (error_num=Set_Amplitude(0,0,0,0,0,0,channel,globals.Flash.max_ampl[channel],0)) { + + // hard-coded count of 10 - not ideal! + case mode_ampl_fixed_points + 0: + if (error_num=Set_Amplitude(0,0,0,0,0,0,channel,globals.Flash.fixed_ampl_points[channel][0],0)) { return error_num; } break; + case mode_ampl_fixed_points + 1: + if (error_num=Set_Amplitude(0,0,0,0,0,0,channel,globals.Flash.fixed_ampl_points[channel][1],0)) { + return error_num; + } + break; + case mode_ampl_fixed_points + 2: + if (error_num=Set_Amplitude(0,0,0,0,0,0,channel,globals.Flash.fixed_ampl_points[channel][2],0)) { + return error_num; + } + break; + case mode_ampl_fixed_points + 3: + if (error_num=Set_Amplitude(0,0,0,0,0,0,channel,globals.Flash.fixed_ampl_points[channel][3],0)) { + return error_num; + } + break; + case mode_ampl_fixed_points + 4: + if (error_num=Set_Amplitude(0,0,0,0,0,0,channel,globals.Flash.fixed_ampl_points[channel][4],0)) { + return error_num; + } + break; + case mode_ampl_fixed_points + 5: + if (error_num=Set_Amplitude(0,0,0,0,0,0,channel,globals.Flash.fixed_ampl_points[channel][5],0)) { + return error_num; + } + break; + case mode_ampl_fixed_points + 6: + if (error_num=Set_Amplitude(0,0,0,0,0,0,channel,globals.Flash.fixed_ampl_points[channel][6],0)) { + return error_num; + } + break; + case mode_ampl_fixed_points + 7: + if (error_num=Set_Amplitude(0,0,0,0,0,0,channel,globals.Flash.fixed_ampl_points[channel][7],0)) { + return error_num; + } + break; + case mode_ampl_fixed_points + 8: + if (error_num=Set_Amplitude(0,0,0,0,0,0,channel,globals.Flash.fixed_ampl_points[channel][8],0)) { + return error_num; + } + break; + case mode_ampl_fixed_points + 9: + if (error_num=Set_Amplitude(0,0,0,0,0,0,channel,globals.Flash.fixed_ampl_points[channel][9],0)) { + return error_num; + } + break; + + case mode_amp_normal: if (error_num=Set_EA(channel,amp_mode_normal)) { return error_num; |