diff --git a/grc/PicoSDR.grc b/grc/PicoSDR.grc index 01f9a7c..d7ea34f 100644 --- a/grc/PicoSDR.grc +++ b/grc/PicoSDR.grc @@ -56,7 +56,7 @@ blocks: id: variable parameters: comment: '' - value: 1_280_000 // 64 + value: 1_280_000 // (1 << 6) states: bus_sink: false bus_source: false @@ -77,23 +77,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [512, 568.0] - rotation: 0 - state: true -- name: blocks_complex_to_mag_squared_0 - id: blocks_complex_to_mag_squared - parameters: - affinity: '' - alias: '' - comment: '' - maxoutbuf: '0' - minoutbuf: '0' - vlen: '1' - states: - bus_sink: false - bus_source: false - bus_structure: null - coordinate: [704, 440.0] + coordinate: [712, 496.0] rotation: 0 state: true - name: blocks_interleaved_char_to_complex_0 @@ -127,24 +111,6 @@ blocks: coordinate: [1000, 32.0] rotation: 0 state: true -- name: blocks_nlog10_ff_0 - id: blocks_nlog10_ff - parameters: - affinity: '' - alias: '' - comment: '' - k: '0' - maxoutbuf: '0' - minoutbuf: '0' - n: '10' - vlen: '1' - states: - bus_sink: false - bus_source: false - bus_structure: null - coordinate: [888, 432.0] - rotation: 0 - state: true - name: blocks_probe_rate_0 id: blocks_probe_rate parameters: @@ -195,54 +161,6 @@ blocks: coordinate: [440, 8.0] rotation: 0 state: true -- name: low_pass_filter_1 - id: low_pass_filter - parameters: - affinity: '' - alias: '' - beta: '6.76' - comment: '' - cutoff_freq: '1900' - decim: '1' - gain: '1' - interp: '1' - maxoutbuf: '0' - minoutbuf: '0' - samp_rate: samp_rate - type: fir_filter_fff - width: '100' - win: window.WIN_HAMMING - states: - bus_sink: false - bus_source: false - bus_structure: null - coordinate: [704, 516.0] - rotation: 0 - state: true -- name: low_pass_filter_1_0 - id: low_pass_filter - parameters: - affinity: '' - alias: '' - beta: '6.76' - comment: '' - cutoff_freq: '15' - decim: '1' - gain: '1' - interp: '1' - maxoutbuf: '0' - minoutbuf: '0' - samp_rate: samp_rate - type: fir_filter_fff - width: '15' - win: window.WIN_BLACKMAN - states: - bus_sink: false - bus_source: false - bus_structure: null - coordinate: [1000, 380.0] - rotation: 0 - state: true - name: network_tcp_source_0 id: network_tcp_source parameters: @@ -546,10 +464,10 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1000, 544.0] + coordinate: [1000, 472.0] rotation: 0 state: true -- name: qtgui_time_sink_x_0_0_0 +- name: qtgui_time_sink_x_0_1 id: qtgui_time_sink_x parameters: affinity: '' @@ -581,9 +499,9 @@ blocks: entags: 'False' grid: 'True' gui_hint: (2, 0, 1, 1) - label1: RSSI + label1: I label10: Signal 10 - label2: Signal 2 + label2: Q label3: Signal 3 label4: Signal 4 label5: Signal 5 @@ -602,10 +520,10 @@ blocks: marker7: '-1' marker8: '-1' marker9: '-1' - name: '"RSSI"' + name: '"IQ / Loop"' nconnections: '1' - size: '1000' - srate: '1000' + size: int(samp_rate // 30) + srate: samp_rate stemplot: 'False' style1: '1' style10: '1' @@ -623,7 +541,7 @@ blocks: tr_mode: qtgui.TRIG_MODE_FREE tr_slope: qtgui.TRIG_SLOPE_POS tr_tag: '""' - type: float + type: complex update_time: 1/30 width1: '1' width10: '1' @@ -635,15 +553,15 @@ blocks: width7: '1' width8: '1' width9: '1' - ylabel: dBm - ymax: '0' - ymin: '-60' + ylabel: Amplitude + ymax: '1' + ymin: '-1' yunit: '""' states: bus_sink: false bus_source: false bus_structure: null - coordinate: [1184, 408.0] + coordinate: [1000, 360.0] rotation: 0 state: true - name: qtgui_waterfall_sink_x_0_0 @@ -709,19 +627,15 @@ blocks: state: true connections: -- [analog_quadrature_demod_cf_0, '0', low_pass_filter_1, '0'] -- [blocks_complex_to_mag_squared_0, '0', blocks_nlog10_ff_0, '0'] +- [analog_quadrature_demod_cf_0, '0', qtgui_time_sink_x_0_0, '0'] - [blocks_interleaved_char_to_complex_0, '0', analog_quadrature_demod_cf_0, '0'] -- [blocks_interleaved_char_to_complex_0, '0', blocks_complex_to_mag_squared_0, '0'] - [blocks_interleaved_char_to_complex_0, '0', blocks_probe_rate_0, '0'] - [blocks_interleaved_char_to_complex_0, '0', digital_costas_loop_cc_0, '0'] - [blocks_interleaved_char_to_complex_0, '0', qtgui_time_sink_x_0, '0'] - [blocks_interleaved_char_to_complex_0, '0', qtgui_waterfall_sink_x_0_0, '0'] -- [blocks_nlog10_ff_0, '0', low_pass_filter_1_0, '0'] - [blocks_probe_rate_0, rate, blocks_message_debug_0, print] - [digital_costas_loop_cc_0, '0', qtgui_const_sink_x_0, '0'] -- [low_pass_filter_1, '0', qtgui_time_sink_x_0_0, '0'] -- [low_pass_filter_1_0, '0', qtgui_time_sink_x_0_0_0, '0'] +- [digital_costas_loop_cc_0, '0', qtgui_time_sink_x_0_1, '0'] - [network_tcp_source_0, '0', blocks_interleaved_char_to_complex_0, '0'] metadata: diff --git a/src/main.c b/src/main.c index cbfb863..30e4b9a 100644 --- a/src/main.c +++ b/src/main.c @@ -39,10 +39,14 @@ #define CLK_SYS_HZ (250 * MHZ) #define BANDWIDTH 1280000 -#define DECIMATION 64 - +#define DECIMATION_BITS 6 #define IQ_BLOCK_LEN 64 +#define RX_SLEEP_US (DECIMATION * BANDWIDTH / (1 * MHZ) / 4) +#define DECIMATION (1 << DECIMATION_BITS) + +static_assert(RX_SLEEP_US > 0, "RX_SLEEP_US must be positive"); + #define XOR_ADDR 0x1000 #define LO_COS_ACCUMULATOR (&pio1->sm[2].pinctrl) #define LO_SIN_ACCUMULATOR (&pio1->sm[3].pinctrl) @@ -52,7 +56,7 @@ static uint32_t lo_cos[LO_WORDS] __attribute__((__aligned__(LO_WORDS * 4))); static uint32_t lo_sin[LO_WORDS] __attribute__((__aligned__(LO_WORDS * 4))); -#define RX_BITS_DEPTH 8 +#define RX_BITS_DEPTH (DECIMATION_BITS + 2) #define RX_WORDS (1 << RX_BITS_DEPTH) static uint32_t rx_cos[RX_WORDS] __attribute__((__aligned__(RX_WORDS * 4))); static uint32_t rx_sin[RX_WORDS] __attribute__((__aligned__(RX_WORDS * 4))); @@ -60,8 +64,6 @@ static uint32_t rx_sin[RX_WORDS] __attribute__((__aligned__(RX_WORDS * 4))); #define SIN_PHASE (UINT_MAX / 4) #define COS_PHASE (0) -static_assert(RX_WORDS > 2 * DECIMATION, "RX buffers too short for given decimation"); - /* rx -> cp -> cos -> sin -> pio_cos -> pio_sin -> rx ... */ static int dma_ch_rx = -1; static int dma_ch_cp = -1; @@ -590,7 +592,7 @@ static void rf_rx(void) while (delta < 2 * DECIMATION) { delta = prev_transfers - dma_hw->ch[dma_ch_in_cos].transfer_count; - sleep_us(10); + sleep_us(RX_SLEEP_US); } prev_transfers -= 2 * DECIMATION; @@ -788,7 +790,8 @@ static void do_rx(int rx_pin, int bias_pin, float freq, char mode) for (int i = 0; i < IQ_BLOCK_LEN / 2; i += 8) { int I = block[i * 2]; int Q = block[i * 2 + 1]; - printf("%+4i | %+5.1f dBm | %+4i %+4i | ", gap, rssi, I, Q); + printf("%+4i | %+5.1f dBm | %+4i %+4i | ", + RX_WORDS / 2 + gap, rssi, I, Q); plot_IQ(I, Q); putchar('\n'); }