Difficulties with twos complement? Perhaps its not being able to use the 19 bit and the ~~ command.
Zap-o
Posts: 452
in Propeller 1
While asking for data that resides in a register aboard the BMP180 digital pressure IC. I do the following...
Take two BYTES out of two registers (BMP180)
Combine them into one LONG labeled AC1
Send this data to the CHECK_SIGN(AC1) for twos complement.
and..
So far, in the codes shown above everything works as expected, using two bytes, then combining to make a long. Unfortunately the BMP180 has the need to take three bytes and combine them into a long yet still needing to accomplish the post extend operation, I ask how?
My trouble is when I need to start at bit 19 instead of the 15th bit.
I Hope this I made this clear enough.
and, Thanks in advance.
Take two BYTES out of two registers (BMP180)
Combine them into one LONG labeled AC1
Send this data to the CHECK_SIGN(AC1) for twos complement.
Pub Read_Constants AC1 := i2c.rd_BYTE(BMP180,$AA) << 8 | i2c.rd_BYTE(BMP180,$AB) 'read one byte of data each, from two registers AC1 is a long. AC1 := check_sign(AC1)
and..
Pub Check_sign(in) : out out := ~~in
So far, in the codes shown above everything works as expected, using two bytes, then combining to make a long. Unfortunately the BMP180 has the need to take three bytes and combine them into a long yet still needing to accomplish the post extend operation, I ask how?
The ~~X portion of the expression extends the sign bit from bit 15 all the way up to bit 31
My trouble is when I need to start at bit 19 instead of the 15th bit.
UP := i2c.rd_BYTE(BMP180,$F6) << 16 | i2c.rd_BYTE(BMP180,$F7) << 8 | i2c.rd_BYTE(BMP180,$F8) Up := Check_sign(Up)
I Hope this I made this clear enough.
and, Thanks in advance.
Comments
Now shift back down using arithmetic shift to replicate the high bit.