From 5b04badb3628c1162fc8eab9bfe296bcf227d904 Mon Sep 17 00:00:00 2001 From: BarryPSmith Date: Mon, 11 Nov 2019 11:26:41 -0800 Subject: [PATCH] Implemented power scaling in setOutputPower, in accordance with datasheet. --- src/modules/SX1262.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/modules/SX1262.cpp b/src/modules/SX1262.cpp index d2482593..d4342243 100644 --- a/src/modules/SX1262.cpp +++ b/src/modules/SX1262.cpp @@ -85,27 +85,37 @@ int16_t SX1262::setFrequency(float freq, bool calibrate) { int16_t SX1262::setOutputPower(int8_t power) { // check allowed power range - if(!((power >= -9) && (power <= 22))) { + if (!((power >= -17) && (power <= 22))) { return(ERR_INVALID_OUTPUT_POWER); } // get current OCP configuration uint8_t ocp = 0; int16_t state = readRegister(SX126X_REG_OCP_CONFIGURATION, &ocp, 1); - if(state != ERR_NONE) { + if (state != ERR_NONE) { return(state); } + int8_t scaledPower; // set PA config for optimal consumption as described in section 13-21 of the datasheet: - // the final column of Table 13-21 suggests that the value passed in SetTxParams is actually scaled depending on the parameters of setPaConfig. However, testing suggests this isn't the case. + // the final column of Table 13-21 suggests that the value passed in SetTxParams + // is actually scaled depending on the parameters of setPaConfig. + // Testing confirms this is approximately right if (power >= 21) { state = SX126x::setPaConfig(0x04, SX126X_PA_CONFIG_SX1262, SX126X_PA_CONFIG_HP_MAX/*0x07*/); - } else if (power >= 18) { + scaledPower = power; + } + else if (power >= 18) { state = SX126x::setPaConfig(0x03, SX126X_PA_CONFIG_SX1262, 0x05); - } else if (power >= 15) { + scaledPower = power + 2; + } + else if (power >= 15) { state = SX126x::setPaConfig(0x02, SX126X_PA_CONFIG_SX1262, 0x03); - } else { + scaledPower = power + 5; + } + else { state = SX126x::setPaConfig(0x02, SX126X_PA_CONFIG_SX1262, 0x02); + scaledPower = power + 8; } if (state != ERR_NONE) { return(state); @@ -116,7 +126,7 @@ int16_t SX1262::setOutputPower(int8_t power) { // set output power // TODO power ramp time configuration - state = SX126x::setTxParams(power); + state = SX126x::setTxParams(scaledPower); if (state != ERR_NONE) { return state; }