Thanks i think that helps with the percentage, but it's reconstructing the two hex bytes with the new data to forward on which is really tricky? If you get me?
Thanks i think that helps with the percentage, but it's reconstructing the two hex bytes with the new data to forward on which is really tricky? If you get me?
In the below simplified sample code two hex bytes of incomming battery current data are
evaluated to give a display of current. The code works very well.
This gives current to two decimal places when divided and a polarity sign to indicate current flowCode:Amps = ((HEXBYTE1 * 128) + HEXBYTE2) - 2048 'Calculate Battery Current if Amps.15 = 1 then 'Calculate AmpSign AmpSign = 45 'Set AmpSign to 45 (-) else AmpSign = 43 'Set AmpSign to 43 (+) endif Amps = ABS Amps Amps = Amps * 2500 Amps = DIV32 512
direction. All that is fine.
Now I need to reduce the Amps by say 8-16% (That's fine) and then recreate the HEXBYTES by
some reverse calculation or application of the above code. So they contain the new value and when evaluated by the above routine would give the new current and sign etc. Does that make sense? I hope somone can give me
me some ideas. Thanks
retepsnikrep , Why not just use the "*/" command? The variable "Amps" is a word so just multiply it by the fraction of 84 to 92 %. The "*/" command will give you the middle 16 bits of the 32 bit result. Then just put the result back into bytes.... Thats what I would do.....
Dave Purola,
N8NTA
Thanks for that.
How about this?
Anyway, a reverse of my code? Does it make sense.
Code:Amps = Amps * 512 Amps DIV32 2500 if AmpSign == 45 then '- Amps = 0 - Amps else ? not sure here endif Amps = Amps + 2048 Byte2 = Amps & &7f 'split of HEXBYTE2 Amps = Amps >> 7 'Div by 128 Byte1 = Amps & 0x1f '
Bookmarks