diff --git a/srslte/examples/usrp_capture.c b/srslte/examples/usrp_capture.c index 1492c4ef7..bc193ebcf 100644 --- a/srslte/examples/usrp_capture.c +++ b/srslte/examples/usrp_capture.c @@ -43,7 +43,7 @@ static bool keep_running = true; char *output_file_name; char *uhd_args=""; -float uhd_gain=40.0, uhd_freq=-1.0, uhd_rate=0.96; +float uhd_gain=40.0, uhd_freq=-1.0, uhd_rate=0.96e6; int nof_samples = -1; void int_handler(int dummy) { @@ -54,7 +54,7 @@ void usage(char *prog) { printf("Usage: %s [agrnv] -f rx_frequency_hz -o output_file\n", prog); printf("\t-a UHD args [Default %s]\n", uhd_args); printf("\t-g UHD Gain [Default %.2f dB]\n", uhd_gain); - printf("\t-r UHD Rate [Default %.6f MHz]\n", uhd_rate); + printf("\t-r UHD Rate [Default %.6f Hz]\n", uhd_rate); printf("\t-n nof_samples [Default %d]\n", nof_samples); printf("\t-v srslte_verbose\n"); } @@ -129,9 +129,23 @@ int main(int argc, char **argv) { sigaddset(&sigset, SIGINT); sigprocmask(SIG_UNBLOCK, &sigset, NULL); - printf("Set RX freq: %.6f MHz\n", cuhd_set_rx_freq(uhd, uhd_freq) / 1000000); - printf("Set RX gain: %.1f dB\n", cuhd_set_rx_gain(uhd, uhd_gain)); - printf("Set RX rate: %.6f MHz\n", cuhd_set_rx_srate(uhd, uhd_rate*1e6) / 1000000); + printf("Set RX freq: %.2f MHz\n", cuhd_set_rx_freq(uhd, uhd_freq) / 1000000); + printf("Set RX gain: %.2f dB\n", cuhd_set_rx_gain(uhd, uhd_gain)); + float srate = cuhd_set_rx_srate(uhd, uhd_rate); + if (srate != uhd_rate) { + if (srate < 10e6) { + cuhd_set_master_clock_rate(uhd, 4*uhd_rate); + } else { + cuhd_set_master_clock_rate(uhd, uhd_rate); + } + srate = cuhd_set_rx_srate(uhd, uhd_rate); + if (srate != uhd_rate) { + fprintf(stderr, "Errror setting samplign frequency %.2f MHz\n", uhd_rate*1e-6); + exit(-1); + } + } + + printf("Correctly RX rate: %.2f MHz\n", srate*1e-6); cuhd_rx_wait_lo_locked(uhd); cuhd_start_rx_stream(uhd); diff --git a/srslte/examples/usrp_capture_sync.c b/srslte/examples/usrp_capture_sync.c index 0738f01f4..2204f3b4b 100644 --- a/srslte/examples/usrp_capture_sync.c +++ b/srslte/examples/usrp_capture_sync.c @@ -132,7 +132,23 @@ int main(int argc, char **argv) { printf("Set RX freq: %.6f MHz\n", cuhd_set_rx_freq(uhd, uhd_freq) / 1000000); printf("Set RX gain: %.1f dB\n", cuhd_set_rx_gain(uhd, uhd_gain)); - printf("Set RX rate: %.6f MHz\n", cuhd_set_rx_srate(uhd, srslte_sampling_freq_hz(nof_prb)) / 1000000); + int srate = srslte_sampling_freq_hz(nof_prb); + if (srate != -1) { + if (srate < 10e6) { + cuhd_set_master_clock_rate(uhd, 4*srate); + } else { + cuhd_set_master_clock_rate(uhd, srate); + } + printf("Setting sampling rate %.2f MHz\n", (float) srate/1000000); + float srate_uhd = cuhd_set_rx_srate(uhd, (double) srate); + if (srate_uhd != srate) { + fprintf(stderr, "Could not set sampling rate\n"); + exit(-1); + } + } else { + fprintf(stderr, "Invalid number of PRB %d\n", nof_prb); + exit(-1); + } cuhd_rx_wait_lo_locked(uhd); cuhd_start_rx_stream(uhd);