Author Topic: AGC always selects maximum gain  (Read 5655 times)

joelucid

  • Hero Member
  • *****
  • Posts: 867
AGC always selects maximum gain
« on: April 02, 2016, 02:13:54 AM »
I've done some tests this morning with AGC (automatic gain control). As reminder: the RFM69 library configures the RFM69HW for AGC with AUTORXRESTART. That means that at the beginning of each packet reception the receiver tunes the gain of the LNA to obtain the optimal sensitivity/ linearity trade-off.

So i wondered what gain the radio would select. I added some code to the irq handler to record the result and found that: AGC ALWAYS selects maximum gain. Even when I put a Moteino with RFM69HW and maximum tx power right next to the receiver.

I then switched on sensitivity boost which presumable cranks up the amplifier even higher. Still: always maximum gain.

If this is a result of the standard radio settings (FDev etc) this could be pretty significant: Switching off AGC halves the time required for RSSI detection and makes listen mode much more power efficient.

Anybody looked at this before or has feedback?

Joe

TomWS

  • Hero Member
  • *****
  • Posts: 1926
Re: AGC always selects maximum gain
« Reply #1 on: April 02, 2016, 09:11:02 AM »
I've done some tests this morning with AGC (automatic gain control). As reminder: the RFM69 library configures the RFM69HW for AGC with AUTORXRESTART. That means that at the beginning of each packet reception the receiver tunes the gain of the LNA to obtain the optimal sensitivity/ linearity trade-off.

So i wondered what gain the radio would select. I added some code to the irq handler to record the result and found that: AGC ALWAYS selects maximum gain. Even when I put a Moteino with RFM69HW and maximum tx power right next to the receiver.

I then switched on sensitivity boost which presumable cranks up the amplifier even higher. Still: always maximum gain.

If this is a result of the standard radio settings (FDev etc) this could be pretty significant: Switching off AGC halves the time required for RSSI detection and makes listen mode much more power efficient.

Anybody looked at this before or has feedback?

Joe
Do you mean the gain is set to maximum initially and then adjusts or that it remains at max?  And, how do you know?  The register only reads the setting to enable auto, I didn't think you could read the actual internal setting.

The reason I ask is, when I first started playing with Moteino and was working on the ATC code, I purposefully disabled AGC so that the ATC could be tested at reasonably close range.  There was a clear difference between AGC off with fixed gain and AGC on with varying TX levels (ie, the receiver with AGC on maintained a relatively constant signal level despite the varying input).

Tom

joelucid

  • Hero Member
  • *****
  • Posts: 867
Re: AGC always selects maximum gain
« Reply #2 on: April 02, 2016, 09:48:42 AM »
Quote
Do you mean the gain is set to maximum initially and then adjusts or that it remains at max?  And, how do you know?  The register only reads the setting to enable auto, I didn't think you could read the actual internal setting.

I read out register 0x18 which contains the current gain as programmed or selected by AGC in bits 3-5. That always reads 8 - or maximum gain. Strange. Actually I got a 0x10 once, showing that it is possible to get other settings. But a rfm69hw at full power doesn't seem to be enough to trigger it regularly.

Joe

WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: AGC always selects maximum gain
« Reply #3 on: April 02, 2016, 04:16:00 PM »
@joelucid: Are you able to receive your measurement of the gain setting in less time than Tdelay after a packet is received?  It appears as though after a packet is received, and after Tdelay amount of time, the AGC resets the gain to G1 (which matches your report of 0x18 being 8 ) and presumably leaves it at G1 until measuring RSSI on the next packet.  At least that part of the AGC's behavior makes sense.  If you haven't already, you might want to test using a low bitrate just as an experiment to give yourself more time to query the gain setting (obviously use a nearby transmitter set to a high Tx for the experiment) and see if the gain is still stuck at G1 immediately after the packet is received. 

[Edit: Maybe it's even possible (?) to measure the gain sometime after RSSI goes high but before the packet is completely received if using the faster bitrates.  Not sure if it's ever discussed in the datasheet, but exactly what RFM69 operations can be done is parallel with the RFM69's other operations is unclear to me.  I do get the impression that at least some amount of parallelism is possible though.]
« Last Edit: April 02, 2016, 05:38:17 PM by WhiteHare »

joelucid

  • Hero Member
  • *****
  • Posts: 867
Re: AGC always selects maximum gain
« Reply #4 on: April 02, 2016, 05:54:25 PM »
From the spec:

"Packet mode: if AutoRxRestartOn = 0, the LNA gain will remain the same for the reception of the following packet. If AutoRxRestartOn = 1, after the controller has emptied the FIFO the receiver will re-enter the WAIT mode described above, after a delay of InterPacketRxDelay, allowing for the distant transmitter to ramp down, hence avoiding a false RSSI detection."

I measure in the Irq handler before emptying the Fifo. So the radio hasn't even started the countdown to a new wait period yet.

WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: AGC always selects maximum gain
« Reply #5 on: April 02, 2016, 06:10:25 PM »
You're right. 

Could it be that the RFM69 resets the gain to G1 the instant it finishes receiving a packet?  That might make more sense anyway, in case maybe it needs some settle time.  Anyhow, if it's inevitable, why should it wait?

[Edit: This would be for the case where AutoRxRestartOn = 1.  For AutoRxRestartOn = 0, then the gain wouldn't change at all unless Rx was restarted or goes into WAIT mode].

[Edit2: I'm just thinking it probably wants to start a new cycle with max gain, so that if there is a faint pre-amble, it will still hear it, and if the RSSI isn't faint, it can turn down the gain at that point.  Well, that's the hypothesis anyway.]
« Last Edit: April 02, 2016, 07:04:59 PM by WhiteHare »

joelucid

  • Hero Member
  • *****
  • Posts: 867
Re: AGC always selects maximum gain
« Reply #6 on: April 04, 2016, 05:49:28 AM »
I think I figured this one out. Ironically in a different context: getting AFC to work.

Here is how AFC and AGC are supposed to work:

1.) The radio is set to RX.
2.) The receiver waits until RSSI exceeds RSSIThresh, indicating an arriving packet.
3.) The receiver sets the gain for the amplifier during reception of preamble
4.) The receiver performs AFC during reception of preamble
5.) Actual package reception.

Here's what actually happens with the RFM69 lib:

1.) Radio is set to RX, RSSIThresh of -110
2.) Radio immediately detects RSSI higher than RSSIThresh and thinks it sees a packet
3.) Radio tunes the LNA assuming the background noise is a signal - ergo it ramps the receiver all the way up
4.) If you try to do AFC the receiver will detune itself by trying to narrow in on the noise
5.) Actual reception with suboptimal settings.

What should be done:

RSSIThresh needs to be set higher than the noise floor. Additionally periodically there should be a restart of AGC and AFC in case a noise activation has occurred.

Joe

WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: AGC always selects maximum gain
« Reply #7 on: April 04, 2016, 07:49:01 AM »
Thanks!  That's a clearer explanation than anything else that I've read to date.

It appears that the RFM69 puts the burden of setting  a proper RSSI threshhold entirely on the users shoulders.  In contrast, for instance, my WiFi device doesn't ask me to do that.  It appears that my WiFi device is constantly measuring RSSI and arrives at its own conclusion as to what the noise floor is.  So, for the RFM69, how to pick the best RSSI threshhold setting would be an interesting thread topic. 
« Last Edit: April 04, 2016, 07:52:38 AM by WhiteHare »

joelucid

  • Hero Member
  • *****
  • Posts: 867
Re: AGC always selects maximum gain
« Reply #8 on: April 04, 2016, 09:28:08 AM »
Quote
So, for the RFM69, how to pick the best RSSI threshhold setting would be an interesting thread topic.

Yeah - same problem as with listen mode where we've understood for some time that selecting the right RSSIThresh is critical. This isn't a static choice: changes a lot whether the Mote is hooked up to a Pi, to a FTDI adaptor, just battery etc. Changes when you touch the board etc.

Also same solution: start with a conservative thresh. Write code to handle noise triggered rx cycles and restarts rx after timeout. If you get no noise triggers lower the threshold. If you get many, raise it.

joelucid

  • Hero Member
  • *****
  • Posts: 867
Re: AGC always selects maximum gain
« Reply #9 on: April 04, 2016, 01:43:17 PM »
I've implemented a prototype for dynamic RSSIthresh management and I've got to say the results show crystal clear how important this topic is:

I'm running at 1200 baud, FDev 1260 hz, RxBW: 2600 hz, AFC on. I'm starting with an RSSIThresh of 220 (corresponding to -110 db).

One Moteino I plug via FTDI adapter into my MacBook's USB. The other only connects to a 9V battery. RSSIThresh for the Mac-bound Moteino converges to 189. On the solo Moteino to 240. That's 25 dBm which you lose if you don't dynamically adjust RSSIThresh.

Can't wait to try this out on a ESP8266 connected RFM69HW.

joelucid

  • Hero Member
  • *****
  • Posts: 867
Re: AGC always selects maximum gain
« Reply #10 on: April 05, 2016, 02:07:15 AM »
Quote
Can't wait to try this out on a ESP8266 connected RFM69HW.

ESP8266 + RFM69HW on the macbook: around the same 189. Same combination on batteries around 204. That's including wifi activity which seems to cause only little interference.

WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: AGC always selects maximum gain
« Reply #11 on: April 05, 2016, 07:51:49 AM »
Quote
Can't wait to try this out on a ESP8266 connected RFM69HW.

ESP8266 + RFM69HW on the macbook: around the same 189. Same combination on batteries around 204. That's including wifi activity which seems to cause only little interference.

Is that a typo?  i.e. Did you mean 240 (i.e. same as solo Moteino) instead of 204?


joelucid

  • Hero Member
  • *****
  • Posts: 867
Re: AGC always selects maximum gain
« Reply #12 on: April 05, 2016, 08:32:15 AM »
Quote
Is that a typo?  i.e. Did you mean 240 (i.e. same as solo Moteino) instead of 204?

No. An ESP8266 (NodeMCU 1.0 in this case) + RFM69HW is much worse than a Moteino in this respect.

joelucid

  • Hero Member
  • *****
  • Posts: 867
Re: AGC always selects maximum gain
« Reply #13 on: April 05, 2016, 08:38:45 AM »
Here's a Moteino hooked up to the old Pi2 (the first two columns) compared to a battery powered moteino 3 meters apart. Notice how badly the Pi performs with its regular RSSI impairments - even though its Threshold isn't too bad.

!SRSSI:-45, STHRESH:212, GRSSI:-44, GTHRESH:239
!SRSSI:-52, STHRESH:212, GRSSI:-44, GTHRESH:238
!SRSSI:-62, STHRESH:211, GRSSI:-44, GTHRESH:238
!SRSSI:-44, STHRESH:211, GRSSI:-44, GTHRESH:238
!SRSSI:-45, STHRESH:212, GRSSI:-44, GTHRESH:237
!SRSSI:-45, STHRESH:212, GRSSI:-45, GTHRESH:237
!SRSSI:-45, STHRESH:212, GRSSI:-45, GTHRESH:237
!SRSSI:-44, STHRESH:210, GRSSI:-44, GTHRESH:237
!SRSSI:-62, STHRESH:210, GRSSI:-45, GTHRESH:237
!SRSSI:-62, STHRESH:211, GRSSI:-44, GTHRESH:237
!SRSSI:-45, STHRESH:210, GRSSI:-44, GTHRESH:238
!SRSSI:-44, STHRESH:210, GRSSI:-44, GTHRESH:239
!SRSSI:-44, STHRESH:211, GRSSI:-44, GTHRESH:238
!SRSSI:-45, STHRESH:210, GRSSI:-44, GTHRESH:237
!SRSSI:-44, STHRESH:210, GRSSI:-45, GTHRESH:237
!SRSSI:-49, STHRESH:209, GRSSI:-44, GTHRESH:238
!SRSSI:-62, STHRESH:209, GRSSI:-44, GTHRESH:238
!SRSSI:-62, STHRESH:210, GRSSI:-44, GTHRESH:238

WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: AGC always selects maximum gain
« Reply #14 on: April 05, 2016, 09:50:55 AM »
At the risk of jumping to conclusions, it looks as though what's aggravating your Moteino-Pi combo must be something that's conducted rather than RF.  Right?  Before now, we never really knew.  I would take that as good news, because if you wanted to you could maybe mitigate against conducted EMI by severing the connection.  So,worst case, maybe optocouplers and some kind of isolated power supply.  Best case: some kind of filter(s) and/or ferrite bead, and/or decoupling capacitors (if you aren't already using them).
« Last Edit: April 05, 2016, 09:58:38 AM by WhiteHare »