LowPowerLab Forum

Hardware support => RF - Range - Antennas - RFM69 library => Topic started by: mah115 on February 10, 2020, 11:28:30 AM

Title: RFM69 library setPowerLevel() bug? [fixed in RFM69 v1.5.0]
Post by: mah115 on February 10, 2020, 11:28:30 AM
On my Moteino M0 with the RFM69HCW, I noticed that when I called the setPowerLevel() function, the power shown on my spectrum analyzer went down 1 dB even if I set the power to 31.  I dug into it and noticed this line in the code:
   if (_isRFM69HW) _powerLevel /= 2;
which converts 0-31 to 0-15.
However, the datasheet says only the upper 16 values are valid.  So we should be writing 16-31 in that field instead of 0-15.  It just so happens that they work, but writing 0 to bit 5 seems to reduce the power level by about 1dB.  Here are some real-world measurements for different values of OutputPower:

31: 16.35 dBm
30: 15.74
29: 15.05
28: 14.35
26: 12.603
21: 7.8
18: 4.71
17: 3.46
16: 2.46
15: 15.125
14: 14.71
13: 14.10
10: 11.63
5: 7.07
2: 3.94
1: 2.77
0: 1.65

Interestingly, it seems like you can get monotonically increasing power levels if you use the sequence 0-16-1-17-2-18...etc so it might be possible to exploit this to get greater granularity in the power levels.  I wonder if this is actually how it's supposed to work, but it was too confusing so the technical writer just said "screw it, I'll just tell them to use the upper 16 values!"
Title: Re: RFM69 library setPowerLevel() bug?
Post by: Felix on February 24, 2020, 02:18:50 PM
What was your eventual code fix for this?
Title: Re: RFM69 library setPowerLevel() bug?
Post by: mah115 on March 04, 2020, 10:16:55 PM
I just removed the divide operation, so setPowerLevel now takes values 16-31.  I'm not dynamically changing the power, so it works well enough for me.  I suppose if we wanted to maintain backwards compatibility,
_powerLevel = _powerLevel/2 +16
would probably do the trick
Title: Re: RFM69 library setPowerLevel() bug?
Post by: Felix on June 15, 2020, 11:04:57 AM
I have to revisit this.
I would add that usually when a signal loss or ATC limit is exceeded, increasing power level by +1 is not helpful. More like +10 is what gives better results.
What are your observations?
Title: Re: RFM69 library setPowerLevel() bug?
Post by: Felix on August 31, 2021, 05:25:21 PM
As follow up and closure to this - I believe the setPowerLevel() bug is now fixed in RFM69 v1.5.0 and I posted a blog about my findings and the fix (https://lowpowerlab.com/2021/08/31/rfm69-tx-output-power-testing-library-fix/). Please try it out (and try the new `setPowerDBm()` function) and let me know if you spot anything amiss.