Module mlx9064x::calculations [−][src]
Expand description
Calculations for turning sensor output into temperatures
The MLX90640 and MLX90641 datasheets have roughly a third of their pages dedicated to mathematical formulas, which can be a little intimidating. Fortunately most of the formulas can be simplified by assuming that treating some raw bits as a signed integer is a “free” operation, and that shifting bits to the left or right is simpler to write using << and >>. In other words:
- If you see an operation similar to $$ \mathrm{If } K_{Foo} \gt (2^n - 1) \to K_{Foo} = K_{Foo} - (2^{n + 1}) $$ It is converting an unsigned integer to a signed one. The portions in parentheses are typically written as the actual value instead of a formula, so for example instead of 27 - 1 and 28, 127 and 256 will be used.
- Masking a value off with a logical AND, followed by a division by a power of two. This is just extracting some of the bits out of a larger word (the word size for these cameras is 16 bits).
- Building off of the previous item, multiplication and division by powers of two are used extensively in the datasheet to perform operations that would typically be written as a logical bit shift to the left (division) or right (multiplication). Be aware that not all divisions by a power of two can be rewritten as bit shifts; sometimes they’re converting a fixed-point value to a floating-point one.
An example of these points from section 11.1.1 of the MLX90640 datasheet:
\begin{align*} K_{Vdd} =& \frac{\eeprom{0x2433} \And \text{ 0xFF00}}{2^8} \newline &\mathrm{If } K_{Vdd} \gt 127 \to K_{Vdd} = K_{Vdd} - 256 \end{align*}
Can be written in Rust as:
fn read_eeprom(address: u16) -> u16 {
unimplemented!();
}
let raw_k_v_dd = ((read_eeprom(0x2433) & 0xFF00) >> 8) as u8;
let k_v_dd = i8::from_be_bytes(raw_k_v_dd.to_be_bytes());
Non-standard integer widths (like 4 or 10) can easily be converted to signed integers with sign extension.
Glossary
- $\alpha$, alpha
- Sensitivity coefficient.
- CP
- Compensation pixel.
- $\varepsilon$, emissivity
- A measure of how well a material emits IR radiation. For a better explanation, see Wikipedia.
- K
- Prefix for constants.
- PTAT
- Proportional to ambient temperature
- $T_a$
- Ambient temperature of the camera.
- $T_{a_{0}}$
- Ambient temperature reference, 25.0 ℃. If it looks like 0, it's probably "o" as this value is really only used in one place.
- $T_o$
- Object temperature, meaning the temperature an individual pixel has detected for an object.
- $V_{DD}$
- Pixel supply voltage.
- $V_{DD_{25}}$
- Pixel supply voltage reference at 25.0 ℃.
Structs
Values that are common to all pixels in a given frame.
The non-pixel values read from the camera’s RAM for each frame.
Functions
Calculate the ambient temperature ($T_a$)
Calculate $\Delta V$
Calculate the temperature measured by a pixel from its raw IR measurement.
Calculate a measurement of raw IR captured by a single pixel
Calculate the temperature for all pixels, starting from the raw IR data
Calculate a measurement of raw IR data for all pixels
Calculate the temperature from all pixels, starting with the raw data from the camera
Calculate the sensitivity correction coefficient
Calculate $T_{a - r}$
Calculate $V_{DD}$
Calculate $V_{PTAT_{art}}$