# Usrp - gnuradio agc

**URL:** <https://www.ruby-forum.com/t/usrp-gnuradio-agc/231179>\
**Category:** GNU Radio\
**Created:** [July 25, 2014, 1:44pm UTC](https://www.ruby-forum.com/t/usrp-gnuradio-agc/231179 "2014-07-25T13:44:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [July 25, 2014, 1:44pm UTC](https://www.ruby-forum.com/t/usrp-gnuradio-agc/231179/1 "2014-07-25T13:44:52Z")

</div>

Hi at all,

I need to implement an AGC to adapt the signal to the ADC’s full  
dynamics.  
I work with an USRP N210 with CBX-40USRP DAUGHTERBOARD…

I investigated that :

There is a programmable gain amplifier (PGA) before the ADCs to amplify  
the  
input signal to utilize the entire input range of the ADCs, in case the  
signal is weak.  
This PGA is software programmable.

Auxiliary Digital I/O Ports:  
The USRP motherboard has high speed 64 bit digital I/O ports.  
These digital I/O pins are connected to the  
daughterboards interface connecters (RxA, TxA, RxB and TxB).  
These signals can be controlled from software by reading/writing to  
special  
FPGA registers and each can be independently configured either as  
digital  
input or digital output.  
Some of these pins are used to control specific operations on the  
installed  
daughterboards such as  
controlling the selection of receiving RF input port, in automatic  
transmit/receive mode,  
controlling power supply feeding for different TX and RX parts,  
synthesizer  
lock detection,…etc.  
It can be also used to implement AGC processing and can be very helpful  
in  
debugging FPGA  
implementations when connected to a logic analyzer.

So, using UHD USRP SINK, the PGA is modified just acting on the field  
Ch0:  
Gain(dB) ???  
Second, there is some block that allow to extract these Auxiliary  
Digital  
I/O Ports ???  
Practically I want extract analog data before the PGA to process it  
software…

---

<div class="post-metadata">

**Author:** ![Simone\_Ciccia\_S2106](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e495f1/32.png) [@Simone\_Ciccia\_S2106](https://www.ruby-forum.com/u/Simone_Ciccia_S2106)\
**Post date:** [July 25, 2014, 3:27pm UTC](https://www.ruby-forum.com/t/usrp-gnuradio-agc/231179/2 "2014-07-25T15:27:40Z")

</div>

Hi Simone,

to make this short: Yes, you just set the gain using that field, or at  
runtime, using the set\_gain() method of the USRP source.

Everything you can do with a USRP is usually wrapped in the USRP  
source/sink blocks, which are basically “just” wrappers that take the  
UHD library (which is the driver for the USRPs) and adapt them to GNU  
Radio.  
As such, there is no “direct” way to modify the digital outputs. This is  
by design – these are largely routed to the daughterboard, in your case  
the CBX, to communicate settings and commands (e.g. setting the gain,  
changing frequency and so on), so as a user you usually “shouldn’t” mess  
with them.  
You can, nevertheless, just modify the UHD driver, add a daughterboard  
sensor interface or the like (by changing the daughterboard interface  
source code) that would, upon querying that sensor, issue some change to  
the IO ports. I don’t recommend this – a) you’ll be on your very own  
and b) what would you do with that? most of the lines are routed to and  
terminated on the CBX [1], so you’d have to modify the hardware. If I  
remember correctly, there is one daughterboard that has an always-on  
AGC, the TVRX2, which is a bit of a special-purpose daughterboard, as  
non-adjustable AGCs only fit signals that fit the AGC – ie. which  
symbol rate is far enough from the AGC loop bandwidth but which  
experience fading at a rate that allows the AGC to do its job.

Getting the signal “before” PGA means you don’t want to use the mixer  
and filters; that basically means you will have to implement spectrum  
sensing in an adjustable pass band yourself, at which point you’re  
building something that is effectively nearly as complex as the CBX  
itself, unless you go for something very simple.

To be honest, unless you have very special needs, using a fast energy  
estimator that sets the daughterboard’s gain in software on a PC would  
clearly be my first step, and modifying/adding hardware would only take  
place if that system couldn’t fulfill the receiver’s needs.  
We had a discussion on removed\_email\_address@domain.invalid, not too long ago,  
about implementing something like that in the FPGA, which would reduce  
latency; I can’t quite remember the name of that thread, though…

Greetings,  
Marcus

[1] [http://files.ettus.com/schematics/cbx/CBX.pdf](http://files.ettus.com/schematics/cbx/CBX.pdf)

---

<div class="post-metadata">

**Author:** ![Simone\_Ciccia\_S2106](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e495f1/32.png) [@Simone\_Ciccia\_S2106](https://www.ruby-forum.com/u/Simone_Ciccia_S2106)\
**Post date:** [July 26, 2014, 9:15am UTC](https://www.ruby-forum.com/t/usrp-gnuradio-agc/231179/3 "2014-07-26T09:15:03Z")

</div>

Hi Simone,

On 25.07.2014 15:55, Simone Ciccia S210664 wrote:

> Hi Marcus,  
> thank you for your answer…
> 
> Ok, suppose that we are in reception,  
> I said before the PGA thinking that at this stage the signal is already in  
> baseband ( MIXER → FILTER → PGA → ADC ), so in this way I will have  
> compared signal level before PGA with the full scale of ADC.  
> Actually, compare the schematics I linked to: the variable attenuation  
> comes before the mixer, so  
> Antenna-\>LNA-\>PGA-\>mixing-\>ADC is the order.  
> But your are right, comparing energy is more simple!  
> Just another question…  
> Using the USRP as receiver, we set the gain as “variable” in UHD source  
> block “options”.  
> Now, the changes of this variable take effect on the USRP during runtime???  
> or just set the initial value and we need to use set\_gain() ???  
> I suppose we’re talking about GRC flow graphs now 🙂  
> Yes, there is a callback that will automatically set the gain when you  
> change the variable at runtime.  
> You _can_ use set\_gain() directly, too.

Greetings,  
Marcus
