mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
set sweep on draw, adjust grid
This commit is contained in:
parent
d105faf709
commit
b2e3fe770d
2
dsp.c
2
dsp.c
|
|
@ -102,7 +102,7 @@ void calclate_gamma(float *gamma)
|
||||||
{
|
{
|
||||||
int16_t *r = refiq_buf;
|
int16_t *r = refiq_buf;
|
||||||
int16_t *s = samp_buf;
|
int16_t *s = samp_buf;
|
||||||
int len = SAMPLE_LEN/5;
|
int len = SAMPLE_LEN;
|
||||||
float acc_r = 0;
|
float acc_r = 0;
|
||||||
float acc_i = 0;
|
float acc_i = 0;
|
||||||
float acc_ref = 0;
|
float acc_ref = 0;
|
||||||
|
|
|
||||||
67
ili9431.c
67
ili9431.c
|
|
@ -346,25 +346,48 @@ ili9341_test(int mode)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int prev_freq;
|
|
||||||
int prev_x;
|
int prev_x;
|
||||||
|
|
||||||
int32_t fstart = 0;
|
int32_t fstart = 0;
|
||||||
int32_t fend = 300000000;
|
int32_t fstop = 300000000;
|
||||||
|
int32_t fspan = 300000000;
|
||||||
|
int32_t fgrid = 50000000;
|
||||||
|
|
||||||
#define OFFSETX 15
|
#define OFFSETX 15
|
||||||
#define OFFSETY 0
|
#define OFFSETY 0
|
||||||
#define WIDTH 291
|
#define WIDTH 291
|
||||||
#define HEIGHT 233
|
#define HEIGHT 233
|
||||||
|
|
||||||
|
void set_sweep(int32_t start, int stop)
|
||||||
|
{
|
||||||
|
int32_t gdigit = 100000000;
|
||||||
|
int32_t grid;
|
||||||
|
fstart = start;
|
||||||
|
fstop = stop;
|
||||||
|
fspan = stop - start;
|
||||||
|
|
||||||
|
while (gdigit > 100) {
|
||||||
|
grid = 5 * gdigit;
|
||||||
|
if (fspan / grid >= 5)
|
||||||
|
break;
|
||||||
|
grid = 2 * gdigit;
|
||||||
|
if (fspan / grid >= 5)
|
||||||
|
break;
|
||||||
|
grid = gdigit;
|
||||||
|
if (fspan / grid >= 5)
|
||||||
|
break;
|
||||||
|
gdigit /= 10;
|
||||||
|
}
|
||||||
|
fgrid = grid;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
circle_grid(int x, int y, int r)
|
circle_inout(int x, int y, int r)
|
||||||
{
|
{
|
||||||
int d = x*x + y*y - r*r;
|
int d = x*x + y*y - r*r;
|
||||||
if (d <= -r)
|
if (d <= -r)
|
||||||
return 1;
|
return 1;
|
||||||
if (d >= r)
|
if (d > r)
|
||||||
return -1;
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -372,7 +395,7 @@ circle_grid(int x, int y, int r)
|
||||||
int
|
int
|
||||||
smith_grid(int x, int y)
|
smith_grid(int x, int y)
|
||||||
{
|
{
|
||||||
int d = circle_grid(x-146, y-116, 116);
|
int d = circle_inout(x-146, y-116, 116);
|
||||||
int c = 0x7bef;
|
int c = 0x7bef;
|
||||||
if (d < 0)
|
if (d < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -381,25 +404,25 @@ smith_grid(int x, int y)
|
||||||
x -= 146+116;
|
x -= 146+116;
|
||||||
y -= 116;
|
y -= 116;
|
||||||
|
|
||||||
if (circle_grid(x, y+58, 58) == 0)
|
if (circle_inout(x, y+58, 58) == 0)
|
||||||
return c;
|
return c;
|
||||||
if (circle_grid(x, y-58, 58) == 0)
|
if (circle_inout(x, y-58, 58) == 0)
|
||||||
return c;
|
return c;
|
||||||
d = circle_grid(x+29, y, 29);
|
d = circle_inout(x+29, y, 29);
|
||||||
if (d > 0) return 0;
|
if (d > 0) return 0;
|
||||||
if (d == 0) return c;
|
if (d == 0) return c;
|
||||||
if (circle_grid(x, y+116, 116) == 0)
|
if (circle_inout(x, y+116, 116) == 0)
|
||||||
return c;
|
return c;
|
||||||
if (circle_grid(x, y-116, 116) == 0)
|
if (circle_inout(x, y-116, 116) == 0)
|
||||||
return c;
|
return c;
|
||||||
d = circle_grid(x+58, y, 58);
|
d = circle_inout(x+58, y, 58);
|
||||||
if (d > 0) return 0;
|
if (d > 0) return 0;
|
||||||
if (d == 0) return c;
|
if (d == 0) return c;
|
||||||
if (circle_grid(x, y+232, 232) == 0)
|
if (circle_inout(x, y+232, 232) == 0)
|
||||||
return c;
|
return c;
|
||||||
if (circle_grid(x, y-232, 232) == 0)
|
if (circle_inout(x, y-232, 232) == 0)
|
||||||
return c;
|
return c;
|
||||||
if (circle_grid(x+87, y, 87) == 0)
|
if (circle_inout(x+87, y, 87) == 0)
|
||||||
return c;
|
return c;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -407,8 +430,12 @@ smith_grid(int x, int y)
|
||||||
int
|
int
|
||||||
rectangular_grid(int x, int y)
|
rectangular_grid(int x, int y)
|
||||||
{
|
{
|
||||||
|
#define FREQ(x) (((x) * (fspan / 1000) / (WIDTH-1)) * 1000 + fstart)
|
||||||
int c = 0x7bef;
|
int c = 0x7bef;
|
||||||
if (((x * 6) % (WIDTH-1)) < 6)
|
int32_t n = FREQ(x-1) / fgrid;
|
||||||
|
int32_t m = FREQ(x) / fgrid;
|
||||||
|
if ((m - n) > 0)
|
||||||
|
//if (((x * 6) % (WIDTH-1)) < 6)
|
||||||
return c;
|
return c;
|
||||||
if ((y % 29) == 0)
|
if ((y % 29) == 0)
|
||||||
return c;
|
return c;
|
||||||
|
|
@ -440,11 +467,11 @@ draw_on_strut(int v0, int d, int color)
|
||||||
if (v0 >= HEIGHT) v0 = HEIGHT-1;
|
if (v0 >= HEIGHT) v0 = HEIGHT-1;
|
||||||
if (v1 >= HEIGHT) v1 = HEIGHT-1;
|
if (v1 >= HEIGHT) v1 = HEIGHT-1;
|
||||||
if (v0 == v1) {
|
if (v0 == v1) {
|
||||||
v = v0; d = 1;
|
v = v0; d = 2;
|
||||||
} else if (v0 < v1) {
|
} else if (v0 < v1) {
|
||||||
v = v0; d = v1 - v0;
|
v = v0; d = v1 - v0 + 1;
|
||||||
} else {
|
} else {
|
||||||
v = v1; d = v0 - v1;
|
v = v1; d = v0 - v1 + 1;
|
||||||
}
|
}
|
||||||
while (d-- > 0)
|
while (d-- > 0)
|
||||||
spi_buffer[v++] = color;
|
spi_buffer[v++] = color;
|
||||||
|
|
@ -465,17 +492,15 @@ float logmag(float *v)
|
||||||
return 11 - log10f(v[0]*v[0] + v[1]*v[1]);
|
return 11 - log10f(v[0]*v[0] + v[1]*v[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void sweep_plot(int32_t freq, int first)
|
void sweep_plot(int32_t freq, int first)
|
||||||
{
|
{
|
||||||
int curr_x = ((float)WIDTH * (freq - fstart) / (fend - fstart));
|
int curr_x = ((float)WIDTH * (freq - fstart) / fspan);
|
||||||
//float value = 11 - log10f(measured[0]*measured[0] + measured[1]*measured[1]);
|
//float value = 11 - log10f(measured[0]*measured[0] + measured[1]*measured[1]);
|
||||||
//value *= 29;
|
//value *= 29;
|
||||||
trace[0].value = logmag(&measured[0]) * 29;
|
trace[0].value = logmag(&measured[0]) * 29;
|
||||||
trace[1].value = logmag(&measured[2]) * 29;
|
trace[1].value = logmag(&measured[2]) * 29;
|
||||||
|
|
||||||
if (first) {
|
if (first) {
|
||||||
prev_freq = freq;
|
|
||||||
prev_x = 0;
|
prev_x = 0;
|
||||||
while (prev_x < curr_x) {
|
while (prev_x < curr_x) {
|
||||||
int len = set_strut_grid(prev_x);
|
int len = set_strut_grid(prev_x);
|
||||||
|
|
|
||||||
3
main.c
3
main.c
|
|
@ -348,6 +348,7 @@ void scan_lcd(void)
|
||||||
|
|
||||||
freq = freq_start;
|
freq = freq_start;
|
||||||
step = (freq_stop - freq_start) / (sweep_points-1);
|
step = (freq_stop - freq_start) / (sweep_points-1);
|
||||||
|
set_sweep(freq_start, freq_stop);
|
||||||
delay = set_frequency(freq);
|
delay = set_frequency(freq);
|
||||||
delay += 2;
|
delay += 2;
|
||||||
for (i = 0; i < sweep_points; i++) {
|
for (i = 0; i < sweep_points; i++) {
|
||||||
|
|
@ -363,7 +364,7 @@ void scan_lcd(void)
|
||||||
__enable_irq();
|
__enable_irq();
|
||||||
|
|
||||||
tlv320aic3204_select_in1();
|
tlv320aic3204_select_in1();
|
||||||
wait_count = 2;
|
wait_count = 3;
|
||||||
while (wait_count)
|
while (wait_count)
|
||||||
;
|
;
|
||||||
__disable_irq();
|
__disable_irq();
|
||||||
|
|
|
||||||
|
|
@ -22,13 +22,13 @@ extern void ui_init(void);
|
||||||
extern void ui_process(void);
|
extern void ui_process(void);
|
||||||
|
|
||||||
// 5ms @ 48kHz
|
// 5ms @ 48kHz
|
||||||
#define AUDIO_BUFFER_LEN 480
|
#define AUDIO_BUFFER_LEN 96
|
||||||
|
|
||||||
extern int16_t rx_buffer[];
|
extern int16_t rx_buffer[];
|
||||||
extern int16_t tx_buffer[];
|
extern int16_t tx_buffer[];
|
||||||
|
|
||||||
#define STATE_LEN 32
|
#define STATE_LEN 32
|
||||||
#define SAMPLE_LEN 240
|
#define SAMPLE_LEN 48
|
||||||
|
|
||||||
extern int16_t ref_state[];
|
extern int16_t ref_state[];
|
||||||
extern int16_t ref_buf[];
|
extern int16_t ref_buf[];
|
||||||
|
|
@ -47,6 +47,7 @@ int si5351_set_frequency_with_offset(int freq, int offset, uint8_t drive_strengt
|
||||||
void ili9341_init(void);
|
void ili9341_init(void);
|
||||||
void ili9341_test(int mode);
|
void ili9341_test(int mode);
|
||||||
|
|
||||||
|
void set_sweep(int32_t start, int stop);
|
||||||
void sweep_plot(int32_t freq, int first);
|
void sweep_plot(int32_t freq, int first);
|
||||||
void sweep_tail(void);
|
void sweep_tail(void);
|
||||||
|
|
||||||
|
|
|
||||||
6
si5351.c
6
si5351.c
|
|
@ -287,7 +287,7 @@ int
|
||||||
si5351_set_frequency_with_offset(int freq, int offset, uint8_t drive_strength)
|
si5351_set_frequency_with_offset(int freq, int offset, uint8_t drive_strength)
|
||||||
{
|
{
|
||||||
int band;
|
int band;
|
||||||
int delay = 1;
|
int delay = 3;
|
||||||
if (freq <= 100000000) {
|
if (freq <= 100000000) {
|
||||||
band = 0;
|
band = 0;
|
||||||
} else if (freq < 150000000) {
|
} else if (freq < 150000000) {
|
||||||
|
|
@ -312,8 +312,6 @@ si5351_set_frequency_with_offset(int freq, int offset, uint8_t drive_strength)
|
||||||
//if (current_band != 0)
|
//if (current_band != 0)
|
||||||
si5351_set_frequency_fixedpll(2, SI5351_PLL_A, PLLFREQ, CLK2_FREQUENCY,
|
si5351_set_frequency_fixedpll(2, SI5351_PLL_A, PLLFREQ, CLK2_FREQUENCY,
|
||||||
SI5351_CLK_DRIVE_STRENGTH_2MA);
|
SI5351_CLK_DRIVE_STRENGTH_2MA);
|
||||||
//delay = 1;
|
|
||||||
delay = 2;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
|
|
@ -323,7 +321,6 @@ si5351_set_frequency_with_offset(int freq, int offset, uint8_t drive_strength)
|
||||||
si5351_set_frequency_fixeddiv(1, SI5351_PLL_B, freq, 6, drive_strength);
|
si5351_set_frequency_fixeddiv(1, SI5351_PLL_B, freq, 6, drive_strength);
|
||||||
si5351_set_frequency_fixedpll(2, SI5351_PLL_B, freq * 6, CLK2_FREQUENCY,
|
si5351_set_frequency_fixedpll(2, SI5351_PLL_B, freq * 6, CLK2_FREQUENCY,
|
||||||
SI5351_CLK_DRIVE_STRENGTH_2MA);
|
SI5351_CLK_DRIVE_STRENGTH_2MA);
|
||||||
delay = 2;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
|
|
@ -333,7 +330,6 @@ si5351_set_frequency_with_offset(int freq, int offset, uint8_t drive_strength)
|
||||||
SI5351_CLK_DRIVE_STRENGTH_2MA);
|
SI5351_CLK_DRIVE_STRENGTH_2MA);
|
||||||
si5351_set_frequency_fixeddiv(0, SI5351_PLL_A, freq + offset, 4,
|
si5351_set_frequency_fixeddiv(0, SI5351_PLL_A, freq + offset, 4,
|
||||||
SI5351_CLK_DRIVE_STRENGTH_2MA);
|
SI5351_CLK_DRIVE_STRENGTH_2MA);
|
||||||
delay = 2;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue