diff --git a/main.c b/main.c index 7a82952..a04c137 100644 --- a/main.c +++ b/main.c @@ -866,6 +866,9 @@ config_t config = { .high_level_offset = 100, // Uncalibrated .correction_frequency = { 10000, 100000, 200000, 500000, 50000000, 140000000, 200000000, 300000000, 330000000, 350000000 }, .correction_value = { +6.0, +2.8, +1.6, -0.4, 0.0, -0.4, +0.4, +3.0, +4.0, +8.1 }, + .cor_am = -14, + .cor_wfm = -21, + .cor_nfm = -23, }; //properties_t current_props; diff --git a/nanovna.h b/nanovna.h index 8c96ac8..92ffd63 100644 --- a/nanovna.h +++ b/nanovna.h @@ -459,6 +459,10 @@ typedef struct config { uint16_t ham_color; uint16_t gridlines; uint16_t hambands; + int8_t cor_am; + int8_t cor_wfm; + int8_t cor_nfm; + int8_t dummy; // uint8_t _reserved[22]; uint32_t checksum; } config_t; diff --git a/sa_core.c b/sa_core.c index 2f7f4b0..29b68a5 100644 --- a/sa_core.c +++ b/sa_core.c @@ -1604,29 +1604,26 @@ pureRSSI_t perform(bool break_on_operation, int i, uint32_t f, int tracking) } if (MODE_OUTPUT(setting.mode)) { if (setting.modulation != MO_NONE && setting.modulation != MO_EXTERNAL && setting.modulation_frequency != 0) { - modulation_delay = 1000 * 200 / setting.modulation_frequency - 20; + modulation_delay = 1000 * 200 / setting.modulation_frequency; // 5 steps so 1MHz/5 modulation_counter = 0; - if (setting.modulation == MO_AM) - modulation_delay += 49; - if (setting.modulation == MO_NFM) - modulation_delay += -22; - if (setting.modulation == MO_WFM) - modulation_delay += -18; + if (setting.modulation == MO_AM) // -14 default + modulation_delay += config.cor_am; + if (setting.modulation == MO_WFM) // -21 default + modulation_delay += config.cor_wfm; + if (setting.modulation == MO_NFM) // -23 default + modulation_delay += config.cor_nfm; } } modulation_again: // ----------------------------------------------------- modulation for output modes --------------------------------------- if (MODE_OUTPUT(setting.mode)){ if (setting.modulation == MO_AM) { // AM modulation - int p = setting.attenuate * 2 + am_modulation[modulation_counter++]; + int p = setting.attenuate * 2 + am_modulation[modulation_counter]; if (p>63) p = 63; else if (p< 0) p = 0; #ifdef __PE4302__ PE4302_Write_Byte(p); #endif - if (modulation_counter == 5) // 3dB modulation depth - modulation_counter = 0; -// my_microsecond_delay(setting.modulation == MO_AM_10Hz ? 20000 : 180); } else if (setting.modulation == MO_NFM || setting.modulation == MO_WFM ) { //FM modulation #ifdef __SI4432__ @@ -1635,12 +1632,10 @@ modulation_again: SI4432_Write_Byte(SI4432_FREQ_OFFSET1, (offset & 0xff )); // Use frequency hopping channel for FM modulation SI4432_Write_Byte(SI4432_FREQ_OFFSET2, ((offset >> 8) & 0x03 )); // Use frequency hopping channel for FM modulation #endif - modulation_counter++; - if (modulation_counter == 5) // 3dB modulation depth - modulation_counter = 0; -// my_microsecond_delay(200); - // chThdSleepMicroseconds(200); } + modulation_counter++; + if (modulation_counter == 5) // 3dB modulation depth + modulation_counter = 0; if (setting.modulation != MO_NONE && setting.modulation != MO_EXTERNAL) { my_microsecond_delay(modulation_delay); } @@ -2179,7 +2174,7 @@ sweep_again: // stay in sweep loop when output mo setting.atten_step = false; // No step attenuate in low mode auto attenuate int changed = false; int delta = 0; - int actual_max_level = (int) (actual_t[max_index[0]] - get_attenuation()); + int actual_max_level = (max_index[0] == 0 ? -100 :(int) (actual_t[max_index[0]] - get_attenuation()) ); // If no max found reduce attenuation if (actual_max_level < AUTO_TARGET_LEVEL && setting.attenuate > 0) { delta = - (AUTO_TARGET_LEVEL - actual_max_level); } else if (actual_max_level > AUTO_TARGET_LEVEL && setting.attenuate < 30) { diff --git a/ui_sa.c b/ui_sa.c index 4c23d1f..129da06 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -407,7 +407,7 @@ enum { KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_REFLEVEL, KM_SCALE, KM_ATTENUATION, KM_ACTUALPOWER, KM_IF, KM_SAMPLETIME, KM_DRIVE, KM_LOWOUTLEVEL, KM_DECAY, KM_NOISE, KM_10MHZ, KM_REPEAT, KM_OFFSET, KM_TRIGGER, KM_LEVELSWEEP, KM_SWEEP_TIME, KM_OFFSET_DELAY, - KM_FAST_SPEEDUP, KM_GRIDLINES, KM_MARKER, KM_MODULATION, + KM_FAST_SPEEDUP, KM_GRIDLINES, KM_MARKER, KM_MODULATION,KM_COR_AM,KM_COR_WFM, KM_COR_NFM, KM_NONE // always at enum end }; @@ -441,6 +441,9 @@ static const struct { {keypads_positive , "MINIMUM\nGRIDLINES"}, // KM_GRIDLINES {keypads_freq , "MARKER\nFREQ"}, // KM_MARKER {keypads_freq , "MODULATION\nFREQ"}, // KM_MODULATION + {keypads_plusmin , "COR\nAM"}, // KM_COR_AM + {keypads_plusmin , "COR\nWFM"}, // KM_COR_WFM + {keypads_plusmin , "COR\nNFM"}, // KM_COR_NFM }; // ===[MENU CALLBACKS]========================================================= @@ -648,7 +651,12 @@ static UI_FUNCTION_ADV_CALLBACK(menu_smodulation_acb){ (void)item; (void)data; if(b){ - b->param_1.text = menu_modulation_text[setting.modulation]; + if (setting.modulation == MO_NONE) + b->param_1.text = menu_modulation_text[setting.modulation]; + else { + plot_printf(uistat.text, sizeof uistat.text, "%5.3fkHz %s", setting.modulation_frequency / 1000.0, menu_modulation_text[setting.modulation]); + b->param_1.text = uistat.text; + } return; } menu_push_submenu(menu_modulation); @@ -1364,7 +1372,7 @@ static const menuitem_t menu_lowoutputmode[] = { { MT_FORM | MT_ADV_CALLBACK, 0, "LOW OUTPUT %s", menu_outputmode_acb}, { MT_FORM | MT_KEYPAD, KM_CENTER, "FREQ: %s", "10kHz..350MHz"}, { MT_FORM | MT_KEYPAD, KM_LOWOUTLEVEL, "LEVEL: %s", "-76..-6"}, - { MT_FORM | MT_ADV_CALLBACK, 0, "MODULATION: %s", menu_smodulation_acb}, + { MT_FORM | MT_ADV_CALLBACK, 0, "MOD: %s", menu_smodulation_acb}, { MT_FORM | MT_KEYPAD, KM_SPAN, "SPAN: %s", "0..350MHz"}, { MT_FORM | MT_KEYPAD | MT_LOW, KM_LEVELSWEEP,"LEVEL CHANGE: %s", "-70..70"}, { MT_FORM | MT_KEYPAD, KM_SWEEP_TIME, "SWEEP TIME: %s", "0..600 seconds"}, @@ -1376,7 +1384,7 @@ static const menuitem_t menu_highoutputmode[] = { { MT_FORM | MT_ADV_CALLBACK, 0, "HIGH OUTPUT %s", menu_outputmode_acb}, { MT_FORM | MT_KEYPAD, KM_CENTER, "FREQ: %s", "240MHz..960MHz"}, { MT_FORM | MT_ADV_CALLBACK, 0, "LEVEL: %+ddBm", menu_sdrive_acb}, - { MT_FORM | MT_ADV_CALLBACK, 0, "MODULATION: %s", menu_smodulation_acb}, + { MT_FORM | MT_ADV_CALLBACK, 0, "MOD: %s", menu_smodulation_acb}, { MT_FORM | MT_KEYPAD, KM_SPAN, "SPAN: %s", NULL}, { MT_FORM | MT_KEYPAD, KM_SWEEP_TIME,"SWEEP TIME: %s", "0..600 seconds"}, { MT_FORM | MT_CANCEL, 0, "MODE", NULL }, @@ -1596,6 +1604,9 @@ static const menuitem_t menu_settings3[] = { { MT_KEYPAD, KM_10MHZ, "CORRECT\nFREQUENCY", "Enter actual l0MHz frequency"}, { MT_KEYPAD, KM_GRIDLINES, "MINIMUM\nGRIDLINES", "Enter minimum horizontal grid divisions"}, + { MT_KEYPAD, KM_COR_AM, "COR\nAM", "Enter AM modulation correction"}, + { MT_KEYPAD, KM_COR_WFM, "COR\nWFM", "Enter WFM modulation correction"}, + { MT_KEYPAD, KM_COR_NFM, "COR\nNFM", "Enter NFM modulation correction"}, #ifdef __HAM_BAND__ { MT_ADV_CALLBACK, 0, "HAM\nBANDS", menu_settings_ham_bands}, #endif @@ -1760,6 +1771,8 @@ static const menuitem_t menu_mode[] = { { MT_FORM | MT_ADV_CALLBACK | MT_ICON, I_LOW_OUTPUT+I_SINUS, "%s to LOW out", menu_mode_acb}, { MT_FORM | MT_ADV_CALLBACK | MT_ICON, I_HIGH_OUTPUT+I_GEN, "%s to HIGH out", menu_mode_acb}, { MT_FORM | MT_ADV_CALLBACK | MT_ICON, I_CONNECT+I_GEN, "Cal. output: %s", menu_sreffer_acb}, +// { MT_SUBMENU, 0, "EXPERT\nCONFIG", menu_settings3}, + #ifdef __ULTRA__ { MT_FORM | MT_CALLBACK | MT_ICON, I_LOW_INPUT+I_SA, "ULTRA HIGH INPUT",menu_mode_cb}, #endif @@ -2050,6 +2063,18 @@ set_numeric_value(void) case KM_MODULATION: set_modulation_frequency((int)uistat.value); break; + case KM_COR_AM: + config.cor_am =(int)uistat.value; + config_save(); + break; + case KM_COR_WFM: + config.cor_wfm =(int)uistat.value; + config_save(); + break; + case KM_COR_NFM: + config.cor_nfm =(int)uistat.value; + config_save(); + break; } }