From 4dfbcca1ed7b924ecc62aeedd28a0b8c8933ef93 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sat, 28 Nov 2020 16:59:23 +0100 Subject: [PATCH] Reduce version specifics --- main.c | 72 +++++++++++++--------- nanovna.h | 65 +++++++++++++++----- sa_cmd.c | 29 ++++++++- sa_core.c | 178 ++++++++++++++++++++++++++++++++++-------------------- si4432.c | 14 ++--- si4432.h | 7 ++- 6 files changed, 245 insertions(+), 120 deletions(-) diff --git a/main.c b/main.c index 4014053..5c25803 100644 --- a/main.c +++ b/main.c @@ -103,7 +103,7 @@ static void transform_domain(void); static int8_t drive_strength = DRIVE_STRENGTH_AUTO; #endif -int8_t sweep_mode = SWEEP_ENABLE; +uint8_t sweep_mode = SWEEP_ENABLE; volatile uint8_t redraw_request = 0; // contains REDRAW_XXX flags // Version text, displayed in Config->Version menu, also send by info command @@ -670,29 +670,29 @@ VNA_SHELL_FUNCTION(cmd_clearconfig) "Do reset manually to take effect. Then do touch cal and save.\r\n"); } -#ifdef __VNA__ +#ifdef __AUDIO__ static struct { int16_t rms[2]; int16_t ave[2]; int callback_count; -#if 0 +#if 1 int32_t last_counter_value; int32_t interval_cycles; int32_t busy_cycles; #endif } stat; - int16_t rx_buffer[AUDIO_BUFFER_LEN * 2]; #ifdef ENABLED_DUMP int16_t dump_buffer[AUDIO_BUFFER_LEN]; int16_t dump_selection = 0; #endif - volatile uint8_t wait_count = 0; volatile uint8_t accumerate_count = 0; +#endif +#ifdef __VNA__ const int8_t bandwidth_accumerate_count[] = { 1, // 1kHz 3, // 300Hz @@ -704,7 +704,7 @@ const int8_t bandwidth_accumerate_count[] = { float measured[2][POINTS_COUNT][2]; #endif measurement_t measured; -#ifdef __VNA__ +#ifdef __AUDIO__ #ifdef ENABLED_DUMP static void duplicate_buffer_to_dump(int16_t *p) @@ -716,7 +716,7 @@ duplicate_buffer_to_dump(int16_t *p) memcpy(dump_buffer, p, sizeof dump_buffer); } #endif - +#ifdef __AUDIO__ void i2s_end_callback(I2SDriver *i2sp, size_t offset, size_t n) { #if PORT_SUPPORTS_RT @@ -758,6 +758,7 @@ static const I2SConfig i2sconfig = { 2 // i2spr }; #endif +#endif #define MAX_DATA 2 VNA_SHELL_FUNCTION(cmd_data) @@ -864,7 +865,12 @@ config_t config = { .magic = CONFIG_MAGIC, .dac_value = 1922, // .touch_cal = { 693, 605, 124, 171 }, // 2.4 inch LCD panel +#ifdef TINYSA3 .touch_cal = { 347, 495, 160, 205 }, // 2.8 inch LCD panel +#endif +#ifdef TINYSA4 + .touch_cal = { 261, 605, 115, 146 }, // 4 inch panel +#endif ._mode = _MODE_USB, ._serial_speed = USART_SPEED_SETTING(SERIAL_DEFAULT_BITRATE), #ifdef __VNA__ @@ -872,10 +878,19 @@ config_t config = { #endif .lcd_palette = LCD_DEFAULT_PALETTE, .vbat_offset = 500, +#ifdef TINYSA4 + .frequency_IF2 = 0, +#endif .low_level_offset = 100, // Uncalibrated .high_level_offset = 100, // Uncalibrated +#ifdef TINYSA3 .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 }, +#endif +#ifdef TINYSA4 + .correction_frequency = { 10000, 100000, 200000, 500000, 50000000, 140000000, 200000000, 300000000, 330000000, 350000000 }, + .correction_value = { 0, 0, 0, 0, 0.0, 0, 0, 0, 0, 0 }, +#endif .setting_frequency_10mhz = 10000000, .cor_am = -14, .cor_wfm = -17, @@ -947,10 +962,11 @@ ensure_edit_config(void) } #include "sa_core.c" -#ifdef __VNA__ +#ifdef __AUDIO__ #define DSP_START(delay) wait_count = delay; #define DSP_WAIT_READY while (wait_count) __WFI(); - +#endif +#ifdef __VNA__ #define DELAY_CHANNEL_CHANGE 2 // main loop for measurement @@ -2252,7 +2268,7 @@ VNA_SHELL_FUNCTION(cmd_color) #if CH_CFG_USE_REGISTRY == FALSE #error "Threads Requite enabled CH_CFG_USE_REGISTRY in chconf.h" #endif -static const char *states[] = {CH_STATE_NAMES}; +const char *states[] = {CH_STATE_NAMES}; VNA_SHELL_FUNCTION(cmd_threads) { thread_t *tp; @@ -2393,21 +2409,23 @@ static const VNAShellCommand commands[] = #ifdef ENABLE_THREADS_COMMAND {"threads" , cmd_threads , 0}, #endif - { "y", cmd_y, 0 }, - { "i", cmd_i, 0 }, - { "v", cmd_v, 0 }, - { "a", cmd_a, 0 }, - { "b", cmd_b, 0 }, - { "t", cmd_t, 0 }, - { "e", cmd_e, 0 }, - { "s", cmd_s, 0 }, - { "m", cmd_m, 0 }, - { "p", cmd_p, 0 }, - { "w", cmd_w, 0 }, - { "o", cmd_o, 0 }, - { "d", cmd_d, 0 }, - { "f", cmd_f, 0 }, -// { "g", cmd_g, 0 }, + { "y", cmd_y, CMD_WAIT_MUTEX }, + { "i", cmd_i, CMD_WAIT_MUTEX }, + { "v", cmd_v, CMD_WAIT_MUTEX }, + { "a", cmd_a, CMD_WAIT_MUTEX }, + { "b", cmd_b, CMD_WAIT_MUTEX }, + { "t", cmd_t, CMD_WAIT_MUTEX }, + { "e", cmd_e, CMD_WAIT_MUTEX }, + { "s", cmd_s, CMD_WAIT_MUTEX }, + { "m", cmd_m, CMD_WAIT_MUTEX }, + { "p", cmd_p, CMD_WAIT_MUTEX }, + { "w", cmd_w, CMD_WAIT_MUTEX }, + { "o", cmd_o, CMD_WAIT_MUTEX }, + { "d", cmd_d, CMD_WAIT_MUTEX }, + { "f", cmd_f, CMD_WAIT_MUTEX }, +#ifdef TINYSA4 + { "g", cmd_g, CMD_WAIT_MUTEX }, + #endif #ifdef __ULTRA_SA__ { "x", cmd_x, 0 }, #endif @@ -2843,7 +2861,7 @@ int main(void) setupSA(); set_sweep_points(POINTS_COUNT); -#ifdef __VNA__ +#ifdef __AUDIO__ /* * I2S Initialize */ @@ -2862,7 +2880,7 @@ int main(void) // menu_mode_cb(setting.mode,0); // } redraw_frame(); -#if 1 +#ifdef TINYSA3 set_mode(M_HIGH); set_sweep_frequency(ST_STOP, (uint32_t) 30000000); sweep(false); diff --git a/nanovna.h b/nanovna.h index 2b12ef8..1ce5c79 100644 --- a/nanovna.h +++ b/nanovna.h @@ -20,12 +20,22 @@ #ifdef TINYSA_F303 #include "adc_F303.h" +#define TINYSA4 +#else +#define TINYSA3 #endif // Need enable HAL_USE_SPI in halconf.h #define __USE_DISPLAY_DMA__ #define __SA__ +#ifdef TINYSA3 #define __SI4432__ +#endif +#ifdef TINYSA4 +#define __SI4463__ +#define __SI4468__ +#define __ADF4351__ +#endif #define __PE4302__ //#define __SIMULATION__ //#define __PIPELINE__ @@ -40,6 +50,20 @@ //#define __ULTRA_SA__ // Adds ADF4351 control for extra high 1st IF stage #define __SPUR__ // Does spur reduction by shifting IF //#define __USE_SERIAL_CONSOLE__ // Enable serial I/O connection (need enable HAL_USE_SERIAL as TRUE in halconf.h) +#ifdef TINYSA3 +#define DEFAULT_IF 433800000 +#define DEFAULT_SPUR_IF 434000000 +#define DEFAULT_MAX_FREQ 350000000 +#define HIGH_MIN_FREQ_MHZ 240 +#define HIGH_MAX_FREQ_MHZ 960 +#endif +#ifdef TINYSA4 +#define DEFAULT_IF 978000000 +#define DEFAULT_SPUR_IF 979000000 +#define DEFAULT_MAX_FREQ 800000000 +#define HIGH_MIN_FREQ_MHZ 850 +#define HIGH_MAX_FREQ_MHZ 1150 +#endif /* * main.c */ @@ -167,7 +191,7 @@ enum { //#define SWEEP_FACTORY 0x20 -extern int8_t sweep_mode; +extern uint8_t sweep_mode; extern bool completed; extern const char *info_about[]; @@ -242,14 +266,14 @@ void set_measurement(int); // extern int settingSpeed; //extern int setting.step_delay; void sweep_remote(void); -#ifdef __VNA__ +#ifdef __AUDIO__ /* * dsp.c */ // 5ms @ 48kHz #define AUDIO_BUFFER_LEN 96 -extern int16_t rx_buffer[]; +extern int16_t rx_buffer[AUDIO_BUFFER_LEN * 2]; #define STATE_LEN 32 #define SAMPLE_LEN 48 @@ -258,7 +282,8 @@ extern int16_t rx_buffer[]; extern int16_t ref_buf[]; extern int16_t samp_buf[]; #endif - +#endif +#ifdef __VNA__ void dsp_process(int16_t *src, size_t len); void reset_dsp_accumerator(void); void calculate_gamma(float *gamma); @@ -266,7 +291,7 @@ void fetch_amplitude(float *gamma); void fetch_amplitude_ref(float *gamma); #endif -#ifdef __VNA__ +#ifdef __AUDIO__ /* * tlv320aic3204.c */ @@ -293,11 +318,11 @@ extern uint16_t graph_bottom; #define BIG_WATERFALL 90 #define SMALL_WATERFALL 180 #define NO_WATERFALL CHART_BOTTOM -#define CHART_BOTTOM 230 +#define CHART_BOTTOM (LCD_HEIGHT-10) #define SCROLL_GRIDY (HEIGHT_SCROLL / NGRIDY) #define NOSCROLL_GRIDY (CHART_BOTTOM / NGRIDY) #else -#define GRIDY (230 / NGRIDY) +#define GRIDY (CHART_BOTTOM / NGRIDY) #endif #define WIDTH (LCD_WIDTH - 1 - OFFSETX) @@ -307,8 +332,8 @@ extern uint16_t graph_bottom; #define CELLHEIGHT (32) #define FREQUENCIES_XPOS1 OFFSETX -#define FREQUENCIES_XPOS2 200 -#define FREQUENCIES_YPOS (LCD_HEIGHT-7) +#define FREQUENCIES_XPOS2 (LCD_WIDTH-120) +#define FREQUENCIES_YPOS (LCD_HEIGHT-8) // #define CELLOFFSETX 0 @@ -318,15 +343,15 @@ extern uint16_t graph_bottom; #define GRID_X_TEXT (AREA_WIDTH_NORMAL - 7*5) // Smith/polar chart -#define P_CENTER_X (CELLOFFSETX + WIDTH/2) -#define P_CENTER_Y (HEIGHT/2) -#define P_RADIUS (HEIGHT/2) +//#define P_CENTER_X (CELLOFFSETX + WIDTH/2) +//#define P_CENTER_Y (HEIGHT/2) +//#define P_RADIUS (HEIGHT/2) // Menu Button // Maximum menu buttons count #define MENU_BUTTON_MAX 8 #define MENU_BUTTON_WIDTH 80 -#define MENU_BUTTON_HEIGHT 28 +#define MENU_BUTTON_HEIGHT (LCD_HEIGHT/8-2) #define MENU_BUTTON_BORDER 1 #define KEYBOARD_BUTTON_BORDER 2 #define FORM_BUTTON_BORDER 2 @@ -341,7 +366,12 @@ extern int16_t area_width; extern int16_t area_height; // Define marker size (can be 0 or 1) +#ifdef TINYSA3 #define _MARKER_SIZE_ 0 +#endif +#ifdef TINYSA4 +#define _MARKER_SIZE_ 1 +#endif // font extern const uint8_t x5x7_bits []; extern const uint8_t x7x11b_bits []; @@ -467,8 +497,11 @@ typedef struct config { uint16_t gridlines; uint16_t hambands; - - int8_t _mode; int8_t cor_am; +#ifdef TINYSA4 + uint32_t frequency_IF2; +#endif + int8_t _mode; + int8_t cor_am; int8_t cor_wfm; int8_t cor_nfm; int8_t dummy; @@ -752,6 +785,7 @@ typedef struct setting int step_delay_mode; int offset_delay; int fast_speedup; + float normalize_level; // Level to set normalize to, zero if not doing anything int modulation_frequency; uint32_t checksum; }setting_t; @@ -1037,6 +1071,7 @@ void calibrate(void); float to_dBm(float); uint32_t calc_min_sweep_time_us(void); pureRSSI_t perform(bool b, int i, uint32_t f, int e); +void interpolate_maximum(int m); enum { M_OFF, M_IMD, M_OIP3, M_PHASE_NOISE, M_STOP_BAND, M_PASS_BAND, M_LINEARITY, M_AM, M_FM, M_THD diff --git a/sa_cmd.c b/sa_cmd.c index fd2c59b..639af24 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -273,7 +273,7 @@ VNA_SHELL_FUNCTION(cmd_if) return; } else { int a = my_atoi(argv[0]); - if (a!= 0 &&( a < 433000000 || a>435000000)) + if (a!= 0 &&( a < (DEFAULT_IF - 2000000) || a>(DEFAULT_IF + 2000000))) goto usage; setting.auto_IF = false; set_IF(a); @@ -343,6 +343,33 @@ VNA_SHELL_FUNCTION(cmd_y) #endif } +VNA_SHELL_FUNCTION(cmd_z) +{ + static const char cmd_z_list[] = "t|r|i"; + if (argc != 1) { + shell_printf("usage: z %s\r\n", cmd_z_list); + return; + } + if (argc == 1) { +#ifdef __SI4432__ + SI4432_Sel = VFO; + int type = get_str_index(argv[0], cmd_z_list); + switch(type) { + case 0: + SI4432_Transmit(3); + break; + case 1: + SI4432_Receive(); + break; + case 2: + SI4432_Reset(); + break; + } +#endif + } +} + + VNA_SHELL_FUNCTION(cmd_selftest) { if (argc < 1 || argc > 2) { diff --git a/sa_core.c b/sa_core.c index c7ebb0d..dcbf097 100644 --- a/sa_core.c +++ b/sa_core.c @@ -16,9 +16,9 @@ * Boston, MA 02110-1301, USA. */ -#ifdef __SI4432__ +//#ifdef __SI4432__ #include "si4432.h" // comment out for simulation -#endif +//#endif #include "stdlib.h" #pragma GCC push_options @@ -67,7 +67,7 @@ void update_min_max_freq(void) switch(setting.mode) { case M_LOW: minFreq = 0; - maxFreq = 350000000; + maxFreq = DEFAULT_MAX_FREQ; break; #ifdef __ULTRA__ case M_ULTRA: @@ -77,15 +77,15 @@ void update_min_max_freq(void) #endif case M_GENLOW: minFreq = 0; - maxFreq = 350000000; + maxFreq = DEFAULT_MAX_FREQ; break; case M_HIGH: #ifdef __ULTRA_SA__ minFreq = 00000000; maxFreq = 2000000000; #else - minFreq = 24*config.setting_frequency_10mhz; - maxFreq = 96*config.setting_frequency_10mhz; + minFreq = HIGH_MIN_FREQ_MHZ * 1000000; + maxFreq = HIGH_MAX_FREQ_MHZ * 1000000; #endif break; case M_GENHIGH: @@ -113,6 +113,7 @@ void reset_settings(int m) setting.show_stored = 0; setting.auto_attenuation = false; setting.subtract_stored = 0; + setting.normalize_level = 0.0; setting.drive=13; setting.atten_step = 0; // Only used in low output mode setting.agc = S_AUTO_ON; @@ -131,7 +132,7 @@ void reset_settings(int m) setting.repeat = 1; setting.tracking_output = false; setting.measurement = M_OFF; - setting.frequency_IF = 433800000; + setting.frequency_IF = DEFAULT_IF; setting.auto_IF = true; setting.offset = 0.0; setting.trigger = T_AUTO; @@ -205,7 +206,7 @@ uint32_t calc_min_sweep_time_us(void) // Estimate minimum sweep time in if (MODE_OUTPUT(setting.mode)) t = 200*sweep_points; // 200 microseconds is the delay set in perform when sweeping in output mode else { - uint32_t bare_sweep_time; + uint32_t bare_sweep_time=0; #ifdef __SI4432__ bare_sweep_time = (SI4432_step_delay + MEASURE_TIME) * (sweep_points); // Single RSSI delay and measurement time in uS while scanning #endif @@ -225,7 +226,7 @@ void set_refer_output(int v) { setting.refer = v; #ifdef __SI4432__ - SI4432_SetReference(setting.refer); + set_calibration_freq(setting.refer); #endif // dirty = true; } @@ -386,6 +387,30 @@ void set_IF(int f) dirty = true; } +#ifdef TINYSA4 +void set_IF2(int f) +{ + + config.frequency_IF2 = f; + dirty = true; + config_save(); +} + +void set_R(int f) +{ + ADF4351_R_counter(f % 10); + ADF4351_spur_mode(f/10); + dirty = true; +} + +void set_modulo(uint32_t f) +{ + ADF4350_modulo = f; + //ADF4351_spur_mode(f); + dirty = true; +} +#endif + #define POWER_STEP 0 // Should be 5 dB but appearently it is lower #define POWER_OFFSET 15 #define SWITCH_ATTENUATION 30 @@ -524,6 +549,7 @@ void set_subtract_storage(void) if (!setting.show_stored) set_storage(); setting.subtract_stored = true; + setting.normalize_level = 0.0; // setting.auto_attenuation = false; } else { setting.subtract_stored = false; @@ -539,6 +565,7 @@ void toggle_normalize(void) stored_t[i] = actual_t[i]; setting.subtract_stored = true; setting.auto_attenuation = false; // Otherwise noise level may move leading to strange measurements + setting.normalize_level = 0.0; } else { setting.subtract_stored = false; } @@ -626,7 +653,7 @@ void set_harmonic(int h) void set_step_delay(int d) // override RSSI measurement delay or set to one of three auto modes { - if ((3 <= d && d < 250) || d > 30000) // values 0 (normal scan), 1 (precise scan) and 2(fast scan) have special meaning and are auto calculated + if ((3 <= d && d < 100) || d > 30000) // values 0 (normal scan), 1 (precise scan) and 2(fast scan) have special meaning and are auto calculated return; if (d <3) { setting.step_delay_mode = d; @@ -688,9 +715,7 @@ void toggle_AGC(void) dirty = true; } -#ifdef __SI4432__ static unsigned char SI4432_old_v[2]; -#endif void auto_set_AGC_LNA(int auto_set, int agc) // Adapt the AGC setting if needed { @@ -906,7 +931,6 @@ void set_fast_speedup(int s) void calculate_step_delay(void) { -#ifdef __SI4432__ if (setting.step_delay_mode == SD_MANUAL || setting.step_delay != 0) { // The latter part required for selftest 3 SI4432_step_delay = setting.step_delay; if (setting.offset_delay != 0) // Override if set @@ -916,6 +940,7 @@ void calculate_step_delay(void) if (setting.frequency_step == 0) { // zero span mode, not dependent on selected RBW SI4432_step_delay = 0; } else { +#ifdef __SI4432__ #if 1 // Table for double offset delay if (actual_rbw_x10 >= 1910) { SI4432_step_delay = 300; SI4432_offset_delay = 100; } else if (actual_rbw_x10 >= 1420) { SI4432_step_delay = 350; SI4432_offset_delay = 100; } @@ -936,6 +961,7 @@ void calculate_step_delay(void) else if (actual_rbw_x10 >= 90) { SI4432_step_delay = 1700; SI4432_offset_delay = 400; } else if (actual_rbw_x10 >= 50) { SI4432_step_delay = 3300; SI4432_offset_delay = 400; } else { SI4432_step_delay = 6400; SI4432_offset_delay =1600; } +#endif #endif if (setting.step_delay_mode == SD_PRECISE) // In precise mode wait twice as long for RSSI to stabalize SI4432_step_delay *= 2; @@ -945,7 +971,6 @@ void calculate_step_delay(void) if (setting.offset_delay != 0) // Override if set SI4432_offset_delay = setting.offset_delay; } -#endif } void apply_settings(void) // Ensure all settings in the setting structure are translated to the right HW setup @@ -961,7 +986,7 @@ void apply_settings(void) // Ensure all settings in the setting structure } #ifdef __SI4432__ - SI4432_SetReference(setting.refer); + set_calibration_freq(setting.refer); #endif update_rbw(); calculate_step_delay(); @@ -1045,10 +1070,10 @@ void setupSA(void) #ifdef __SI4432__ SI4432_Init(); #endif - old_freq[0] = 0; - old_freq[1] = 0; - real_old_freq[0] = 0; - real_old_freq[1] = 0; + for (int i = 0; i < sizeof(old_freq)/sizeof(unsigned long) ; i++) { + old_freq[i] = 0; + real_old_freq[i] = 0; + } #ifdef __SI4432__ SI4432_Sel = SI4432_RX ; SI4432_Receive(); @@ -1082,7 +1107,7 @@ void setupSA(void) void set_freq(int V, unsigned long freq) // translate the requested frequency into a setting of the SI4432 { - if (old_freq[V] == freq) // Do not change HW if not needed + if (old_freq[V] == freq) // Do not change HW if not needed return; if (V <= 1) { #ifdef __SI4432__ @@ -1198,8 +1223,10 @@ case M_ULTRA: } else { set_switch_receive(); } +#endif set_AGC_LNA(); +#ifdef __SI4432__ SI4432_Sel = SI4432_LO ; if (setting.tracking_output) set_switch_transmit(); @@ -1207,13 +1234,13 @@ case M_ULTRA: set_switch_off(); // SI4432_Receive(); For noise testing only SI4432_Transmit(setting.drive); - // SI4432_SetReference(setting.refer); + // set_calibration_freq(setting.refer); #endif break; case M_HIGH: // Direct into 1 mute: #ifdef __SI4432__ - // SI4432_SetReference(-1); // Stop reference output + // set_calibration_freq(-1); // Stop reference output SI4432_Sel = SI4432_RX ; // both as receiver to avoid spurs set_switch_receive(); SI4432_Receive(); @@ -1225,8 +1252,8 @@ mute: } else { set_switch_receive(); } - set_AGC_LNA(); #endif + set_AGC_LNA(); break; case M_GENLOW: // Mixed output from 0 @@ -1279,27 +1306,28 @@ void update_rbw(void) // calculate the actual_rbw and the vbwSteps (# } else { setting.vbw_x10 = 3000; // trick to get right default rbw in zero span mode } - actual_rbw_x10 = setting.rbw_x10; // requested rbw - if (actual_rbw_x10 == 0) { // if auto rbw + uint32_t temp_actual_rbw_x10 = setting.rbw_x10; // requested rbw , 32 bit !!!!!! + if (temp_actual_rbw_x10 == 0) { // if auto rbw if (setting.step_delay_mode==SD_FAST) { // if in fast scanning if (setting.fast_speedup > 2) - actual_rbw_x10 = 6*setting.vbw_x10; // rbw is four the frequency step to ensure no gaps in coverage as there are some weird jumps + temp_actual_rbw_x10 = 6*setting.vbw_x10; // rbw is six times the frequency step to ensure no gaps in coverage as there are some weird jumps else - actual_rbw_x10 = 4*setting.vbw_x10; // rbw is four the frequency step to ensure no gaps in coverage as there are some weird jumps + temp_actual_rbw_x10 = 4*setting.vbw_x10; // rbw is four times the frequency step to ensure no gaps in coverage as there are some weird jumps } else - actual_rbw_x10 = 2*setting.vbw_x10; // rbw is twice the frequency step to ensure no gaps in coverage + temp_actual_rbw_x10 = 2*setting.vbw_x10; // rbw is twice the frequency step to ensure no gaps in coverage } - if (actual_rbw_x10 < 26) - actual_rbw_x10 = 26; - if (actual_rbw_x10 > 6000) - actual_rbw_x10 = 6000; - +#ifdef __SI4432__ + if (temp_actual_rbw_x10 < 26) + temp_actual_rbw_x10 = 26; + if (temp_actual_rbw_x10 > 6000) + temp_actual_rbw_x10 = 6000; +#endif + actual_rbw_x10 = temp_actual_rbw_x10; // Now it fits in 16 bit +#ifdef __SI4432__ if (setting.spur_removal && actual_rbw_x10 > 3000) actual_rbw_x10 = 2500; // if spur suppression reduce max rbw to fit within BPF - -#ifdef __SI4432__ SI4432_Sel = MODE_SELECT(setting.mode); - actual_rbw_x10 = SI4432_SET_RBW(actual_rbw_x10); // see what rbw the SI4432 can realize + actual_rbw_x10 = set_rbw(actual_rbw_x10); // see what rbw the SI4432 can realize #endif if (setting.frequency_step > 0 && MODE_INPUT(setting.mode)) { // When doing frequency scanning in input mode vbwSteps = ((int)(2 * (setting.vbw_x10 + (actual_rbw_x10/2)) / actual_rbw_x10)); // calculate # steps in between each frequency step due to rbw being less than frequency step @@ -1416,8 +1444,8 @@ search_maximum(int m, int center, int span) } //static int spur_old_stepdelay = 0; -static const unsigned int spur_IF = 433800000; // The IF frequency for which the spur table is value -static const unsigned int spur_alternate_IF = 434000000; // if the frequency is found in the spur table use this IF frequency +static const unsigned int spur_IF = DEFAULT_IF; // The IF frequency for which the spur table is value +static const unsigned int spur_alternate_IF = DEFAULT_SPUR_IF; // if the frequency is found in the spur table use this IF frequency static const int spur_table[] = // Frequencies to avoid { // 580000, // 433.8 MHz table @@ -1653,10 +1681,12 @@ pureRSSI_t perform(bool break_on_operation, int i, uint32_t f, int tracking) } } if (setting.mode == M_LOW && S_IS_AUTO(setting.agc) && !check_for_AM && UNIT_IS_LOG(setting.unit)) { // If in low input mode with auto AGC and log unit +#ifdef __SI4432__ if (f < 1500000) auto_set_AGC_LNA(false, f*9/1500000); else auto_set_AGC_LNA(true, 0); +#endif } // Calculate the RSSI correction for later use if (MODE_INPUT(setting.mode)){ // only cases where the value can change on 0 point of sweep @@ -1678,7 +1708,7 @@ pureRSSI_t perform(bool break_on_operation, int i, uint32_t f, int tracking) modulation_delay += config.cor_nfm; // -17 default // modulation_index = 0; // default value } - if ((setting.mode == M_GENLOW && f > 480000000 - 433000000) || + if ((setting.mode == M_GENLOW && f > 480000000 - DEFAULT_IF) || (setting.mode == M_GENHIGH && f > 480000000) ) modulation_index += 2; current_fm_modulation = (int *)fm_modulation[modulation_index]; @@ -1736,7 +1766,7 @@ modulation_again: if (/* MODE_INPUT(setting.mode) && */ i > 0 && FREQ_IS_CW()) // In input mode in zero span mode after first setting of the LO's goto skip_LO_setting; // No more LO changes required, save some time and jump over the code - long local_IF; + int32_t local_IF; again: // Spur reduction jumps to here for second measurement @@ -1744,7 +1774,7 @@ modulation_again: local_IF = 0; else { if (setting.auto_IF) - local_IF = setting.spur_removal ? 433900000 : spur_IF; + local_IF = setting.spur_removal ? DEFAULT_IF : spur_IF; else local_IF = setting.frequency_IF; } @@ -1760,18 +1790,17 @@ modulation_again: #endif #ifdef __SPUR__ } else if (setting.mode== M_LOW && setting.spur_removal){ // If in low input mode and spur reduction is on - if (S_IS_AUTO(setting.below_IF) && lf < 150000000) // if below 150MHz and auto_below_IF + if (S_IS_AUTO(setting.below_IF) && (lf < local_IF / 2 || lf > local_IF) ) // if below 150MHz and auto_below_IF <-------------------TODO --------------------- { // else low/above IF if (setting.spur_removal == 1) setting.below_IF = S_AUTO_ON; // use below IF in first pass else setting.below_IF = S_AUTO_OFF; // and above IF in second pass } - else { - int32_t spur_offset = actual_rbw_x10 * 100; // Can not use below IF so calculate IF shift that hopefully will kill the spur. + else + { if (setting.spur_removal == -1) // If second spur pass - spur_offset = - spur_offset; // IF shift in the other direction - local_IF = local_IF + spur_offset; // apply IF spur shift + local_IF = local_IF + 1000000; // apply IF spur shift } #endif } @@ -1781,7 +1810,10 @@ modulation_again: // --------------------- IF know, set the RX SI4432 frequency ------------------------ #ifdef __SI4432__ - set_freq (SI4432_RX , local_IF); + if (setting.mode == M_LOW || setting.mode == M_GENLOW ) + { + set_freq (SI4432_RX , local_IF); + } #endif #ifdef __ULTRA__ } else if (setting.mode == M_ULTRA) { // No above/below IF mode in Ultra @@ -1816,12 +1848,9 @@ modulation_again: #endif { // Else set LO ('s) #ifdef __ULTRA_SA__ - //#define IF_1 2550000000 -#define IF_2 2025000000 // First IF in Ultra SA mode - - set_freq (2, IF_2 + lf); // Scanning LO up to IF2 - set_freq (3, IF_2 - 433800000); // Down from IF2 to fixed second IF in Ultra SA mode - set_freq (SI4432_LO, 433800000); // Second IF fixed in Ultra SA mode + set_freq (2, config.frequency_IF2 + lf); // Scanning LO up to IF2 + set_freq (3, config.frequency_IF2 - DEFAULT_IF); // Down from IF2 to fixed second IF in Ultra SA mode + set_freq (SI4432_LO, DEFAULT_IF); // Second IF fixed in Ultra SA mode #else #ifdef __SI4432__ if (setting.mode == M_LOW && !setting.tracking && S_STATE(setting.below_IF)) // if in low input mode and below IF @@ -1972,8 +2001,12 @@ static bool sweep(bool break_on_operation) // if (setting.mode== -1) // return; // START_PROFILE; +#ifdef TINYSA3 palClearPad(GPIOB, GPIOB_LED); - +#endif +#ifdef TINYSA4 + palClearPad(GPIOC, GPIOC_LED); +#endif downslope = true; // Initialize the peak search algorithm temppeakLevel = -150; float temp_min_level = 100; @@ -2025,6 +2058,7 @@ sweep_again: // stay in sweep loop when output mo // ----------------------- in loop AGC --------------------------------- +#ifdef __SI4432__ if (!in_selftest && setting.mode == M_HIGH && S_IS_AUTO(setting.agc) && UNIT_IS_LOG(setting.unit)) { #define AGC_RSSI_THRESHOLD (-55+get_attenuation()) @@ -2042,7 +2076,7 @@ sweep_again: // stay in sweep loop when output mo else auto_set_AGC_LNA(TRUE, 0); } - +#endif // Delay between points if needed, (all delays can apply in SI4432 fill) if (setting.measure_sweep_time_us == 0){ // If not already in buffer @@ -2069,8 +2103,9 @@ sweep_again: // stay in sweep loop when output mo if (setting.average != AV_OFF) temp_t[i] = RSSI; if (setting.subtract_stored) { - RSSI = RSSI - stored_t[i] ; + RSSI = RSSI - stored_t[i] + setting.normalize_level; } +#ifdef __SI4432__ //#define __DEBUG_AGC__ #ifdef __DEBUG_AGC__ // For debugging the AGC control stored_t[i] = (SI4432_Read_Byte(0x69) & 0x01f) * 3.0 - 90.0; // Display the AGC value in the stored trace @@ -2085,6 +2120,7 @@ sweep_again: // stay in sweep loop when output mo } last_AGC_value = AGC_value; } +#endif if (scandirty || setting.average == AV_OFF) { // Level calculations actual_t[i] = RSSI; age[i] = 0; @@ -2241,6 +2277,7 @@ sweep_again: // stay in sweep loop when output mo #define __MIRROR_MASKING__ #ifdef __MIRROR_MASKING__ +#ifdef __SI4432__ if (setting.mode == M_HIGH && setting.mirror_masking) { int mirror_offset = 2 * 937000 / setting.frequency_step; // int mask_start = 0; @@ -2263,6 +2300,7 @@ sweep_again: // stay in sweep loop when output mo } } +#endif #endif // -------------------------- auto attenuate ---------------------------------- @@ -2314,6 +2352,7 @@ sweep_again: // stay in sweep loop when output mo if (!in_selftest && MODE_INPUT(setting.mode)) { +#ifdef __SI4432__ if (S_IS_AUTO(setting.agc)) { float actual_max_level = actual_t[max_index[0]] - get_attenuation(); if (UNIT_IS_LINEAR(setting.unit)) { // Auto AGC in linear mode @@ -2337,6 +2376,7 @@ sweep_again: // stay in sweep loop when output mo } } } else +#endif signal_is_AM = false; } @@ -2566,8 +2606,13 @@ sweep_again: // stay in sweep loop when output mo // redraw_marker(peak_marker, FALSE); // STOP_PROFILE; - +#ifdef TINYSA3 palSetPad(GPIOB, GPIOB_LED); +#endif +#ifdef TINYSA4 + palSetPad(GPIOC, GPIOC_LED); +#endif + return true; } @@ -3367,7 +3412,7 @@ void test_prepare(int i) { setting.tracking = false; //Default test setup setting.atten_step = false; - setting.frequency_IF = 433800000; // Default frequency + setting.frequency_IF = DEFAULT_IF; // Default frequency setting.auto_IF = true; setting.auto_attenuation = false; switch(test_case[i].setup) { // Prepare test conditions @@ -3389,7 +3434,7 @@ common_silent: set_mode(M_LOW); setting.tracking = true; //Sweep BPF setting.auto_IF = false; - setting.frequency_IF = 433900000; // Center on SAW filters + setting.frequency_IF = DEFAULT_IF; // Center on SAW filters set_refer_output(2); goto common; case TP_10MHZ: // 10MHz input @@ -3530,7 +3575,7 @@ void self_test(int test) reset_settings(M_LOW); test_prepare(TEST_SILENCE); setting.auto_IF = false; - setting.frequency_IF=433850000; + setting.frequency_IF=DEFAULT_IF; setting.frequency_step = 30000; if (setting.test_argument > 0) setting.frequency_step=setting.test_argument; @@ -3547,7 +3592,7 @@ void self_test(int test) f += setting.frequency_step; shell_printf("\n\rStarting with %4.2f, %4.2f and IF at %d and step of %d\n\r", p2, p1, setting.frequency_IF, setting.frequency_step ); f = 400000; - while (f < 100000000) { + while (f < DEFAULT_MAX_FREQ) { p = PURE_TO_float(perform(false, 1, f, false)); #define SPUR_DELTA 6 if ( p2 < p1 - SPUR_DELTA && p < p1 - SPUR_DELTA) { @@ -3595,7 +3640,7 @@ void self_test(int test) in_selftest = true; // reset_settings(M_LOW); setting.auto_IF = false; - setting.frequency_IF=433900000; + setting.frequency_IF=DEFAULT_IF; ui_mode_normal(); test_prepare(TEST_RBW); setting.step_delay = 8000; @@ -3614,9 +3659,8 @@ void self_test(int test) #endif setting.step_delay = setting.step_delay * 5 / 4; setting.offset_delay = setting.step_delay / 2; -#ifdef __SI4432__ - setting.rbw_x10 = SI4432_force_RBW(j); -#endif + setting.rbw_x10 = force_RBW(j); + shell_printf("RBW = %f, ",setting.rbw_x10/10.0); #if 0 set_sweep_frequency(ST_SPAN, (uint32_t)(setting.rbw_x10 * 1000)); // Wide @@ -3705,12 +3749,12 @@ void self_test(int test) case 2: reset_settings(M_LOW); set_sweep_frequency(ST_START, 300000000); - set_sweep_frequency(ST_STOP, 350000000); + set_sweep_frequency(ST_STOP, DEFAULT_MAX_FREQ); break; case 3: reset_settings(M_HIGH); set_sweep_frequency(ST_START, 300000000); - set_sweep_frequency(ST_STOP, 350000000); + set_sweep_frequency(ST_STOP, DEFAULT_MAX_FREQ); break; case 4: reset_settings(M_GENLOW); diff --git a/si4432.c b/si4432.c index 718ad23..95831b0 100644 --- a/si4432.c +++ b/si4432.c @@ -327,7 +327,7 @@ const int SI4432_RBW_count = ((int)(sizeof(RBW_choices)/sizeof(RBW_t))); static pureRSSI_t SI4432_RSSI_correction = float_TO_PURE_RSSI(-120); -uint16_t SI4432_force_RBW(int i) +uint16_t force_rbw(int i) { SI4432_Write_Byte(SI4432_IF_FILTER_BW, RBW_choices[i].reg); // Write RBW settings to Si4432 SI4432_RSSI_correction = float_TO_PURE_RSSI(RBW_choices[i].RSSI_correction_x_10 - 1200)/10; // Set RSSI correction @@ -335,12 +335,12 @@ uint16_t SI4432_force_RBW(int i) return RBW_choices[i].RBWx10; // RBW achieved by Si4432 in kHz * 10 } -uint16_t SI4432_SET_RBW(uint16_t WISH) { +uint16_t set_rbw(uint16_t WISH) { int i; for (i=0; i < SI4432_RBW_count - 1; i++) if (WISH <= RBW_choices[i].RBWx10) break; - return SI4432_force_RBW(i); + return force_rbw(i); } @@ -559,7 +559,7 @@ void SI4432_Sub_Init(void) // Clock Recovery Gearshift Value SI4432_Write_Byte(SI4432_CLOCK_RECOVERY_GEARSHIFT, 0x00); // IF Filter Bandwidth - SI4432_SET_RBW(100) ; + set_rbw(100) ; // // Register 0x75 Frequency Band Select // uint8_t sbsel = 1 ; // recommended setting // uint8_t hbsel = 0 ; // low bands @@ -657,7 +657,7 @@ void SI4432_Init() // SI4432_Write_Byte(Si4432_UC_OUTPUT_CLOCK, 0x02) ; // Set 10MHz output } -void SI4432_SetReference(int freq) +void set_calibration_freq(int freq) { SI4432_Sel = SI4432_LO; //Select Lo module if (freq < 0 || freq > 7 ) { @@ -727,8 +727,8 @@ bool PE4302_Write_Byte(unsigned char DATA ) //-----------------SI4432 dummy------------------ void SI4432_Write_Byte(unsigned char ADR, unsigned char DATA ) {} unsigned char SI4432_Read_Byte(unsigned char ADR) {return ADR;} -float SI4432_SET_RBW(float WISH) {return (WISH > 600.0?600: (WISH<3.0?3:WISH));} -void SI4432_SetReference(int p) {} +float set_rbw(float WISH) {return (WISH > 600.0?600: (WISH<3.0?3:WISH));} +void set_calibration_freq(int p) {} void SI4432_Set_Frequency(long f) {} void PE4302_Write_Byte(unsigned char DATA ) {} void PE4302_init(void) {} diff --git a/si4432.h b/si4432.h index 1152e36..1247ce3 100644 --- a/si4432.h +++ b/si4432.h @@ -119,6 +119,7 @@ uint8_t SI4432_Read_Byte( uint8_t ADR ); void SI4432_Transmit(int d); void SI4432_Receive(void); +void SI4432_Reset(void); void SI4432_Init(void); void SI4432_Drive(int); @@ -129,10 +130,10 @@ float Simulated_SI4432_RSSI(uint32_t i, int s); #endif void SI4432_Set_Frequency ( uint32_t Freq ); -uint16_t SI4432_force_RBW(int i); -uint16_t SI4432_SET_RBW(uint16_t WISH); +uint16_t force_rbw(int i); +uint16_t set_rbw(uint16_t WISH); extern const int SI4432_RBW_count; -void SI4432_SetReference(int freq); +void set_calibration_freq(int freq); #ifdef __FAST_SWEEP__ void SI4432_Fill(int s, int start); #if 0