Update SNR measurement

multi_trace
erikkaashoek 5 years ago
parent ce73de29e4
commit f34a667bed

@ -88,12 +88,12 @@ static char *long_to_string_with_divisor(char *p,
#define FREQ_PREFIX_SPACE 4
static char *
ulong_freq(char *p, ulong_t freq, uint32_t precision)
ulong_freq(char *p, ulong_t freq, uint32_t width, uint32_t precision)
{
uint8_t flag = FREQ_PSET;
flag|= precision == 0 ? FREQ_PREFIX_SPACE : FREQ_NO_SPACE;
if (precision == 0 || precision > MAX_FREQ_PRESCISION)
if (/* precision == 0 || */ precision > MAX_FREQ_PRESCISION)
precision = MAX_FREQ_PRESCISION;
char *q = p + MAX_FREQ_PRESCISION;
char *b = q;
@ -136,6 +136,8 @@ ulong_freq(char *p, ulong_t freq, uint32_t precision)
// Get string size
uint32_t i = (b - q);
if (width > 0 && i>width)
i=width;
// copy string
// Replace first ' ' by '.', remove ' ' if size too big
do {
@ -152,6 +154,8 @@ ulong_freq(char *p, ulong_t freq, uint32_t precision)
if (!(flag & FREQ_PSET) && precision-- == 0)
break;
} while (--i);
if (p[-1] == '.') // No '.' at end
p--;
// Put pref (amd space before it if need)
if (flag & FREQ_PREFIX_SPACE && s != ' ')
*p++ = ' ';
@ -393,7 +397,9 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) {
else
#endif
value.ux = va_arg(ap, uint32_t);
p=ulong_freq(p, value.ux, precision);
if (state&DEFAULT_PRESCISION)
precision = MAX_FREQ_PRESCISION;
p=ulong_freq(p, value.ux, width, precision);
break;
#if CHPRINTF_USE_FLOAT
case 'F':

@ -106,7 +106,7 @@ const char *info_about[]={
};
bool dirty = true;
bool completed = false;
uint8_t completed = false;
uint8_t enable_after_complete = 0;
#ifdef TINYSA4
@ -926,7 +926,7 @@ config_t config = {
static const marker_t def_markers[MARKERS_MAX] = {
{ M_ENABLED, M_REFERENCE | M_TRACKING, 0, 30, 0 },
{ M_ENABLED, M_TRACKING, 0, 30, 0 },
{ M_DISABLED, M_NORMAL, 0, 40, 0 },
{ M_DISABLED, M_NORMAL, 0, 60, 0 },
{ M_DISABLED, M_NORMAL, 0, 80, 0 }

@ -300,7 +300,7 @@ enum {
#endif
extern uint8_t sweep_mode;
extern bool completed;
extern uint8_t completed;
extern const char *info_about[];
#ifdef TINYSA4
@ -737,7 +737,7 @@ enum {
};
enum {
M_DISABLED = false, M_ENABLED = true
M_DISABLED = 0, M_ENABLED = 1
};
@ -757,8 +757,8 @@ enum {
void enableTracesAtComplete(uint8_t mask);
typedef struct {
uint8_t enabled;
uint8_t mtype;
uint8_t enabled;
uint8_t ref;
int16_t index;
freq_t frequency;
@ -807,6 +807,7 @@ int marker_search_left_max(int m);
int marker_search_right_max(int m);
int marker_search_left_min(int m);
int marker_search_right_min(int m);
void markers_reset(void);
// _request flag for update screen
#define REDRAW_CELLS (1<<0)
@ -1440,7 +1441,7 @@ void interpolate_maximum(int m);
void calibrate_modulation(int modulation, int8_t *correction);
enum {
M_OFF, M_IMD, M_OIP3, M_PHASE_NOISE, M_STOP_BAND, M_PASS_BAND, M_LINEARITY, M_AM, M_FM, M_THD, M_CP, M_DECONV
M_OFF, M_IMD, M_OIP3, M_PHASE_NOISE, M_SNR, M_PASS_BAND, M_LINEARITY, M_AM, M_FM, M_THD, M_CP, M_DECONV
};
enum {

@ -1029,7 +1029,7 @@ draw_cell(int m, int n)
}
#endif
#ifdef __CHANNEL_POWER__
if (setting.measurement == M_CP) {
if (setting.measurement == M_CP||setting.measurement == M_SNR) {
c = GET_PALTETTE_COLOR(LCD_TRIGGER_COLOR);
for (x = 0; x < w; x++)
if (x+x0 == WIDTH/3 || x+x0 == 2*WIDTH/3 ) {
@ -1489,14 +1489,19 @@ static void cell_draw_marker_info(int x0, int y0)
}
}
#ifdef __CHANNEL_POWER__
if (setting.measurement==M_CP) {
if (setting.measurement==M_CP || setting.measurement==M_SNR) {
ili9341_set_foreground(LCD_FG_COLOR);
freq_t bw = get_sweep_frequency(ST_SPAN)/3;
for (int c=0; c<3;c++) {
int xpos = 10 + (c)*(WIDTH/3) + CELLOFFSETX - x0;
int ypos = 1 - y0;
cell_printf(xpos, ypos, FONT_b"%4.1fdBm", channel_power[c]);
cell_printf(xpos, ypos, FONT_b"%4.1fdBm/%3QHz", channel_power[c], bw);
ypos = 14 - y0;
cell_printf(xpos, ypos, FONT_b"%4.1f%%", 100.0 * channel_power_watt[c] /(channel_power_watt[0] + channel_power_watt[1] + channel_power_watt[2]) );
if (setting.measurement==M_CP )
cell_printf(xpos, ypos, FONT_b"%4.1f%%", 100.0 * channel_power_watt[c] /(channel_power_watt[0] + channel_power_watt[1] + channel_power_watt[2]) );
else if (c == 1)
cell_printf(xpos, ypos, FONT_b"SNR: %4.1fdB", channel_power[1] - (channel_power[0] + channel_power[2])/2 );
}
return;
}

@ -357,13 +357,7 @@ void reset_settings(int m)
break;
}
setting.level = level_max(); // This is the level with above settings.
for (uint8_t i = 0; i< MARKERS_MAX; i++) {
markers[i].enabled = M_DISABLED;
markers[i].mtype = M_NORMAL;
markers[i].ref = 0;
}
markers[0].mtype = M_REFERENCE | M_TRACKING;
markers[0].enabled = M_ENABLED;
markers_reset();
setting._active_marker = 0;
set_external_gain(0.0); // This also updates the help text!!!!! Must be below level_min and level_max being set
set_sweep_points(POINTS_COUNT);
@ -4444,13 +4438,6 @@ static volatile int dummy;
} else if (setting.measurement == M_PHASE_NOISE && markers[0].index > 10) { // ------------Phase noise measurement
markers[1].index = markers[0].index + (setting.mode == M_LOW ? WIDTH/4 : -WIDTH/4); // Position phase noise marker at requested offset
markers[1].frequency = frequencies[markers[1].index];
} else if (setting.measurement == M_STOP_BAND && markers[0].index > 10) { // -------------Stop band measurement
markers[1].index = marker_search_left_min(0);
if (markers[1].index < 0) markers[1].index = 0;
markers[1].frequency = frequencies[markers[1].index];
markers[2].index = marker_search_right_min(0);
if (markers[2].index < 0) markers[1].index = setting._sweep_points - 1;
markers[2].frequency = frequencies[markers[2].index];
} else if ((setting.measurement == M_PASS_BAND || setting.measurement == M_FM) && markers[0].index > 10) { // ----------------Pass band measurement
int t = 0;
float v = actual_t[markers[0].index] - (in_selftest ? 6.0 : 3.0);
@ -4485,7 +4472,8 @@ static volatile int dummy;
#endif
}
#ifdef __CHANNEL_POWER__
} else if (setting.measurement == M_CP) { // ----------------CHANNEL_POWER measurement
} else if (setting.measurement == M_CP || setting.measurement == M_SNR) { // ----------------CHANNEL_POWER measurement
freq_t bw = get_sweep_frequency(ST_SPAN)/3;
int old_unit = setting.unit;
setting.unit = U_WATT;
for (int c = 0; c < 3 ;c++) {
@ -4494,7 +4482,7 @@ static volatile int dummy;
for (int i =0; i < sp_div3; i++) {
channel_power_watt[c] += value(actual_t[i + c*sp_div3]);
}
float rbw_cor = (float)(get_sweep_frequency(ST_SPAN)/3) / ((float)actual_rbw_x10 * 100.0);
float rbw_cor = ((float)bw) / ((float)actual_rbw_x10 * 100.0);
channel_power_watt[c] = channel_power_watt[c] * rbw_cor /(float)sp_div3;
channel_power[c] = to_dBm(channel_power_watt[c]);
}
@ -4644,6 +4632,18 @@ marker_search_right_max(int m)
return found;
}
void markers_reset()
{
for (uint8_t i = 0; i< MARKERS_MAX; i++) {
markers[i].enabled = M_DISABLED;
markers[i].mtype = M_DELTA;
markers[i].ref = 0;
}
markers[0].mtype = M_TRACKING;
markers[0].enabled = M_ENABLED;
active_marker = 0;
}
int marker_search_max(int m)
{
int i = 0;

@ -726,6 +726,12 @@ static UI_FUNCTION_CALLBACK(menu_marker_op_cb)
//redraw_all();
}
static UI_FUNCTION_CALLBACK(menu_markers_reset_cb)
{
(void)item;
markers_reset();
}
static UI_FUNCTION_CALLBACK(menu_marker_search_cb)
{
(void)item;

@ -781,13 +781,7 @@ UI_FUNCTION_CALLBACK(menu_autosettings_cb)
(void)data;
reset_settings(setting.mode);
active_marker = 0;
for (int i = 1; i<MARKER_COUNT; i++ ) {
markers[i].enabled = M_DISABLED;
}
markers[0].enabled = M_ENABLED;
markers[0].mtype = M_REFERENCE | M_TRACKING;
markers_reset();
// set_refer_output(1);
// SetPowerLevel(100); // Reset
@ -1135,13 +1129,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb)
return;
}
menu_move_back(false);
for (int i = 0; i< MARKERS_MAX; i++) {
markers[i].enabled = M_DISABLED;
markers[i].mtype = M_DELTA;
markers[i].ref = 0; // Default DELTA referring to marker 1
}
markers[0].enabled = M_ENABLED;
markers[0].mtype = M_REFERENCE | M_TRACKING;
markers_reset();
#ifdef __MEASURE__
if ((data != M_OFF && setting.measurement != M_OFF) || data == M_OFF )
@ -1162,8 +1150,8 @@ static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb)
break;
case M_IMD: // IMD
reset_settings(setting.mode);
for (int i = 0; i< MARKERS_MAX; i++) {
markers[i].enabled = M_ENABLED;
for (int i = 1; i< MARKERS_MAX; i++) {
markers[i].mtype = M_DELTA;
}
kp_help_text = "Frequency of fundamental";
ui_mode_keypad(KM_CENTER);
@ -1202,17 +1190,15 @@ static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb)
set_average(AV_4);
break;
case M_STOP_BAND: // STop band measurement
case M_SNR: // STop band measurement
reset_settings(setting.mode);
markers[1].enabled = M_ENABLED;
markers[2].enabled = M_ENABLED;
kp_help_text = "Frequency of signal";
ui_mode_keypad(KM_CENTER);
kp_help_text = "Width of signal";
kp_help_text = "Bandwidth";
ui_mode_keypad(KM_SPAN);
set_sweep_frequency(ST_SPAN, uistat.value*4);
// set_measurement(M_STOP_BAND);
// SetAverage(4);
set_sweep_frequency(ST_SPAN, uistat.value*3);
// set_measurement(M_SNR);
set_average(AV_4);
break;
case M_PASS_BAND: // pass band measurement
@ -1530,6 +1516,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_marker_ref_select_acb)
(void)item;
if(b){
// b->icon = markers[data-1].enabled ? BUTTON_ICON_CHECK : BUTTON_ICON_NOCHECK;
b->icon = (markers[active_marker].ref == data-1 ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP );
b->param_1.i = data;
return;
}
@ -2337,6 +2324,7 @@ static const menuitem_t menu_marker[] = {
{ MT_SUBMENU, 0, "MODIFY\nMARKERS", menu_marker_select},
{ MT_SUBMENU, 0, "MARKER\nOPS", menu_marker_ops},
{ MT_SUBMENU, 0, "SEARCH\nMARKER", menu_marker_search},
{ MT_CALLBACK, 0, "RESET\nMARKERS", menu_markers_reset_cb},
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel
};
@ -2602,7 +2590,7 @@ static const menuitem_t menu_measure[] = {
{ MT_ADV_CALLBACK, M_IMD, "HARMONIC", menu_measure_acb},
{ MT_ADV_CALLBACK, M_OIP3, "OIP3", menu_measure_acb},
{ MT_ADV_CALLBACK, M_PHASE_NOISE,"PHASE\nNOISE", menu_measure_acb},
{ MT_ADV_CALLBACK, M_STOP_BAND, "SNR", menu_measure_acb},
{ MT_ADV_CALLBACK, M_SNR, "SNR", menu_measure_acb},
{ MT_ADV_CALLBACK, M_PASS_BAND, "-3dB\nWIDTH", menu_measure_acb},
{ MT_SUBMENU, 0, S_RARROW" MORE", menu_measure2},
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
@ -3346,7 +3334,7 @@ redraw_cal_status:
// if (setting.mode == M_LOW) {
// Attenuation
ili9341_set_foreground(setting.auto_attenuation ? LCD_BRIGHT_COLOR_GREEN : LCD_FG_COLOR);
ili9341_set_foreground(setting.auto_attenuation ? LCD_FG_COLOR : LCD_BRIGHT_COLOR_GREEN);
lcd_printf(x, y, "Atten:\n%4.2FdB", get_attenuation());
y = add_quick_menu(y+= YSTEP, (menuitem_t *)menu_atten);
// }
@ -3440,7 +3428,7 @@ redraw_cal_status:
// Offset
if (setting.external_gain != 0.0) {
ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN);
lcd_printf(x, y, "Amp:\n%4.1fdB",setting.external_gain);
lcd_printf(x, y, "Gain:\n%4.1fdB",setting.external_gain);
y = add_quick_menu(y+=YSTEP, (menuitem_t *)KM_EXT_GAIN);
}

Loading…
Cancel
Save

Powered by TurnKey Linux.