View previous topic :: View next topic |
Author |
Message |
autova
Joined: 24 May 2011 Posts: 14
|
hmc help |
Posted: Fri Jun 10, 2011 11:06 pm |
|
|
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: 19535
|
|
Posted: Sat Jun 11, 2011 2:44 am |
|
|
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
|
|
Posted: Sat Jun 11, 2011 8:13 pm |
|
|
what do u means by unsigned ??? can u explain a little bit detail .
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Sun Jun 12, 2011 5:44 am |
|
|
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: 1615 Location: Central Illinois, USA
|
|
|
|