Skip to content

Commit 8714efb

Browse files
committed
Convert power setting to actual power output.
1 parent 94d8978 commit 8714efb

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

Firmware/LoRaSerial_Firmware/Commands.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ void checkCommand()
607607
reportERROR();
608608
break;
609609
case ('7'): //ATS7=
610-
if (settingValue >= 0 && settingValue <= 20)
610+
if (settingValue >= 14 && settingValue <= 30)
611611
{
612612
settings.radioBroadcastPower_dbm = settingValue;
613613
reportOK();

Firmware/LoRaSerial_Firmware/Radio.ino

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,11 @@ void configureRadio()
235235
if (radio.setFrequency(channels[0]) == RADIOLIB_ERR_INVALID_FREQUENCY)
236236
success = false;
237237

238-
// Set output power (accepted range is -3 - 17 dBm)
239-
// NOTE: 20 dBm value allows high power operation, but transmission duty cycle MUST NOT exceed 1%
240-
if (radio.setOutputPower(settings.radioBroadcastPower_dbm) == RADIOLIB_ERR_INVALID_OUTPUT_POWER)
238+
//The SX1276 and RadioLib accepts a value of 2 to 17, with 20 enabling the power amplifier
239+
//Measuring actual power output the radio will output 14dBm (25mW) to 27.9dBm (617mW) in constant transmission
240+
//So we use a lookup to convert between the user's chosen power and the radio setting
241+
int radioPowerSetting = covertdBmToSetting(settings.radioBroadcastPower_dbm);
242+
if (radio.setOutputPower(radioPowerSetting) == RADIOLIB_ERR_INVALID_OUTPUT_POWER)
241243
success = false;
242244

243245
if (radio.setBandwidth(settings.radioBandwidth) == RADIOLIB_ERR_INVALID_BANDWIDTH)
@@ -822,3 +824,34 @@ bool receiveInProcess()
822824
//if ((radioStatus & 0b1) == 0) return (false); //If bit 0 is cleared, there is no receive in progress
823825
//return (true); //If bit 0 is set, forget the other bits, there is a receive in progress
824826
}
827+
828+
//Convert the user's requested dBm to what the radio should be set to, to hit that power level
829+
//3 is lowest allowed setting using SX1276+RadioLib
830+
uint8_t covertdBmToSetting(uint8_t userSetting)
831+
{
832+
if(userSetting < 14) return 3; //Error check
833+
834+
switch (userSetting)
835+
{
836+
case 14: return (2); break;
837+
case 15: return (3); break;
838+
case 16: return (4); break;
839+
case 17: return (5); break;
840+
case 18: return (6); break;
841+
case 19: return (7); break;
842+
case 20: return (7); break;
843+
case 21: return (8); break;
844+
case 22: return (9); break;
845+
case 23: return (10); break;
846+
case 24: return (11); break;
847+
case 25: return (12); break;
848+
case 26: return (13); break;
849+
case 27: return (20); break;
850+
case 28: return (20); break;
851+
case 29: return (20); break;
852+
case 30: return (20); break;
853+
default: return (3); break;
854+
}
855+
856+
857+
}

Firmware/LoRaSerial_Firmware/Train.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void moveToTrainingFreq()
9090
settings.pointToPoint = false;
9191

9292
//Turn power as low as possible. We assume two units will be near each other.
93-
settings.radioBroadcastPower_dbm = 0;
93+
settings.radioBroadcastPower_dbm = 14;
9494

9595
generateHopTable(); //Generate frequency table based on current settings
9696

Firmware/LoRaSerial_Firmware/settings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ typedef struct struct_settings {
131131
bool encryptData = true; //AES encrypt each packet
132132
uint8_t encryptionKey[16] = { 0x37, 0x78, 0x21, 0x41, 0xA6, 0x65, 0x73, 0x4E, 0x44, 0x75, 0x67, 0x2A, 0xE6, 0x30, 0x83, 0x08 };
133133
bool dataScrambling = false; //Use IBM Data Whitening to reduce DC bias
134-
uint16_t radioBroadcastPower_dbm = 20; //Max software setting is 20 but radios with built-in PA will get 30dBm(1W) with rx/tx_en pins
134+
uint16_t radioBroadcastPower_dbm = 30; //Transmit power in dBm. Max is 30dBm (1W), min is 14dBm (25mW).
135135
float frequencyMin = 902.0; //MHz
136136
float frequencyMax = 928.0; //MHz
137137
uint8_t numberOfChannels = 50; //Divide the min/max freq band into this number of channels and hop between.

0 commit comments

Comments
 (0)