Waterfall improvement and extra measurements

tinySA
erikkaashoek 6 years ago
parent 1a356f5253
commit a6b9e48921

@ -309,9 +309,9 @@ static const uint8_t ili9341_init_seq[] = {
// gamma set for curve 01/2/04/08 // gamma set for curve 01/2/04/08
ILI9341_GAMMA_SET, 1, 0x01, ILI9341_GAMMA_SET, 1, 0x01,
// positive gamma correction // positive gamma correction
//ILI9341_POSITIVE_GAMMA_CORRECTION, 15, 0x1F, 0x1A, 0x18, 0x0A, 0x0F, 0x06, 0x45, 0x87, 0x32, 0x0A, 0x07, 0x02, 0x07, 0x05, 0x00, ILI9341_POSITIVE_GAMMA_CORRECTION, 15, 0x1F, 0x1A, 0x18, 0x0A, 0x0F, 0x06, 0x45, 0x87, 0x32, 0x0A, 0x07, 0x02, 0x07, 0x05, 0x00,
// negativ gamma correction // negativ gamma correction
//ILI9341_NEGATIVE_GAMMA_CORRECTION, 15, 0x00, 0x25, 0x27, 0x05, 0x10, 0x09, 0x3A, 0x78, 0x4D, 0x05, 0x18, 0x0D, 0x38, 0x3A, 0x1F, ILI9341_NEGATIVE_GAMMA_CORRECTION, 15, 0x00, 0x25, 0x27, 0x05, 0x10, 0x09, 0x3A, 0x78, 0x4D, 0x05, 0x18, 0x0D, 0x38, 0x3A, 0x1F,
// Column Address Set // Column Address Set
//ILI9341_COLUMN_ADDRESS_SET, 4, 0x00, 0x00, 0x01, 0x3f, // width 320 //ILI9341_COLUMN_ADDRESS_SET, 4, 0x00, 0x00, 0x01, 0x3f, // width 320
// Page Address Set // Page Address Set

@ -201,7 +201,7 @@
/* /*
* UART driver system settings. * UART driver system settings.
*/ */
#define STM32_UART_USE_USART1 FALSE #define STM32_UART_USE_USART1 TRUE
#define STM32_UART_USE_USART2 FALSE #define STM32_UART_USE_USART2 FALSE
#define STM32_UART_USART1_IRQ_PRIORITY 3 #define STM32_UART_USART1_IRQ_PRIORITY 3
#define STM32_UART_USART2_IRQ_PRIORITY 3 #define STM32_UART_USART2_IRQ_PRIORITY 3

@ -365,6 +365,10 @@ void set_marker_search(int mode);
int marker_search(void); int marker_search(void);
int marker_search_left(int from); int marker_search_left(int from);
int marker_search_right(int from); int marker_search_right(int from);
int marker_search_left_max(int from);
int marker_search_right_max(int from);
int marker_search_left_min(int from);
int marker_search_right_min(int from);
// _request flag for update screen // _request flag for update screen
#define REDRAW_CELLS (1<<0) #define REDRAW_CELLS (1<<0)
@ -380,7 +384,10 @@ extern volatile uint8_t redraw_request;
*/ */
// SPI bus revert byte order // SPI bus revert byte order
//gggBBBbb RRRrrGGG //gggBBBbb RRRrrGGG
#define RGB565(r,g,b) ( (((g)&0x1c)<<11) | (((b)&0xf8)<<5) | ((r)&0xf8) | (((g)&0xe0)>>5) ) #define byteReverse16(x) (uint16_t)(((x) << 8) & 0xff00) | (((x) >> 8) & 0xff)
#define RGB565(r,g,b) byteReverse16( ((((uint16_t)r)<<8)&0b1111100000000000) | ((((uint16_t)g)<<3)&0b0000011111100000) | ((((uint16_t)b)>>3)&0b0000000000011111) )
//#define RGB565(r,g,b) ( (((g)&0x1c)<<11) | (((b)&0xf8)<<5) | ((r)&0xf8) | (((g)&0xe0)>>5) )
#define RGBHEX(hex) ( (((hex)&0x001c00)<<3) | (((hex)&0x0000f8)<<5) | (((hex)&0xf80000)>>16) | (((hex)&0x00e000)>>13) ) #define RGBHEX(hex) ( (((hex)&0x001c00)<<3) | (((hex)&0x0000f8)<<5) | (((hex)&0xf80000)>>16) | (((hex)&0x00e000)>>13) )
// Define size of screen buffer in pixels (one pixel 16bit size) // Define size of screen buffer in pixels (one pixel 16bit size)
@ -651,7 +658,7 @@ void wait_user(void);
void calibrate(void); void calibrate(void);
enum { enum {
M_OFF, M_IMD, M_OIP3, M_PHASE_NOISE M_OFF, M_IMD, M_OIP3, M_PHASE_NOISE, M_STOP_BAND, M_PASS_BAND
}; };
/*EOF*/ /*EOF*/

@ -1141,10 +1141,10 @@ marker_position(int m, int t, int *x, int *y)
*y = CELL_Y(index); *y = CELL_Y(index);
} }
static int greater(int x, int y) { return x > y; } static int greater(int x, int y, int d) { return x - d > y; }
static int lesser(int x, int y) { return x < y; } static int lesser(int x, int y, int d) { return x - d < y; }
static int (*compare)(int x, int y) = greater; static int (*compare)(int x, int y, int d) = greater;
int int
marker_search(void) marker_search(void)
@ -1158,7 +1158,7 @@ marker_search(void)
int value = CELL_Y(trace_index[TRACE_ACTUAL][0]); int value = CELL_Y(trace_index[TRACE_ACTUAL][0]);
for (i = 0; i < sweep_points; i++) { for (i = 0; i < sweep_points; i++) {
int new_value = CELL_Y(trace_index[TRACE_ACTUAL][i]); int new_value = CELL_Y(trace_index[TRACE_ACTUAL][i]);
if ((*compare)(value, new_value)) { if ((*compare)(value, new_value, 0)) {
value = new_value; value = new_value;
found = i; found = i;
} }
@ -1179,30 +1179,32 @@ search_is_greater(void)
return(compare == greater); return(compare == greater);
} }
#define MINMAX_DELTA 10
int int
marker_search_left(int from) marker_search_left(int from)
{ {
int i; int i;
int found = -1; int found = -1;
#define MINMAX_DELTA -5
if (uistat.current_trace == -1) if (uistat.current_trace == -1)
return -1; return -1;
int value = CELL_Y(trace_index[TRACE_ACTUAL][from]); int value = CELL_Y(trace_index[TRACE_ACTUAL][from]);
for (i = from - 1; i >= 0; i--) { for (i = from - 1; i >= 0; i--) {
int new_value = CELL_Y(trace_index[TRACE_ACTUAL][i]); int new_value = CELL_Y(trace_index[TRACE_ACTUAL][i]);
if ((*compare)(value + MINMAX_DELTA, new_value)) if ((*compare)(value, new_value, MINMAX_DELTA))
break; break;
value = new_value;
} }
for (; i >= 0; i--) { for (; i >= 0; i--) {
int new_value = CELL_Y(trace_index[TRACE_ACTUAL][i]); int new_value = CELL_Y(trace_index[TRACE_ACTUAL][i]);
if ((*compare)(new_value, value - MINMAX_DELTA)) { if ((*compare)(new_value, value, -MINMAX_DELTA)) {
break; break;
} }
found = i; if ((*compare)(value, new_value, 0)) {
value = new_value; found = i;
value = new_value;
}
} }
return found; return found;
} }
@ -1218,18 +1220,19 @@ marker_search_right(int from)
int value = CELL_Y(trace_index[TRACE_ACTUAL][from]); int value = CELL_Y(trace_index[TRACE_ACTUAL][from]);
for (i = from + 1; i < sweep_points; i++) { for (i = from + 1; i < sweep_points; i++) {
int new_value = CELL_Y(trace_index[TRACE_ACTUAL][i]); int new_value = CELL_Y(trace_index[TRACE_ACTUAL][i]);
if ((*compare)(value+MINMAX_DELTA, new_value)) if ((*compare)(value, new_value, MINMAX_DELTA))
break; break;
value = new_value; value = new_value;
} }
for (; i < sweep_points; i++) { for (; i < sweep_points; i++) {
int new_value = CELL_Y(trace_index[TRACE_ACTUAL][i]); int new_value = CELL_Y(trace_index[TRACE_ACTUAL][i]);
if ((*compare)(new_value, value-MINMAX_DELTA)) { if ((*compare)(new_value, value, -MINMAX_DELTA)) {
break; break;
} }
found = i; if ((*compare)(value, new_value, 0)) {
value = new_value; found = i;
value = new_value;
}
} }
return found; return found;
} }
@ -1532,12 +1535,20 @@ draw_all_cells(bool flush_markmap)
return r, g, b return r, g, b
*/ */
int r,g,b; int r,g,b;
float ratio = (int)(510.0 * (actual_t[i] - w_min) / (w_max - actual_t[i])); float ratio = (int)(510.0 * (actual_t[i] - w_min) / (w_max - w_min));
// float ratio = (i*2); // Uncomment for testing the waterfall colors
b = 255 - ratio; b = 255 - ratio;
if (b > 255) b = 255;
if (b < 0) b = 0; if (b < 0) b = 0;
r = ratio - 255; r = ratio - 255;
if (r > 255) r = 255;
if (r < 0) r = 0; if (r < 0) r = 0;
// g = 255 - b; // if red is too weak to be seen.....
g = 255 - b - r; g = 255 - b - r;
#define gamma_correct(X,L) X = (L + X * (255 - L)/255 )
gamma_correct(r,128);
gamma_correct(g,128);
gamma_correct(b,128);
#if 0 #if 0
int k = (actual_t[i]+120)* 2 * 8; int k = (actual_t[i]+120)* 2 * 8;
k &= 255; k &= 255;

@ -99,6 +99,13 @@ void reset_settings(int m)
set_sweep_frequency(ST_SPAN, 0); set_sweep_frequency(ST_SPAN, 0);
break; break;
} }
for (int i = 0; i< MARKERS_MAX; i++) {
markers[i].enabled = M_DISABLED;
markers[i].mtype = M_NORMAL;
}
markers[0].mtype = M_REFERENCE | M_TRACKING;
markers[0].enabled = M_ENABLED;
dirty = true; dirty = true;
} }
@ -965,7 +972,7 @@ static bool sweep(bool break_on_operation)
if (temppeakLevel > actual_t[i]) { // Follow down if (temppeakLevel > actual_t[i]) { // Follow down
temppeakIndex = i; // Latest minimum temppeakIndex = i; // Latest minimum
temppeakLevel = actual_t[i]; temppeakLevel = actual_t[i];
} else if (temppeakLevel + setting_noise < actual_t[i]) { // Local minimum found } else if (temppeakLevel + setting_noise < actual_t[i] ) { // Local minimum found
temppeakIndex = i; // This is now the latest maximum temppeakIndex = i; // This is now the latest maximum
temppeakLevel = actual_t[i]; temppeakLevel = actual_t[i];
downslope = false; downslope = false;
@ -974,7 +981,7 @@ static bool sweep(bool break_on_operation)
if (temppeakLevel < actual_t[i]) { // Follow up if (temppeakLevel < actual_t[i]) { // Follow up
temppeakIndex = i; temppeakIndex = i;
temppeakLevel = actual_t[i]; temppeakLevel = actual_t[i];
} else if (temppeakLevel - setting_noise > actual_t[i]) { // Local max found } else if (actual_t[i] < temppeakLevel - setting_noise) { // Local max found
int j = 0; // Insertion index int j = 0; // Insertion index
while (j<cur_max && actual_t[max_index[j]] >= temppeakLevel) // Find where to insert while (j<cur_max && actual_t[max_index[j]] >= temppeakLevel) // Find where to insert
@ -1085,6 +1092,23 @@ static bool sweep(bool break_on_operation)
} }
} else if (setting_measurement == M_PHASE_NOISE && markers[0].index > 10) { } else if (setting_measurement == M_PHASE_NOISE && markers[0].index > 10) {
markers[1].index = markers[0].index + (setting_mode == M_LOW ? 290/4 : -290/4); // Position phase noise marker at requested offset markers[1].index = markers[0].index + (setting_mode == M_LOW ? 290/4 : -290/4); // Position phase noise marker at requested offset
} else if (setting_measurement == M_STOP_BAND && markers[0].index > 10) {
markers[1].index = marker_search_left_min(markers[0].index);
if (markers[1].index < 0) markers[1].index = 0;
markers[2].index = marker_search_right_min(markers[0].index);
if (markers[2].index < 0) markers[1].index = POINTS_COUNT - 1;
} else if (setting_measurement == M_PASS_BAND && markers[0].index > 10) {
int t = markers[0].index;
float v = actual_t[t];
while (t > 0 && actual_t[t] > v - 3.0)
t --;
if (t > 0)
markers[1].index = t;
t = markers[0].index;
while (t < POINTS_COUNT - 1 && actual_t[t] > v - 3.0)
t ++;
if (t < POINTS_COUNT - 1 )
markers[2].index = t;
} }
#endif #endif
peakIndex = max_index[0]; peakIndex = max_index[0];
@ -1116,7 +1140,130 @@ static bool sweep(bool break_on_operation)
return true; return true;
} }
//------------------------------- SEARCH ---------------------------------------------
int
marker_search_left_max(int from)
{
int i;
int found = -1;
if (uistat.current_trace == -1)
return -1;
int value = actual_t[from];
for (i = from - 1; i >= 0; i--) {
int new_value = actual_t[i];
if (new_value < value) {
value = new_value;
found = i;
} else if (new_value > value + setting_noise )
break;
}
for (; i >= 0; i--) {
int new_value = actual_t[i];
if (new_value > value) {
value = new_value;
found = i;
} else if (new_value < value - setting_noise )
break;
}
return found;
}
int
marker_search_right_max(int from)
{
int i;
int found = -1;
if (uistat.current_trace == -1)
return -1;
int value = actual_t[from];
for (i = from + 1; i < sweep_points; i++) {
int new_value = actual_t[i];
if (new_value < value) { // follow down
value = new_value;
found = i;
} else if (new_value > value + setting_noise) // larger then lowest value + noise
break; // past the minimum
}
for (; i < sweep_points; i++) {
int new_value = actual_t[i];
if (new_value > value) { // follow up
value = new_value;
found = i;
} else if (new_value < value - setting_noise)
break;
}
return found;
}
#define MINMAX_DELTA 10
int
marker_search_left_min(int from)
{
int i;
int found = from;
if (uistat.current_trace == -1)
return -1;
int value = actual_t[from];
for (i = from - 1; i >= 0; i--) {
int new_value = actual_t[i];
if (new_value > value) {
value = new_value; // follow up
// found = i;
} else if (new_value < value - MINMAX_DELTA )
break; // past the maximum
}
for (; i >= 0; i--) {
int new_value = actual_t[i];
if (new_value < value) {
value = new_value; // follow down
found = i;
} else if (new_value > value + MINMAX_DELTA )
break;
}
return found;
}
int
marker_search_right_min(int from)
{
int i;
int found = from;
if (uistat.current_trace == -1)
return -1;
int value = actual_t[from];
for (i = from + 1; i < sweep_points; i++) {
int new_value = actual_t[i];
if (new_value > value) { // follow up
value = new_value;
// found = i;
} else if (new_value < value - MINMAX_DELTA) // less then largest value - noise
break; // past the maximum
}
for (; i < sweep_points; i++) {
int new_value = actual_t[i];
if (new_value < value) { // follow down
value = new_value;
found = i;
} else if (new_value > value + MINMAX_DELTA) // larger then smallest value + noise
break;
}
return found;
}
// -------------------------- CAL STATUS ---------------------------------------------
const char *averageText[] = { "OFF", "MIN", "MAX", "MAXD", " A 4", "A 16"}; const char *averageText[] = { "OFF", "MIN", "MAX", "MAXD", " A 4", "A 16"};
const char *dBText[] = { "1dB/", "2dB/", "5dB/", "10dB/", "20dB/"}; const char *dBText[] = { "1dB/", "2dB/", "5dB/", "10dB/", "20dB/"};
const int refMHz[] = { 30, 15, 10, 4, 3, 2, 1 }; const int refMHz[] = { 30, 15, 10, 4, 3, 2, 1 };

25
ui.c

@ -781,16 +781,24 @@ menu_marker_search_cb(int item, uint8_t data)
return; return;
switch (data) { switch (data) {
case 0: /* search Left */
i = marker_search_left_min(markers[active_marker].index);
break;
case 1: /* search right */
i = marker_search_right_min(markers[active_marker].index);
break;
#if 0
case 0: /* maximum */ case 0: /* maximum */
case 1: /* minimum */ case 1: /* minimum */
set_marker_search(data); set_marker_search(data);
i = marker_search(); i = marker_search();
break; break;
#endif
case 2: /* search Left */ case 2: /* search Left */
i = marker_search_left(markers[active_marker].index); i = marker_search_left_max(markers[active_marker].index);
break; break;
case 3: /* search right */ case 3: /* search right */
i = marker_search_right(markers[active_marker].index); i = marker_search_right_max(markers[active_marker].index);
break; break;
case 4: /* tracking */ case 4: /* tracking */
markers[active_marker].mtype ^= M_TRACKING; markers[active_marker].mtype ^= M_TRACKING;
@ -1651,7 +1659,10 @@ static void
erase_menu_buttons(void) erase_menu_buttons(void)
{ {
// ili9341_fill(area_width, 0, 320 - area_width, area_height, DEFAULT_BG_COLOR); // ili9341_fill(area_width, 0, 320 - area_width, area_height, DEFAULT_BG_COLOR);
ili9341_fill(320-MENU_BUTTON_WIDTH, 0, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT*8, DEFAULT_BG_COLOR); if (current_menu_is_form())
ili9341_fill(5*5, 0,320-5*5, MENU_BUTTON_HEIGHT*8, DEFAULT_BG_COLOR);
else
ili9341_fill(320-MENU_BUTTON_WIDTH, 0, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT*8, DEFAULT_BG_COLOR);
draw_frequencies(); draw_frequencies();
} }
@ -1843,15 +1854,15 @@ lever_move_marker(int status)
if (active_marker >= 0 && markers[active_marker].enabled) { if (active_marker >= 0 && markers[active_marker].enabled) {
if ((status & EVT_DOWN) && markers[active_marker].index > 0) { if ((status & EVT_DOWN) && markers[active_marker].index > 0) {
markers[active_marker].index -= step; markers[active_marker].index -= step;
if (markers[active_marker].index < 5) if (markers[active_marker].index < 0)
markers[active_marker].index = 5 ; markers[active_marker].index = 0 ;
markers[active_marker].frequency = frequencies[markers[active_marker].index]; markers[active_marker].frequency = frequencies[markers[active_marker].index];
redraw_marker(active_marker); redraw_marker(active_marker);
} }
if ((status & EVT_UP) && markers[active_marker].index < sweep_points-1) { if ((status & EVT_UP) && markers[active_marker].index < sweep_points-1) {
markers[active_marker].index += step; markers[active_marker].index += step;
if (markers[active_marker].index > POINTS_COUNT-5) if (markers[active_marker].index > POINTS_COUNT-1)
markers[active_marker].index = POINTS_COUNT-5 ; markers[active_marker].index = POINTS_COUNT-1 ;
markers[active_marker].frequency = frequencies[markers[active_marker].index]; markers[active_marker].frequency = frequencies[markers[active_marker].index];
redraw_marker(active_marker); redraw_marker(active_marker);
} }

@ -685,6 +685,36 @@ static void menu_measure_cb(int item, uint8_t data)
set_measurement(M_PHASE_NOISE); set_measurement(M_PHASE_NOISE);
SetAverage(4); SetAverage(4);
break;
case M_STOP_BAND: // STop band measurement
reset_settings(GetMode());
markers[1].enabled = M_ENABLED;
markers[1].mtype = M_DELTA;
markers[2].enabled = M_ENABLED;
markers[2].mtype = M_DELTA;
ui_mode_keypad(KM_CENTER);
ui_process_keypad();
ui_mode_keypad(KM_SPAN);
ui_process_keypad();
set_sweep_frequency(ST_SPAN, uistat.value*4);
set_measurement(M_STOP_BAND);
// SetAverage(4);
break;
case M_PASS_BAND: // STop band measurement
reset_settings(GetMode());
markers[1].enabled = M_ENABLED;
markers[1].mtype = M_DELTA;
markers[2].enabled = M_ENABLED;
markers[2].mtype = M_DELTA;
ui_mode_keypad(KM_CENTER);
ui_process_keypad();
ui_mode_keypad(KM_SPAN);
ui_process_keypad();
set_sweep_frequency(ST_SPAN, uistat.value*2);
set_measurement(M_PASS_BAND);
// SetAverage(4);
break; break;
} }
#endif #endif
@ -1014,10 +1044,10 @@ static const menuitem_t menu_marker_type[] = {
const menuitem_t menu_marker_search[] = { const menuitem_t menu_marker_search[] = {
//{ MT_CALLBACK, "OFF", menu_marker_search_cb }, //{ MT_CALLBACK, "OFF", menu_marker_search_cb },
{ MT_CALLBACK, 0, "MAXIMUM", menu_marker_search_cb }, { MT_CALLBACK, 0, "\2MIN\0" S_LARROW" LEFT", menu_marker_search_cb },
{ MT_CALLBACK, 1, "MINIMUM", menu_marker_search_cb }, { MT_CALLBACK, 1, "\2MIN\0" S_RARROW" RIGHT", menu_marker_search_cb },
{ MT_CALLBACK, 2, "\2SEARCH\0" S_LARROW" LEFT", menu_marker_search_cb }, { MT_CALLBACK, 2, "\2MAX\0" S_LARROW" LEFT", menu_marker_search_cb },
{ MT_CALLBACK, 3, "\2SEARCH\0" S_RARROW" RIGHT", menu_marker_search_cb }, { MT_CALLBACK, 3, "\2MAX\0" S_RARROW" RIGHT", menu_marker_search_cb },
{ MT_CALLBACK, 4, "TRACKING", menu_marker_search_cb }, { MT_CALLBACK, 4, "TRACKING", menu_marker_search_cb },
{ MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel { MT_NONE, 0, NULL, NULL } // sentinel
@ -1104,9 +1134,11 @@ static const menuitem_t menu_settings[] =
static const menuitem_t menu_measure[] = { static const menuitem_t menu_measure[] = {
{ MT_CALLBACK, M_OFF, "OFF", menu_measure_cb}, { MT_CALLBACK, M_OFF, "OFF", menu_measure_cb},
{ MT_CALLBACK, M_IMD, "IMD", menu_measure_cb}, { MT_CALLBACK, M_IMD, "MARMONICS",menu_measure_cb},
{ MT_CALLBACK, M_OIP3, "OIP3", menu_measure_cb}, { MT_CALLBACK, M_OIP3, "OIP3", menu_measure_cb},
{ MT_CALLBACK, M_PHASE_NOISE, "\2PHASE\0NOISE",menu_measure_cb}, { MT_CALLBACK, M_PHASE_NOISE, "\2PHASE\0NOISE",menu_measure_cb},
{ MT_CALLBACK, M_STOP_BAND, "\2STOP\0BAND",menu_measure_cb},
{ MT_CALLBACK, M_PASS_BAND, "\2PASS\0BAND",menu_measure_cb},
{ MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel { MT_NONE, 0, NULL, NULL } // sentinel
}; };

Loading…
Cancel
Save

Powered by TurnKey Linux.