Skip to content

Commit c7d071e

Browse files
committed
added librtsdr options vcocmin/vcocmax/vcoalgo for testing
* see #91 * vcocmin/vcocmax: sets VCO current for R820T/2 * added tuner internal caching for VCO current, that register isn't written when unnecessary * added vcoalgo option: - vcoalgo=2 allows to select/use r82xx_set_pll() from https://github.com/rtlsdrblog/rtl-sdr.git - vcoalgo=1 is previous algorithm, just with higher vco_max=3.9GHz - vcoalgo=0 is previous algorithm - the default: kept this until steve-m#10 is measured * rtl_test: added options -f and -e to define where to start and end the tuner range test .. for quicker testing if the new options change/extend the tuner's frequency range Signed-off-by: hayati ayguen <[email protected]>
1 parent 907da08 commit c7d071e

File tree

4 files changed

+265
-31
lines changed

4 files changed

+265
-31
lines changed

include/tuner_r82xx.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ enum r82xx_xtal_cap_value {
6868

6969
struct r82xx_config {
7070
uint8_t i2c_addr;
71+
uint8_t vco_curr_min; /* VCO min/max current for R18/0x12 bits [7:5] in 0 .. 7. use 0xff for default */
72+
uint8_t vco_curr_max; /* value is inverted: programmed is 7-value, that 0 is lowest current */
73+
uint8_t vco_algo;
7174
uint32_t xtal;
7275
enum r82xx_chip rafael_chip;
7376
unsigned int max_i2c_msg_len;
@@ -89,6 +92,7 @@ struct r82xx_priv {
8992
* on which the band center shall be positioned */
9093
uint8_t fil_cal_code;
9194
uint8_t input;
95+
uint8_t last_vco_curr;
9296
int has_lock;
9397
int init_done;
9498
int sideband;

src/librtlsdr.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@
9999
#define LOG_API_SET_FREQ 0
100100

101101
#define INIT_R820T_TUNER_GAIN 0
102+
#define ENABLE_VCO_OPTIONS 1
103+
102104

103105
/* activate/use RTL's IF AGC control .. from https://github.com/old-dab/rtlsdr
104106
* purpose: make AGC more smooth .. and NOT freeze
@@ -379,6 +381,10 @@ int r820t_init(void *dev) {
379381
devt->r82xx_c.rafael_chip = CHIP_R820T;
380382
}
381383

384+
devt->r82xx_c.vco_curr_min = 0xff; /* VCO min/max current for R18/0x12 bits [7:5] in 0 .. 7. use 0xff for default */
385+
devt->r82xx_c.vco_curr_max = 0xff; /* value is inverted: programmed is 7-value, that 0 is lowest current */
386+
devt->r82xx_c.vco_algo = 0x00;
387+
382388
rtlsdr_get_xtal_freq(devt, NULL, &devt->r82xx_c.xtal);
383389

384390
devt->r82xx_c.max_i2c_msg_len = 8;
@@ -4184,6 +4190,11 @@ const char * rtlsdr_get_opt_help(int longInfo)
41844190
"\t\t 0: use I & Q; 1: use I; 2: use Q; 3: use I below threshold frequency;\n"
41854191
"\t\t 4: use Q below threshold frequency (=RTL-SDR v3)\n"
41864192
"\t\t other values set the threshold frequency\n"
4193+
#if ENABLE_VCO_OPTIONS
4194+
"\t\tvcocmin=<current> set R820T/2 VCO current min: 0..7: higher value is more current\n"
4195+
"\t\tvcocmax=<current> set R820T/2 VCO current max: 0..7\n"
4196+
"\t\tvcoalgo=<algo> set R820T/2 VCO algorithm. 0: default. 1: with vcomax=3.9G. 2: Youssef/Carl\n"
4197+
#endif
41874198
"\t\tTp=<gpio_pin> set GPIO pin for Bias T, default =0 for rtl-sdr.com compatible V3\n"
41884199
"\t\tT=<bias_tee> 1 activates power at antenna one some dongles, e.g. rtl-sdr.com's V3\n"
41894200
#ifdef WITH_UDP_SERVER
@@ -4196,7 +4207,12 @@ const char * rtlsdr_get_opt_help(int longInfo)
41964207
"\t[-O\tset RTL options string seperated with ':', e.g. -O 'bc=30000:agc=0' ]\n"
41974208
"\t\tverbose:f=<freqHz>:bw=<bw_in_kHz>:bc=<if_in_Hz>:sb=<sideband>\n"
41984209
"\t\tagc=<tuner_gain_mode>:gain=<tenth_dB>:ifm=<tuner_if_mode>:dagc=<rtl_agc>\n"
4210+
#if ENABLE_VCO_OPTIONS
4211+
"\t\tds=<direct_sampling>:dm=<ds_mode_thresh>:vcocmin=<c>:vcocmax=<c>:vcoalgo=<a>\n"
4212+
"\t\tT=<bias_tee>\n"
4213+
#else
41994214
"\t\tds=<direct_sampling>:dm=<ds_mode_thresh>:T=<bias_tee>\n"
4215+
#endif
42004216
#ifdef WITH_UDP_SERVER
42014217
"\t\tport=<udp_port default with 1>\n"
42024218
#endif
@@ -4314,6 +4330,47 @@ int rtlsdr_set_opt_string(rtlsdr_dev_t *dev, const char *opts, int verbose)
43144330
dev->direct_sampling_threshold = dm;
43154331
ret = rtlsdr_set_ds_mode(dev, dev->direct_sampling_mode, dev->direct_sampling_threshold);
43164332
}
4333+
#if ENABLE_VCO_OPTIONS
4334+
else if (!strncmp(optPart, "vcocmin=", 8)) {
4335+
int current = atoi(optPart +8);
4336+
if ( 0 <= current && current <= 7 )
4337+
{
4338+
dev->r82xx_c.vco_curr_min = 7 - current;
4339+
ret = 0;
4340+
if (verbose)
4341+
fprintf(stderr, "\nrtlsdr_set_opt_string(): parsed vcocmin config %d\n", current);
4342+
} else if (verbose) {
4343+
fprintf(stderr, "\nrtlsdr_set_opt_string(): error parsing vcocmin config: valid range 0 .. 7\n");
4344+
ret = 1;
4345+
}
4346+
}
4347+
else if (!strncmp(optPart, "vcocmax=", 8)) {
4348+
int current = atoi(optPart +8);
4349+
if ( 0 <= current && current <= 7 )
4350+
{
4351+
dev->r82xx_c.vco_curr_max = 7 - current;
4352+
ret = 0;
4353+
if (verbose)
4354+
fprintf(stderr, "\nrtlsdr_set_opt_string(): parsed vcocmax config %d\n", current);
4355+
} else if (verbose) {
4356+
fprintf(stderr, "\nrtlsdr_set_opt_string(): error parsing vcocmax config: valid range 0 .. 7\n");
4357+
ret = 1;
4358+
}
4359+
}
4360+
else if (!strncmp(optPart, "vcoalgo=", 8)) {
4361+
int algo = atoi(optPart +8);
4362+
if ( 0 <= algo && algo <= 2 )
4363+
{
4364+
dev->r82xx_c.vco_curr_max = algo;
4365+
ret = 0;
4366+
if (verbose)
4367+
fprintf(stderr, "\nrtlsdr_set_opt_string(): parsed vcoalgo config %d\n", algo);
4368+
} else if (verbose) {
4369+
fprintf(stderr, "\nrtlsdr_set_opt_string(): error parsing vcoalgo config: valid range 0 .. 2\n");
4370+
ret = 1;
4371+
}
4372+
}
4373+
#endif
43174374
else if (!strncmp(optPart, "tp=", 3) || !strncmp(optPart, "Tp=", 3) || !strncmp(optPart, "TP=", 3) ) {
43184375
int gpio_pin_no = atoi(optPart +3);
43194376
if (verbose)

src/rtl_test.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ void usage(void)
107107
"\t[-d device_index or serial (default: 0)]\n"
108108
"%s"
109109
"\t[-t enable tuner range benchmark]\n"
110+
"\t[-f first/begin frequency for tuner range benchmark, default: 0]\n"
111+
"\t[-e end frequency for tuner range benchmark, default: 3e9 = 3G ]\n"
110112
#ifndef _WIN32
111113
"\t[-p[seconds] enable PPM error measurement (default: 10 seconds)]\n"
112114
#endif
@@ -338,9 +340,9 @@ static int set_center_freq_wait(rtlsdr_dev_t *dev, uint32_t freq, const char * s
338340
}
339341

340342

341-
void tuner_benchmark(void)
343+
void tuner_benchmark(uint32_t beg_freq, uint32_t end_freq)
342344
{
343-
uint32_t current = max_step(0);
345+
uint32_t current = beg_freq; /* max_step(0); */
344346
uint32_t band_start = 0;
345347
uint32_t low_bound = 0, high_bound = 0;
346348
int rc;
@@ -357,16 +359,16 @@ void tuner_benchmark(void)
357359
*/
358360

359361
/* handle bands starting at 0Hz */
360-
rc = set_center_freq_wait(dev, 0, "FIND_START");
362+
rc = set_center_freq_wait(dev, current, "FIND_START");
361363
if (rc < 0)
362364
state = FIND_START;
363365
else {
364-
band_start = 0;
366+
band_start = current;
365367
report_band_start(band_start);
366368
state = FIND_END;
367369
}
368370

369-
while (current < 3e9 && !do_exit) {
371+
while (current < end_freq && !do_exit) {
370372
switch (state) {
371373
case FIND_START:
372374
/* scanning for the start of a new band */
@@ -508,10 +510,12 @@ int main(int argc, char **argv)
508510
int dev_index = 0;
509511
int dev_given = 0;
510512
uint32_t out_block_size = DEFAULT_BUF_LENGTH;
513+
uint32_t tuner_bench_beg_freq = 0;
514+
uint32_t tuner_bench_end_freq = 0;
511515
int count;
512516
int gains[100];
513517

514-
while ((opt = getopt(argc, argv, "d:s:b:O:tp::Sh")) != -1) {
518+
while ((opt = getopt(argc, argv, "d:s:b:O:tf:e:p::Sh")) != -1) {
515519
switch (opt) {
516520
case 'd':
517521
dev_index = verbose_device_search(optarg);
@@ -529,6 +533,12 @@ int main(int argc, char **argv)
529533
case 't':
530534
test_mode = TUNER_BENCHMARK;
531535
break;
536+
case 'f':
537+
tuner_bench_beg_freq = (uint32_t)atofs(optarg);
538+
break;
539+
case 'e':
540+
tuner_bench_end_freq = (uint32_t)atofs(optarg);
541+
break;
532542
case 'p':
533543
test_mode = PPM_BENCHMARK;
534544
if (optarg)
@@ -598,7 +608,7 @@ int main(int argc, char **argv)
598608
}
599609

600610
if (test_mode == TUNER_BENCHMARK) {
601-
tuner_benchmark();
611+
tuner_benchmark(tuner_bench_beg_freq, tuner_bench_end_freq);
602612
goto exit;
603613
}
604614

0 commit comments

Comments
 (0)