From e194b1f8bcb42405d20e20e6db1a5594b05b61d4 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Fri, 3 Apr 2020 12:54:49 +0200 Subject: [PATCH] Increase output power selectable range --- sa_core.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++------ ui_sa.c | 30 ++++++++++++---------- 2 files changed, 84 insertions(+), 22 deletions(-) diff --git a/sa_core.c b/sa_core.c index 08c945e..997d4e6 100644 --- a/sa_core.c +++ b/sa_core.c @@ -8,6 +8,7 @@ int setting_mode = M_LOW; int dirty = true; int scandirty = true; int setting_attenuate = 0; +int setting_step_atten; int setting_rbw = 0; int setting_average = 0; int setting_show_stored = 0; @@ -40,6 +41,7 @@ void reset_settings(int m) { setting_mode = m; setting_attenuate = 0; + setting_step_atten = 0; setting_rbw = 0; setting_average = 0; setting_show_stored = 0; @@ -64,6 +66,7 @@ void reset_settings(int m) SetRefpos(-10); break; case M_GENLOW: + setting_drive=1; // 0-3 , 3=+20dBm minFreq = 0; maxFreq = 520000000; set_sweep_frequency(ST_CENTER, (int32_t) 10000000); @@ -121,7 +124,14 @@ void set_measurement(int m) } void SetDrive(int d) { - setting_drive = d; + setting_drive = (d & 3); + if (setting_mode == M_GENHIGH) { + if (!(d & 4)) + setting_step_atten = 1; + else + setting_step_atten = 0; + setting_drive = d; + } dirty = true; } @@ -142,14 +152,55 @@ int GetMode(void) dirty = true; } + +#define POWER_STEP 0 // Should be 5 dB but appearently it is lower +#define POWER_OFFSET 2 +#define SWITCH_ATTENUATION 29 + +int GetAttenuation(void) +{ + if (setting_mode == M_GENLOW) { + if (setting_step_atten) + return ( - (POWER_OFFSET + setting_attenuate - (setting_step_atten-1)*POWER_STEP + SWITCH_ATTENUATION)); + else + return ( -(POWER_OFFSET + setting_attenuate)); + } + return(setting_attenuate); +} + + void SetAttenuation(int a) { + a = a + POWER_OFFSET; + if (setting_mode == M_GENLOW) { + if( a > - SWITCH_ATTENUATION + 3*POWER_STEP) { + setting_step_atten = 0; + } else { + a = a + SWITCH_ATTENUATION; +#if 0 + if (a >= 2 * POWER_STEP) { + setting_step_atten = 3; // Max drive + a = a - 2 * POWER_STEP; + } else if (a >= POWER_STEP ) { + setting_step_atten = 2; // Max drive + a = a - POWER_STEP; + } else { + setting_step_atten = 1; + } +#else + setting_step_atten = 1; // drive level is unpredictable +#endif + } + a = -a; + } else { + setting_step_atten = 0; + } if (a<0) - a = 0; + a = 0; if (a> 31) a=31; - if (setting_attenuate == a) - return; +// if (setting_attenuate == a) +// return; setting_attenuate = a; dirty = true; } @@ -440,8 +491,13 @@ case M_HIGH: // Direct into 1 break; case M_GENLOW: // Mixed output from 0 SI4432_Sel = 0; - SetSwitchTransmit(); - SI4432_Transmit(setting_drive); + if (setting_step_atten) { + SetSwitchReceive(); + SI4432_Transmit(setting_step_atten-1); + } else { + SetSwitchTransmit(); + SI4432_Transmit(0); // To prevent damage to the BPF always set low drive + } SI4432_Sel = 1; SetSwitchReceive(); @@ -454,8 +510,12 @@ case M_GENHIGH: // Direct output from 1 SetSwitchReceive(); SI4432_Sel = 1; - SetSwitchTransmit(); - SI4432_Transmit(setting_drive); + if (setting_step_atten) { + SetSwitchReceive(); + } else { + SetSwitchTransmit(); + } + SI4432_Transmit(setting_drive & 3); break; } diff --git a/ui_sa.c b/ui_sa.c index 6c66358..bf90342 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -12,6 +12,7 @@ void SetRefLevel(int); void set_refer_output(int); int get_refer_output(void); void SetAttenuation(int); +int GetAttenuation(void); void SetPowerLevel(int); void SetGenerate(int); void SetRBW(int); @@ -317,8 +318,9 @@ static void menu_reffer_cb(int item, uint8_t data) // draw_cal_status(); } -const int menu_drive_value[]={5,10,15,20}; -const char *menu_drive_text[]={"5dBm","10dBm","15dBm","20dBm"}; +//const int menu_drive_value[]={5,10,15,20}; +const char *menu_drive_text[]={"-15dBm","-10dBm","-5dBm","0dBm","5dBm","10dBm","15dBm","20dBm"}; + static void menu_drive_cb(int item, uint8_t data) { (void)item; @@ -524,19 +526,21 @@ static void menu_pause_cb(int item, uint8_t data) // ===[MENU DEFINITION]========================================================= static const menuitem_t menu_drive[] = { - { MT_CALLBACK, 0, " 5dBm", menu_drive_cb}, - { MT_CALLBACK, 1, " 10dBm", menu_drive_cb}, - { MT_CALLBACK, 2, " 15dBm", menu_drive_cb}, { MT_CALLBACK, 3, " 20dBm", menu_drive_cb}, + { MT_CALLBACK, 2, " 15dBm", menu_drive_cb}, + { MT_CALLBACK, 1, " 10dBm", menu_drive_cb}, + { MT_CALLBACK, 0, " 5dBm", menu_drive_cb}, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; static const menuitem_t menu_drive_wide[] = { - { MT_FORM | MT_CALLBACK, 0, " 5dBm", menu_drive_cb}, - { MT_FORM | MT_CALLBACK, 1, " 10dBm", menu_drive_cb}, - { MT_FORM | MT_CALLBACK, 2, " 15dBm", menu_drive_cb}, - { MT_FORM | MT_CALLBACK, 3, " 20dBm", menu_drive_cb}, + { MT_FORM | MT_CALLBACK, 6, " 15dBm", menu_drive_cb}, + { MT_FORM | MT_CALLBACK, 5, " 10dBm", menu_drive_cb}, + { MT_FORM | MT_CALLBACK, 4, " 5dBm", menu_drive_cb}, + { MT_FORM | MT_CALLBACK, 2, " -5dBm", menu_drive_cb}, + { MT_FORM | MT_CALLBACK, 1, "-10dBm", menu_drive_cb}, + { MT_FORM | MT_CALLBACK, 0, "-15dBm", menu_drive_cb}, { MT_FORM | MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_FORM | MT_NONE, 0, NULL, NULL } // sentinel }; @@ -936,7 +940,7 @@ static void menu_item_modify_attribute( } } else if (menu == menu_drive || menu == menu_drive_wide) { - if (item == setting_drive){ + if (menu[item].data == setting_drive){ mark = true; } @@ -1016,7 +1020,7 @@ static void fetch_numeric_target(void) plot_printf(uistat.text, sizeof uistat.text, "%ddB", uistat.value / 1000); break; case KM_ATTENUATION: - uistat.value = setting_attenuate; + uistat.value = GetAttenuation(); plot_printf(uistat.text, sizeof uistat.text, "%ddB", uistat.value); break; case KM_ACTUALPOWER: @@ -1036,8 +1040,7 @@ static void fetch_numeric_target(void) plot_printf(uistat.text, sizeof uistat.text, "%3ddB", uistat.value); break; case KM_LOWOUTLEVEL: - uistat.value = setting_attenuate; - uistat.value = -5 - uistat.value; // compensation for dB offset during low output mode + uistat.value = GetAttenuation(); // compensation for dB offset during low output mode plot_printf(uistat.text, sizeof uistat.text, "%ddB", uistat.value); break; case KM_DECAY: @@ -1105,7 +1108,6 @@ set_numeric_value(void) SetDrive(uistat.value); break; case KM_LOWOUTLEVEL: - uistat.value = -5 - uistat.value ; // compensation for dB offset during low output mode SetAttenuation(uistat.value); break; case KM_DECAY: