diff --git a/main.c b/main.c index ccf0c42..d43d65d 100644 --- a/main.c +++ b/main.c @@ -867,8 +867,8 @@ config_t config = { .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, + .cor_wfm = -17, + .cor_nfm = -17, }; //properties_t current_props; diff --git a/sa_core.c b/sa_core.c index fddf268..23fb449 100644 --- a/sa_core.c +++ b/sa_core.c @@ -1483,10 +1483,23 @@ static int modulation_counter = 0; #define MODULATION_STEPS 8 static const int am_modulation[MODULATION_STEPS] = { 5, 1, 0, 1, 5, 9, 11, 9 }; // AM modulation -#define ND 12 -//static const int nfm_modulation[MODULATION_STEPS] = { 2*ND, 3*ND, 4*ND, 3*ND, 2*ND, ND, 0, ND}; // narrow FM modulation avoid sign changes -static const int nfm_modulation[MODULATION_STEPS] = { 2*ND,(int)( 3.5*ND ), 4*ND, (int)(3.5*ND), 2*ND, (int)(0.5*ND), 0, (int)(0.5*ND)}; // narrow FM modulation avoid sign changes -static const int wfm_modulation[MODULATION_STEPS] = { 0, 140, 190, 140, 0, -140, -190, -140 }; // wide FM modulation +// +// Offset is 156.25Hz when below 600MHz and 312.5 when above. +// +#define LND 16 // Total NFM deviation is LND * 4 * 156.25 = 5kHz when below 600MHz or 600MHz - 434MHz +#define HND 8 +#define LWD 96 // Total WFM deviation is LWD * 4 * 156.25 = 30kHz when below 600MHz +#define HWD 48 +static const int fm_modulation[4][MODULATION_STEPS] = // Avoid sign changes in NFM +{ + { 2*LND,(int)( 3.5*LND ), 4*LND, (int)(3.5*LND), 2*LND, (int)(0.5*LND), 0, (int)(0.5*LND)}, + { 0*LWD,(int)( 1.5*LWD ), 2*LWD, (int)(1.5*LWD), 0*LWD, (int)(-1.5*LWD), (int)-2*LWD, (int)(-1.5*LWD)}, + { 2*HND,(int)( 3.5*HND ), 4*HND, (int)(3.5*HND), 2*HND, (int)(0.5*HND), 0, (int)(0.5*HND)}, + { 0*HWD,(int)( 1.5*HWD ), 2*HWD, (int)(1.5*HWD), 0*HWD, (int)(-1.5*HWD), (int)-2*HWD, (int)(-1.5*HWD)}, +}; // narrow FM modulation avoid sign changes + +static const int fm_modulation_offset[4] = { LND*625/2, 0, LND*625/2, 0}; + deviceRSSI_t age[POINTS_COUNT]; // Array used for 1: calculating the age of any max and 2: buffer for fast sweep RSSI values; @@ -1499,6 +1512,7 @@ static systime_t sweep_elapsed = 0; // Time since fi pureRSSI_t perform(bool break_on_operation, int i, uint32_t f, int tracking) // Measure the RSSI for one frequency, used from sweep and other measurement routines. Must do all HW setup { int modulation_delay = 0; + int modulation_index = 0; if (i == 0 && dirty ) { // if first point in scan and dirty calculate_correction(); // pre-calculate correction factor dividers to avoid float division apply_settings(); // Initialize HW @@ -1605,16 +1619,27 @@ pureRSSI_t perform(bool break_on_operation, int i, uint32_t f, int tracking) if (i == 0 || setting.frequency_step != 0) correct_RSSI_freq = get_frequency_correction(f); } + int *current_fm_modulation; if (MODE_OUTPUT(setting.mode)) { if (setting.modulation != MO_NONE && setting.modulation != MO_EXTERNAL && setting.modulation_frequency != 0) { modulation_delay = (1000000/ MODULATION_STEPS ) / setting.modulation_frequency; // 5 steps so 1MHz/5 modulation_counter = 0; 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; + else { // must be FM + if (setting.modulation == MO_WFM) { // -17 default + modulation_delay += config.cor_wfm; + modulation_index = 1; + } else { // must be NFM + modulation_delay += config.cor_nfm; // -17 default + // modulation_index = 0; // default value + } + if ((setting.mode == M_GENLOW && f > 480000000 - 433000000) || + (setting.mode == M_GENHIGH && f > 480000000) ) + modulation_index += 2; + current_fm_modulation = (int *)fm_modulation[modulation_index]; + f -= fm_modulation_offset[modulation_index]; // Shift output frequency + } } } modulation_again: @@ -1631,9 +1656,9 @@ modulation_again: else if (setting.modulation == MO_NFM || setting.modulation == MO_WFM ) { //FM modulation #ifdef __SI4432__ SI4432_Sel = SI4432_LO ; - int offset = setting.modulation == MO_NFM ? nfm_modulation[modulation_counter] : wfm_modulation[modulation_counter] ; - 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 + int offset = current_fm_modulation[modulation_counter]; + SI4432_Write_2_Byte(SI4432_FREQ_OFFSET1, (offset & 0xff ), ((offset >> 8) & 0x03 )); // Use frequency hopping channel for FM modulation +// SI4432_Write_Byte(SI4432_FREQ_OFFSET2, ); // Use frequency hopping channel for FM modulation #endif } modulation_counter++; diff --git a/si4432.c b/si4432.c index 9fd947a..57ff034 100644 --- a/si4432.c +++ b/si4432.c @@ -158,6 +158,22 @@ void SI4432_Write_Byte(uint8_t ADR, uint8_t DATA ) // SI4432_guard = 0; } +void SI4432_Write_2_Byte(uint8_t ADR, uint8_t DATA1, uint8_t DATA2) +{ +// if (SI4432_guard) +// while(1) ; +// SI4432_guard = 1; +// SPI2_CLK_LOW; + palClearPad(GPIOC, SI_nSEL[SI4432_Sel]); +// chThdSleepMicroseconds(SELECT_DELAY); + ADR |= 0x80 ; // RW = 1 + shiftOut( ADR ); + shiftOut( DATA1 ); + shiftOut( DATA2 ); + palSetPad(GPIOC, SI_nSEL[SI4432_Sel]); +// SI4432_guard = 0; +} + void SI4432_Write_3_Byte(uint8_t ADR, uint8_t DATA1, uint8_t DATA2, uint8_t DATA3 ) { // if (SI4432_guard) diff --git a/si4432.h b/si4432.h index 6baebb1..1152e36 100644 --- a/si4432.h +++ b/si4432.h @@ -114,6 +114,7 @@ extern int SI4432_frequency_changed; extern int SI4432_offset_changed; void SI4432_Write_Byte(uint8_t ADR, uint8_t DATA ); +void SI4432_Write_2_Byte(uint8_t ADR, uint8_t DATA1, uint8_t DATA2); uint8_t SI4432_Read_Byte( uint8_t ADR ); void SI4432_Transmit(int d); diff --git a/ui.c b/ui.c index 7b5be97..4f54a72 100644 --- a/ui.c +++ b/ui.c @@ -190,9 +190,12 @@ static int btn_wait_release(void) uint16_t changed = last_button ^ cur_button; if (dt >= BUTTON_DOWN_LONG_TICKS && (cur_button & (1<=0 && status & EVT_BUTTON_SINGLE_CLICK) { menu_invoke(selection); } else { do { @@ -2245,7 +2248,7 @@ ui_process_menu(void) } if (status & EVT_DOWN) { // skip menu item if disabled - while (menuDisabled(menu[selection-1].type)) + while (selection > 0 && menuDisabled(menu[selection-1].type)) selection--; // close menu if item is 0, else step down if (selection > 0) diff --git a/ui_sa.c b/ui_sa.c index eca7c1c..1114588 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1604,7 +1604,7 @@ 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_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__