diff --git a/.cproject b/.cproject
index ec54bde..4714753 100644
--- a/.cproject
+++ b/.cproject
@@ -21,12 +21,21 @@
-
+
+
+
-
+
+
+
+
+
+
-
+
+
+
@@ -41,4 +50,6 @@
+
+
diff --git a/main.c b/main.c
index acfac0c..b119432 100644
--- a/main.c
+++ b/main.c
@@ -2209,7 +2209,7 @@ int xtoi(char *t)
else if ('a' <= *t && *t <= 'f')
v = v*16 + *t - 'a' + 10;
else if ('A' <= *t && *t <= 'F')
- v = v*16 + *t - 'a' + 10;
+ v = v*16 + *t - 'A' + 10;
else
return v;
t++;
@@ -2217,7 +2217,7 @@ int xtoi(char *t)
return v;
}
-VNA_SHELL_FUNCTION(cmd_x)
+VNA_SHELL_FUNCTION(cmd_y)
{
int rvalue;
int lvalue = 0;
@@ -2236,9 +2236,34 @@ VNA_SHELL_FUNCTION(cmd_x)
}
}
+VNA_SHELL_FUNCTION(cmd_x)
+{
+ uint32_t reg;
+
+
+ if (argc != 1) {
+ shell_printf("usage: x value(0-FFFFFFFF)\r\n");
+ return;
+ }
+ reg = xtoi(argv[0]);
+
+ if ((reg & 7) == 5) {
+ if (reg & (1<<22))
+ VFO = 1;
+ else
+ VFO = 0;
+ reg &= ~0xc00000; // Force led to show lock
+ reg |= 0x400000;
+ }
+ ADF4351_WriteRegister32(VFO, reg);
+ shell_printf("x=%x\r\n", reg);
+}
+
+
VNA_SHELL_FUNCTION(cmd_i)
{
int rvalue;
+return; // Don't use!!!!
SI4432_Init();
shell_printf("SI4432 init done\r\n");
if (argc == 1) {
@@ -2251,9 +2276,10 @@ VNA_SHELL_FUNCTION(cmd_i)
VNA_SHELL_FUNCTION(cmd_o)
{
(void) argc;
- int32_t value = my_atoi(argv[0]);
- if (VFO == 0)
- frequency_IF = value;
+ return;
+ uint32_t value = my_atoi(argv[0]);
+// if (VFO == 0)
+// frequency_IF = value;
setFreq(VFO, value);
}
@@ -2308,13 +2334,25 @@ VNA_SHELL_FUNCTION(cmd_m)
{
(void)argc;
(void)argv;
+
+ SetMode(0);
+ setting_tracking = false; //Default test setup
+ setting_step_atten = false;
+ SetAttenuation(0);
+ SetReflevel(-10);
+ set_sweep_frequency(ST_START,frequencyStart - frequency_IF );
+ set_sweep_frequency(ST_STOP, frequencyStop - frequency_IF);
+ draw_cal_status();
+
pause_sweep();
int32_t f_step = (frequencyStop-frequencyStart)/ points;
palClearPad(GPIOC, GPIOC_LED); // disable led and wait for voltage stabilization
+ int old_step = setting_frequency_step;
setting_frequency_step = f_step;
update_rbw();
chThdSleepMilliseconds(10);
streamPut(shell_stream, '{');
+ dirty = true;
for (int i = 0; i 870000000)
+ minFreq = setting_harmonic * 240000000;
+ if (setting_harmonic == 0)
+ maxFreq = 4360000000;
+ else
+ maxFreq = 960000000 * setting_harmonic;
+ set_sweep_frequency(ST_START, (uint32_t) minFreq);
+ set_sweep_frequency(ST_STOP, (uint32_t) maxFreq);
+ setting_attenuate = 0;
break;
#endif
case M_GENLOW:
@@ -355,14 +362,29 @@ int GetActualRBW(void)
return((int) actual_rbw);
}
-#ifdef __ULTRA
+#ifdef __ULTRA__
void SetSpur(int v)
{
setting_spur = v;
+ if (setting_spur && actual_rbw > 360)
+ SetRBW(300);
dirty = true;
}
#endif
+void set_harmonic(int h)
+{
+ setting_harmonic = h;
+ minFreq = 870000000;
+ if (setting_harmonic * 240000000 > 870000000)
+ minFreq = setting_harmonic * 240000000;
+ maxFreq = 4360000000;
+ if (setting_harmonic != 0 && 960000000.0 * setting_harmonic < 4360000000.0)
+ maxFreq = ((uint32_t)960000000) * (uint32_t)setting_harmonic;
+ set_sweep_frequency(ST_START, (uint32_t) minFreq);
+ set_sweep_frequency(ST_STOP, (uint32_t) maxFreq);
+}
+
void SetStepDelay(int d)
{
setting_step_delay = d;
@@ -450,17 +472,6 @@ void SetMode(int m)
void apply_settings(void)
{
- if (setting_step_delay == 0){
- if (actual_rbw >142.0) actualStepDelay = 450;
- else if (actual_rbw > 75.0) actualStepDelay = 550;
- else if (actual_rbw > 56.0) actualStepDelay = 650;
- else if (actual_rbw > 37.0) actualStepDelay = 800;
- else if (actual_rbw > 18.0) actualStepDelay = 1100;
- else if (actual_rbw > 9.0) actualStepDelay = 2000;
- else if (actual_rbw > 5.0) actualStepDelay = 3500;
- else actualStepDelay = 6000;
- } else
- actualStepDelay = setting_step_delay;
PE4302_Write_Byte(setting_attenuate * 2);
#if 0
if (setting_modulation == MO_NFM ) {
@@ -477,6 +488,17 @@ void apply_settings(void)
SetRX(setting_mode);
SI4432_SetReference(setting_refer);
update_rbw();
+ if (setting_step_delay == 0){
+ if (actual_rbw >142.0) actualStepDelay = 450;
+ else if (actual_rbw > 75.0) actualStepDelay = 550;
+ else if (actual_rbw > 56.0) actualStepDelay = 650;
+ else if (actual_rbw > 37.0) actualStepDelay = 800;
+ else if (actual_rbw > 18.0) actualStepDelay = 1100;
+ else if (actual_rbw > 9.0) actualStepDelay = 2000;
+ else if (actual_rbw > 5.0) actualStepDelay = 3500;
+ else actualStepDelay = 6000;
+ } else
+ actualStepDelay = setting_step_delay;
}
//------------------------------------------
@@ -496,17 +518,17 @@ void setupSA(void)
PE4302_Write_Byte(0);
}
-static unsigned long old_freq[2] = { 0, 0 };
+static unsigned long old_freq[4] = { 0, 0, 0, 0 };
void setFreq(int V, unsigned long freq)
{
- SI4432_Sel = V;
if (old_freq[V] != freq) {
- if (V == 0) {
- V = -V;
- V = -V;
+ if (V <= 1) {
+ SI4432_Sel = V;
+ SI4432_Set_Frequency(freq);
+ } else {
+ ADF4351_set_frequency(V-2,freq,3);
}
- SI4432_Set_Frequency(freq);
old_freq[V] = freq;
}
}
@@ -851,11 +873,7 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking)
if (MODE_HIGH(setting_mode))
local_IF = 0;
else
- local_IF = frequency_IF
-#ifdef __ULTRA__
- + (int)(actual_rbw < 300.0?setting_spur * 1000 * actual_rbw:0)
-#endif
- ;
+ local_IF = frequency_IF;
if (i == 0 && dirty) {
apply_settings();
@@ -892,8 +910,14 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking)
float RSSI = -150.0;
int t = 0;
do {
- uint32_t lf = (uint32_t)(f + (int)((t * 500 - vbwSteps * 250) * actual_rbw));
- if (lf < 0) lf = 0;
+ int offs = (int)((t * 500 - vbwSteps * 250) * actual_rbw);
+// if (-offs > (uint32_t)f) // Ensure lf >0 0
+// offs = -(uint32_t)(f + offs);
+ uint32_t lf = (uint32_t)(f + offs);
+#ifdef __ULTRA__
+ float spur_RSSI = 0;
+again:
+#endif
if (setting_mode == M_LOW && tracking) {
setFreq (0, frequency_IF + lf - reffer_freq[setting_refer]); // Offset so fundamental of reffer is visible
local_IF = frequency_IF ;
@@ -908,7 +932,9 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking)
setFreq (0, local_IF);
#ifdef __ULTRA__
} else if (setting_mode == M_ULTRA) {
-// local_IF = frequency_IF;
+ local_IF = frequency_IF + (int)(actual_rbw < 350.0 ? setting_spur*300000 : 0 );
+ setFreq (0, local_IF);
+ // local_IF = frequency_IF + (int)(actual_rbw < 300.0?setting_spur * 1000 * actual_rbw:0);
#endif
} else
local_IF= 0;
@@ -946,6 +972,17 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking)
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;
+#ifdef __ULTRA__
+ if (setting_spur == 1) { // First pass
+ spur_RSSI = subRSSI;
+ setting_spur = -1;
+ goto again; // Skip all other processing
+ } else if (setting_spur == -1) { // Second pass
+ subRSSI = ( subRSSI < spur_RSSI ? subRSSI : spur_RSSI); // Minimum of two passes
+ setting_spur = 1;
+ }
+#endif
+
if (RSSI < subRSSI)
RSSI = subRSSI;
t++;
@@ -968,9 +1005,6 @@ static bool sweep(bool break_on_operation)
temppeakLevel = -150;
float temp_min_level = 100;
// spur_old_stepdelay = 0;
-#ifdef __ULTRA__
-again:
-#endif
for (int i = 0; i < sweep_points; i++) {
RSSI = perform(break_on_operation, i, frequencies[i], setting_tracking);
@@ -982,14 +1016,7 @@ again:
}
if (MODE_INPUT(setting_mode)) {
-#ifdef __ULTRA__
- 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
-#endif
+
temp_t[i] = RSSI;
if (setting_subtract_stored) {
RSSI = RSSI - stored_t[i] ;
@@ -1077,13 +1104,6 @@ again:
temp_min_level = actual_t[i];
}
-#ifdef __ULTRA__
- if (setting_spur == 1) {
- setting_spur = -1;
- goto again;
- } else if (setting_spur == -1)
- setting_spur = 1;
-#endif
if (scandirty) {
scandirty = false;
draw_cal_status();
@@ -1999,7 +2019,7 @@ quit:
in_selftest = false;
sweep_mode = SWEEP_ENABLE;
set_refer_output(0);
- reset_settings(M_LOW);
+ SetMode(M_LOW);
#endif
}
diff --git a/si4432.c b/si4432.c
index b0492bf..a194bf5 100644
--- a/si4432.c
+++ b/si4432.c
@@ -536,15 +536,17 @@ void ADF_shiftOut(uint8_t val)
SPI3_SDI_HIGH;
else
SPI3_SDI_LOW;
- chThdSleepMicroseconds(1);
+ chThdSleepMicroseconds(10);
SPI3_CLK_HIGH;
+ chThdSleepMicroseconds(10);
SPI3_CLK_LOW;
+ chThdSleepMicroseconds(10);
}
}
//unsigned long registers[6] = {0x4580A8, 0x80080C9, 0x4E42, 0x4B3, 0xBC803C, 0x580005} ;
//unsigned long registers[6] = {0x4C82C8, 0x80083E9, 0x6E42, 0x8004B3, 0x8C81FC, 0x580005} ;
-unsigned long registers[6] = {0x320000, 0x8008011, 0x18004E42, 0x4B3,0x8C803C , 0x00580005} ;
+unsigned long registers[6] = {0x548018, 0x8008029, 0x4E42, 0x8407D3,0x932474 , 0x580005} ;
int debug = 0;
int ADF4351_LE[2] = { 9, 10};
int ADF4351_Mux = 7;
@@ -593,18 +595,16 @@ void ADF4351_Setup()
// bitSet (registers[2], 17); // R set to 8
// bitClear (registers[2], 14); // R set to 8
- ADF4351_R_counter(1);
- ADF4351_level(3);
- ADF4351_channel_spacing(10);
-
- while(1) {
+// while(1) {
//
- ADF4351_set_frequency(1,100000000,0);
-// ADF4351_set_frequency(1,150000000,0);
+ ADF4351_set_frequency(0,100000000,0);
+ ADF4351_set_frequency(0,150000000,0);
+ ADF4351_set_frequency(1,100000000,0);
+ ADF4351_set_frequency(1,150000000,0);
// ADF4351_Set(0);
// ADF4351_Set(1);
chThdSleepMilliseconds(1000);
- }
+// }
// bitSet (registers[2], 17); // R set to 8
// bitClear (registers[2], 14); // R set to 8
// for (int i=0; i<6; i++) pinMode(ADF4351_LE[i], OUTPUT); // Setup pins
@@ -619,12 +619,13 @@ void ADF4351_Setup()
void ADF4351_WriteRegister32(int channel, const uint32_t value)
{
palClearPad(GPIOA, ADF4351_LE[channel]);
-// chThdSleepMicroseconds(SELECT_DELAY);
- for (int i = 3; i >= 0; i--) ADF_shiftOut((value >> 8 * i) & 0xFF);
+ chThdSleepMicroseconds(10);
+ for (int i = 3; i >= 0; i--) ADF_shiftOut((value >> (8 * i)) & 0xFF);
+ chThdSleepMicroseconds(10);
palSetPad(GPIOA, ADF4351_LE[channel]);
-// chThdSleepMicroseconds(SELECT_DELAY);
+ chThdSleepMicroseconds(10);
palClearPad(GPIOA, ADF4351_LE[channel]);
-// chThdSleepMicroseconds(SELECT_DELAY);
+ chThdSleepMicroseconds(10);
}
void ADF4351_disable_output()
@@ -839,8 +840,8 @@ void ADF4351_prep_frequency(int channel, unsigned long freq, int drive) // freq
bitSet (registers[4], 4); // +5dBm
}
*/
- bitSet (registers[4], 5); // enable + output
- bitClear (registers[4], 8); // enable B output
+// bitSet (registers[4], 5); // enable + output
+// bitClear (registers[4], 8); // enable B output
#if 0
if (FRAC == 0)
@@ -856,7 +857,7 @@ void ADF4351_prep_frequency(int channel, unsigned long freq, int drive) // freq
//bitSet (registers[4], 10); // Mute till lock
bitSet (registers[3], 23); // Fast lock
#endif
- bitSet (registers[4], 10); // Mute till lock
+ // bitSet (registers[4], 10); // Mute till lock
// ADF4351_Set(channel);
}
diff --git a/ui_sa.c b/ui_sa.c
index 745bf81..81f89c0 100644
--- a/ui_sa.c
+++ b/ui_sa.c
@@ -12,6 +12,8 @@ void set_refer_output(int);
int get_refer_output(void);
void SetAttenuation(int);
int GetAttenuation(void);
+void set_harmonic(int);
+extern int setting_harmonic;
int search_is_greater(void);
void set_auto_attenuation(void);
void set_auto_reflevel(void);
@@ -888,6 +890,13 @@ static void choose_active_marker(void)
active_marker = -1;
}
+static void menu_harmonic_cb(int item, uint8_t data)
+{
+ (void)item;
+ set_harmonic(data);
+ draw_menu();
+}
+
static void menu_settings2_cb(int item, uint8_t data)
{
(void)item;
@@ -1157,6 +1166,17 @@ static const menuitem_t menu_dfu[] = {
{ MT_FORM | MT_NONE, 0, NULL, NULL } // sentinel
};
+#ifdef __ULTRA__
+static const menuitem_t menu_harmonic[] =
+{
+ { MT_CALLBACK, 2, "2", menu_harmonic_cb},
+ { MT_CALLBACK, 3, "3", menu_harmonic_cb},
+ { MT_CALLBACK, 4, "4", menu_harmonic_cb},
+ { MT_CALLBACK, 5, "5", menu_harmonic_cb},
+ { MT_CANCEL, 0, S_LARROW" BACK", NULL },
+ { MT_NONE, 0, NULL, NULL } // sentinel
+};
+#endif
static const menuitem_t menu_settings2[] =
{
{ MT_CALLBACK, 0, "AGC", menu_settings2_cb},
@@ -1176,6 +1196,9 @@ static const menuitem_t menu_settings[] =
{ MT_KEYPAD, KM_IF, "\2IF\0FREQ", NULL},
{ MT_KEYPAD, KM_SAMPLETIME, "\2SAMPLE\0TIME", NULL},
{ MT_SUBMENU,0, "\2LO\0DRIVE", menu_drive},
+#ifdef __ULTRA__
+ { MT_SUBMENU,0, "HARMONIC", menu_harmonic},
+#endif
{ MT_SUBMENU, 0, S_RARROW" MORE", menu_settings2},
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
@@ -1472,6 +1495,9 @@ static void menu_item_modify_attribute(
if (item ==0 && setting_tracking_output){
mark = true;
}
+ } else if (MT_MASK(menu[item].type) == MT_CALLBACK && menu == menu_harmonic) {
+ if (data == setting_harmonic)
+ mark = true;
} else if (menu == menu_settings2 || menu == menu_settingshigh2) {
if (item ==0 && setting_agc){
mark = true;