change command name from data to dump, add data command to fetch array, marker position

This commit is contained in:
TT 2016-10-25 01:16:05 +09:00
parent 520ebef659
commit 0d6c718a47
3 changed files with 109 additions and 27 deletions

View file

@ -556,10 +556,10 @@ draw_on_strut(int v0, int d, int color)
} }
trace_t trace[TRACES_MAX] = { trace_t trace[TRACES_MAX] = {
{ 1, TRC_LOGMAG, 0, RGB565(0,255,255), 0 }, { 1, TRC_LOGMAG, 0, 1.0, RGB565(0,255,255), 0 },
{ 1, TRC_LOGMAG, 1, RGB565(255,0,40), 0 }, { 1, TRC_LOGMAG, 1, 1.0, RGB565(255,0,40), 0 },
{ 1, TRC_SMITH, 0, RGB565(0,0,255), 1 }, { 1, TRC_SMITH, 0, 1.0, RGB565(0,0,255), 1 },
{ 1, TRC_PHASE, 1, RGB565(50,255,0), 1 } { 1, TRC_PHASE, 1, 1.0, RGB565(50,255,0), 1 }
}; };
uint32_t trace_index[TRACES_MAX][101]; uint32_t trace_index[TRACES_MAX][101];
@ -598,12 +598,11 @@ float swr(float *v)
#define RADIUS ((HEIGHT-1)/2) #define RADIUS ((HEIGHT-1)/2)
void void
cartesian_scale(float re, float im, int *xp, int *yp) cartesian_scale(float re, float im, int *xp, int *yp, float scale)
{ {
//float scale = 4e-3; //float scale = 4e-3;
float scale = RADIUS; int x = re * RADIUS * scale;
int x = re * scale; int y = im * RADIUS * scale;
int y = im * scale;
if (x < -RADIUS) x = -RADIUS; if (x < -RADIUS) x = -RADIUS;
if (y < -RADIUS) y = -RADIUS; if (y < -RADIUS) y = -RADIUS;
if (x > RADIUS) x = RADIUS; if (x > RADIUS) x = RADIUS;
@ -733,7 +732,7 @@ trace_into_index(int x, int t, int i, float coeff[2])
case TRC_SMITH: case TRC_SMITH:
case TRC_ADMIT: case TRC_ADMIT:
case TRC_POLAR: case TRC_POLAR:
cartesian_scale(coeff[0], coeff[1], &x1, &y1); cartesian_scale(coeff[0], coeff[1], &x1, &y1, trace[t].scale);
idx = INDEX(x1, y1, i); idx = INDEX(x1, y1, i);
break; break;
} }
@ -748,7 +747,7 @@ void plot_into_index(float measured[2][101][2])
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 n = trace[t].source; int n = trace[t].channel;
trace_index[t][i] = trace_into_index(x, t, i, measured[n][i]); trace_index[t][i] = trace_into_index(x, t, i, measured[n][i]);
} }
} }
@ -1025,11 +1024,25 @@ draw_cell(int m, int n)
} }
} }
#endif #endif
#if 0
if (m == 0 && n == 0) { if (m == 0 && n == 0) {
draw_marker(w, h, 8, 12, trace[0].color, '1'); draw_marker(w, h, 8, 12, trace[0].color, '1');
draw_marker(w, h, 18, 20, trace[1].color, '2'); draw_marker(w, h, 18, 20, trace[1].color, '2');
draw_marker(w, h, 4, 30, trace[2].color, '3'); draw_marker(w, h, 4, 30, trace[2].color, '3');
} }
#endif
i = 30;
for (t = 0; t < TRACES_MAX; t++) {
if (!trace[t].enabled)
continue;
uint32_t index = trace_index[t][i];
int x = CELL_X(index) - x0;
int y = CELL_Y(index) - y0;
if (x > -12 && x < w+12 && y >= 0 && y < h+12)
draw_marker(w, h, x, y, trace[t].color, '1');
}
ili9341_bulk(OFFSETX + x0, OFFSETY + y0, w, h); ili9341_bulk(OFFSETX + x0, OFFSETY + y0, w, h);
} }

100
main.c
View file

@ -266,6 +266,29 @@ static const I2SConfig i2sconfig = {
}; };
static void cmd_data(BaseSequentialStream *chp, int argc, char *argv[]) static void cmd_data(BaseSequentialStream *chp, int argc, char *argv[])
{
int i;
int len;
int sel = 0;
if (argc == 1)
sel = atoi(argv[0]);
if (sel == 0 || sel == 1) {
pause_sweep();
for (i = 0; i < 101; i++) {
chprintf(chp, "%f %f\r\n", measured[sel][i][0], measured[sel][i][1]);
}
} else if (sel >= 2 && sel < 7) {
pause_sweep();
for (i = 0; i < 101; i++) {
chprintf(chp, "%f %f\r\n", cal_data[sel-2][i][0], cal_data[sel-2][i][1]);
}
} else {
chprintf(chp, "usage: data [array]\r\n");
}
}
static void cmd_dump(BaseSequentialStream *chp, int argc, char *argv[])
{ {
int i, j; int i, j;
int len; int len;
@ -371,7 +394,7 @@ void scan_lcd(void)
delay = set_frequency(frequencies[0]); delay = set_frequency(frequencies[0]);
delay += 2; delay += 2;
for (i = 0; i < sweep_points; i++) { for (i = 0; i < sweep_points; i++) {
wait_count = delay + 1; wait_count = delay + 2;
tlv320aic3204_select_in3(); tlv320aic3204_select_in3();
while (wait_count) while (wait_count)
; ;
@ -381,7 +404,7 @@ void scan_lcd(void)
__enable_irq(); __enable_irq();
tlv320aic3204_select_in1(); tlv320aic3204_select_in1();
wait_count = 2 + 1; wait_count = 2 + 2;
while (wait_count) while (wait_count)
; ;
__disable_irq(); __disable_irq();
@ -485,6 +508,32 @@ eterm_copy(int dst, int src)
memcpy(cal_data[dst], cal_data[src], sizeof cal_data[dst]); memcpy(cal_data[dst], cal_data[src], sizeof cal_data[dst]);
} }
struct open_model {
float c0;
float c1;
float c2;
float c3;
} open_model = { 50, 0, -300, 27 };
#if 1
static void
adjust_ed(void)
{
int i;
for (i = 0; i < 101; i++) {
// z=1/(jwc*z0) = 1/(2*pi*f*c*z0) Note: normalized with Z0
// s11ao = (z-1)/(z+1) = (1-1/z)/(1+1/z) = (1-jwcz0)/(1+jwcz0)
// prepare 1/s11ao for effeiciency
float c = 1000e-15;
float z0 = 50;
//float z = 6.2832 * frequencies[i] * c * z0;
float z = 0.02;
cal_data[ETERM_ED][i][0] += z;
}
}
#endif
static void static void
eterm_calc_es(void) eterm_calc_es(void)
{ {
@ -493,7 +542,8 @@ eterm_calc_es(void)
// z=1/(jwc*z0) = 1/(2*pi*f*c*z0) Note: normalized with Z0 // z=1/(jwc*z0) = 1/(2*pi*f*c*z0) Note: normalized with Z0
// s11ao = (z-1)/(z+1) = (1-1/z)/(1+1/z) = (1-jwcz0)/(1+jwcz0) // s11ao = (z-1)/(z+1) = (1-1/z)/(1+1/z) = (1-jwcz0)/(1+jwcz0)
// prepare 1/s11ao for effeiciency // prepare 1/s11ao for effeiciency
float c = 150e-15; float c = 50e-15;
//float c = 1.707e-12;
float z0 = 50; float z0 = 50;
float z = 6.2832 * frequencies[i] * c * z0; float z = 6.2832 * frequencies[i] * c * z0;
float sq = 1 + z*z; float sq = 1 + z*z;
@ -524,9 +574,9 @@ eterm_calc_er(int sign)
{ {
int i; int i;
for (i = 0; i < 101; i++) { for (i = 0; i < 101; i++) {
// Er = sign*(1-sign*Es)S11mo' // Er = sign*(1-sign*Es)S11ms'
float s11or = cal_data[CAL_SHORT][i][0] - cal_data[ETERM_ED][i][0]; float s11sr = cal_data[CAL_SHORT][i][0] - cal_data[ETERM_ED][i][0];
float s11oi = cal_data[CAL_SHORT][i][1] - cal_data[ETERM_ED][i][1]; float s11si = cal_data[CAL_SHORT][i][1] - cal_data[ETERM_ED][i][1];
float esr = cal_data[ETERM_ES][i][0]; float esr = cal_data[ETERM_ES][i][0];
float esi = cal_data[ETERM_ES][i][1]; float esi = cal_data[ETERM_ES][i][1];
if (sign > 0) { if (sign > 0) {
@ -534,14 +584,15 @@ eterm_calc_er(int sign)
esi = -esi; esi = -esi;
} }
esr = 1 + esr; esr = 1 + esr;
float err = esr * s11or - esi * s11oi; float err = esr * s11sr - esi * s11si;
float eri = esr * s11oi + esi * s11or; float eri = esr * s11si + esi * s11sr;
if (sign < 0) { if (sign < 0) {
err = -err; err = -err;
eri = -eri; eri = -eri;
} }
cal_data[ETERM_ER][i][0] = err; cal_data[ETERM_ER][i][0] = err;
cal_data[ETERM_ER][i][1] = eri; cal_data[ETERM_ER][i][1] = eri;
cal_data[ETERM_ES][i][1] = 0;
} }
cal_status &= ~CALSTAT_SHORT; cal_status &= ~CALSTAT_SHORT;
cal_status |= CALSTAT_ER; cal_status |= CALSTAT_ER;
@ -619,22 +670,35 @@ static void cmd_cal(BaseSequentialStream *chp, int argc, char *argv[])
char *cmd = argv[0]; char *cmd = argv[0];
if (strcmp(cmd, "load") == 0) { if (strcmp(cmd, "load") == 0) {
cal_status |= CALSTAT_LOAD; cal_status |= CALSTAT_LOAD;
chMtxLock(&mutex);
memcpy(cal_data[CAL_LOAD], measured[0], sizeof measured[0]); memcpy(cal_data[CAL_LOAD], measured[0], sizeof measured[0]);
chMtxUnlock(&mutex);
} else if (strcmp(cmd, "open") == 0) { } else if (strcmp(cmd, "open") == 0) {
cal_status |= CALSTAT_OPEN; cal_status |= CALSTAT_OPEN;
cal_status &= ~(CALSTAT_ES|CALSTAT_APPLY);
chMtxLock(&mutex);
memcpy(cal_data[CAL_OPEN], measured[0], sizeof measured[0]); memcpy(cal_data[CAL_OPEN], measured[0], sizeof measured[0]);
chMtxUnlock(&mutex);
} else if (strcmp(cmd, "short") == 0) { } else if (strcmp(cmd, "short") == 0) {
cal_status |= CALSTAT_SHORT; cal_status |= CALSTAT_SHORT;
cal_status &= ~(CALSTAT_ER|CALSTAT_APPLY);
chMtxLock(&mutex);
memcpy(cal_data[CAL_SHORT], measured[0], sizeof measured[0]); memcpy(cal_data[CAL_SHORT], measured[0], sizeof measured[0]);
chMtxUnlock(&mutex);
} else if (strcmp(cmd, "thru") == 0) { } else if (strcmp(cmd, "thru") == 0) {
cal_status |= CALSTAT_THRU; cal_status |= CALSTAT_THRU;
chMtxLock(&mutex);
memcpy(cal_data[CAL_THRU], measured[1], sizeof measured[0]); memcpy(cal_data[CAL_THRU], measured[1], sizeof measured[0]);
chMtxUnlock(&mutex);
} else if (strcmp(cmd, "isoln") == 0) { } else if (strcmp(cmd, "isoln") == 0) {
cal_status |= CALSTAT_ISOLN; cal_status |= CALSTAT_ISOLN;
chMtxLock(&mutex);
memcpy(cal_data[CAL_ISOLN], measured[1], sizeof measured[0]); memcpy(cal_data[CAL_ISOLN], measured[1], sizeof measured[0]);
chMtxUnlock(&mutex);
} else if (strcmp(cmd, "done") == 0) { } else if (strcmp(cmd, "done") == 0) {
if (!(cal_status & CALSTAT_LOAD)) if (!(cal_status & CALSTAT_LOAD))
eterm_set(ETERM_ED, 0.0, 0.0); eterm_set(ETERM_ED, 0.0, 0.0);
//adjust_ed();
if ((cal_status & CALSTAT_SHORT) && (cal_status & CALSTAT_OPEN)) { if ((cal_status & CALSTAT_SHORT) && (cal_status & CALSTAT_OPEN)) {
eterm_calc_es(); eterm_calc_es();
eterm_calc_er(-1); eterm_calc_er(-1);
@ -703,7 +767,7 @@ static void cmd_recall(BaseSequentialStream *chp, int argc, char *argv[])
const char *trc_type_name[] = { const char *trc_type_name[] = {
"LogMAG", "Phase", "Smith", "Admit", "Polar", "Linear", "SWR" "LogMAG", "Phase", "Smith", "Admit", "Polar", "Linear", "SWR"
}; };
const char *trc_source_name[] = { const char *trc_channel_name[] = {
"S11", "S21" "S11", "S21"
}; };
@ -715,8 +779,8 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
for (t = 0; t < 4; t++) { for (t = 0; t < 4; t++) {
if (trace[t].enabled) { if (trace[t].enabled) {
const char *type = trc_type_name[trace[t].type]; const char *type = trc_type_name[trace[t].type];
const char *source = trc_source_name[trace[t].source]; const char *channel = trc_channel_name[trace[t].channel];
chprintf(chp, "%d %s %s\r\n", t, type, source); chprintf(chp, "%d %s %s\r\n", t, type, channel);
} }
} }
return; return;
@ -726,8 +790,8 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
goto usage; goto usage;
if (argc == 1) { if (argc == 1) {
const char *type = trc_type_name[trace[t].type]; const char *type = trc_type_name[trace[t].type];
const char *source = trc_source_name[trace[t].source]; const char *channel = trc_channel_name[trace[t].channel];
chprintf(chp, "%d %s %s\r\n", t, type, source); chprintf(chp, "%d %s %s\r\n", t, type, channel);
return; return;
} }
if (argc > 1) { if (argc > 1) {
@ -761,15 +825,18 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
trace[t].enabled = TRUE; trace[t].enabled = TRUE;
} else if (strcmp(argv[1], "off") == 0) { } else if (strcmp(argv[1], "off") == 0) {
trace[t].enabled = FALSE; trace[t].enabled = FALSE;
} else if (strcmp(argv[1], "scale") == 0 && argc >= 3) {
trace[t].scale = atoi(argv[2]);
goto exit;
} }
} }
if (argc > 2) { if (argc > 2) {
int src = atoi(argv[2]); int src = atoi(argv[2]);
if (src != 0 && src != 1) if (src != 0 && src != 1)
goto usage; goto usage;
trace[t].source = src; trace[t].channel = src;
} }
exit:
return; return;
usage: usage:
chprintf(chp, "trace [n] [logmag|phase|smith|swr] [src]\r\n"); chprintf(chp, "trace [n] [logmag|phase|smith|swr] [src]\r\n");
@ -877,7 +944,7 @@ static void cmd_stat(BaseSequentialStream *chp, int argc, char *argv[])
#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(460) #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(454)
static const ShellCommand commands[] = static const ShellCommand commands[] =
{ {
@ -887,6 +954,7 @@ static const ShellCommand commands[] =
{ "time", cmd_time }, { "time", cmd_time },
{ "dac", cmd_dac }, { "dac", cmd_dac },
{ "data", cmd_data }, { "data", cmd_data },
{ "dump", cmd_dump },
{ "port", cmd_port }, { "port", cmd_port },
{ "stat", cmd_stat }, { "stat", cmd_stat },
{ "gain", cmd_gain }, { "gain", cmd_gain },

View file

@ -58,7 +58,8 @@ enum {
typedef struct { typedef struct {
int enabled; int enabled;
int type; int type;
int source; int channel;
float scale;
uint16_t color; uint16_t color;
uint8_t polar; uint8_t polar;
} trace_t; } trace_t;