The Digilent Pmod CMPS2 (Revision A) is a 3-axis anisotropic magneto-resistive sensor. With Memsic's MMC34160PJ, the local magnetic field strength in a ±16 Gauss range with a heading accuracy of 1° and up to 0.5 mG of resolution.
| Parameter | Min | Typical | Max | Units |
|---|---|---|---|---|
| Power Supply Voltage | 1.62 | 1.8 | 3.6 | V |
| Output Resolution | 12 | 14 | 16 | bits |
| Alignment Error | -3 | ±1 | +3 | degrees |
| Parameter | Condition | Value | Units | |
| Total RMS Noise | 16 bits at 7.92 ms/S | 1.5 | mG | |
| Total RMS Noise | 16 bits at 4.08 ms/S | 2.0 | mG | |
| Total RMS Noise | 14 bits at 2.16 ms/S | 4.0 | mG | |
| Total RMS Noise | 12 bits at 1.20 ms/S | 6.0 | mG | |
| Max Output Data Rate | 16 bits at 7.92 ms/S | 125 | Hz | |
| Max Output Data Rate | 16 bits at 4.08/S | 250 | Hz | |
| Max Output Data Rate | 14 bits at 2.16 ms/S | 450 | Hz | |
| Max Output Data Rate | 12 bits at 1.20 ms/S | 800 | Hz | |
| Parameter | Value | Units | ||
| Field Range for Each Axis | ±16 | G | ||
| Header J1 | Header J2 | Jumper JP1 | ||||||
|---|---|---|---|---|---|---|---|---|
| Pin | Signal | Description | Pin | Signal | Description | Pin | Status | Description |
| 1 | N/C | Not Connected | 1 | N/C | Not Connected | SCL | Loaded | 4.7 kΩ Pullup to Vcc |
| 2 | N/C | Not Connected | 2 | N/C | Not Connected | SCL | Unloaded | No Pullup to Vcc |
| 3 | SCL | Serial Clock | 3 | SCL | Serial Clock | SDA | Loaded | 4.7 kΩ Pullup to Vcc |
| 4 | SDA | Serial Data | 4 | SDA | Serial Data | SDA | Unloaded | No Pullup to Vcc |
| 5 | GND | Power Supply Ground | 5 | GND | Power Supply Ground | |||
| 6 | VCC | Power Supply (3.3V) | 6 | VCC | Power Supply (3.3V) | |||
The pins on the pin header are spaced 100 mil apart. The PCB is 1.25 inches long on the sides parallel to the pins on the pin header and 0.8 inches long on the sides perpendicular to the pin header.
The Pmod CMPS2 utilizes the MMC34160PJ to collect magnetic field data. While communicating with the host board via the I²C protocol using an I²C address of 0x0110000/ users can measure the ±16 G field surrounding the device.
The Pmod CMPS2 communicates with the host board via the I²C protocol. By first sending the 7-bit I²C device address of 0110000 and then a read/write bit (high/low logic level, respectively), followed by the register address of interest at a maximum clock frequency of 400 kHz users can both configure and read from the Pmod CMPS2. An additional set of pins on header J2 is provided so that users may daisy chain the Pmod CMPS2 with other I²C devices.
Each Cartesian axis has two registers to store the high and low data bytes for each measurement. The data registers are arranged in a low byte, high byte arrangement.
| Data Registers addresses 0x00 to 0x05 | |
|---|---|
| Address | Register Name |
| 0x00 | X out LSB |
| 0x01 | X out MSB |
| 0x02 | Y out LSB |
| 0x03 | Y out MSB |
| 0x04 | Z out LSB |
| 0x05 | Z out MSB |
| Bit Name | Bit Number | Bit Description | Bit Values | Functional Description |
|---|---|---|---|---|
| RSV | [7] | Reserved | 0¹ | Reserved Bit |
| RSV | [6] | Reserved | 0¹ | Reserved Bit |
| RSV | [5] | Reserved | 0¹ | Reserved Bit |
| RSV | [4] | Reserved | 0¹ | Reserved Bit |
| ST_XYZ_OK | [3] | ST_XYZ_OK | 0¹ | Indicates that the selftest was OK when this bit is a “1” |
| Rd_Done | [2] | Rd_Done | 0¹ | Indicates that chip was successfully able to read its memory. |
| Pump On | [1] | Pump On | 0¹ | This bit indicates the status of the charge pump. |
| RSV | [0] | Meas Done | 0¹ | Indicates that a measurement event is completed. |
| Internal Control 0 | Internal Control 1 | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Bit Name | Bit Number | Bit Description | Bit Values | Functional Description | Bit Name | Bit Number | Bit Description | Bit Values | Functional Description | |
| Refill Cap | [7] | Refill Cap | 0¹ | Setting this bit will recharge the capacitor at the CAP pin, it is requested to be issued before the SET/RESET command | RST | [7] | Software reset bit | 0¹ | Normal Operation, this bit self clears | |
| RST | [6] | Reset Sensor | 0¹ | Setting this bit will reset the sensor | TEMP-tst | [6] | Temp test | 0¹ | Factory-use register | |
| SET | [5] | Set Sensor | 0¹ | Setting this bit will set the sensor | ST_XYZ | [5] | Selftest check | 0¹ | Set this bit an execute TM command, the result can be read as bit ST-XYZ_OK | |
| No Boost | [4] | No boost | 0¹ | Disable the charge pump | Z-inhibit | [4] | Z-inhibit | 0¹ | Factory-use register | |
| CM Freq1² | [3] | Continuous Measurement bit 1 | 0¹ | Controls the continuous measurement rate of the chip | Y-inhibit | [3] | Y-inhibit | 0¹ | Factory-use register | |
| CM Freq0² | [2] | Continuous Measurement bit 0 | 0¹ | Controls the continuous measurement rate of the chip | X-inhibit | [2] | X-inhibit | 0¹ | Factory-use register | |
| Cont Mode On | [1] | Continuous Measurement Mode | 0¹ | Setting this bit enables Continuous Measurement Mode | BW1³ | [1] | Bandwidth bit | 0¹ | Controls the output resolution and measurement time | |
| TM | [0] | Take Measurement | 0¹ | Setting this bit will initiate a reading | BW0³ | [0] | Bandwidth bit | 0¹ | Controls the output resolution and measurement time | |
Notes:
¹ - This is the value on power-up and reset
² - For more details see the Continuous Measurement Mode section
³ - For more details see the Output Resolution and Measurement Time section
| Continuous Measurement Mode Settings | ||
|---|---|---|
| CM Freq1 | CM Freq0 | Frequency |
| 0 | 0 | 1.5 Hz |
| 0 | 1 | 13 Hz |
| 1 | 0 | 25 Hz |
| 1 | 1 | 50 Hz |
| Bandwidth Output Resolution and Measurement Time | |||
|---|---|---|---|
| BW1 | BW0 | Output Resolution | Measurement Time |
| 0 | 0 | 16 bits | 7.92 mS |
| 0 | 1 | 16 bits | 4.08 mS |
| 1 | 0 | 14 bits | 2.16 mS |
| 1 | 1 | 12 bits | 1.20 mS |
Here is the series of commands to acquire a set of magnetometer data from the Pmod CMPS2 via pseudo I²C code.
I2CBegin(0xA0); //device ID 0x30 with a write (0) bit
I2CWrite(0x07); //address 0x07 corresponds to Control Register 0
I2CWrite(0x01); //0x01 initiates a data acquisition
I2CBegin(0xA0); //device ID 0x30 with a write (0) bit
I2CWrite(0x03); //indicate you wish to interact with address 0x03
I2CBegin(0xA1); //device ID 0x30 with a read (1) bit
I2CBegin(0xA0); //device ID 0x30 with a write (0) bit
I2CWrite(0x00); //address 0x00 as the first register to be read
I2CBegin(0xA1); //device ID 0x30 with a read (1) bit
I2CReadMultiple(6); //read six bytes, sending an ACK to the slave device between each byte received and a NACK after the last byte
The Pmod CMPS2 is an ideal Pmod to use as a compass. Like all compasses, it is recommended that the Pmod CMPS2 is calibrated before using the module.
To calibrate the magnetometer, the offset associated with the magnetic sensors and the environment needs to be calculated and removed from future measurements.
The internal offset can be calculated and accounted for through the following method:
I2CBegin(0xA0); //device ID 0x30 with a write (0) bit
I2CWrite(0x07); //address 0x07 corresponds to Control Register 0
I2CWrite(0x80); //0x80 refills the capacitor
I2CBegin(0xA0); //device ID 0x30 with a write (0) bit
I2CWrite(0x07); //address 0x07 corresponds to Control Register 0
I2CWrite(0x20); //0x20 starts the SET action
I2CBegin(0xA0); //device ID 0x30 with a write (0) bit
I2CWrite(0x07); //address 0x07 corresponds to Control Register 0
I2CWrite(0x01); //0x01 initiates a data acquisition
I2CBegin(0xA0); //device ID 0x30 with a write (0) bit
I2CWrite(0x03); //indicate you wish to interact with address 0x03
I2CBegin(0xA1); //device ID 0x30 with a read (1) bit
I2CBegin(0xA0); //device ID 0x30 with a write (0) bit
I2CWrite(0x00); //address 0x00 as the first register to be read
I2CBegin(0xA1); //device ID 0x30 with a read (1) bit
I2CReadMultiple(6); //read six bytes, sending an ACK to the slave device between each byte received and a NACK after the last byte
I2CBegin(0xA0); //device ID 0x30 with a write (0) bit
I2CWrite(0x07); //address 0x07 corresponds to Control Register 0
I2CWrite(0x80); //0x80 refills the capacitor
I2CBegin(0xA0); //device ID 0x30 with a write (0) bit
I2CWrite(0x07); //address 0x07 corresponds to Control Register 0
I2CWrite(0x40); //0x40 starts the RESET action
I2CBegin(0xA0); //device ID 0x30 with a write (0) bit
I2CWrite(0x07); //address 0x07 corresponds to Control Register 0
I2CWrite(0x01); //0x01 initiates a data acquisition
I2CBegin(0xA0); //device ID 0x30 with a write (0) bit
I2CWrite(0x03); //indicate you wish to interact with address 0x03
I2CBegin(0xA1); //device ID 0x30 with a read (1) bit
I2CBegin(0xA0); //device ID 0x30 with a write (0) bit
I2CWrite(0x00); //address 0x00 as the first register to be read
I2CBegin(0xA1); //device ID 0x30 with a read (1) bit
I2CReadMultiple(6); //read six bytes, sending an ACK to the slave device between each byte received and a NACK after the last byte
The other method of calibration is to remove the hard iron bias introduced to the magnetometer by the surrounding environment by measuring (either continually or for a set time) all of the possible magnetometer readings in a Cartesian sphere and keep track of the highest and lowest readings for each axis. The offset can then be calculated in the same fashion as described above with the SET and RESET actions. The advantage of this method is when the Pmod CMPS2 is continually changing locations or when other external magnetic fields may be introduced into the test environment.
The Memsic MMC34160PJ provides data for each axis in units of Gauss, but the information is generally more legible when presented as a compass heading. The method for converting Gauss units to a compass heading is provided below.
←-
An example timing diagram for reading and writing to the Pmod CMPS2 taken from the Memsic datasheet is provided below:
When using an external power supply to run the Pmod, be sure to stay within the parameters provided in Specifications.
The schematics of the Pmod CMPS2 are available here. Additional information about the humidity sensor including communication modes and specific timings of the chip can be found by checking out its datasheet here.
Example code demonstrating how to get information from the Pmod CMPS2 can be found on its Resource Center here.
If you have any questions or comments about the Pmod CMPS2, feel free to post them under the appropriate section (“Add-on Boards”) of the Digilent Forum.