From b2e3fe770d29e37a056f297363dd5347e0f8ac2e Mon Sep 17 00:00:00 2001 From: TT Date: Fri, 30 Sep 2016 09:42:49 +0900 Subject: [PATCH] set sweep on draw, adjust grid --- dsp.c | 2 +- ili9431.c | 69 +++++++++++++++++++++++++++++++++++++------------------ main.c | 3 ++- nanovna.h | 5 ++-- si5351.c | 6 +---- 5 files changed, 54 insertions(+), 31 deletions(-) diff --git a/dsp.c b/dsp.c index b10c9c0..b590210 100644 --- a/dsp.c +++ b/dsp.c @@ -102,7 +102,7 @@ void calclate_gamma(float *gamma) { int16_t *r = refiq_buf; int16_t *s = samp_buf; - int len = SAMPLE_LEN/5; + int len = SAMPLE_LEN; float acc_r = 0; float acc_i = 0; float acc_ref = 0; diff --git a/ili9431.c b/ili9431.c index 83f8917..b43b7c4 100644 --- a/ili9431.c +++ b/ili9431.c @@ -346,25 +346,48 @@ ili9341_test(int mode) -int prev_freq; int prev_x; int32_t fstart = 0; -int32_t fend = 300000000; +int32_t fstop = 300000000; +int32_t fspan = 300000000; +int32_t fgrid = 50000000; #define OFFSETX 15 #define OFFSETY 0 #define WIDTH 291 #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 -circle_grid(int x, int y, int r) +circle_inout(int x, int y, int r) { int d = x*x + y*y - r*r; if (d <= -r) return 1; - if (d >= r) + if (d > r) return -1; return 0; } @@ -372,7 +395,7 @@ circle_grid(int x, int y, int r) int 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; if (d < 0) return 0; @@ -380,26 +403,26 @@ smith_grid(int x, int y) return c; x -= 146+116; y -= 116; - - if (circle_grid(x, y+58, 58) == 0) + + if (circle_inout(x, y+58, 58) == 0) return c; - if (circle_grid(x, y-58, 58) == 0) + if (circle_inout(x, y-58, 58) == 0) 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 c; - if (circle_grid(x, y+116, 116) == 0) + if (circle_inout(x, y+116, 116) == 0) return c; - if (circle_grid(x, y-116, 116) == 0) + if (circle_inout(x, y-116, 116) == 0) 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 c; - if (circle_grid(x, y+232, 232) == 0) + if (circle_inout(x, y+232, 232) == 0) return c; - if (circle_grid(x, y-232, 232) == 0) + if (circle_inout(x, y-232, 232) == 0) return c; - if (circle_grid(x+87, y, 87) == 0) + if (circle_inout(x+87, y, 87) == 0) return c; return 0; } @@ -407,8 +430,12 @@ smith_grid(int x, int y) int rectangular_grid(int x, int y) { +#define FREQ(x) (((x) * (fspan / 1000) / (WIDTH-1)) * 1000 + fstart) 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; if ((y % 29) == 0) return c; @@ -440,11 +467,11 @@ draw_on_strut(int v0, int d, int color) if (v0 >= HEIGHT) v0 = HEIGHT-1; if (v1 >= HEIGHT) v1 = HEIGHT-1; if (v0 == v1) { - v = v0; d = 1; + v = v0; d = 2; } else if (v0 < v1) { - v = v0; d = v1 - v0; + v = v0; d = v1 - v0 + 1; } else { - v = v1; d = v0 - v1; + v = v1; d = v0 - v1 + 1; } while (d-- > 0) spi_buffer[v++] = color; @@ -465,17 +492,15 @@ float logmag(float *v) return 11 - log10f(v[0]*v[0] + v[1]*v[1]); } - 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]); //value *= 29; trace[0].value = logmag(&measured[0]) * 29; trace[1].value = logmag(&measured[2]) * 29; if (first) { - prev_freq = freq; prev_x = 0; while (prev_x < curr_x) { int len = set_strut_grid(prev_x); diff --git a/main.c b/main.c index 81932b1..635d929 100644 --- a/main.c +++ b/main.c @@ -348,6 +348,7 @@ void scan_lcd(void) freq = freq_start; step = (freq_stop - freq_start) / (sweep_points-1); + set_sweep(freq_start, freq_stop); delay = set_frequency(freq); delay += 2; for (i = 0; i < sweep_points; i++) { @@ -363,7 +364,7 @@ void scan_lcd(void) __enable_irq(); tlv320aic3204_select_in1(); - wait_count = 2; + wait_count = 3; while (wait_count) ; __disable_irq(); diff --git a/nanovna.h b/nanovna.h index f722fa6..9ab6d93 100644 --- a/nanovna.h +++ b/nanovna.h @@ -22,13 +22,13 @@ extern void ui_init(void); extern void ui_process(void); // 5ms @ 48kHz -#define AUDIO_BUFFER_LEN 480 +#define AUDIO_BUFFER_LEN 96 extern int16_t rx_buffer[]; extern int16_t tx_buffer[]; #define STATE_LEN 32 -#define SAMPLE_LEN 240 +#define SAMPLE_LEN 48 extern int16_t ref_state[]; 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_test(int mode); +void set_sweep(int32_t start, int stop); void sweep_plot(int32_t freq, int first); void sweep_tail(void); diff --git a/si5351.c b/si5351.c index 503231d..1deb42a 100644 --- a/si5351.c +++ b/si5351.c @@ -287,7 +287,7 @@ int si5351_set_frequency_with_offset(int freq, int offset, uint8_t drive_strength) { int band; - int delay = 1; + int delay = 3; if (freq <= 100000000) { band = 0; } 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) si5351_set_frequency_fixedpll(2, SI5351_PLL_A, PLLFREQ, CLK2_FREQUENCY, SI5351_CLK_DRIVE_STRENGTH_2MA); - //delay = 1; - delay = 2; break; 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_fixedpll(2, SI5351_PLL_B, freq * 6, CLK2_FREQUENCY, SI5351_CLK_DRIVE_STRENGTH_2MA); - delay = 2; break; 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_set_frequency_fixeddiv(0, SI5351_PLL_A, freq + offset, 4, SI5351_CLK_DRIVE_STRENGTH_2MA); - delay = 2; break; }