Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect calculation of power values #50

Closed
terrillmoore opened this issue Feb 7, 2018 · 1 comment
Closed

Incorrect calculation of power values #50

terrillmoore opened this issue Feb 7, 2018 · 1 comment
Assignees
Labels

Comments

@terrillmoore
Copy link
Member

This code looks wrong.

// no boost used for now
s1_t pw = (s1_t)LMIC.txpow;
if(pw >= 17) {
pw = 15;
} else if(pw < 2) {
pw = 2;
}
// check board type for BOOST pin
writeReg(RegPaConfig, (u1_t)(0x80|(pw&0xf)));
writeReg(RegPaDac, readReg(RegPaDac)|0x4);

  1. If pw is 16, it will pass through unchanged, but then the mask with 0xF will cause bits 3..0 of RegPaConfig to be set to zero instead of the desired 0xF.
  2. if pw is 2..15, it will be written to RegPaConfig, but since bit 7 is also set, the output power is interpreted as 17-(15-OutputPower) [or OutputPower + 2]. So pw == 2 sets output power = 4 dBm; pw == 15 or >= 17 sets 17 dBm; and pw == 16 sets 0 dBm.

It would be best to revise this code along with the fixes for #46 so that we can handle PaSelect == 0; in that case MaxPower should be set based on the region's maximum output power, allowing finest control and then OutputPower would be adjusted within the resulting range. (We could get as low as -4.2 dBm.)

@terrillmoore
Copy link
Member Author

Curiously, once the bug is fixed, the code is essentially identical to that of the SX1272.

@terrillmoore terrillmoore changed the title Incorrect calulation of power values Incorrect calculation of power values Feb 7, 2018
terrillmoore added a commit that referenced this issue Feb 7, 2018
Fix programming of RegPaConfig bits 3:0 (issue #50)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant