It means the mask is applied to the variable being masked and bacause it is an AND, only the bits that are a 1 in both number appear in the result eg assume the number 26 for d[0]
00011010 = 26 = d[o]
00000111 = 7 = 1st mask
00000010 = 2 = 1st result
00011010 = 26 = d[o]
00001000 = 8 = 2nd mask
00001000 = 2 = 2nd result
Hope that makes sense
Keith
www.diyha.co.uk
www.kat5.tv
I see why they use that formula. What's an easy way (fast/less code) to convert this number into usable information.
The first byte will go from 0 to 7 but also from 15 to 8. When it is 0-7, the number is negative....0, -1, -2, -3..... When it is 15 to 8 (stepping down), the number is positive. In this case 15=1, 14=2, 13=3.....
I'm still not sure I understand the original equation correctly but when I was driving I got something like this:
D0=15 and D1=243. I know this is charging current and D0=1, which is a rollover from D1. In other words, once D1 increases from 255 to 256, D1 goes to 0 and D0 increases by 1. In this case, it went from 15 to 0. More current stepped down from 15 to 14. How would I apply this to that formula:
v[0]=0.1*(((d[0]o)-(d[0]Ϩ))*256+d[1])
v[0]=.1*(((7)-(8))*256+243
v[0]=.1*(-1)*256+243
v[0]=-.1*256+243
v[0]= -25.6 + 243
v[0] = 217.4
This number doesn't seem correct from a functional perspective but also when plugging in 14 in D0, I would expect the number to increase, not decrease. Is my math above correct?
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