Some things to keep in mind here (and elsewhere too):
1) The max number from the analog conversion is 1023, which is the maximum number expressible with the 10 bits from the converter. SO, the maximum resolution you can get is 360/1023= .3519 degrees per bit
2) Converting from raw A2D number to degrees is simple, just (assuming max reading is 1023, and min is zero) A2Dreading x 360 / 1023. However, it is important to perform the calculation by doing the multiplication first, then the division. If you divide first you’ll loose a lot of precision (do you see why?) You’re working with integer numbers here, so the decimal parts get lost quickly. Alain has a good point when he scale up the reading, just be careful you do not overflow the variable; his use of 64 is the most you can scale this number up
Max scale factor = biggest word / biggest expected number = 65535 / 1023 = 64.0165… so use 64. PBP does have some facilities for handling double precision multiplicands (32 bit products), but that’s trouble to deal with.
Bookmarks