Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better gain support for RTLSDR #565

Closed
ratay opened this issue Nov 7, 2018 · 0 comments · Fixed by #566
Closed

Better gain support for RTLSDR #565

ratay opened this issue Nov 7, 2018 · 0 comments · Fixed by #566
Assignees
Labels

Comments

@ratay
Copy link

ratay commented Nov 7, 2018

Is your feature request related to a problem?

I'm still not satisfied with gain settings on RTLSDR device
so I made little research of it
after looking sources of rtlsdr.dll I found:

  • there are 6 basic types of RTLSDR (E4000,FC0012,FC0013,FC2580,R820T,R828D)
  • some of them allows random value of gain, some of them only predefined
  • for example my tuner (fc0012) allows only several predefined values:
int fc0012_set_gain(void *dev, int gain)
{
	int ret;
	uint8_t tmp = 0;

	ret = fc0012_readreg(dev, 0x13, &tmp);
	tmp &= 0xe0;

	switch (gain) {
	case -99:		/* -9.9 dB */
		tmp |= 0x02;
		break;
	case -40:		/* -4 dB */
		break;
	case 71:
		tmp |= 0x08;	/* 7.1 dB */
		break;
	case 179:
		tmp |= 0x17;	/* 17.9 dB */
		break;
	case 192:
	default:
		tmp |= 0x10;	/* 19.2 dB */
		break;
	}

	ret = fc0012_writereg(dev, 0x13, tmp);
	return ret;
} 
  • as you can see if another value is used driver choose value 19.2dB

  • similar situation in driver E4000 - only error appears when non listed value is used:

  static const int32_t lnagain[] = {
	-50,	0,
	-25,	1,
	0,	4,
	25,	5,
	50,	6,
	75,	7,
	100,	8,
	125,	9,
	150,	10,
	175,	11,
	200,	12,
	250,	13,
	300,	14,
};

int e4k_set_lna_gain(struct e4k_state *e4k, int32_t gain)
{
	uint32_t i;
	for(i = 0; i < ARRAY_SIZE(lnagain)/2; ++i) {
		if(lnagain[i*2] == gain) {
			e4k_reg_set_mask(e4k, E4K_REG_GAIN1, 0xf, lnagain[i*2+1]);
			return gain;
		}
	}
	return -EINVAL;
}

Describe the solution you'd like

so for correct operation rtlsdr_get_tuner_gains must be used for getting allowed values:

int rtlsdr_get_tuner_gains(rtlsdr_dev_t *dev, int *gains)
{
	/* all gain values are expressed in tenths of a dB */
	const int e4k_gains[] = { -10, 15, 40, 65, 90, 115, 140, 165, 190, 215,
				  240, 290, 340, 420 };
	const int fc0012_gains[] = { -99, -40, 71, 179, 192 };
	const int fc0013_gains[] = { -99, -73, -65, -63, -60, -58, -54, 58, 61,
				       63, 65, 67, 68, 70, 71, 179, 181, 182,
				       184, 186, 188, 191, 197 };
	const int fc2580_gains[] = { 0 /* no gain values */ };
	const int r82xx_gains[] = { 0, 9, 14, 27, 37, 77, 87, 125, 144, 157,
				     166, 197, 207, 229, 254, 280, 297, 328,
				     338, 364, 372, 386, 402, 421, 434, 439,
				     445, 480, 496 }; 
   ....
Describe alternatives you've considered
Additional context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants