Author Topic: Bug & Mystery in setPowerLevel on rfm69hw  (Read 20005 times)

joelucid

  • Hero Member
  • *****
  • Posts: 868
Bug & Mystery in setPowerLevel on rfm69hw
« on: April 01, 2015, 03:41:38 AM »
Guys,

I'm having transmit inconsistencies with my rfm69hw Moteinos. I noticed that the RSSI doesn't behave as it should when I change the powerLevel so I wrote a little sketch to send packets at various power levels and graphed the results.



I get two interesting results:

1): setPowerLevel( n ) == setPowerLevel( n - 16 )

I kind of expected something like this since the data sheet says that the pout formula is -11 dbm + OutputPower but the power range +5 to +20 dbm, leaving open what happens for n < 16.

2.) the transmitter seems to function in two "modes". Often RSSI drops by about 20 for no apparent reason. The linear relationship between power level and rssi is otherwise still there so this is extremely strange.

I know how to fix 1) using PA1 only. Anyone have an idea what 2) could be about?

Joe
 

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Bug & Mystery in setPowerLevel on rfm69hw
« Reply #1 on: April 01, 2015, 08:07:03 AM »
<...snip>
I get two interesting results:

1): setPowerLevel( n ) == setPowerLevel( n - 16 )

I kind of expected something like this since the data sheet says that the pout formula is -11 dbm + OutputPower but the power range +5 to +20 dbm, leaving open what happens for n < 16.
Welcome to the club.  This is a known phenomenon with the HW.  The ATC library I mentioned makes the power level setting monotonically increasing if you're using the HW.  With the HW you call setPowerLevel with a value from 32 to 51.  From the comments in the ATC code:
Code: [Select]
    // the allowable range of power level value, if >31 is: 32 -> 51, where...
    // 32->47 use PA2 only and sets powerLevel register 0-15,
    // 48->49 uses both PAs, and sets powerLevel register 14-15,
    // 50->51 uses both PAs, sets powerBoost, and sets powerLevel register 14-15.
2.) the transmitter seems to function in two "modes". Often RSSI drops by about 20 for no apparent reason. The linear relationship between power level and rssi is otherwise still there so this is extremely strange.
<snip...>
I haven't seen this one...

Tom

joelucid

  • Hero Member
  • *****
  • Posts: 868
Re: Bug & Mystery in setPowerLevel on rfm69hw
« Reply #2 on: April 01, 2015, 08:33:03 AM »
Tom, thanks for the pointer to your lib. In my view this should go into the stock RFM69 lib. At the very least 0-15 should all set powerLevel to 0 to keep things monotonic. Otherwise every automatic power adaption implementation will run into this issue.

Some more datapoints for the second issue which seems to be interference from a raspberry pi.

- The problem only exists when the moteino is connected to a raspberry pi.
- It also exists when all cables between moteino & pi are wrapped in aluminum foil.
- It also exists when the moteino gets its own power supply (gnd shared with the mac).
- It doesn't exist when the moteino is connected to a macbook but in the same physical position wrt the Pi.
- It doesn't exist when the moteino is connected to a macbook in the same physical position but powered by the Pi instead of the mac.

So for now it looks as if the TX/RX/DTR connections to the Pi cause the problem.

joelucid

  • Hero Member
  • *****
  • Posts: 868
Solved: Re: Bug & Mystery in setPowerLevel on rfm69hw
« Reply #3 on: April 01, 2015, 09:00:35 AM »
I've solved this:

I replaced the Raspberry Model B with a Raspberry B Model 2 I had lying around. RSSI went from [-60,-40] to a pretty solid -32. I don't know what they've changed but the new model seems much less prone to interference. I use the new model also at home which explains why I've consistently had worse reception at my weekend house (using the old model) than at home.

Joe

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Bug & Mystery in setPowerLevel on rfm69hw
« Reply #4 on: April 01, 2015, 09:08:11 AM »
That's an interesting find.
I had a Model B for the longest time doing all my gateway receiving with a Moteino and it was doing great, never had an issue.

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Solved: Re: Bug & Mystery in setPowerLevel on rfm69hw
« Reply #5 on: April 01, 2015, 10:34:17 AM »
I've solved this:

I replaced the Raspberry Model B with a Raspberry B Model 2 I had lying around. RSSI went from [-60,-40] to a pretty solid -32. I don't know what they've changed but the new model seems much less prone to interference. I use the new model also at home which explains why I've consistently had worse reception at my weekend house (using the old model) than at home.

Joe
Interesting.  Do you have a scope to check out power supply noise?

Tom

joelucid

  • Hero Member
  • *****
  • Posts: 868
Re: Bug & Mystery in setPowerLevel on rfm69hw
« Reply #6 on: April 01, 2015, 11:08:48 AM »
Tom, sorry no scope. But the old Pi was running on an Apple iPad power supply so I don't think it was too bad. The new Raspberry is hooked up to a iPhone power supply - I doubt that's cleaner.

Additionally the moteino worked well while powered by the old Pi as long as the serial connection went to the Mac.

joelucid

  • Hero Member
  • *****
  • Posts: 868
Re: Bug & Mystery in setPowerLevel on rfm69hw
« Reply #7 on: April 01, 2015, 11:11:03 AM »
@Felix, are there any plans to fix the setPowerLevel code in RFM69.cpp? If there was a discussion on the topic already before I joined I'd appreciate a pointer to understand any concerns.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Bug & Mystery in setPowerLevel on rfm69hw
« Reply #8 on: April 01, 2015, 04:31:09 PM »
Ok I give up. I fixed it. Please get latest RFM69.

joelucid

  • Hero Member
  • *****
  • Posts: 868
Re: Bug & Mystery in setPowerLevel on rfm69hw
« Reply #9 on: April 01, 2015, 04:46:45 PM »
Thanks Felix!

Robert

  • Jr. Member
  • **
  • Posts: 66
  • Country: be
Re: Bug & Mystery in setPowerLevel on rfm69hw
« Reply #10 on: June 01, 2015, 11:02:05 AM »
Sorry to come back to this issue.
Looking a the RFM69 documentation and from the allowed settings described in the RFM69 library only two modes are possible:

For RFM69, PA0 set, the power range is from -18 to +13dBm (from the Pout formula offset is -18, so output power 0 means -18 and 31 means +13)
For RFM69H, PA0 is reset, PA1,PA2 are set and RegOcp is set to x05x, however there is no high output because, RegTestPa1 and RegTestPa2 are defaulted
The power range is therefore from +2 to +17 dBm (from the Pout Formula, offset is -14, so minimum output power 16 means +2 dBm, 31 means +17)

My concern is the update done for the setPowerLevel function, which doesn’t allow to set the power for a RFM69HW module anymore.
The reason is that the value given to the power is now divided by two, meaning that the maximum value is now 15 which is out of the possible range.

In fact the problem is a several levels.

1. After power ON the RegPaLevel is set to 0x9F (1011111) i.e. PA0 set and output power 31
2. By default the parameter _powerLevel is also set to 31.
   At the radio initialisation the function setHighPower is called but the setting is different according the RFM model.
   if RFM69H is set  then PA0 is set to 0,  PA1 and PA2 are set to 1, the power value is left as it was (this case 31)
   if RFM69 then PA1 is set to 1, PA1 and PA2 are set to 0, and the power is modified by the value of _powerLevel (this case 31) which is OK

void RFM69::setHighPower(bool onOff) {
  _isRFM69HW = onOff;
  writeReg(REG_OCP, _isRFM69HW ? RF_OCP_OFF : RF_OCP_ON);
  if (_isRFM69HW) // turning ON
    writeReg(REG_PALEVEL, (readReg(REG_PALEVEL) & 0x1F) | RF_PALEVEL_PA1_ON | RF_PALEVEL_PA2_ON); // enable P1 & P2 amplifier stages
  else
    writeReg(REG_PALEVEL, RF_PALEVEL_PA0_ON | RF_PALEVEL_PA1_OFF | RF_PALEVEL_PA2_OFF | _powerLevel); // enable P0 only
}



   This means that for a RFM69H module the maximum power of 17 dBm is achieved (I used it like this while combining my network with motes running RFM69   without problems)
3. Now using the function setPowerLevel,  for instance by setting the value to 18
   in case of RFM69 is set, PA0,1,2 are unchanged and the power is modified by the value of _powerLevel (this case 18)
   if RFM69H is set,  PA0,1,2 are unchanged but the power is modified by the value of _powerLevel (which is the parameter value divided by 2, in this case 9) Why?

void RFM69::setPowerLevel(uint8_t powerLevel)
{
  _powerLevel = (powerLevel > 31 ? 31 : powerLevel);
  if (_isRFM69HW) _powerLevel /= 2;
  writeReg(REG_PALEVEL, (readReg(REG_PALEVEL) & 0xE0) | _powerLevel);
}

4. If now we want to set the power level to its maximum using setHighPower(true) the result is the following:
    if RFM69H is set then PA0 is set to 0,  PA1 and PA2 are set to 1, the power value is left as it was (this case 9)
    if RFM69 then PA1 is set to 1, PA1 and PA2 are set to 0, and the power is modified by the value of _powerLevel (this case 18)

So in my point of view is that there is a confusion between setPowerLevel and setHighPower.

setHighPower (true or false) means activate the RFM69H Power Amplifiers (and not High output), this function should only modify the PA bits and RegOcp and not modify the output power value (as it is currently only for the RFM69 module) which may still configured as by default to 31.

setPowerLevel (value 0-31) should modify the output power only (as it was before independently of the RFM69 module). A test my be done on the value which should be between 0 and 31 fort a RFM module and 16 to 31 for a RFMH module.

Set High Output (+5 to 20dBm) if necessary should be achieved with another function setting the RegTestPa1 an Pa2 according to table 11, but this is another story.

Hoping to be correct with these explanations

Robert

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Bug & Mystery in setPowerLevel on rfm69hw
« Reply #11 on: June 01, 2015, 12:19:48 PM »
Robert,
The answer lies in how the HopeRF modules have implemented the PA outputs of the SX1231H chip. I won't go into details, the library works properly. For more on that please see the 1231H datasheet.
setHighPower is simply a switch to tell the library whether you got a W or HW, that's it, the rest is taken care of.
setPowerLevel(0-31) lets you adjust the power output in 32 steps. The actual output power will depend on whether you got a W or HW, again - all taken care of.

Robert

  • Jr. Member
  • **
  • Posts: 66
  • Country: be
Re: Bug & Mystery in setPowerLevel on rfm69hw
« Reply #12 on: June 02, 2015, 12:02:05 PM »
Hum…
From the measurements below (relative short distance), setting the output power to 31 or to 16 for a RFM69H doesn’t shows significant differences.
Testing on a longer distance shall probably give a better understanding.

However I still don’t understand:
1.  why the power level is now divided by 2 for the RFM69H when setting the power level
2.  why when setting high power the power level is set to the register for a RFM69 module and not for a RFM69H

NOTE: The minimum to use RFM69H is to have Pa0 set to 0 !!!
Measurements
For what it is worth I have made some measurements (unfortunately I don’t have a tool to measure the exact signal power of the sender).

1. RFM69H mote running Struct_send & RFM69 mote running Struct_recieve; distance between motes ~50 meters
  a. Default sender configuration (no change with SetPowerLevel) i.e. maximum power
   RegPaLevel   0x11 = 0x7F or output power = 31
   RegOcp      0x13 = 0x0F
   RegTestPa1   0x5A = 0x55
   RegTestPa2   0x5C = 0x70
        Average Receiver RSSI = -82dBm
  b. sender configuration SetPowerLevel = 31
   RegPaLevel   0x11 = 0x6F or output power = 15
   RegOcp      0x13 = 0x0F
   RegTestPa1   0x5A = 0x55
   RegTestPa2   0x5C = 0x70
        Average Receiver RSSI = -80dBm
  c. sender configuration SetPowerLevel = 0
   RegPaLevel   0x11 = 0x60 or output power = 0
   RegOcp      0x13 = 0x0F
   RegTestPa1   0x5A = 0x55
   RegTestPa2   0x5C = 0x70
        Average Receiver RSSI = -94dBm
  a. Default sender configuration (no change with SetPowerLevel) i.e. maximum power but with RegTestPa1 and RegPa2 set for high Output
   RegPaLevel   0x11 = 0x7F or output power = 31
   RegOcp      0x13 = 0x0F
   RegTestPa1   0x5A = 0x5D
   RegTestPa2   0x5C = 0x7C
        Average Receiver RSSI = -78dBm

Conclusions: With this tests:
  No significant difference is measured between an output power level set to 31 or to 16 (looks even better when power output is reduced!)
  Setting the RegTestPa1 and Pa2 to high output indicates a small improvement      


2. RFM69 mote running Struct_send & RFM69 mote running Struct_recieve; distance between motes ~50 meters
  a. Default sender configuration (no change with SetPowerLevel) i.e. maximum power
   RegPaLevel   0x11 = 0x9F or output power = 31
   RegOcp      0x13 = 0x1A
   RegTestPa1   0x5A = 0x55
   RegTestPa2   0x5C = 0x70
        Average Receiver RSSI = -80dBm
  b. sender configuration SetPowerLevel = 0
   RegPaLevel   0x11 = 0x80 or output power = 0
   RegOcp      0x13 = 0x1A
   RegTestPa1   0x5A = 0x55
   RegTestPa2   0x5C = 0x70
        Average Receiver RSSI = NO ACKNOWLEDGE
  c. sender configuration SetPowerLevel = 16
   RegPaLevel   0x11 = 0x90 or output power = 16
   RegOcp      0x13 = 0x1A
   RegTestPa1   0x5A = 0x55
   RegTestPa2   0x5C = 0x70
        Average Receiver RSSI = -96dBm
Conclusions: With this tests:
  With the current relative short distance distance, an RFM69 at full power gives a result similar to the RFM69H, hiwver reducing the power has a series impact on the received signal level.

Robert

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Bug & Mystery in setPowerLevel on rfm69hw
« Reply #13 on: June 02, 2015, 12:48:21 PM »
I assume you mean RFM69HW, I'm not aware of any RFM69H device. 

Re the power settings, this is a known phenomenon; with the HW, the powerlevel field can only be set to one of 16 values (0-15 or 16-31) with the same result (ie, 0 = 16, 1=17, etc) as long as at least PA1 is enabled (you get nothing if PA1 & PA2 are disabled).  There have been several discussions throughout the forum on this.

Tom

Robert

  • Jr. Member
  • **
  • Posts: 66
  • Country: be
Re: Bug & Mystery in setPowerLevel on rfm69hw
« Reply #14 on: June 02, 2015, 02:28:23 PM »
Hi Tom,

Yes Rfm69h is rfm69hw.

For my question 1.
I don't know where you get this, but thanks for the math (ie, 0 = 16, 1=17, etc) I agree about this 16 values and it therfore explains that the default power of 31 gives the same result as the one of 16 for an Rfm69hw module.

For question 2.
it looks a little bit stange for me, but because of the first response this has no actulal settings impact.

Thanks
Robert