A lot of changes

- Store actual frequency in config
- Measure FM deviation
- Center zoom updated to work with dragged marker
- Improved touch calibration markers
master
erikkaashoek 5 years ago
parent 915038233f
commit 38fd765666

@ -880,6 +880,7 @@ config_t config = {
.high_level_offset = 100, // Uncalibrated
.correction_frequency = { 10000, 100000, 200000, 500000, 50000000, 140000000, 200000000, 300000000, 330000000, 350000000 },
.correction_value = { +6.0, +2.8, +1.6, -0.4, 0.0, -0.4, +0.4, +3.0, +4.0, +8.1 },
.setting_frequency_10mhz = 10000000,
.cor_am = -14,
.cor_wfm = -17,
.cor_nfm = -17,

@ -469,6 +469,7 @@ typedef struct config {
int8_t cor_am;
int8_t cor_wfm;
int8_t cor_nfm;
uint32_t setting_frequency_10mhz;
int8_t dummy;
// uint8_t _reserved[22];
uint32_t checksum;

@ -2123,6 +2123,12 @@ static void cell_draw_marker_info(int x0, int y0)
#endif
plot_printf(buf, sizeof buf, "DEPTH: %3d%%", depth);
goto show_computed;
} else if (setting.measurement == M_FM){
int32_t dev = ( markers[2].frequency - markers[1].frequency - actual_rbw_x10 * 100 ) >> 1;
if (dev < 0 )
break;
plot_printf(buf, sizeof buf, "DEVIATION:%6.1qHz", dev);
goto show_computed;
}
}
if (i >= 2 && setting.measurement == M_THD) {

@ -84,8 +84,8 @@ void update_min_max_freq(void)
minFreq = 00000000;
maxFreq = 2000000000;
#else
minFreq = 24*setting_frequency_10mhz;
maxFreq = 96*setting_frequency_10mhz;
minFreq = 24*config.setting_frequency_10mhz;
maxFreq = 96*config.setting_frequency_10mhz;
#endif
break;
case M_GENHIGH:
@ -256,6 +256,19 @@ void set_gridlines(int d)
update_grid();
}
//int setting_frequency_10mhz = 10000000;
void set_10mhz(uint32_t f)
{
if (f < 9000000 || f > 11000000)
return;
config.setting_frequency_10mhz = f;
config_save();
dirty = true;
update_grid();
}
void set_measurement(int m)
{
setting.measurement = m;
@ -1318,6 +1331,21 @@ int binary_search_frequency(int f) // Search which index in the frequency t
return -1;
}
uint32_t interpolate_maximum(int m)
{
const int idx = markers[m].index;
markers[m].frequency = frequencies[idx];
if (idx > 0 && idx < sweep_points-1)
{
const float y1 = actual_t[idx - 1];
const float y2 = actual_t[idx + 0];
const float y3 = actual_t[idx + 1];
const float d = 0.5f * (y1 - y3) / ((y1 - (2 * y2) + y3) + 1e-12f);
//const float bin = (float)idx + d;
const int32_t delta_Hz = abs((int64_t)frequencies[idx + 0] - frequencies[idx + 1]);
markers[m].frequency += (int32_t)(delta_Hz * d);
}
}
#define MAX_MAX 4
int
@ -1382,7 +1410,8 @@ search_maximum(int m, int center, int span)
}
}
markers[m].index = max_index[0];
markers[m].frequency = frequencies[markers[m].index];
interpolate_maximum(m);
// markers[m].frequency = frequencies[markers[m].index];
return found;
}
@ -2353,7 +2382,8 @@ sweep_again: // stay in sweep loop when output mo
while (m < MARKERS_MAX) {
if (markers[m].enabled && markers[m].mtype & M_TRACKING) { // Available marker found
markers[m].index = max_index[i];
markers[m].frequency = frequencies[markers[m].index];
interpolate_maximum(m);
// markers[m].frequency = frequencies[markers[m].index];
#if 0
float v = actual_t[markers[m].index] - 10.0; // -10dB points
int index = markers[m].index;
@ -2375,19 +2405,7 @@ sweep_again: // stay in sweep loop when output mo
#endif
#if 1 // Hyperbolic interpolation, can be removed to save memory
const int idx = markers[m].index;
if (idx > 0 && idx < sweep_points-1)
{
const float y1 = actual_t[idx - 1];
const float y2 = actual_t[idx + 0];
const float y3 = actual_t[idx + 1];
const float d = 0.5f * (y1 - y3) / ((y1 - (2 * y2) + y3) + 1e-12f);
//const float bin = (float)idx + d;
const int32_t delta_Hz = abs((int64_t)frequencies[idx + 0] - frequencies[idx + 1]);
markers[m].frequency += (int32_t)(delta_Hz * d);
}
#endif
interpolate_maximum(m);
m++;
break; // Next maximum
}
@ -2398,7 +2416,7 @@ sweep_again: // stay in sweep loop when output mo
while (m < MARKERS_MAX) { // Insufficient maxima found
if (markers[m].enabled && markers[m].mtype & M_TRACKING) { // More available markers found
markers[m].index = 0; // Enabled but no max so set to left most frequency
markers[m].frequency = frequencies[markers[m].index];
markers[m].frequency = frequencies[0];
}
m++; // Try next marker
}
@ -2437,7 +2455,7 @@ sweep_again: // stay in sweep loop when output mo
markers[2].index = marker_search_right_min(markers[0].index);
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 && markers[0].index > 10) { // ----------------Pass band measurement
} 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] - 3.0;
while (t < markers[0].index && actual_t[t+1] < v) // Find left -3dB point

@ -118,13 +118,6 @@ static void shiftOutBuf(uint8_t *buf, uint16_t size) {
}
#endif
int setting_frequency_10mhz = 10000000;
void set_10mhz(uint32_t f)
{
setting_frequency_10mhz = f;
}
#ifdef __SI4432__
#define CS_SI0_HIGH palSetPad(GPIOC, GPIO_RX_SEL)
#define CS_SI1_HIGH palSetPad(GPIOC, GPIO_LO_SEL)
@ -376,8 +369,8 @@ void SI4432_Set_Frequency ( uint32_t Freq ) {
hbsel = 0;
}
uint8_t sbsel = 1 << 6;
uint32_t N = (Freq / setting_frequency_10mhz - 24)&0x1F;
uint32_t K = Freq % setting_frequency_10mhz;
uint32_t N = (Freq / config.setting_frequency_10mhz - 24)&0x1F;
uint32_t K = Freq % config.setting_frequency_10mhz;
uint32_t Carrier = (K<<2) / 625;
uint8_t Freq_Band = N | hbsel | sbsel;
// int count = 0;

15
ui.c

@ -333,7 +333,8 @@ touch_cal_exec(void)
ili9341_clear_screen();
ili9341_line(0, 0, 0, 32);
ili9341_line(0, 0, 32, 0);
ili9341_drawstring("TOUCH UPPER LEFT", 10, 10);
ili9341_line(0, 0, 32, 32);
ili9341_drawstring("TOUCH UPPER LEFT", 40, 40);
touch_wait_release();
x1 = last_touch_x;
@ -342,7 +343,8 @@ touch_cal_exec(void)
ili9341_clear_screen();
ili9341_line(LCD_WIDTH-1, LCD_HEIGHT-1, LCD_WIDTH-1, LCD_HEIGHT-32);
ili9341_line(LCD_WIDTH-1, LCD_HEIGHT-1, LCD_WIDTH-32, LCD_HEIGHT-1);
ili9341_drawstring("TOUCH LOWER RIGHT", 230, 220);
ili9341_line(LCD_WIDTH-1, LCD_HEIGHT-1, LCD_WIDTH-32, LCD_HEIGHT-32);
ili9341_drawstring("TOUCH LOWER RIGHT", 210, 200);
touch_wait_release();
x2 = last_touch_x;
@ -844,7 +846,10 @@ static UI_FUNCTION_CALLBACK(menu_marker_search_cb)
}
if (i != -1) {
markers[active_marker].index = i;
markers[active_marker].frequency = frequencies[i];
if (data > 1) // Maximum related
interpolate_maximum(active_marker);
else
markers[active_marker].frequency = frequencies[i];
}
draw_menu();
redraw_marker(active_marker);
@ -2114,7 +2119,8 @@ lever_search_marker(int status)
i = marker_search_right_max(markers[active_marker].index);
if (i != -1) {
markers[active_marker].index = i;
markers[active_marker].frequency = frequencies[i];
interpolate_maximum(active_marker);
// markers[active_marker].frequency = frequencies[i];
}
redraw_marker(active_marker);
}
@ -2146,6 +2152,7 @@ lever_zoom_span(int status)
uint32_t span = get_sweep_frequency(ST_SPAN);
if (uistat.auto_center_marker) {
uint32_t freq = get_marker_frequency(active_marker);
search_maximum(active_marker, freq, 10 );
if (freq != 0)
set_sweep_frequency(ST_CENTER, freq);
}

@ -757,7 +757,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb)
#ifdef __MEASURE__
switch(data) {
case M_OFF: // Off
reset_settings(setting.mode);
// reset_settings(setting.mode);
set_measurement(M_OFF);
break;
case M_IMD: // IMD
@ -884,16 +884,26 @@ static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb)
reset_settings(setting.mode);
for (int i = 0; i< 3; i++) {
markers[i].enabled = M_ENABLED;
markers[i].mtype = M_DELTA | M_TRACKING;
markers[i].mtype = M_DELTA;
}
markers[0].mtype = M_REFERENCE | M_TRACKING;
markers[0].mtype = M_REFERENCE;
kp_help_text = "Frequency of signal";
ui_mode_keypad(KM_CENTER);
ui_process_keypad();
kp_help_text = "Frequency deviation";
set_marker_frequency(0, uistat.value);
kp_help_text = "Modulation frequency: 1 .. 2.5kHz";
ui_mode_keypad(KM_SPAN);
ui_process_keypad();
set_sweep_frequency(ST_SPAN, uistat.value*30);
if (uistat.value < 1000 || uistat.value > 2500)
break;
set_RBW(uistat.value/100);
// actual_rbw_x10
kp_help_text = "Frequency deviation: 3 .. 500kHz";
ui_mode_keypad(KM_SPAN);
ui_process_keypad();
if (uistat.value < 12000)
uistat.value = 12000; // minimum span
set_sweep_frequency(ST_SPAN, uistat.value*4);
set_measurement(M_FM);
break;
case M_THD:
@ -1013,6 +1023,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_marker_select_acb)
return;
}
markers[data-1].enabled = true;
// interpolate_maximum(data-1); // possibly not a maximum
markers[data-1].frequency = frequencies[markers[data-1].index];
active_marker_select(data-1);
menu_push_submenu(menu_marker_modify);
@ -2016,7 +2027,7 @@ static void fetch_numeric_target(void)
plot_printf(uistat.text, sizeof uistat.text, "%3d", ((int32_t)uistat.value));
break;
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);
break;
case KM_OFFSET:
@ -2128,7 +2139,6 @@ set_numeric_value(void)
break;
case KM_10MHZ:
set_10mhz(uistat.value);
dirty = true;
break;
case KM_OFFSET:
set_offset(uistat.value);

Loading…
Cancel
Save

Powered by TurnKey Linux.