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

HMC6352 16 reading averaging

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



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

View user's profile Send private message Send e-mail

HMC6352 16 reading averaging
PostPosted: Sun Oct 12, 2008 8:53 am     Reply with quote

Hi.
I am still using a HMC6352 compass and I want to remove some of the jitter by using the function in the chip to use the average of the past 16 values of the magnetometers.
On page 8 of the data sheet the following shows how to.
Quote:
Measurement Summing
This EEPROM summed measurement byte permits designers/users to back average or data smooth the output data
(heading, magnetometer values) to reduce the amount of jitter in the data presentation. The default value is 04(hex) which
is four measurements summed. A value of 00(hex) would be no summing. Up to 16 sets of magnetometer data may be
selected for averaging. This slave address is written into EEPROM address 06(hex) and loaded to RAM on the power up.


However in the I2C protocol I have no idea where to place the 0x16 value to find the averaged readings.

I have gone through the data sheet several times but seem to struggle to find the exact order of the protocol.
At the moment I am doing it as follows:
Code:
int16 HMC6352_read_heading(void)
{
int8 lsb;
int8 msb;

i2c_start();
i2c_write(HMC6352_I2C_WRITE_ADDRESS); //0x42
i2c_write(HMC6352_GET_DATA_COMMAND); //0x41
i2c_stop();

delay_ms(7); 

i2c_start();
i2c_write(HMC6352_I2C_READ_ADDRESS); //0x43
msb = i2c_read();
lsb = i2c_read(0);
i2c_stop();

return((int16)lsb | ((int16)msb << 8)); 
}


Can someone please advise how the protocol falls into place in this chip.
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Oct 12, 2008 9:53 am     Reply with quote

According to the data sheet:

1. I2c_write 0x42 // i2c_write(HMC6352_I2C_WRITE_ADDRESS)
2. I2c_write 0x77 // "w" command
3. I2c_write 0x06 // EEPROM Address
4. I2c_write 0x16 // number of summed readings

The writes are done in sequence, one after the other.
The chip should ACK each write command.

Send a start, the four commands then a stop


Last edited by dyeatman on Sun Oct 12, 2008 9:57 am; edited 2 times in total
Gerhard



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

View user's profile Send private message Send e-mail

PostPosted: Sun Oct 12, 2008 9:54 am     Reply with quote

I tried doing it as follows but something is amiss because it does not work.
Code:
int16 HMC6352_read_heading(void)
{
int8 lsb;
int8 msb;
i2c_start();
i2c_write(HMC6352_I2C_WRITE_ADDRESS);
i2c_write(0x77);//write to eeprom
delay_us(80);
i2c_write(0x06);//write to eeprom adress 0x06
i2c_write(0x16);//enable 16 value averageing
i2c_stop();


i2c_start();
i2c_write(HMC6352_I2C_WRITE_ADDRESS);//0x42
i2c_write(HMC6352_GET_DATA_COMMAND); //0x41
i2c_stop();

delay_ms(7); 

i2c_start();
i2c_write(HMC6352_I2C_READ_ADDRESS);//0x43
msb = i2c_read();
lsb = i2c_read(0);
i2c_stop();

return((int16)lsb | ((int16)msb << 8)); 
}
Gerhard



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

View user's profile Send private message Send e-mail

PostPosted: Sun Oct 12, 2008 9:56 am     Reply with quote

Thanks dyeatman.

Should it be in sequence with one i2c_start at beginning of each comand and stop at each comand or one start comand, 3 data comands and then 1 stop comand.
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Oct 12, 2008 9:58 am     Reply with quote

I replied to your question by editing my original response and adding one command I omitted... sorry..
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Oct 12, 2008 10:02 am     Reply with quote

The data sheet does say you need 70usec afte the "w' command before sending the 0x06. It seems to imply another delay needed after the 0x06 as well. I would add it just in case....
Gerhard



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

View user's profile Send private message Send e-mail

PostPosted: Sun Oct 12, 2008 10:14 am     Reply with quote

Just to ensure that I am understanding correctly. Is this what you suggest?

Code:
i2c_start();
i2c_write(HMC6352_I2C_WRITE_ADDRESS);
i2c_write(0x77);//write to eeprom
delay_us(80);
i2c_write(0x16);
delay_us(80);
i2c_write(0x16);//enable 16 value averageing
i2c_stop();

Thanks for the help.
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Oct 12, 2008 10:19 am     Reply with quote

Actually:

Code:
i2c_start();
i2c_write(HMC6352_I2C_WRITE_ADDRESS);
i2c_write(0x77);//write to eeprom
delay_us(80);
i2c_write(0x06);
delay_us(80);
i2c_write(0x16);//enable 16 value averageing
i2c_stop();

You also have to power the compass unit off and back on for this to take effect.
Ttelmah
Guest







PostPosted: Sun Oct 12, 2008 12:25 pm     Reply with quote

I'd also think that the number used to set the average, would need to be 0x10 (16), not 0x16 (22). Since 16 is the maximum allowed, 22, would probably not work at all.

Best Wishes
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Oct 12, 2008 12:29 pm     Reply with quote

Thanks Ttelmah
I had intended to make it decimal for clarity...but I got carried away with the hex. That's what I get for doing several things at once while also trying to pay attention to the forum!
Ttelmah
Guest







PostPosted: Mon Oct 13, 2008 2:10 am     Reply with quote

Know the feeling all too well.... Smile

Best Wishes
_Gerhard
Guest







PostPosted: Mon Oct 13, 2008 6:00 am     Reply with quote

Thanks dyeatman and Ttelmah. I got it working with your help.

Good Day Gerhard
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