Hi Christopher
Your equation simply does this calculation
v[0] = 0.1 * number
where
Number is the value in d[0], d[1] MSB, LSB
Number ranges from -7 to +7 where bit 3 (weight 8) is the sign bit.
How does it work? Let's break it up
v[0]=0.1*(((d[0]o)-(d[0]Ϩ))*256+d[1])
Keep aside the 0.1 for the moment
Starting with ( ( (d[0] & #111) ....
you keep only bits 0,1,2 of the MSB (max value of #111 is 7)
......-(d[0]Ϩ))
subtract 0 for d[0].3 = 0 or 8 if d[0].3 is 1
d[0].3 is 1 when the number is negative.
( ( (value)-(weight of sign bit) ) * 256 ) ...
Now, multiply this number by 256 or in binary 100hex. Simply means the author wants to move the MSB number by 8 bits left.
Equivalent code would be "MSB number left shifted by 8 bits"
(...... + d[1] )
Now, add in the LSB of the number to get the whole 12bit (4 from msb, 8 from lsb) value
Now you have the entire number with its sign taken care of in some temporary variable generated by the compiler.
v[0] = 0.1 * temporary number
This is the part PBP will not be able to handle for you since it does not accept fractions.
What you can do to overcome this is
v[0] = temp number / 10 which is the same as 0.1 * temp number
Cheers
Jerson




Bookmarks