*/ is the MidWord multiplier.
When you multiply 2 16-bit values together, you'll get up to a 32-bit result (4 bytes). The Midword, is the 2 bytes in the middle.
For instance, let's say you have an A/D value of 600, and you multiply it times 5000, that gives you 3,000,000. And if you express that in Hexadecimal, it looks like ...
002D:C6C0
The MidWord is 2DC6, or 11,718.
That's the same as (600 * 5000) / 256. The /256 is implied, and happens without the extra time required to do a division. So, it can be allot faster than using DIV32.
The rest of the formula is, >> 2, or shiftright 2 places. Which is the same as /4. Since the result has already been divided by 256, /4 makes the total divisor equal to 1024 (256*4). And, the result will be 2,929, which represents 2.929 Volts input to the ADC.
So, the whole formula is really just (600 * 5000) / 1024. But in a way that PBP can handle it with 16-bit numbers.<hr>
OK, so how to go the other direction...
You'll need the integer numbers (10 to 250) I'll call it Offset. Then just do the reverse formula.I would like to take 0.01 to 0.250V
AD_Cal = (Offset * 1024) / 5000
This one doesn't fit in with the */ operator, so you'll need to use DIV32.This gives a result of 51, which can then be added or subtracted from the AD result as necessary.Code:Offset = 250 ; 0.250V - Must be a WORD Var AD_Cal = Offset * 1024 AD_Cal = DIV32 5000
HTH,




Bookmarks