CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Concatenate "0b" to an 11 signed bit?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
onanieo



Joined: 09 Nov 2007
Posts: 5
Location: Edinburg, Texas

View user's profile Send private message AIM Address

Concatenate "0b" to an 11 signed bit?
PostPosted: Fri Nov 09, 2007 2:07 pm     Reply with quote

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
_________________
onanieo@gmail.com
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 09, 2007 2:21 pm     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Fri Nov 09, 2007 2:34 pm     Reply with quote

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?
_________________
onanieo@gmail.com
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Fri Nov 09, 2007 3:13 pm     Reply with quote

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

View user's profile Send private message AIM Address

onanieo
PostPosted: Fri Nov 09, 2007 5:27 pm     Reply with quote

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
_________________
onanieo@gmail.com
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 09, 2007 5:29 pm     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Fri Nov 09, 2007 5:35 pm     Reply with quote

HM55B Compass Module

http://www.hobbyengineering.com/H2112.html

it gives out a 22 bit measurement....streaming...(after booting up the module..etc)
_________________
onanieo@gmail.com
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 09, 2007 5:47 pm     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Fri Nov 09, 2007 6:36 pm     Reply with quote

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.
_________________
onanieo@gmail.com
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group