Added sample mean calculation

Removed_REF_marker
erikkaashoek 5 years ago
parent fae783f2a9
commit 62d83ee44f

@ -866,7 +866,8 @@ config_t config = {
.menu_active_color = DEFAULT_MENU_ACTIVE_COLOR, .menu_active_color = DEFAULT_MENU_ACTIVE_COLOR,
.trace_color = { DEFAULT_TRACE_1_COLOR, DEFAULT_TRACE_2_COLOR, DEFAULT_TRACE_3_COLOR}, .trace_color = { DEFAULT_TRACE_1_COLOR, DEFAULT_TRACE_2_COLOR, DEFAULT_TRACE_3_COLOR},
// .touch_cal = { 693, 605, 124, 171 }, // 2.4 inch LCD panel // .touch_cal = { 693, 605, 124, 171 }, // 2.4 inch LCD panel
.touch_cal = { 347, 495, 160, 205 }, // 2.8 inch LCD panel // .touch_cal = { 347, 495, 160, 205 }, // 2.8 inch LCD panel
.touch_cal = { 261, 605, 115, 146 }, // 4 inch panel
._mode = _MODE_USB, ._mode = _MODE_USB,
._serial_speed = USART_SPEED_SETTING(SERIAL_DEFAULT_BITRATE), ._serial_speed = USART_SPEED_SETTING(SERIAL_DEFAULT_BITRATE),
#ifdef __VNA__ #ifdef __VNA__
@ -874,6 +875,7 @@ config_t config = {
#endif #endif
.vbat_offset = 500, .vbat_offset = 500,
.frequency_IF2 = 2048600000, .frequency_IF2 = 2048600000,
.setting_frequency_10mhz = 1000015.0,
.low_level_offset = 100, // Uncalibrated .low_level_offset = 100, // Uncalibrated
.high_level_offset = 100, // Uncalibrated .high_level_offset = 100, // Uncalibrated
.correction_frequency = { 10000, 100000, 200000, 500000, 50000000, 140000000, 200000000, 300000000, 330000000, 350000000 }, .correction_frequency = { 10000, 100000, 200000, 500000, 50000000, 140000000, 200000000, 300000000, 330000000, 350000000 },
@ -2278,7 +2280,7 @@ VNA_SHELL_FUNCTION(cmd_color)
#if CH_CFG_USE_REGISTRY == FALSE #if CH_CFG_USE_REGISTRY == FALSE
#error "Threads Requite enabled CH_CFG_USE_REGISTRY in chconf.h" #error "Threads Requite enabled CH_CFG_USE_REGISTRY in chconf.h"
#endif #endif
static const char *states[] = {CH_STATE_NAMES}; const char *states[] = {CH_STATE_NAMES};
VNA_SHELL_FUNCTION(cmd_threads) VNA_SHELL_FUNCTION(cmd_threads)
{ {
thread_t *tp; thread_t *tp;

@ -237,7 +237,7 @@ void set_decay(int);
void set_noise(int); void set_noise(int);
void toggle_tracking_output(void); void toggle_tracking_output(void);
extern int32_t frequencyExtra; extern int32_t frequencyExtra;
void set_10mhz(uint32_t); void set_10mhz(float);
void set_modulation(int); void set_modulation(int);
void set_modulation_frequency(int); void set_modulation_frequency(int);
int search_maximum(int m, int center, int span); int search_maximum(int m, int center, int span);
@ -473,6 +473,7 @@ typedef struct config {
uint16_t gridlines; uint16_t gridlines;
uint16_t hambands; uint16_t hambands;
uint32_t frequency_IF2; uint32_t frequency_IF2;
float setting_frequency_10mhz;
int8_t cor_am; int8_t cor_am;
int8_t cor_wfm; int8_t cor_wfm;
int8_t cor_nfm; int8_t cor_nfm;

@ -87,8 +87,8 @@ void update_min_max_freq(void)
minFreq = 00000000; minFreq = 00000000;
maxFreq = 2000000000; maxFreq = 2000000000;
#else #else
minFreq = 24*setting_frequency_10mhz; minFreq = 24*config.setting_frequency_10mhz;
maxFreq = 96*setting_frequency_10mhz; maxFreq = 96*config.setting_frequency_10mhz;
#endif #endif
break; break;
case M_GENHIGH: case M_GENHIGH:
@ -182,8 +182,8 @@ void reset_settings(int m)
minFreq = 00000000; minFreq = 00000000;
maxFreq = 2000000000; maxFreq = 2000000000;
#else #else
minFreq = 13*setting_frequency_10mhz; minFreq = 13*config.setting_frequency_10mhz;
maxFreq = 120*setting_frequency_10mhz; maxFreq = 120*config.setting_frequency_10mhz;
#endif #endif
set_sweep_frequency(ST_START, minFreq); set_sweep_frequency(ST_START, minFreq);
set_sweep_frequency(ST_STOP, maxFreq); set_sweep_frequency(ST_STOP, maxFreq);
@ -1448,9 +1448,11 @@ search_maximum(int m, int center, int span)
//static int spur_old_stepdelay = 0; //static int spur_old_stepdelay = 0;
static const unsigned int spur_IF = 433600000; // The IF frequency for which the spur table is value static const unsigned int spur_IF = 433600000; // The IF frequency for which the spur table is value
static const unsigned int spur_alternate_IF = 433900000; // if the frequency is found in the spur table use this IF frequency static const unsigned int spur_alternate_IF = 434100000; // if the frequency is found in the spur table use this IF frequency
static const int spur_table[] = // Frequencies to avoid static const int spur_table[] = // Frequencies to avoid
{ {
117716000,
746083000,
#if 0 #if 0
// 580000, // 433.8 MHz table // 580000, // 433.8 MHz table
// 880000, //? // 880000, //?
@ -1871,6 +1873,9 @@ modulation_again:
#ifdef __ADF4351__ #ifdef __ADF4351__
// START_PROFILE; // START_PROFILE;
if (setting.mode == M_LOW) { if (setting.mode == M_LOW) {
if (i > 0 && setting.frequency_step < 1000) {
set_freq (SI4463_RX, setting.frequency_IF - setting.frequency_step*i); // sweep RX, local_IF = 0 in high mode
} else {
uint32_t extra_IF = local_IF; uint32_t extra_IF = local_IF;
if (config.frequency_IF2 != 0) { if (config.frequency_IF2 != 0) {
extra_IF = config.frequency_IF2; extra_IF = config.frequency_IF2;
@ -1883,6 +1888,7 @@ modulation_again:
set_freq (ADF4351_LO, extra_IF-lf); // set LO SI4432 to below IF frequency set_freq (ADF4351_LO, extra_IF-lf); // set LO SI4432 to below IF frequency
} else } else
set_freq (ADF4351_LO, extra_IF+lf); // otherwise to above IF set_freq (ADF4351_LO, extra_IF+lf); // otherwise to above IF
}
} else if (setting.mode == M_HIGH) { } else if (setting.mode == M_HIGH) {
set_freq (SI4463_RX, local_IF+lf); // sweep RX, local_IF = 0 in high mode set_freq (SI4463_RX, local_IF+lf); // sweep RX, local_IF = 0 in high mode
} }

@ -209,11 +209,12 @@ static void shiftOutBuf(uint8_t *buf, uint16_t size) {
} }
#endif #endif
int setting_frequency_10mhz = 10000000; //float setting_frequency_10mhz = 1000000.0;
void set_10mhz(uint32_t f) void set_10mhz(float f)
{ {
setting_frequency_10mhz = f; config.setting_frequency_10mhz = f;
config_save();
} }
int SI4432_step_delay = 1500; int SI4432_step_delay = 1500;
@ -904,6 +905,7 @@ int debug = 0;
int ADF4351_LE[2] = { 10, 11}; int ADF4351_LE[2] = { 10, 11};
int ADF4351_Mux = 7; int ADF4351_Mux = 7;
int ADF4351_frequency_changed = false;
//#define DEBUG(X) // Serial.print( X ) //#define DEBUG(X) // Serial.print( X )
//#define DEBUGLN(X) Serial.println( X ) //#define DEBUGLN(X) Serial.println( X )
@ -1012,6 +1014,7 @@ void ADF4351_set_frequency(int channel, uint32_t freq, int drive) // freq / 10H
ADF4351_prep_frequency(channel,freq + offs, drive); ADF4351_prep_frequency(channel,freq + offs, drive);
//START_PROFILE; //START_PROFILE;
ADF4351_Set(channel); ADF4351_Set(channel);
ADF4351_frequency_changed = true;
//STOP_PROFILE; //STOP_PROFILE;
} }
@ -1082,7 +1085,7 @@ void ADF4351_prep_frequency(int channel, unsigned long freq, int drive) // freq
(void)drive; (void)drive;
// START_PROFILE; // START_PROFILE;
// if (channel == 0) // if (channel == 0)
RFout=freq/1000000.0; // To MHz RFout=freq/config.setting_frequency_10mhz; // To MHz
// else // else
// RFout=freq/1000002.764; // To MHz // RFout=freq/1000002.764; // To MHz
@ -1234,7 +1237,8 @@ void ADF4351_prep_frequency(int channel, unsigned long freq, int drive) // freq
#define Npresc 0 // No High performance mode #define Npresc 0 // No High performance mode
#define MIN_DELAY 1 int SI4463_frequency_changed = false;
#define MIN_DELAY 2
#include <string.h> #include <string.h>
@ -1497,14 +1501,23 @@ int16_t Si446x_RSSI(void)
// if (s != SI446X_STATE_RX) // if (s != SI446X_STATE_RX)
// SI4463_start_rx(0); // SI4463_start_rx(0);
uint8_t data[3] = { volatile uint8_t data[3] = {
SI446X_CMD_GET_MODEM_STATUS, SI446X_CMD_GET_MODEM_STATUS,
0xFF 0xFF
}; };
// volatile si446x_state_t s = getState(); // volatile si446x_state_t s = getState();
//START_PROFILE; //START_PROFILE;
if (SI4432_step_delay) if (SI4432_step_delay && ADF4351_frequency_changed) {
my_microsecond_delay(SI4432_step_delay); my_microsecond_delay(SI4432_step_delay);
ADF4351_frequency_changed = false;
}
int i = 3; //setting.repeat;
int RSSI_RAW[3];
do{
again: again:
data[0] = SI446X_CMD_GET_MODEM_STATUS; data[0] = SI446X_CMD_GET_MODEM_STATUS;
data[1] = 0xFF; data[1] = 0xFF;
@ -1512,14 +1525,39 @@ again:
SI4463_do_api(data, 2, data, 3); SI4463_do_api(data, 2, data, 3);
if (data[2] == 255) if (data[2] == 255)
goto again; goto again;
if (data[2] == 0) if (data[2] == 0){
data[2] += 1;
goto again; goto again;
volatile int16_t rssi = data[2] - 120 * 2; }
if (rssi < -238) if (data[2] > 150)
while(1) data[2] = data[2]+1;
rssi = rssi; RSSI_RAW[--i] = data[2] - 120 * 2;
// if (rssi < -238)
// while(1)
// rssi = rssi;
//STOP_PROFILE; //STOP_PROFILE;
return DEVICE_TO_PURE_RSSI(rssi);
if (i == 0) break;
my_microsecond_delay(100);
}while(1);
int t;
if (RSSI_RAW[0] > RSSI_RAW[1]) {
t = RSSI_RAW[1];
RSSI_RAW[1] = RSSI_RAW[0];
RSSI_RAW[0] = t;
}
if (RSSI_RAW[1] > RSSI_RAW[2]) {
t = RSSI_RAW[2];
RSSI_RAW[2] = RSSI_RAW[1];
RSSI_RAW[1] = t;
}
if (RSSI_RAW[0] > RSSI_RAW[1]) {
t = RSSI_RAW[1];
RSSI_RAW[1] = RSSI_RAW[0];
RSSI_RAW[0] = t;
}
return DEVICE_TO_PURE_RSSI(RSSI_RAW[1]);
} }
@ -1776,7 +1814,7 @@ void SI4463_set_freq(uint32_t freq, uint32_t step_size)
{ {
int Odiv; int Odiv;
int D; int D;
uint32_t offs = ((freq / 1000)* 195) / 1000; uint32_t offs = ((freq / 1000)* 0) / 1000;
float RFout=(freq+offs)/1000000.0; // To MHz float RFout=(freq+offs)/1000000.0; // To MHz
if (RFout >= 820) { // till 1140MHz if (RFout >= 820) { // till 1140MHz
@ -1847,7 +1885,7 @@ void SI4463_set_freq(uint32_t freq, uint32_t step_size)
}; };
SI4463_do_api(data2, sizeof(data2), NULL, 0); SI4463_do_api(data2, sizeof(data2), NULL, 0);
SI4463_start_rx(0); SI4463_start_rx(0);
my_microsecond_delay(1000); my_microsecond_delay(3000);
} }

31
ui.c

@ -406,6 +406,7 @@ touch_position(int *x, int *y)
*y = (last_touch_y - config.touch_cal[1]) * 16 / config.touch_cal[3]; *y = (last_touch_y - config.touch_cal[1]) * 16 / config.touch_cal[3];
} }
void void
show_version(void) show_version(void)
{ {
@ -421,6 +422,36 @@ show_version(void)
do {shift>>=1; y+=5;} while (shift&1); do {shift>>=1; y+=5;} while (shift&1);
ili9341_drawstring(info_about[i++], x, y+=5); ili9341_drawstring(info_about[i++], x, y+=5);
} }
static char buf[96];
extern const char *states[];
#define ENABLE_THREADS_COMMAND
#ifdef ENABLE_THREADS_COMMAND
thread_t *tp;
tp = chRegFirstThread();
do {
uint32_t max_stack_use = 0U;
#if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE)
uint32_t stklimit = (uint32_t)tp->wabase;
#if CH_DBG_FILL_THREADS == TRUE
uint8_t *p = (uint8_t *)tp->wabase; while(p[max_stack_use]==CH_DBG_STACK_FILL_VALUE) max_stack_use++;
#endif
#else
uint32_t stklimit = 0U;
#endif
plot_printf(buf, sizeof(buf), "%08x|%08x|%08x|%08x|%4u|%4u|%9s|%12s",
stklimit, (uint32_t)tp->ctx.sp, max_stack_use, (uint32_t)tp,
(uint32_t)tp->refs - 1, (uint32_t)tp->prio, states[tp->state],
tp->name == NULL ? "" : tp->name);
ili9341_drawstring(buf, x, y+=FONT_STR_HEIGHT);
tp = chRegNextThread(tp);
} while (tp != NULL);
#endif
while (true) { while (true) {
if (touch_check() == EVT_TOUCH_PRESSED) if (touch_check() == EVT_TOUCH_PRESSED)
break; break;

@ -1638,7 +1638,7 @@ static const menuitem_t menu_sweep_speed[] =
static const menuitem_t menu_settings3[] = static const menuitem_t menu_settings3[] =
{ {
{ MT_KEYPAD, KM_10MHZ, "CORRECT\nFREQUENCY", "Enter actual l0MHz frequency"}, { MT_KEYPAD, KM_10MHZ, "CORRECT\nFREQUENCY", "Enter actual lMHz frequency"},
{ MT_KEYPAD, KM_GRIDLINES, "MINIMUM\nGRIDLINES", "Enter minimum horizontal grid divisions"}, { 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_WFM, "COR\nWFM", "Enter WFM modulation correction"},
@ -2010,7 +2010,7 @@ static void fetch_numeric_target(void)
plot_printf(uistat.text, sizeof uistat.text, "%3d", ((int32_t)uistat.value)); plot_printf(uistat.text, sizeof uistat.text, "%3d", ((int32_t)uistat.value));
break; break;
case KM_10MHZ: case KM_10MHZ:
uistat.value = setting_frequency_10mhz; uistat.value = config.setting_frequency_10mhz;
plot_printf(uistat.text, sizeof uistat.text, "%3.6fMHz", uistat.value / 1000000.0); plot_printf(uistat.text, sizeof uistat.text, "%3.6fMHz", uistat.value / 1000000.0);
break; break;
case KM_OFFSET: case KM_OFFSET:

Loading…
Cancel
Save

Powered by TurnKey Linux.