Digital Compass
Posted: Fri Jul 15, 2011 3:59 pm
Digital Compass
My latest project is a electronic digital compass.
While browsing a component site, I spotted this interesting module.
CMPS03 Compass Module.
Fig1. The PCB as received from the supplier.
North is at right angle to the left side of the pcb.
The 2 x 8 pin chips nearest the left side are the Philips KMZ51 magnetic detector devices.
Data sheet for the compass can be downloaded from here.
http://www.robot-electronics.co.uk/htm/cmps3tech.htm
Required Hardware.
EB006 Multi-programmer.
EB005 LCD Display.
EB016 Prototyping Board.
The unit must be used horizontally or on a flat surface non metallic surface, serious errors will be introduced if these recommendations are not followed.
The unit consists of a small PCB (approx 35mm square), fitted with a SIL header plug. This has standard spacing allowing it to be plugged into a standard protoboard.
The functional part of the circuit is 2 Philips KMZ51 magnetic field sensor IC’s mounted at right angles to each other. These pick up the earth’s magnetic field and can calculate the direction the unit is facing.
Module Calibration
It is recommend to ensure the unit is working properly before attempting calibration.
It may be necessary to calibrate the unit.
A standard magnetic needle compass is needed to do this.
The module is positioned to point to the 4 main points of the compass (N E S W)
At each point, a value of 255 is written to the module via the I2C bus
Alternatively it can be calibrated by connecting the cal input (pin6) to ground (pin9) by a push switch.
This way will be fitted to the final version using a jumper to allow the button to be totally disconnected from the module when not needed, this will prevent it being pressed accidentally and corrupting the calibration.
This method is preferable to using the I2C bus method as it allows the unit to be recalibrated in the field where access to a pc may not be possible.
As above the unit is calibrated at the 4 main points of the compass, the button is pressed momentarily to set the value before being moved to the next position.
Data Output
0 to 255 = 0 to 360° (1 byte)
This means each value read is equal to approximately 1.4°
The data is read by using a 12C bus protocol.
Steps to read the data are as follows
I2C Initialise
I2C Start
I2C Transmit Byte 0xC0 Send start bit to the compass with read/write bit low
I2C Transmit Byte 1 Register to be read
I2C Restart
I2C Transmit Byte 0xC1 Send start bit to the compass with read/write bit high
I2C Receive Byte 1 Register to read Return Value = out
I2C Stop
This will put the current value read from the I2C bus into the variable “out”
Because the program is using integer math the calculation will be done as follows
Angle = ((out * 7) / 4)
This way the measured value can be multiplied by approximately 1.4
By converting the output value to a float, the accuracy can be improved
Angle = fmul(out,1.406)
A still more accurate method is available where the output is 3599 for an angle of 359.9°
This uses a 16bit word and is read as 2 bytes (Highbyte LowByte)
This uses registers 2 & 3 and is read in a similar way
out = lowbyte + (highbyte <<8)
angle = fdiv(out,10)
My latest project is a electronic digital compass.
While browsing a component site, I spotted this interesting module.
CMPS03 Compass Module.
Fig1. The PCB as received from the supplier.
North is at right angle to the left side of the pcb.
The 2 x 8 pin chips nearest the left side are the Philips KMZ51 magnetic detector devices.
Data sheet for the compass can be downloaded from here.
http://www.robot-electronics.co.uk/htm/cmps3tech.htm
Required Hardware.
EB006 Multi-programmer.
EB005 LCD Display.
EB016 Prototyping Board.
The unit must be used horizontally or on a flat surface non metallic surface, serious errors will be introduced if these recommendations are not followed.
The unit consists of a small PCB (approx 35mm square), fitted with a SIL header plug. This has standard spacing allowing it to be plugged into a standard protoboard.
The functional part of the circuit is 2 Philips KMZ51 magnetic field sensor IC’s mounted at right angles to each other. These pick up the earth’s magnetic field and can calculate the direction the unit is facing.
Module Calibration
It is recommend to ensure the unit is working properly before attempting calibration.
It may be necessary to calibrate the unit.
A standard magnetic needle compass is needed to do this.
The module is positioned to point to the 4 main points of the compass (N E S W)
At each point, a value of 255 is written to the module via the I2C bus
Alternatively it can be calibrated by connecting the cal input (pin6) to ground (pin9) by a push switch.
This way will be fitted to the final version using a jumper to allow the button to be totally disconnected from the module when not needed, this will prevent it being pressed accidentally and corrupting the calibration.
This method is preferable to using the I2C bus method as it allows the unit to be recalibrated in the field where access to a pc may not be possible.
As above the unit is calibrated at the 4 main points of the compass, the button is pressed momentarily to set the value before being moved to the next position.
Data Output
0 to 255 = 0 to 360° (1 byte)
This means each value read is equal to approximately 1.4°
The data is read by using a 12C bus protocol.
Steps to read the data are as follows
I2C Initialise
I2C Start
I2C Transmit Byte 0xC0 Send start bit to the compass with read/write bit low
I2C Transmit Byte 1 Register to be read
I2C Restart
I2C Transmit Byte 0xC1 Send start bit to the compass with read/write bit high
I2C Receive Byte 1 Register to read Return Value = out
I2C Stop
This will put the current value read from the I2C bus into the variable “out”
Because the program is using integer math the calculation will be done as follows
Angle = ((out * 7) / 4)
This way the measured value can be multiplied by approximately 1.4
By converting the output value to a float, the accuracy can be improved
Angle = fmul(out,1.406)
A still more accurate method is available where the output is 3599 for an angle of 359.9°
This uses a 16bit word and is read as 2 bytes (Highbyte LowByte)
This uses registers 2 & 3 and is read in a similar way
out = lowbyte + (highbyte <<8)
angle = fdiv(out,10)