RadioLib icon indicating copy to clipboard operation
RadioLib copied to clipboard

Add PA Optimal Settings configuration option for SX1262?

Open Quency-D opened this issue 2 months ago • 9 comments

I saw in the manual that different optimal settings have different energy consumption, and that lower energy consumption options can be configured for certain areas where high output power isn't needed. However, the current code seems to only have one fixed setting. Is it possible to add all four options shown below?

  state = SX126x::setPaConfig(0x04, RADIOLIB_SX126X_PA_CONFIG_SX1262);

Image Image

Quency-D avatar Oct 17 '25 07:10 Quency-D

the current code seems to only have one fixed setting

That is not really accurate - the setPaConfig method is public, so you can set any combination of parameters - with the caveat that it needs to be called after setting the Tx power, and that the method allows you complete control over the PA, so if you set incorrect values (not specified by datasheet) then you risk damaging the module.

jgromes avatar Oct 17 '25 08:10 jgromes

That is not really accurate - the setPaConfig method is public, so you can set any combination of parameters

Sorry, that wasn't quite accurate, but what do you think of putting the four configuration options in the manual directly into the code and then choosing one from the four?

Quency-D avatar Oct 17 '25 08:10 Quency-D

The problem is that the user manual does not specify how to set a different output power for optimized consumption, other than the values listed. For example, let's say the user wants to set +9 dBm - the optimal settings in the datasheet do not include this output power level. When writing the SX126x driver, I chose to ensure accurate power level at the cost of efficiency, because I did not have a way to externally verify the output power.

The datasheet also isn't very transparent as to the impact the different settings have. So trying to find the most optimal solution for each supported power level seems a bit risky, since the library is deployed in extremely varied environments.

Overall it might be worth a bit of time to investigate though.

jgromes avatar Oct 17 '25 08:10 jgromes

OK, I initially thought there were only four fixed options. Now after reading the documentation carefully, I've discovered there are many other configuration options. I'll take a closer look.

Quency-D avatar Oct 17 '25 09:10 Quency-D

Thanks to completing the RadioHAT revision C with built-in INA219 current monitor and with a RF power meter dongle hooked up, I was able to finally run some tests on this, and the results are interesting. It seems that by optimizing the PA configuration, we could gain quite a lot in efficiency, however, my initial hunch that this might lead to actual output being lower than expected also seems to have been correct.

I first tried the original, unoptimized PA configuration for +17 dBm output, then an optimized version according to the datasheet (paDutyCycle 0x02 and hpMax 0x03), and finally as a sanity check, +15 dBm unpotimized configuration. The results are below:

  +17 dBm unoptimized: 91 mA, 300 mW, 16.5 dBm out
  +17 dBm optimized:   58 mA, 190 mW, 14.8 dBm out
  +15 dBm unoptimized: 82 mA, 270 mW, 14.3 dBm out

I know the USB RF power meter isn't great and its numbers are indicative only, but it is definitely interesting that the optimized version of +17 dBm is more efficient than unoptimized +15 dBm while outputting comparatively similar RF power level. It's roughly 30% gain in efficiency, which is significant.

The way forward I see here is to do an exhaustive test of all the possible PA configurations with couple different SX1262 units. From the results, we can create a lookup table for the most optimal configuration for any given output power level. Then we can give the users the choice to either the original simple approach, or this more complex but optimized one (though I'm not yet sure which should be the default).

cc @StevenCellist

jgromes avatar Nov 30 '25 17:11 jgromes

This looks amazing for the SX1262. With it being the most common radio currently in use, this is very nice. The peak power of a transmission is one of the main battery drains and low-battery reset reasons in LoRaWAN devices especially. So I'd say we definitely try to find optimal settings, and IMO they can be set as default as long as we can guarantee that the effective values do not exceed the requested value. Probably with a note or explainer on the wiki.

StevenCellist avatar Nov 30 '25 19:11 StevenCellist

Great work ! As we were discussing, I also achieved a significant reduction in consumption. The only concern is that I personally obtained much lower output power with the optimised version.

In fact, I tried a distance test with +15db vs. +20db optimised and got better results with +15db. It would be good if someone could confirm this.

devRomeos avatar Dec 04 '25 18:12 devRomeos

I did the same test again with a significantly better power meter, the results seem to somewhat track with the previous test:

  +17 dBm unoptimized: 91 mA, 300 mW, 17.38 dBm out
  +17 dBm optimized:   58 mA, 190 mW, 16.46 dBm out
  +15 dBm unoptimized: 82 mA, 270 mW, 15.46 dBm out
  +16 dBm unoptimized: 82 mA, 270 mW, 16.50 dBm out

So there is definitely a bit of a drop between the optimized output level and what should be there.

jgromes avatar Dec 05 '25 17:12 jgromes

Experimental optimization is now available in the sx126x-pa-optimize branch. For now, it is only implemented for SX1262. The values used for optimization have been measured by exhaustively testing all possible combinations of paDutyCycle, hpMax and the power value in setTxParams.

Result of this testing is summarized in the chart below. The blue line is the actual, measured output power from the SX1262. The red dots are the power consumption of the module at that specific power level, so it can be seen that there is a large range of possible settings that have different power consumption, but produce pretty much the same output. The default values that have been used so far (with paDutyCycle=4 and hpMax=7) are marked in yellow - so it seems these are the absolute worst possible settings. In contrast, the newly optimized values are shown in green. Across all output powers, this leads to about 30-50% power saving.

I will need to do further tests with other SX1262 units, and then also with SX1261 and SX1268 as the PAs in those will likely beahve a bit differently.

I would also like to invite others to test out the branch, as it seems suspicious to me this level of optimization can be achieved without some impact I am not yet seeing.

Image

jgromes avatar Dec 06 '25 20:12 jgromes

I was able to run the tests again on a calibrated spectrum analyzer, and it seems that I was a bit too ambitious in the original optimization, as the result underperformed by about 1 - 2 dB. I fixed this by running the measurements again, and the result is also committed in the branch. For those curious, all data I measured and the processing scripts used are uploaded in https://github.com/radiolib-org/power-tests

The key result is in this file, which shows side-by-side comparison of the unoptimized and optimized PA power consumption. Depending on the output level, we still get 20 - 30% power saving. We do not reach the power consumption shown in the datasheet (for example, Semtech claims 17 dBm will draw 58 mA with optimized settings, while our optimization draws about 72 mA), however, I am confident our optimization performs the same or better than the unoptimized config, which is not the case for Semtech recommended configuration.

The next step will be to run this campaign on an SX1268 to generate the optimized PA table for that one. I will also try to get some more SX1262 and SX1268 devices to validate with. Unfortunately I don't have any SX1261 and none of the vendors I usually get my stuff from seem to have them, so for now this one will remain unoptimized.

jgromes avatar Dec 14 '25 08:12 jgromes