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

Bug in packetFrequencyError #716

Open
Nick507 opened this issue Mar 9, 2025 · 2 comments
Open

Bug in packetFrequencyError #716

Nick507 opened this issue Mar 9, 2025 · 2 comments

Comments

@Nick507
Copy link

Nick507 commented Mar 9, 2025

In function LoRaClass::packetFrequencyError()
there is a wrong conversion: freqError -= 524288;
it must be freqError -= 1048576;
because 1<<20 = 1048576

@torntrousers
Copy link
Contributor

Hello @Nick507, I added that packetFrequencyError function, back in 2018, so i don't remember the code super well! I think it might have been derived from code from a Semtech library. Could you give any more explanation on how you found the problem or why you think its a bug?

@Nick507
Copy link
Author

Nick507 commented Mar 10, 2025

Hello Anthony, according to sx127x datasheet, frequency error value is 20 bit two's complement value (4.1.5. Frequency Error Indication). The algorithm of converting negative value from two's complement form is to substract 2^N from that value, where N is number of bits, which is 20 in this case.
https://en.wikipedia.org/wiki/Two%27s_complement
524288 is the 2^19.
The simple example:
1111 - is -1 for 4bit two's complement value (according to wiki)
most significant bit is set, it means that this is negative value, and need to convert it: 15-16=-1, where
15=1111 (our value)
16=2^4=1<<4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants