diff --git a/main.c b/main.c index 78790ba..157e039 100644 --- a/main.c +++ b/main.c @@ -37,10 +37,10 @@ #include #include -extern uint32_t minFreq; -extern uint32_t maxFreq; -uint32_t frequencyStart; -uint32_t frequencyStop; +extern float minFreq; +extern float maxFreq; +float frequencyStart; +float frequencyStop; int32_t frequencyExtra; #define START_MIN minFreq #define STOP_MAX maxFreq diff --git a/nanovna.h b/nanovna.h index 40ca6b3..3c6b621 100644 --- a/nanovna.h +++ b/nanovna.h @@ -30,6 +30,7 @@ #define __MEASURE__ #define __SELFTEST__ #define __CALIBRATE__ +#define __ULTRA__ /* * main.c @@ -124,12 +125,12 @@ int shell_printf(const char *fmt, ...); void toggle_sweep(void); void load_default_properties(void); -extern float perform(bool b, int i, int32_t f, int e); +extern float perform(bool b, int i, uint32_t f, int e); enum { AV_OFF, AV_MIN, AV_MAX_HOLD, AV_MAX_DECAY, AV_4, AV_16 }; enum { - M_LOW, M_HIGH, M_GENLOW, M_GENHIGH, + M_LOW, M_HIGH, M_GENLOW, M_GENHIGH, M_ULTRA }; enum { @@ -137,7 +138,11 @@ enum { }; #define MODE_OUTPUT(x) ((x) == M_GENLOW || (x) == M_GENHIGH ) +#ifdef __ULTRA__ +#define MODE_INPUT(x) ((x) == M_LOW || (x) == M_HIGH || (x) == M_ULTRA ) +#else #define MODE_INPUT(x) ((x) == M_LOW || (x) == M_HIGH ) +#endif #define MODE_HIGH(x) ((x) == M_HIGH || (x) == M_GENHIGH ) #define MODE_LOW(x) ((x) == M_LOW || (x) == M_GENLOW ) #define MODE_SELECT(x) (MODE_HIGH(x) ? 1 : 0) @@ -575,7 +580,7 @@ typedef struct uistat { int8_t digit; /* 0~5 */ int8_t digit_mode; int8_t current_trace; /* 0..3 */ - int32_t value; // for editing at numeric input area + float value; // for editing at numeric input area // uint32_t previous_value; uint8_t lever_mode; uint8_t marker_delta; diff --git a/sa_core.c b/sa_core.c index 2aa9f9b..631c45e 100644 --- a/sa_core.c +++ b/sa_core.c @@ -33,9 +33,9 @@ int setting_measurement; int vbwSteps = 1; -//int setting_spur = 0; -uint32_t minFreq = 0; -uint32_t maxFreq = 520000000; +int setting_spur = 0; +float minFreq = 0; +float maxFreq = 520000000; int setting_refer = -1; // Off by default const int reffer_freq[] = {30000000, 15000000, 10000000, 4000000, 3000000, 2000000, 1000000}; @@ -69,15 +69,24 @@ void reset_settings(int m) trace[TRACE_TEMP].enabled = false; setting_measurement = M_OFF; -// setting_spur = 0; + setting_spur = 0; switch(m) { case M_LOW: minFreq = 0; maxFreq = 520000000; - set_sweep_frequency(ST_START, (int32_t) 0); - set_sweep_frequency(ST_STOP, (int32_t) 350000000); + set_sweep_frequency(ST_START, (uint32_t) 0); + set_sweep_frequency(ST_STOP, (uint32_t) 350000000); setting_attenuate = 30; break; +#ifdef __ULTRA__ + case M_ULTRA: + minFreq = 770000000; + maxFreq = 4360000000; + set_sweep_frequency(ST_START, (uint32_t) 960000000); + set_sweep_frequency(ST_STOP, (uint32_t) 2100000000); + setting_attenuate = 30; + break; +#endif case M_GENLOW: setting_drive=8; minFreq = 0; @@ -290,6 +299,10 @@ void SetPowerLevel(int o) config.high_level_offset = new_offset; else if (setting_mode == M_LOW) config.low_level_offset = new_offset; +#ifdef __ULTRA__ + else if (setting_mode == M_ULTRA) + config.low_level_offset = new_offset; +#endif } else { config.low_level_offset = 100; @@ -338,13 +351,13 @@ int GetActualRBW(void) { return((int) actual_rbw); } -#if 0 + + void SetSpur(int v) { -// setting_spur = v; + setting_spur = v; dirty = true; } -#endif void SetStepDelay(int d) { @@ -422,6 +435,10 @@ void SetScale(int s) { //} void SetMode(int m) { +#ifdef __ULTRA__ + if (m == 6) + m = M_ULTRA; +#endif if (setting_mode == m) return; reset_settings(m); @@ -511,6 +528,9 @@ void SetRX(int m) { switch(m) { case M_LOW: // Mixed into 0 +#ifdef __ULTRA__ +case M_ULTRA: +#endif SI4432_Sel = 0; SI4432_Receive(); if (setting_step_atten) { @@ -821,14 +841,14 @@ static int modulation_counter = 0; char age[POINTS_COUNT]; -float perform(bool break_on_operation, int i, int32_t f, int tracking) +float perform(bool break_on_operation, int i, uint32_t f, int tracking) { - // long local_IF = (MODE_LOW(setting_mode)?frequency_IF + (int)(actual_rbw < 300.0?setting_spur * 1000 * actual_rbw :0):0); long local_IF; if (MODE_HIGH(setting_mode)) local_IF = 0; else - local_IF = frequency_IF; + local_IF = frequency_IF + (int)(actual_rbw < 300.0?setting_spur * 1000 * actual_rbw:0); +// local_IF = frequency_IF; if (i == 0 && dirty) { apply_settings(); @@ -865,7 +885,7 @@ float perform(bool break_on_operation, int i, int32_t f, int tracking) float RSSI = -150.0; int t = 0; do { - int lf = (uint32_t)(f + (int)((t * 500 - vbwSteps * 250) * actual_rbw)); + uint32_t lf = (uint32_t)(f + (int)((t * 500 - vbwSteps * 250) * actual_rbw)); if (lf < 0) lf = 0; if (setting_mode == M_LOW && tracking) { setFreq (0, frequency_IF + lf - reffer_freq[setting_refer]); // Offset so fundamental of reffer is visible @@ -874,11 +894,15 @@ float perform(bool break_on_operation, int i, int32_t f, int tracking) if (setting_mode == M_LOW && !in_selftest && avoid_spur(f)) { local_IF = spur_alternate_IF; } else { - local_IF = frequency_IF ; +// local_IF = frequency_IF ; } if (setting_mode == M_GENLOW && setting_modulation == MO_EXTERNAL) local_IF += lf; setFreq (0, local_IF); +#ifdef __ULTRA__ + } else if (setting_mode == M_ULTRA) { +// local_IF = frequency_IF; +#endif } else local_IF= 0; #if 0 @@ -887,13 +911,32 @@ float perform(bool break_on_operation, int i, int32_t f, int tracking) break; } #endif - setFreq (1, local_IF + lf); +#ifdef __ULTRA__ + if (setting_mode == M_ULTRA) { +// if (lf > 3406000000 ) +// setFreq (1, local_IF/5 + lf/5); +// else + if (lf > 2446000000 ) + setFreq (1, local_IF/5 + lf/5); + else +// if (lf > 1486000000) + setFreq (1, local_IF/3 + lf/3); +// else +// setFreq (1, local_IF/2 + lf/2); + } else +#endif + setFreq (1, local_IF + lf); if (MODE_OUTPUT(setting_mode)) // No substepping in output mode return(0); float signal_path_loss; - if (setting_mode == M_LOW) - signal_path_loss = -9.5; // Loss in dB, -9.5 for v0.1, -12.5 for v0.2 +#ifdef __ULTRA__ + if (setting_mode == M_ULTRA) + signal_path_loss = -15; // Loss in dB, -9.5 for v0.1, -12.5 for v0.2 else +#endif + if (setting_mode == M_LOW) + signal_path_loss = -9.5; // Loss in dB, -9.5 for v0.1, -12.5 for v0.2 + else signal_path_loss = 7; // Loss in dB (+ is gain) float subRSSI = SI4432_RSSI(lf, MODE_SELECT(setting_mode))+settingLevelOffset()+ setting_attenuate - signal_path_loss; if (RSSI < subRSSI) @@ -918,7 +961,7 @@ static bool sweep(bool break_on_operation) temppeakLevel = -150; float temp_min_level = 100; // spur_old_stepdelay = 0; - //again: +again: for (int i = 0; i < sweep_points; i++) { RSSI = perform(break_on_operation, i, frequencies[i], setting_tracking); @@ -930,12 +973,12 @@ static bool sweep(bool break_on_operation) } if (MODE_INPUT(setting_mode)) { - // if (setting_spur == 1) { // First pass - // temp_t[i] = RSSI; - // continue; // Skip all other processing - // } - // if (setting_spur == -1) // Second pass - // RSSI = ( RSSI < temp_t[i] ? RSSI : temp_t[i]); // Minimum of two passes + if (setting_spur == 1) { // First pass + temp_t[i] = RSSI; + continue; // Skip all other processing + } + if (setting_spur == -1) // Second pass + RSSI = ( RSSI < temp_t[i] ? RSSI : temp_t[i]); // Minimum of two passes temp_t[i] = RSSI; if (setting_subtract_stored) { RSSI = RSSI - stored_t[i] ; @@ -1023,11 +1066,11 @@ static bool sweep(bool break_on_operation) temp_min_level = actual_t[i]; } - // if (setting_spur == 1) { - // setting_spur = -1; - // goto again; - // } else if (setting_spur == -1) - // setting_spur = 1; + if (setting_spur == 1) { + setting_spur = -1; + goto again; + } else if (setting_spur == -1) + setting_spur = 1; if (scandirty) { scandirty = false; @@ -1335,7 +1378,7 @@ void draw_cal_status(void) buf[5]=0; ili9341_drawstring(buf, x, y); } -#if 0 +#if 1 if (setting_spur) { ili9341_set_foreground(BRIGHT_COLOR_BLUE); y += YSTEP*2; @@ -1383,7 +1426,7 @@ void draw_cal_status(void) ili9341_drawstring("Scan:", x, y); y += YSTEP; - int32_t t = (int)((2* vbwSteps * sweep_points * ( actualStepDelay / 100) )) /10 /* * (setting_spur ? 2 : 1) */; // in mS + int32_t t = (int)((2* vbwSteps * sweep_points * ( actualStepDelay / 100) )) /10 * (setting_spur ? 2 : 1); // in mS if (t>1000) plot_printf(buf, BLEN, "%dS",(t+500)/1000); else diff --git a/ui.c b/ui.c index e508c71..a665681 100644 --- a/ui.c +++ b/ui.c @@ -2051,7 +2051,7 @@ keypad_click(int key) /* numeric input done */ double value = my_atof(kp_buf) * scale; #if 1 - uistat.value = (int)value; + uistat.value = value; set_numeric_value(); #else switch (keypad_mode) { diff --git a/ui_sa.c b/ui_sa.c index b21fa89..a29ce65 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -23,7 +23,7 @@ void SetDrive(int d); void SetIF(int f); void SetStepDelay(int t); extern int setting_rbw; -void SetSpur(int); +extern int setting_spur; int GetSpur(void); void SetAverage(int); int GetAverage(void); @@ -473,6 +473,7 @@ extern const menuitem_t menu_highoutputmode[]; extern const menuitem_t menu_modulation[]; extern const menuitem_t menu_top[]; extern const menuitem_t menu_tophigh[]; +extern const menuitem_t menu_topultra[]; static void menu_mode_cb(int item, uint8_t data) { @@ -492,6 +493,9 @@ static void menu_mode_cb(int item, uint8_t data) case 4: menu_push_submenu(menu_highoutputmode); break; + case 7: + menu_push_submenu(menu_topultra); + break; } // draw_cal_status(); } @@ -614,13 +618,13 @@ static void menu_drive_cb(int item, uint8_t data) -#if 0 +#if 1 static void menu_spur_cb(int item, uint8_t data) { (void)data; (void)item; - if (GetSpur()) + if (setting_spur) SetSpur(0); else SetSpur(1); // must be 0 or 1 !!!! @@ -1250,6 +1254,7 @@ static const menuitem_t menu_stimulus[] = { { MT_KEYPAD, KM_SPAN, "SPAN", NULL}, { MT_KEYPAD, KM_CW, "\2ZERO\0SPAN", NULL}, { MT_SUBMENU,0, "RBW", menu_rbw}, + { MT_CALLBACK,0, "\2SPUR\0REMOVAL", menu_spur_cb}, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; @@ -1264,10 +1269,29 @@ static const menuitem_t menu_mode[] = { { MT_FORM | MT_CALLBACK | MT_ICON, I_HIGH_OUTPUT+I_GEN, "HIGH OUTPUT", menu_mode_cb}, { MT_FORM | MT_SUBMENU | MT_ICON, I_CONNECT+I_GEN, "CAL OUTPUT: %s", menu_reffer}, { MT_FORM | MT_SUBMENU | MT_ICON, I_EMPTY+I_CONFIG, "CONFIG", menu_config}, -// { MT_CANCEL, 0, S_LARROW" BACK", NULL }, +#ifdef __ULTRA__ + { MT_FORM | MT_CALLBACK | MT_ICON, I_LOW_INPUT+I_SA, "ULTRA HIGH INPUT",menu_mode_cb}, +#endif + // { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_FORM | MT_NONE, 0, NULL, NULL } // sentinel }; #if 1 + +#ifdef __ULTRA__ +const menuitem_t menu_topultra[] = { + { MT_CALLBACK, 0, "RESET", menu_autosettings_cb}, + { MT_SUBMENU, 0, "FREQ", menu_stimulus}, + { MT_SUBMENU, 0, "LEVEL", menu_level}, + { MT_SUBMENU, 0, "DISPLAY", menu_display}, + { MT_SUBMENU, 0, "MARKER", menu_marker}, + { MT_SUBMENU, 0, "MEASURE", menu_measure}, + { MT_SUBMENU, 0, "SETTINGS", menu_settings}, + { MT_CANCEL, 0, S_LARROW" MODE",NULL}, + { MT_NONE, 0, NULL, NULL } // sentinel, + // MENUITEM_CLOSE, +}; +#endif + const menuitem_t menu_top[] = { { MT_CALLBACK, 0, "RESET", menu_autosettings_cb}, { MT_SUBMENU, 0, "FREQ", menu_stimulus}, @@ -1367,6 +1391,9 @@ static void menu_item_modify_attribute( if (item == 5 /* PAUSE */ && !(sweep_mode&SWEEP_ENABLE)) { mark = true; } + if (item == 6 && setting_spur) { + mark = true; + } } else if (menu == menu_average) { if (item == GetAverage()){ mark = true;