adafruit / TinyLoRa

LoRaWAN Library
69 stars 38 forks source link

SetPower function #30

Closed clavisound closed 5 years ago

clavisound commented 5 years ago

Third attempt for setPower support, it's user-friendly. 'User' optionally writes lora.setPower(17); to set +17dBm, or lora.setPower(-80) for -80dBm. If user does not use lora.setPower(), default is +17dBm (like adafruit original TinyLoRa). But I discovered some weird stuff.

  1. The documentation I think is wrong, or I didn't understood something! I would like someone to verify my remarks. p. 79 and p. 89 documentation states: i. Pmax = 10.8 * 0.6 * MaxPower [dBm] (this seems ok) ii. Pout = Pmax - (15 - OutputPower) [dBm] instead of iii. Pout = Pmax - (15 + OutputPower) [dBm] It's not logical with increased power to have less dBm's! Datasheet / Documentation: https://www.hoperf.com/data/upload/portal/20190801/RFM95W-V2.0.pdf

So I use the last (iii) formula for the calculations, not the documentation's (ii).

  1. Even more bizzare. The documentation says the range is -4 to +17dBm (+20 special case), but in my test is -80 to +17 (+20 untested). Huge gap between 0 and -80dBm. I didn't test +20.

  2. We have three options with HOPE RFM9x. a. without PA_BOOST (-4 to +15dBm) - in my tests: approx. -75 to -84. b. with PA_BOOST (0 to +17dBm) - in my tests: -0,20 to -14,50 (see first test) c. with PA_BOOST and HI_POWER (aka: +20dBm) - untested. It requires antenna with at least 3:1 VWSR (I have DIY antenna with cable 1/4 monopole as stated in adafruit tutorial). I don't want to risk damage.

Conclusions

  1. It works.
  2. Greeater range than documented. Instead of -4 to +20, -84 to +20.

and finally

  1. Does not break old .ino's like my first attempt.
  2. I can submit an ino file that cycles lora.setPower.

Happy testing / undestanding.

To undestand the situation I also wrote a c program https://github.com/clavisound/hope-rfm9x/blob/master/hope-rfm9x-dbm.c I wanted to check which values are easy / meaningful to use. I think it's overkill:

a. to have access to all combinations (some are overlapping). b. Granularity of 1dBm is fine.

How setPower works: The chip has 4 (four) possible 'values' in two registers. PA_BOOST, MAX_POWER, OUTPUT_POWER (one register), HIGH_POWER_SETTINGS (second register). With the c programm, I tried to deciph what I needed.

So I splitted the options in three categories / ranges.

  1. -4 to 0dBm is abandoned (in reality -80 to -83). Overkill to have this option. I kept only -80 option. PA_BOOST forbidden, HIGH_POWER_SETTINGS disabled (aka value 0x84), OUTPUT_POWER=0, MAX_POWER variable 0 to 7
  2. 0 to 17dBm PA_BOOST enabled, HIGH_POWER_SETTINGS disabled, OUTPUT_POWER=0 to 15, MAX_POWER=7
  3. 20 (untested) PA_BOOST ENABLED, HIGH_POWER_SETTINGS enabled (aka value 0x87), OUTPUT_POWER=15, MAX_POWER=7

Tests not done:

  1. compare the power consumption -80dBm vs +17dBm

Testing made with SF7, approx. 12cm distance from concentrator (n-fuse, 2dBi antenna) @CH7 (867.9Mhz). DIY antenna on adafruit LoRa, not optimized.

setPower uses this range with values: PaBoost = 1, MaxPower = 7, OutputPower = 0-15.

dBm (setPower)  RSSI (n-fuse)   SNR     sum
17      -10     9,80        -0,20
16      -7      9       2
15      -10     9,50        -0,50
14      -11     9,80        -1,20
13      -13     9,80        -3,20
12      -13     11      -2
11      -15     9,80        -5,20
10      -16     9       -7
8       -19     9       -10
7       -19     10      -9
6       -20     8,50        -11,50
5       -22     10,50       -11,50
4       -25     9,80        -15,20
4       -23     9,80        -13,20
3       -27     9,50        -17,50
2       -27     10,50       -16,50
1       -25     10,50       -14,50

Tests done with 'private' library.

This is wrong. Instead of -4dBm it seems approx. -80dBm. No reception in 3 meters and SF10, I don't find usefull to deploy this range: overkill to my taste. Using only -80 (equals -84). (MaxPower = 0-7, OutputPower 0)

-79     -100        8,50        -91,50
-80     -104        7       -97
-81     -103        5       -98
-82     -104        3,20        -100,80
-83     -103        5,20        -97,80
-84     -102        5,20        -96,80

Only 4dB more power that previous test. Also not deployed to this library.

Experiment with MaxPower = 7, OutputPower 0-15)

OutputPower RSSI        SNR     sum
1       -96     7,80        -88,20
2       -99     9       -90
3       -98     7,20        -90,80
4       -99     6,80        -92,20
5       -98     7,20        -90,80
6       -99     7,80        -91,20
7       -99     7,20        -91,80
8       -101        7,50        -93,50
9       -99     7,80        -91,20
10      -101        7,80        -93,20
11      -98     8       -90
12      -97     8,50        -88,50
13      -96     8       -88
14      -98     7,50        -90,50

I have also added / deleted some whitespaces.