Subsection12.3.3Part 3: The LSM303AGR, and Its Datasheet
Our device is the STMicro LSM303AGR, the chip whose WHO_AM_I register we read yesterday. It carries a 3-axis accelerometer, a 3-axis magnetometer, and a temperature sensor; weāll only use the accelerometer. Inside it (FigureĀ 12.3.13), the signal follows the path we just discussed: a pair of variable capacitors per axis, then, through a multiplexer, one charge amplifier (a capacitance-to-voltage circuit) and one analog-to-digital converter shared by all three axes, and control logic that puts the result on the I2C bus. You interact with the chip through its control and data registers, over I2C (SPI is the other option, and the breakout wires it for I2C by default), and through hardware interrupt pins weāre not using.
Figure12.3.13.The LSM303AGRās block diagram, from its datasheet. The accelerometer is the upper half, boxed in blue: six sense capacitors, a pair per axis (X±, Y±, Z±), feed a multiplexer, and the three axes share one charge amplifier and one analog-to-digital converter behind it, the same architecture as the STM32C031C6ās ADC (ChapterĀ 6), which likewise multiplexes several input channels through one shared converter. Control logic answers on the SCL and SDA pins, boxed in red (the datasheet prints them SCL/SPC and SDA/SDI/SDO, because the same pins serve SPI). The lower half is a magnetometer, which we donāt use; the chip also contains a temperature sensor.
The signal follows the path we just discussed: a pair of variable capacitors per axis, then, through a multiplexer, one charge amplifier (a capacitance-to-voltage circuit) and one analog-to-digital converter shared by all three axes, and control logic that puts the result on the I2C bus.
You interact with it through control and data registers, over I2C (SPI is the other option; the breakout wires it for I2C by default), and through hardware interrupt pins weāre not using.
The accelerometer is the boxed upper half: six sense capacitors, a pair per axis, into the multiplexer, and the one charge amplifier and A/D converter they share.
Inside the sensor, an A/D converter turns the amplified signal into a number, as the ADC on our microcontroller turns a voltage into a number.
We also choose the measurement range: ±2 g, ±4 g, ±8 g, or ±16 g, where 1 g is the acceleration of gravity, 9.8 m/s², and a milli-g (mg) is a thousandth of that. The larger the range, the more acceleration each step has to cover.
A step is one least significant bit of the output: the smallest change in acceleration that changes the number. The size of a step is the sensitivity, in milli-g per step.
The next number to take from the datasheet is the size of one step of the converterās output. The A/D converter inside the sensor works like the ADC on our microcontroller: it turns an analog quantity, here the amplified signal from the sense capacitors, into a number with a fixed number of bits. One step is one least significant bit of that number: the smallest change in acceleration that changes the output. The size of that step is the sensitivity, and it depends on two choices the datasheet lets us make: the number of bits (the more bits, the finer the steps) and the measurement range (the larger the range, the more acceleration each step has to cover). We can derive it before we read it off the table.
The datasheetās sensor-characteristics table (LSM303AGR datasheet, §2.1, Table 3, pp. 13ā14) says how acceleration at the input is turned into bits at the output. The sensorās A/D converter turns a continuous signal into a digital one, and the datasheet lets us choose how many bits we get (8, 10, or 12) and the measurement range: ±2 g, ±4 g, ±8 g, or ±16 g, where 1 g is the acceleration of gravity, 9.8 m/s², and one milli-g (mg) is a thousandth of that. Weāll use ±2 g, and the sensorās normal resolution mode, which gives 10 valid bits per reading.
The sensitivity is the size of one step of the output: how much acceleration one least significant bit stands for. From the range and the bit count, compute it, in milli-g per step. This is the same calculation we did for the ADC (ChapterĀ 6): the full range, divided into \(2^{bits}\) bins.
The sensitivity is the size of one step: how much acceleration does one least significant bit stand for? Compute it, in milli-g (mg), for the ±2 g range in normal mode, which gives 10 valid bits. (The same calculation as for the ADC: the full range, divided into 2^bits bins.)
Figure12.3.18.The sensor-characteristics tableās sensitivity and zero-g offset rows (LSM303AGR datasheet §2.1, Table 3, pp. 13ā14). Top: the full-scale range rows. Middle: one sensitivity row per range and resolution mode (high-resolution is 12 bits, normal 10, low-power 8). At ±2 g in normal mode the table prints 3.9 mg/LSB, milli-g per least significant bit, the size of one step: the number we derived as 4 g / 2¹Ⱐ= 3.90625 mg (the ±2 g range spans 4 g, from ā2 g to +2 g). Bottom: the zero-g offset row. A sensor lying perfectly flat reads typically ±40 mg away from the true value, and the tableās Min and Max columns allow ±80.
The unmasked table confirms the arithmetic. The three modes trade resolution against speed: fewer bits means bigger steps, and low-power mode runs at rates the other two cannot.
The zero-g offset row is below it: lying perfectly flat, the sensor reads typically ±40 mg away from the true value, and the datasheetās Min and Max columns allow ±80. 40 mg would be ten of our steps, 80 mg would be twenty, and a significant amount of error.
The table in FigureĀ 12.3.18 confirms the arithmetic. The three modes trade resolution against speed: fewer bits means bigger steps, and low-power mode runs at rates the other two cannot. The zero-g offset row is below it: lying perfectly flat, the sensor reads typically ±40 mg away from the true value, and the datasheetās Min and Max columns allow ±80. 40 mg would be ten of our steps, 80 mg would be twenty, and a significant amount of error.
Figure12.3.20.The breakout boardās schematic (partial). The board carries what the chip needs: pull-up resistors on SDA and SCL, and a regulator to supply the chip. The 6-pin header brings power, ground, SCL, SDA and the magnetometer interrupt out to the breadboard.