SoapyHackRF - RF Amplifier gain setting

1,306 views
Skip to first unread message

Gavin Jacobs

unread,
Sep 3, 2017, 3:45:14 PM9/3/17
to Pothos Users
I am using the SoapyHackRF module in conjunction with the Osmocom Sink in GNUradio. One of the settings in the Osmocom block is "Ch0: RF Gain (dB)". I have this linked to a QT GUI button, so that when I press the button, the gain value changes to 14, and when I release the button it changes to 0. This corresponds to turning on and off of the RF Amp in HackRF. It works fine with the hackrf driver that comes with osmocom, but not with the hackrf driver that comes with soapySDR. So I dug into it a bit and found in the source file HackRF_Settings.cpp, there is are two overloads of setGain(); the first has 3 arguments and the second has 4 - the extra argument is the "name" of the gain to be set. I expected the second overload to be called with name argument set to "AMP", but I can see from some DEBUG statements the first overload is being used, which sets the other two gains, instead of the AMP gain. How can I get the AMP gain changed at runtime? What is the link from osmocom, through soapySDR, to SoapyHackRF?

Thanks,
Jake



Josh Blum

unread,
Sep 3, 2017, 6:53:20 PM9/3/17
to pothos...@googlegroups.com
In gr-osmosdr the set_gain name version and overall gain version both call directly into their corresponding calls:
https://github.com/osmocom/gr-osmosdr/blob/master/lib/soapy/soapy_source_c.cc#L230

The SoapyHackRF does indeed have control over individual AMP, LNA, and VGA options here:
https://github.com/pothosware/SoapyHackRF/blob/master/HackRF_Settings.cpp#L343

And it also has the following procedure to distribute the gain into those elements automatically when the overall gain value is used:
https://github.com/pothosware/SoapyHackRF/blob/master/HackRF_Settings.cpp#L280

The osmo hackrf also has set_gain, set_if_gain and set_bb_gain for these different elements:
https://github.com/osmocom/gr-osmosdr/blob/master/lib/hackrf/hackrf_source_c.cc#L667

So I think the osmo hackrf and SoapyHackRF implementations are just in disagreement about what is good automatic behaviour and which elements are bb/if gain specifically. Different osmosdr wrappers do different things with these calls, so I'm not sure exactly what the correct procedure should be.

* The osmo hackrf uses "VGA" for the bb gain, while SoapyHackRF uses "AMP"
* osmo hackrf uses "LNA" for the if gain, and SoapyHackRF also uses "LNA"
* osmo hackrf set_gain only sets "AMP" while SoapyHackRF has a distribution algorithm

Obviously there are a few differences. SoapyHackRF is supposed to list the gain elements "in order RF to baseband" I think that VGA and AMP got swapped, but I dont have the hackrf digram to confirm. I didn't write the module so I cant way what was intentional or what may have been an mistake. If you see something wrong, or can make an improvement, I recommend making a pull request to SoapyHackRF -- that way any others watching or maintaining can see the changes and comment.

But as it stands now, it looks like set_bb_gain() which can be called from the grc block will actually turn AMP on and off.

-josh


Thanks,
Jake


Gavin Jacobs

unread,
Sep 7, 2017, 4:42:08 PM9/7/17
to Pothos Users, jo...@joshknows.com
Josh,
Thanks for those clarifications. I have worked through the references and compared to the osmocom implementation of hackrf, and I agree with your assessment that VGA and AMP are in the wrong order. I did verify that changing bb_gain at run time would indeed turn the amp on and off, and that would be ok for the sink because bb_gain is not used; but for the source it is problematic because we need to change both bb_gain and rf_gain independently.  I am working on the correction.

I have never tried to do a "pull request" for any project, so I read the Hello-World tutorial on github. The suggested workflow is to create a branch, edit the files, then create a pull request for the project team, and then if it is approved the branch gets merged. Some other tutorials suggest making a fork/clone on my computer and then edit, etc. Which is the way to go? I only ask because I don't see any other branches and it appears that the only commits are on the master branch. Also, there has only been one other pull request in the project history, so I couldn't quite see how it's done.

Thanks for your patience.

Josh Blum

unread,
Sep 8, 2017, 10:42:43 AM9/8/17
to Gavin Jacobs, Pothos Users


On 09/07/2017 03:42 PM, Gavin Jacobs wrote:
> Josh,
> Thanks for those clarifications. I have worked through the references and
> compared to the osmocom implementation of hackrf, and I agree with your
> assessment that VGA and AMP are in the wrong order. I did verify that
> changing bb_gain at run time would indeed turn the amp on and off, and that
> would be ok for the sink because bb_gain is not used; but for the source it
> is problematic because we need to change both bb_gain and rf_gain
> independently. I am working on the correction.
>
> I have never tried to do a "pull request" for any project, so I read the
> Hello-World tutorial on github. The suggested workflow is to create a
> branch, edit the files, then create a pull request for the project team,
> and then if it is approved the branch gets merged. Some other tutorials
> suggest making a fork/clone on my computer and then edit, etc. Which is the
> way to go? I only ask because I don't see any other branches and it appears
> that the only commits are on the master branch. Also, there has only been
> one other pull request in the project history, so I couldn't quite see how
> it's done.
>
> Thanks for your patience.

Cool np. So in general for a pull request:

1) from the soapyhackrf git hub page click "fork" to get a copy of the
repo on your personal github page
2) clone this project from your personal github page on to your PC
3) make any modifications and branches as desired and push to the "origin"
4) a pull request wizard option basically shows up on your personal
github fork

More info https://help.github.com/articles/creating-a-pull-request/

-josh

PS Also, if you are interested in direct repo access, I can set that up
too. Either one works, just let me know your github username.
Reply all
Reply to author
Forward
0 new messages