View previous topic :: View next topic |
Author |
Message |
onanieo
Joined: 09 Nov 2007 Posts: 5 Location: Edinburg, Texas
|
Concatenate "0b" to an 11 signed bit? |
Posted: Fri Nov 09, 2007 2:07 pm |
|
|
How do you concatenate '0b' to a signed 11-bit number??
What I'm trying to do is this calculate atan2(dataY, dataX)
char dataXY; dataXY has 22 bits from a device module output
then I divided dataXY into two 11bit variables, saving them to two variables:
first 11 bits to dataX and last 11 bits to dataY.
I want to have dataX and dataY treated as binary numbers instead of char so this is why I need to add "0b" in front of the 11 bits......
then I want to make the signed binary number into float (typecast) so I can calculate the arctan.
Please help!
-Celeste _________________ [email protected] |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Nov 09, 2007 2:21 pm |
|
|
Quote: |
char dataXY; dataXY has 22 bits from a device module output |
A 'char' is only 8 bits. It can't hold 22 bits. |
|
|
onanieo
Joined: 09 Nov 2007 Posts: 5 Location: Edinburg, Texas
|
|
Posted: Fri Nov 09, 2007 2:34 pm |
|
|
So after I change it to int32 from char, do I still have to concatenate "0b" to the 11 bits or will it be treated as binary? _________________ [email protected] |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Fri Nov 09, 2007 3:13 pm |
|
|
Where is this 22 bit data coming from? Is it from a string of ASCII characters, or a character string of bytes?
The only place you might need "0b" is in declaring a constant. Once the code is compiled bytes is bytes, the PIC doesn't care what they represent. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
onanieo
Joined: 09 Nov 2007 Posts: 5 Location: Edinburg, Texas
|
onanieo |
Posted: Fri Nov 09, 2007 5:27 pm |
|
|
the 22 bit data is coming from a device module..compass module. it outputs 22 bits. so I save it into a variable: dataXY then i want to divide it into two vars...
first half for dataX and other half for dataY
my main goal is to get atan2(dataY, dataX);...
to do that we need the variables in float.. at least that is what i know so I'm trying to get the 11 bit variables changed to float so that i can solve for atan2(dataY, dataX)
the solution that i can think of is trying to change the binary to float by typecasting....
but i think i'm stuck at changing the datatype..... i'll try to get the code in _________________ [email protected] |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Nov 09, 2007 5:29 pm |
|
|
Post the manufacturer and part number of the compass module.
Also post a link to the website for it. |
|
|
onanieo
Joined: 09 Nov 2007 Posts: 5 Location: Edinburg, Texas
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Nov 09, 2007 5:47 pm |
|
|
There's a driver for the HM55B compass here:
http://www.glacialwanderer.com/robots/robots/mapBot/mapbot_diag.zip
Look at these files:
Quote: |
main.c -- This calls compass functions in the driver.
HM55B.c -- This is the compass driver file.
|
Notice that he calls these two functions in main().
Quote: |
calibrateCompass();
getCompassAngle();
|
Do it the same way as shown in the main.c file. |
|
|
onanieo
Joined: 09 Nov 2007 Posts: 5 Location: Edinburg, Texas
|
|
Posted: Fri Nov 09, 2007 6:36 pm |
|
|
Thanks.
We're looking at the codes now. He used 18F6722 and we're using PIC 16F877A I don't know how different it would be if we're using a different pic. _________________ [email protected] |
|
|
|