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

hmc help

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



Joined: 24 May 2011
Posts: 14

View user's profile Send private message

hmc help
PostPosted: Fri Jun 10, 2011 11:06 pm     Reply with quote

Code:
void main()
{
int16 heading0;
int16 heading;
set_tris_d(0x00);
set_tris_b(0x00);


heading0 = heading/10;

while(1)
  {



   heading = HMC6352_read_heading();

   heading = heading /10 - heading0;

  if(heading >= 90)
     output_high(PIN_B0);

  else
     output_low(PIN_B0);

   delay_ms(500);

  }

}


i want when i turn 90 degree , led will on but then before 90 degree the led already on . whats the problem ? anyone help me ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19430

View user's profile Send private message

PostPosted: Sat Jun 11, 2011 2:44 am     Reply with quote

First problem. Your code it treating the angles as _unsigned_. The compass unit returns signed numbers. If (for instance) it is returning -10 degrees, then this will be 0xFF9C. If it then moves to -100 degrees this will change to 0xFC18, giving a sum result of 0xFFA6!......
Second problem. You have not read the heading, when you load heading0....

You need to load the heading first, treat the numbers as signed, and also handle the possibility (depending on which way you are turning), of the angles going down rather than up as you turn.

Best Wishes
autova



Joined: 24 May 2011
Posts: 14

View user's profile Send private message

PostPosted: Sat Jun 11, 2011 8:13 pm     Reply with quote

what do u means by unsigned ??? can u explain a little bit detail .

Sad
temtronic



Joined: 01 Jul 2010
Posts: 9196
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jun 12, 2011 5:44 am     Reply with quote

I read the datatsheet and if correctly setup, in 'heading' mode, the chip will send back the 2 bytes for the direction from 0000 to 3599, so an unsigned integer16 for the result should work fine

using the CCS function make16(......) will help as I don't know what

heading = HMC6352_read_heading();

actually returns into 'heading'.


You can easily lookup these CCS functions and types by pressing F11 while your project is open,or view any of the fine examples CCS provides in the examples folder.
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sun Jun 12, 2011 11:41 am     Reply with quote

autova wrote:
what do u means by unsigned ??? can u explain a little bit detail .



http://en.wikipedia.org/wiki/Integer_%28computer_science%29


Tsk tsk.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
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