mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
add impedance and L/C parameter value on marker of smith chart
This commit is contained in:
parent
ea8b4d71c2
commit
04d1ec19ab
16
Font5x7.c
16
Font5x7.c
|
|
@ -604,18 +604,18 @@ const uint16_t x5x7_bits [] =
|
||||||
/* Character (0x1f):
|
/* Character (0x1f):
|
||||||
bbw=5, bbh=7, bbx=0, bby=-1, width=5
|
bbw=5, bbh=7, bbx=0, bby=-1, width=5
|
||||||
+----------------+
|
+----------------+
|
||||||
| |
|
| ** |
|
||||||
| |
|
|* * |
|
||||||
| |
|
|* * |
|
||||||
| * |
|
| ** |
|
||||||
| |
|
| |
|
||||||
| |
|
| |
|
||||||
| |
|
| |
|
||||||
+----------------+ */
|
+----------------+ */
|
||||||
0x0000,
|
0x6000,
|
||||||
0x0000,
|
0x9000,
|
||||||
0x0000,
|
0x9000,
|
||||||
0x2000,
|
0x6000,
|
||||||
0x0000,
|
0x0000,
|
||||||
0x0000,
|
0x0000,
|
||||||
0x0000,
|
0x0000,
|
||||||
|
|
|
||||||
10
flash.c
10
flash.c
|
|
@ -81,17 +81,22 @@ caldata_save(int id)
|
||||||
current_config.checksum = checksum(¤t_config, sizeof current_config);
|
current_config.checksum = checksum(¤t_config, sizeof current_config);
|
||||||
|
|
||||||
flash_unlock();
|
flash_unlock();
|
||||||
|
|
||||||
|
/* erase flash pages */
|
||||||
void *p = dst;
|
void *p = dst;
|
||||||
void *tail = p + sizeof(config_t);
|
void *tail = p + sizeof(config_t);
|
||||||
while (p < tail) {
|
while (p < tail) {
|
||||||
flash_erase_page((uint32_t)p);
|
flash_erase_page((uint32_t)p);
|
||||||
p += FLASH_PAGESIZE;
|
p += FLASH_PAGESIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* write to flahs */
|
||||||
while(count-- > 0) {
|
while(count-- > 0) {
|
||||||
flash_program_half_word((uint32_t)dst, *src++);
|
flash_program_half_word((uint32_t)dst, *src++);
|
||||||
dst++;
|
dst++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* after saving data, make active configuration points to flash */
|
||||||
active = (config_t*)saveareas[id];
|
active = (config_t*)saveareas[id];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -111,8 +116,11 @@ caldata_recall(int id)
|
||||||
if (checksum(src, sizeof(config_t)) != 0)
|
if (checksum(src, sizeof(config_t)) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
memcpy(dst, src, sizeof(config_t));
|
/* active configuration points to save data on flash memory */
|
||||||
active = src;
|
active = src;
|
||||||
|
|
||||||
|
/* duplicated saved data onto sram to be able to modify marker/trace */
|
||||||
|
memcpy(dst, src, sizeof(config_t));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
74
nanovna.h
74
nanovna.h
|
|
@ -70,22 +70,23 @@ void ili9341_drawstring_5x7(char *str, int x, int y, uint16_t fg, uint16_t bg);
|
||||||
/*
|
/*
|
||||||
* plot.c
|
* plot.c
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define OFFSETX 15
|
#define OFFSETX 15
|
||||||
#define OFFSETY 0
|
#define OFFSETY 0
|
||||||
#define WIDTH 291
|
#define WIDTH 291
|
||||||
#define HEIGHT 233
|
#define HEIGHT 233
|
||||||
|
|
||||||
|
#define GRIDY 29
|
||||||
|
|
||||||
extern int area_width;
|
extern int area_width;
|
||||||
extern int area_height;
|
extern int area_height;
|
||||||
|
|
||||||
void plot_init(void);
|
extern const uint16_t x5x7_bits [];
|
||||||
void set_sweep(int32_t start, int stop);
|
extern const uint32_t numfont20x24[][24];
|
||||||
void redraw(void);
|
|
||||||
void force_draw_cells(void);
|
|
||||||
|
|
||||||
void redraw_marker(int marker, int update_info);
|
|
||||||
|
|
||||||
|
#define S_PI "\034"
|
||||||
|
#define S_MICRO "\035"
|
||||||
|
#define S_OHM "\036"
|
||||||
|
#define S_DEGREE "\037"
|
||||||
|
|
||||||
#define TRACES_MAX 4
|
#define TRACES_MAX 4
|
||||||
|
|
||||||
|
|
@ -95,21 +96,28 @@ enum {
|
||||||
|
|
||||||
extern const char *trc_type_name[];
|
extern const char *trc_type_name[];
|
||||||
|
|
||||||
|
// LOGMAG: SCALE, REFPOS, REFVAL
|
||||||
|
// PHASE: SCALE, REFPOS, REFVAL
|
||||||
|
// DELAY: SCALE, REFPOS, REFVAL
|
||||||
|
// SMITH: SCALE, <REFPOS>, <REFVAL>
|
||||||
|
// LINMAG: SCALE, REFPOS, REFVAL
|
||||||
|
// SWR: SCALE, REFPOS, REFVAL
|
||||||
|
|
||||||
|
// Electrical Delay
|
||||||
|
// Phase
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int enabled;
|
int enabled;
|
||||||
int type;
|
int type;
|
||||||
int channel;
|
int channel;
|
||||||
float scale;
|
float scale;
|
||||||
|
//float ref;
|
||||||
uint16_t color;
|
uint16_t color;
|
||||||
uint8_t polar;
|
uint8_t polar;
|
||||||
} trace_t;
|
} trace_t;
|
||||||
|
|
||||||
//extern trace_t trace[TRACES_MAX];
|
//extern trace_t trace[TRACES_MAX];
|
||||||
|
|
||||||
extern float measured[2][101][2];
|
|
||||||
|
|
||||||
void trace_get_info(int t, char *buf, int len);
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int enabled;
|
int enabled;
|
||||||
//uint32_t frequency;
|
//uint32_t frequency;
|
||||||
|
|
@ -119,6 +127,21 @@ typedef struct {
|
||||||
//extern marker_t markers[4];
|
//extern marker_t markers[4];
|
||||||
//extern int active_marker;
|
//extern int active_marker;
|
||||||
|
|
||||||
|
void plot_init(void);
|
||||||
|
void set_sweep(int32_t start, int stop);
|
||||||
|
void redraw(void);
|
||||||
|
void force_draw_cells(void);
|
||||||
|
void redraw_marker(int marker, int update_info);
|
||||||
|
void trace_get_info(int t, char *buf, int len);
|
||||||
|
void plot_into_index(float measured[2][101][2]);
|
||||||
|
void draw_cell_all(void);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* main.c
|
||||||
|
*/
|
||||||
|
extern float measured[2][101][2];
|
||||||
|
|
||||||
#define CAL_LOAD 0
|
#define CAL_LOAD 0
|
||||||
#define CAL_OPEN 1
|
#define CAL_OPEN 1
|
||||||
#define CAL_SHORT 2
|
#define CAL_SHORT 2
|
||||||
|
|
@ -144,20 +167,9 @@ typedef struct {
|
||||||
#define ETERM_EX 4 /* error term isolation */
|
#define ETERM_EX 4 /* error term isolation */
|
||||||
|
|
||||||
|
|
||||||
void plot_into_index(float measured[2][101][2]);
|
|
||||||
void draw_cell_all(void);
|
|
||||||
|
|
||||||
extern const uint16_t x5x7_bits [];
|
|
||||||
extern const uint32_t numfont20x24[][24];
|
|
||||||
|
|
||||||
#define CHAR_PI '\0x1c'
|
|
||||||
#define CHAR_MICRO '\0x1d'
|
|
||||||
#define CHAR_OHM '\0x1e'
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* flash.c
|
* flash.c
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define SAVEAREA_MAX 5
|
#define SAVEAREA_MAX 5
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
@ -193,16 +205,20 @@ extern config_t current_config;
|
||||||
#define markers current_config._markers
|
#define markers current_config._markers
|
||||||
#define active_marker current_config._active_marker
|
#define active_marker current_config._active_marker
|
||||||
|
|
||||||
|
|
||||||
int caldata_save(int id);
|
int caldata_save(int id);
|
||||||
int caldata_recall(int id);
|
int caldata_recall(int id);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ui.c
|
||||||
|
*/
|
||||||
|
|
||||||
#define PULSE do { palClearPad(GPIOC, GPIOC_LED); palSetPad(GPIOC, GPIOC_LED);} while(0)
|
|
||||||
|
|
||||||
void ui_init(void);
|
void ui_init(void);
|
||||||
void ui_show(void);
|
void ui_show(void);
|
||||||
void ui_hide(void);
|
void ui_hide(void);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* misclinous
|
||||||
|
*/
|
||||||
|
#define PULSE do { palClearPad(GPIOC, GPIOC_LED); palSetPad(GPIOC, GPIOC_LED);} while(0)
|
||||||
|
|
||||||
|
/*EOF*/
|
||||||
|
|
|
||||||
100
plot.c
100
plot.c
|
|
@ -164,7 +164,7 @@ rectangular_grid(int x, int y)
|
||||||
//if (((x - grid_offset) % grid_width) == 0)
|
//if (((x - grid_offset) % grid_width) == 0)
|
||||||
if (x == 0 || x == (WIDTH-1))
|
if (x == 0 || x == (WIDTH-1))
|
||||||
return c;
|
return c;
|
||||||
if ((y % 29) == 0)
|
if ((y % GRIDY) == 0)
|
||||||
return c;
|
return c;
|
||||||
if ((((x + grid_offset) * 10) % grid_width) < 10)
|
if ((((x + grid_offset) * 10) % grid_width) < 10)
|
||||||
return c;
|
return c;
|
||||||
|
|
@ -187,7 +187,7 @@ int
|
||||||
rectangular_grid_y(int y)
|
rectangular_grid_y(int y)
|
||||||
{
|
{
|
||||||
int c = grid_color;
|
int c = grid_color;
|
||||||
if ((y % 29) == 0)
|
if ((y % GRIDY) == 0)
|
||||||
return c;
|
return c;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -304,12 +304,86 @@ trace_into_index(int x, int t, int i, float coeff[2])
|
||||||
}
|
}
|
||||||
if (v < 0) v = 0;
|
if (v < 0) v = 0;
|
||||||
if (v > 8) v = 8;
|
if (v > 8) v = 8;
|
||||||
y = v * 29;
|
y = v * GRIDY;
|
||||||
return INDEX(x, y, i);
|
return INDEX(x, y, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
string_value_with_prefix(char *buf, int len, float val, char unit)
|
||||||
|
{
|
||||||
|
char prefix;
|
||||||
|
int n;
|
||||||
|
if (val < 1e-12) {
|
||||||
|
prefix = 'f';
|
||||||
|
val *= 1e15;
|
||||||
|
} else if (val < 1e-9) {
|
||||||
|
prefix = 'p';
|
||||||
|
val *= 1e12;
|
||||||
|
} else if (val < 1e-6) {
|
||||||
|
prefix = 'n';
|
||||||
|
val *= 1e9;
|
||||||
|
} else if (val < 1e-3) {
|
||||||
|
prefix = S_MICRO[0];
|
||||||
|
val *= 1e6;
|
||||||
|
} else if (val < 1) {
|
||||||
|
prefix = 'm';
|
||||||
|
val *= 1e3;
|
||||||
|
} else if (val < 1e3) {
|
||||||
|
prefix = 0;
|
||||||
|
} else if (val < 1e6) {
|
||||||
|
prefix = 'k';
|
||||||
|
val /= 1e3;
|
||||||
|
} else if (val < 1e9) {
|
||||||
|
prefix = 'M';
|
||||||
|
val /= 1e6;
|
||||||
|
} else {
|
||||||
|
prefix = 'G';
|
||||||
|
val /= 1e9;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (val < 10) {
|
||||||
|
n = chsnprintf(buf, len, "%.2f", val);
|
||||||
|
} else if (val < 100) {
|
||||||
|
n = chsnprintf(buf, len, "%.1f", val);
|
||||||
|
} else {
|
||||||
|
n = chsnprintf(buf, len, "%d", (int)val);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prefix)
|
||||||
|
buf[n++] = prefix;
|
||||||
|
if (unit)
|
||||||
|
buf[n++] = unit;
|
||||||
|
buf[n] = '\0';
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define PI2 6.283184
|
||||||
|
|
||||||
void
|
void
|
||||||
trace_get_value_string(int t, char *buf, int len, float coeff[2])
|
gamma2imp(char *buf, int len, const float coeff[2], uint32_t frequency)
|
||||||
|
{
|
||||||
|
// z = (gamma+1)/(gamma-1) * z0
|
||||||
|
float z0 = 50;
|
||||||
|
float d = z0 / ((1-coeff[0])*(1-coeff[0])+coeff[1]*coeff[1]);
|
||||||
|
float zr = ((1+coeff[0])*(1-coeff[0]) + coeff[1]*coeff[1]) * d;
|
||||||
|
float zi = 2*coeff[1] * d;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
n = string_value_with_prefix(buf, len, zr, S_OHM[0]);
|
||||||
|
buf[n++] = ' ';
|
||||||
|
|
||||||
|
if (zi < 0) {
|
||||||
|
float c = -1 / (PI2 * frequency * zi);
|
||||||
|
string_value_with_prefix(buf+n, len-n, c, 'F');
|
||||||
|
} else {
|
||||||
|
float l = zi / (PI2 * frequency);
|
||||||
|
string_value_with_prefix(buf+n, len-n, l, 'H');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
trace_get_value_string(int t, char *buf, int len, float coeff[2], uint32_t frequency)
|
||||||
{
|
{
|
||||||
float v;
|
float v;
|
||||||
switch (trace[t].type) {
|
switch (trace[t].type) {
|
||||||
|
|
@ -319,7 +393,7 @@ trace_get_value_string(int t, char *buf, int len, float coeff[2])
|
||||||
break;
|
break;
|
||||||
case TRC_PHASE:
|
case TRC_PHASE:
|
||||||
v = phase(coeff);
|
v = phase(coeff);
|
||||||
chsnprintf(buf, len, "%.2f deg", v * 90);
|
chsnprintf(buf, len, "%.2f" S_DEGREE, v * 90);
|
||||||
break;
|
break;
|
||||||
case TRC_LINEAR:
|
case TRC_LINEAR:
|
||||||
v = linear(coeff);
|
v = linear(coeff);
|
||||||
|
|
@ -330,6 +404,10 @@ trace_get_value_string(int t, char *buf, int len, float coeff[2])
|
||||||
chsnprintf(buf, len, "%.2f", v);
|
chsnprintf(buf, len, "%.2f", v);
|
||||||
break;
|
break;
|
||||||
case TRC_SMITH:
|
case TRC_SMITH:
|
||||||
|
gamma2imp(buf, len, coeff, frequency);
|
||||||
|
break;
|
||||||
|
case TRC_ADMIT:
|
||||||
|
case TRC_POLAR:
|
||||||
chsnprintf(buf, len, "%.2f %.2fj", coeff[0], coeff[1]);
|
chsnprintf(buf, len, "%.2f %.2fj", coeff[0], coeff[1]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -341,21 +419,21 @@ trace_get_info(int t, char *buf, int len)
|
||||||
const char *type = trc_type_name[trace[t].type];
|
const char *type = trc_type_name[trace[t].type];
|
||||||
switch (trace[t].type) {
|
switch (trace[t].type) {
|
||||||
case TRC_LOGMAG:
|
case TRC_LOGMAG:
|
||||||
chsnprintf(buf, len, "Ch%d %s %ddB/",
|
chsnprintf(buf, len, "CH%d %s %ddB/",
|
||||||
trace[t].channel, type, (int)(trace[t].scale*10));
|
trace[t].channel, type, (int)(trace[t].scale*10));
|
||||||
break;
|
break;
|
||||||
case TRC_PHASE:
|
case TRC_PHASE:
|
||||||
chsnprintf(buf, len, "Ch%d %s %ddeg/",
|
chsnprintf(buf, len, "CH%d %s %d" S_DEGREE "/",
|
||||||
trace[t].channel, type, (int)(trace[t].scale*90));
|
trace[t].channel, type, (int)(trace[t].scale*90));
|
||||||
break;
|
break;
|
||||||
case TRC_SMITH:
|
case TRC_SMITH:
|
||||||
case TRC_ADMIT:
|
case TRC_ADMIT:
|
||||||
case TRC_POLAR:
|
case TRC_POLAR:
|
||||||
chsnprintf(buf, len, "Ch%d %s %.1fFS",
|
chsnprintf(buf, len, "CH%d %s %.1fFS",
|
||||||
trace[t].channel, type, trace[t].scale);
|
trace[t].channel, type, trace[t].scale);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
chsnprintf(buf, len, "Ch%d %s %.1f/",
|
chsnprintf(buf, len, "CH%d %s %.1f/",
|
||||||
trace[t].channel, type, trace[t].scale);
|
trace[t].channel, type, trace[t].scale);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -879,14 +957,14 @@ cell_draw_marker_info(int m, int n, int w, int h)
|
||||||
for (t = 0; t < TRACES_MAX; t++) {
|
for (t = 0; t < TRACES_MAX; t++) {
|
||||||
if (!trace[t].enabled)
|
if (!trace[t].enabled)
|
||||||
continue;
|
continue;
|
||||||
int xpos = 1 + (j%2)*152;
|
int xpos = 1 + (j%2)*146;
|
||||||
int ypos = 1 + (j/2)*7;
|
int ypos = 1 + (j/2)*7;
|
||||||
xpos -= m * CELLWIDTH;
|
xpos -= m * CELLWIDTH;
|
||||||
ypos -= n * CELLHEIGHT;
|
ypos -= n * CELLHEIGHT;
|
||||||
trace_get_info(t, buf, sizeof buf);
|
trace_get_info(t, buf, sizeof buf);
|
||||||
cell_drawstring_5x7(w, h, buf, xpos, ypos, trace[t].color);
|
cell_drawstring_5x7(w, h, buf, xpos, ypos, trace[t].color);
|
||||||
xpos += 84;
|
xpos += 84;
|
||||||
trace_get_value_string(t, buf, sizeof buf, measured[trace[t].channel][idx]);
|
trace_get_value_string(t, buf, sizeof buf, measured[trace[t].channel][idx], frequencies[idx]);
|
||||||
cell_drawstring_5x7(w, h, buf, xpos, ypos, trace[t].color);
|
cell_drawstring_5x7(w, h, buf, xpos, ypos, trace[t].color);
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue