will help you Yeah this is a common mistake. One thinks 10 bits = 2^10 = 1024 and so there will be 1024 steps, right? Nope, 10 bit ADCs only give output up to 1023 (3FFh), because that is the largest number you can fit into 10 bits.

So if you do arithmetic on 1024 instead of 1023, you introduce a very slight inaccuracy in the calculation. I've done this bug myself and it sat in production code for over 10 years without anyone noticing, and when I fixed the bug nobody noticed a difference either :) But naturally we should always strive for program correctness.

code :