MLX90632 Driver Library  a258525c
Universal MCU library for the 90632
MLX90632 Internal library functions

range measurements implementation for MLX90632 driver with virtual i2c communication More...

Macros

#define POW10   10000000000LL
 
#define VERSION   "test"
 
#define STATIC   static
 
#define POW10   10000000000LL
 
#define VERSION   "test"
 
#define STATIC   static
 

Functions

int mlx90632_start_measurement (void)
 Trigger start measurement for mlx90632. More...
 
STATIC int32_t mlx90632_channel_new_select (int32_t ret, uint8_t *channel_new, uint8_t *channel_old)
 Based on mlx90632_start_measurement return value fill channel_new and channel_old variables with proper values. More...
 
STATIC int32_t mlx90632_read_temp_ambient_raw (int16_t *ambient_new_raw, int16_t *ambient_old_raw)
 Read ambient raw old and new values based on mlx90632_start_measurement return value. More...
 
STATIC int32_t mlx90632_read_temp_object_raw (int32_t start_measurement_ret, int16_t *object_new_raw, int16_t *object_old_raw)
 Read object raw old and new values based on mlx90632_start_measurement return value. More...
 
int32_t mlx90632_read_temp_raw (int16_t *ambient_new_raw, int16_t *ambient_old_raw, int16_t *object_new_raw, int16_t *object_old_raw)
 Read raw ambient and object temperature. More...
 
int32_t mlx90632_read_temp_raw_burst (int16_t *ambient_new_raw, int16_t *ambient_old_raw, int16_t *object_new_raw, int16_t *object_old_raw)
 Read raw ambient and object temperature in sleeping step mode. More...
 
double mlx90632_preprocess_temp_ambient (int16_t ambient_new_raw, int16_t ambient_old_raw, int16_t Gb)
 Calculation of raw ambient output. More...
 
double mlx90632_preprocess_temp_object (int16_t object_new_raw, int16_t object_old_raw, int16_t ambient_new_raw, int16_t ambient_old_raw, int16_t Ka)
 Calculation of raw object output. More...
 
double mlx90632_calc_temp_ambient (int16_t ambient_new_raw, int16_t ambient_old_raw, int32_t P_T, int32_t P_R, int32_t P_G, int32_t P_O, int16_t Gb)
 Calculation of ambient temperature. More...
 
STATIC double mlx90632_calc_temp_object_iteration (double prev_object_temp, int32_t object, double TAdut, int32_t Ga, int32_t Fa, int32_t Fb, int16_t Ha, int16_t Hb, double emissivity)
 Iterative calculation of object temperature. More...
 
STATIC double mlx90632_calc_temp_object_iteration_reflected (double prev_object_temp, int32_t object, double TAdut, double TaTr4, int32_t Ga, int32_t Fa, int32_t Fb, int16_t Ha, int16_t Hb, double emissivity)
 Iterative calculation of object temperature when the environment temperature differs from the sensor temperature. More...
 
void mlx90632_set_emissivity (double value)
 Set emissivity which is retained in single variable. More...
 
double mlx90632_get_emissivity (void)
 Read value of emissivity. More...
 
double mlx90632_calc_temp_object (int32_t object, int32_t ambient, int32_t Ea, int32_t Eb, int32_t Ga, int32_t Fa, int32_t Fb, int16_t Ha, int16_t Hb)
 Calculation of object temperature. More...
 
double mlx90632_calc_temp_object_reflected (int32_t object, int32_t ambient, double reflected, int32_t Ea, int32_t Eb, int32_t Ga, int32_t Fa, int32_t Fb, int16_t Ha, int16_t Hb)
 Calculation of object temperature when the environment temperature differs from the sensor temperature. More...
 
int32_t mlx90632_init (void)
 Initialize MLX90632 driver and confirm EEPROM version. More...
 
int32_t mlx90632_addressed_reset (void)
 Trigger system reset for mlx90632. More...
 
int32_t mlx90632_get_measurement_time (uint16_t meas)
 Reads the refresh rate and calculates the time needed for a single measurment from the EEPROM settings. More...
 
int32_t mlx90632_calculate_dataset_ready_time (void)
 Reads the refresh rate and calculates the time needed for a whole measurment table from the EEPROM settings. More...
 
int32_t mlx90632_start_measurement_burst (void)
 Trigger start of burst measurement for mlx90632. More...
 
STATIC int32_t mlx90632_unlock_eeporm ()
 
STATIC int32_t mlx90632_wait_for_eeprom_not_busy ()
 
STATIC int32_t mlx90632_erase_eeprom (uint16_t address)
 
STATIC int32_t mlx90632_write_eeprom (uint16_t address, uint16_t data)
 
int32_t mlx90632_set_refresh_rate (mlx90632_meas_t measRate)
 Sets the refresh rate of the sensor using the MLX90632_EE_MEAS_1 and MLX90632_EE_MEAS_2 registers. More...
 
mlx90632_meas_t mlx90632_get_refresh_rate (void)
 Gets the value in MLX90632_EE_MEAS_1 and converts it to the appropriate MLX90632_MEAS enum. More...
 
STATIC int32_t mlx90632_read_temp_ambient_raw_extended (int16_t *ambient_new_raw, int16_t *ambient_old_raw)
 Read ambient raw old and new values for the extended range based on mlx90632_start_measurement return value. More...
 
STATIC int32_t mlx90632_read_temp_object_raw_extended (int16_t *object_new_raw)
 Read object raw values for the extended range based on mlx90632_start_measurement return value. More...
 
int32_t mlx90632_read_temp_raw_extended (int16_t *ambient_new_raw, int16_t *ambient_old_raw, int16_t *object_new_raw)
 Read raw ambient and object temperature for extended range. More...
 
int32_t mlx90632_read_temp_raw_extended_burst (int16_t *ambient_new_raw, int16_t *ambient_old_raw, int16_t *object_new_raw)
 Read raw ambient and object temperature for extended range sleeping step mode. More...
 
double mlx90632_preprocess_temp_ambient_extended (int16_t ambient_new_raw, int16_t ambient_old_raw, int16_t Gb)
 Calculation of raw ambient output for the extended range. More...
 
double mlx90632_preprocess_temp_object_extended (int16_t object_new_raw, int16_t ambient_new_raw, int16_t ambient_old_raw, int16_t Ka)
 Calculation of raw object output for the extended range. More...
 
double mlx90632_calc_temp_ambient_extended (int16_t ambient_new_raw, int16_t ambient_old_raw, int32_t P_T, int32_t P_R, int32_t P_G, int32_t P_O, int16_t Gb)
 Calculation of ambient temperature for the extended range. More...
 
static double mlx90632_calc_temp_object_iteration_extended (double prev_object_temp, int32_t object, double TAdut, double TaTr4, int32_t Ga, int32_t Fa, int32_t Fb, int16_t Ha, int16_t Hb, double emissivity)
 Iterative calculation of object temperature. More...
 
double mlx90632_calc_temp_object_extended (int32_t object, int32_t ambient, double reflected, int32_t Ea, int32_t Eb, int32_t Ga, int32_t Fa, int32_t Fb, int16_t Ha, int16_t Hb)
 Calculation of object temperature for the extended range. More...
 
int32_t mlx90632_set_meas_type (uint8_t type)
 Switch the measurement type of the MLX90632. More...
 
int32_t mlx90632_get_meas_type (void)
 Get the current measurement type set in the MLX90632. More...
 

Variables

static const char mlx90632version [] = { VERSION }
 
static double emissivity = 0.0
 

Detailed Description

range measurements implementation for MLX90632 driver with virtual i2c communication

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Macro Definition Documentation

#define POW10   10000000000LL

Definition at line 34 of file mlx90632_extended_meas.c.

#define POW10   10000000000LL

Definition at line 35 of file mlx90632.c.

#define STATIC   static

Definition at line 41 of file mlx90632_extended_meas.c.

#define STATIC   static

Definition at line 44 of file mlx90632.c.

#define VERSION   "test"

Definition at line 37 of file mlx90632_extended_meas.c.

#define VERSION   "test"

Definition at line 38 of file mlx90632.c.

Function Documentation

int32_t mlx90632_addressed_reset ( void  )

Trigger system reset for mlx90632.

Perform full reset of mlx90632 using reset command. It also waits for at least 150us to ensure the mlx90632 device is properly reset and ready for further communications.

Return values
<0Something failed. Check errno.h for more information
0The mlx90632 device was properly reset and is now ready for communication.
Note
This function is using usleep so it is blocking!

Definition at line 475 of file mlx90632.c.

476 {
477  int32_t ret;
478 
479  ret = mlx90632_i2c_write(0x3005, MLX90632_RESET_CMD);
480  if (ret < 0)
481  return ret;
482 
483  usleep(150, 200);
484 
485  return 0;
486 }
int32_t mlx90632_i2c_write(int16_t register_address, uint16_t value)
Write value to register_address of the mlx90632.
void usleep(int min_range, int max_range)
Blocking function for sleeping in microseconds.
#define MLX90632_RESET_CMD
Reset sensor (address or global)
Definition: mlx90632.h:187
double mlx90632_calc_temp_ambient ( int16_t  ambient_new_raw,
int16_t  ambient_old_raw,
int32_t  P_T,
int32_t  P_R,
int32_t  P_G,
int32_t  P_O,
int16_t  Gb 
)

Calculation of ambient temperature.

DSPv5 implementation of ambient temperature calculation

Parameters
[in]ambient_new_rawambient temperature from MLX90632_RAM_3. The channel 1 or 2 is determined by value in MLX90632_STAT_CYCLE_POS
[in]ambient_old_rawambient temperature from MLX90632_RAM_3. The channel 1 or 2 is determined by value not in MLX90632_STAT_CYCLE_POS
[in]P_TRegister value on MLX90632_EE_P_T
[in]P_RRegister value on MLX90632_EE_P_R
[in]P_GRegister value on MLX90632_EE_P_G
[in]P_ORegister value on MLX90632_EE_P_O
[in]GbRegister value on MLX90632_EE_Gb
Returns
Calculated ambient temperature degrees Celsius

Definition at line 264 of file mlx90632.c.

266 {
267  double Asub, Bsub, Ablock, Bblock, Cblock, AMB;
268 
269  AMB = mlx90632_preprocess_temp_ambient(ambient_new_raw, ambient_old_raw, Gb);
270 
271  Asub = ((double)P_T) / (double)17592186044416.0;
272  Bsub = (double)AMB - ((double)P_R / (double)256.0);
273  Ablock = Asub * (Bsub * Bsub);
274  Bblock = (Bsub / (double)P_G) * (double)1048576.0;
275  Cblock = (double)P_O / (double)256.0;
276 
277  return Bblock + Ablock + Cblock;
278 }
double mlx90632_preprocess_temp_ambient(int16_t ambient_new_raw, int16_t ambient_old_raw, int16_t Gb)
Calculation of raw ambient output.
Definition: mlx90632.c:242
double mlx90632_calc_temp_ambient_extended ( int16_t  ambient_new_raw,
int16_t  ambient_old_raw,
int32_t  P_T,
int32_t  P_R,
int32_t  P_G,
int32_t  P_O,
int16_t  Gb 
)

Calculation of ambient temperature for the extended range.

Parameters
[in]ambient_new_rawambient temperature from MLX90632_RAM_3 from meas num 17
[in]ambient_old_rawambient temperature from MLX90632_RAM_3 from meas num 18
[in]P_TRegister value on MLX90632_EE_P_T
[in]P_RRegister value on MLX90632_EE_P_R
[in]P_GRegister value on MLX90632_EE_P_G
[in]P_ORegister value on MLX90632_EE_P_O
[in]GbRegister value on MLX90632_EE_Gb
Returns
Calculated ambient temperature degrees Celsius

Definition at line 207 of file mlx90632_extended_meas.c.

209 {
210  double Asub, Bsub, Ablock, Bblock, Cblock, AMB;
211 
212  AMB = mlx90632_preprocess_temp_ambient_extended(ambient_new_raw, ambient_old_raw, Gb);
213 
214  Asub = ((double)P_T) / (double)17592186044416.0;
215  Bsub = AMB - ((double)P_R / (double)256.0);
216  Ablock = Asub * (Bsub * Bsub);
217  Bblock = (Bsub / (double)P_G) * (double)1048576.0;
218  Cblock = (double)P_O / (double)256.0;
219 
220  return Bblock + Ablock + Cblock;
221 }
double mlx90632_preprocess_temp_ambient_extended(int16_t ambient_new_raw, int16_t ambient_old_raw, int16_t Gb)
Calculation of raw ambient output for the extended range.
double mlx90632_calc_temp_object ( int32_t  object,
int32_t  ambient,
int32_t  Ea,
int32_t  Eb,
int32_t  Ga,
int32_t  Fa,
int32_t  Fb,
int16_t  Ha,
int16_t  Hb 
)

Calculation of object temperature.

DSPv5 implementation of object temperature calculation with customer calibration data

Parameters
[in]objectobject temperature from mlx90632_preprocess_temp_object
[in]ambientambient temperature from mlx90632_preprocess_temp_ambient
[in]EaRegister value on MLX90632_EE_Ea
[in]EbRegister value on MLX90632_EE_Eb
[in]GaRegister value on MLX90632_EE_Ga
[in]FbRegister value on MLX90632_EE_Fb
[in]FaRegister value on MLX90632_EE_Fa
[in]HaRegister value on MLX90632_EE_Ha
[in]HbRegister value on MLX90632_EE_Hb
Note
emissivity Value provided by user of the object emissivity using mlx90632_set_emissivity function.
Returns
Calculated object temperature in milliCelsius

Definition at line 389 of file mlx90632.c.

392 {
393  double kEa, kEb, TAdut;
394  double temp = 25.0;
395  double tmp_emi = mlx90632_get_emissivity();
396  int8_t i;
397 
398  kEa = ((double)Ea) / ((double)65536.0);
399  kEb = ((double)Eb) / ((double)256.0);
400  TAdut = (((double)ambient) - kEb) / kEa + 25;
401 
402  //iterate through calculations
403  for (i = 0; i < 5; ++i)
404  {
405  temp = mlx90632_calc_temp_object_iteration(temp, object, TAdut, Ga, Fa, Fb, Ha, Hb, tmp_emi);
406  }
407  return temp;
408 }
STATIC double mlx90632_calc_temp_object_iteration(double prev_object_temp, int32_t object, double TAdut, int32_t Ga, int32_t Fa, int32_t Fb, int16_t Ha, int16_t Hb, double emissivity)
Iterative calculation of object temperature.
Definition: mlx90632.c:300
double mlx90632_get_emissivity(void)
Read value of emissivity.
Definition: mlx90632.c:377
double mlx90632_calc_temp_object_extended ( int32_t  object,
int32_t  ambient,
double  reflected,
int32_t  Ea,
int32_t  Eb,
int32_t  Ga,
int32_t  Fa,
int32_t  Fb,
int16_t  Ha,
int16_t  Hb 
)

Calculation of object temperature for the extended range.

Parameters
[in]objectobject temperature from mlx90632_preprocess_temp_object
[in]ambientsensor ambient temperature from mlx90632_preprocess_temp_ambient
[in]reflectedreflected (environment) temperature from a sensor different than the MLX90632 or acquired by other means
[in]EaRegister value on MLX90632_EE_Ea
[in]EbRegister value on MLX90632_EE_Eb
[in]GaRegister value on MLX90632_EE_Ga
[in]FbRegister value on MLX90632_EE_Fb
[in]FaRegister value on MLX90632_EE_Fa
[in]HaRegister value on MLX90632_EE_Ha
[in]HbRegister value on MLX90632_EE_Hb
Note
emissivity Value provided by user of the object emissivity using mlx90632_set_emissivity function.
Returns
Calculated object temperature in milliCelsius

Definition at line 267 of file mlx90632_extended_meas.c.

270 {
271  double kEa, kEb, TAdut;
272  double temp = 25.0;
273  double tmp_emi = mlx90632_get_emissivity();
274  double TaTr4;
275  double ta4;
276  int8_t i;
277 
278  kEa = ((double)Ea) / ((double)65536.0);
279  kEb = ((double)Eb) / ((double)256.0);
280  TAdut = (((double)ambient) - kEb) / kEa + 25;
281 
282  TaTr4 = reflected + 273.15;
283  TaTr4 = TaTr4 * TaTr4;
284  TaTr4 = TaTr4 * TaTr4;
285  ta4 = TAdut + 273.15;
286  ta4 = ta4 * ta4;
287  ta4 = ta4 * ta4;
288  TaTr4 = TaTr4 - (TaTr4 - ta4) / tmp_emi;
289 
290  //iterate through calculations
291  for (i = 0; i < 5; ++i)
292  {
293  temp = mlx90632_calc_temp_object_iteration_extended(temp, object, TAdut, TaTr4, Ga, Fa / 2, Fb, Ha, Hb, tmp_emi);
294  }
295 
296  return temp;
297 }
static double mlx90632_calc_temp_object_iteration_extended(double prev_object_temp, int32_t object, double TAdut, double TaTr4, int32_t Ga, int32_t Fa, int32_t Fb, int16_t Ha, int16_t Hb, double emissivity)
Iterative calculation of object temperature.
double mlx90632_get_emissivity(void)
Read value of emissivity.
Definition: mlx90632.c:377
STATIC double mlx90632_calc_temp_object_iteration ( double  prev_object_temp,
int32_t  object,
double  TAdut,
int32_t  Ga,
int32_t  Fa,
int32_t  Fb,
int16_t  Ha,
int16_t  Hb,
double  emissivity 
)

Iterative calculation of object temperature.

DSPv5 requires 3 iterations to reduce noise for object temperature. Since each iteration requires same calculations this helper function is implemented.

Parameters
[in]prev_object_temppreviously calculated object temperature. If there is no previously calculated temperature input 25.0
[in]objectobject temperature from mlx90632_preprocess_temp_object
[in]TAdutambient temperature coefficient
[in]GaRegister value on MLX90632_EE_Ga
[in]FaRegister value on MLX90632_EE_Fa
[in]FbRegister value on MLX90632_EE_Fb
[in]HaRegister value on MLX90632_EE_Ha
[in]HbRegister value on MLX90632_EE_Hb
[in]emissivityValue provided by user of the object emissivity
Returns
Calculated object temperature for current iteration in milliCelsius

Definition at line 300 of file mlx90632.c.

303 {
304  double calcedGa, calcedGb, calcedFa, TAdut4, first_sqrt;
305  // temp variables
306  double KsTAtmp, Alpha_corr;
307  double Ha_customer, Hb_customer;
308 
309 
310  Ha_customer = Ha / ((double)16384.0);
311  Hb_customer = Hb / ((double)1024.0);
312  calcedGa = ((double)Ga * (prev_object_temp - 25)) / ((double)68719476736.0);
313  KsTAtmp = (double)Fb * (TAdut - 25);
314  calcedGb = KsTAtmp / ((double)68719476736.0);
315  Alpha_corr = (((double)(Fa * POW10)) * Ha_customer * (double)(1 + calcedGa + calcedGb)) /
316  ((double)70368744177664.0);
317  calcedFa = object / (emissivity * (Alpha_corr / POW10));
318  TAdut4 = (TAdut + 273.15) * (TAdut + 273.15) * (TAdut + 273.15) * (TAdut + 273.15);
319 
320  first_sqrt = sqrt(calcedFa + TAdut4);
321 
322  return sqrt(first_sqrt) - 273.15 - Hb_customer;
323 }
#define POW10
Definition: mlx90632.c:35
static double emissivity
Definition: mlx90632.c:371
static double mlx90632_calc_temp_object_iteration_extended ( double  prev_object_temp,
int32_t  object,
double  TAdut,
double  TaTr4,
int32_t  Ga,
int32_t  Fa,
int32_t  Fb,
int16_t  Ha,
int16_t  Hb,
double  emissivity 
)
static

Iterative calculation of object temperature.

The DSP requires few iterations to reduce noise for object temperature. Since each iteration requires same calculations this helper function is implemented.

Parameters
[in]prev_object_temppreviously calculated object temperature. If there is no previously calculated temperature input 25.0
[in]objectobject temperature from mlx90632_preprocess_temp_object_extended
[in]TAdutambient temperature coefficient
[in]TaTr4compensation coefficient for reflected (environment) temperature
[in]GaRegister value on MLX90632_EE_Ga
[in]FaRegister value on MLX90632_EE_Fa
[in]FbRegister value on MLX90632_EE_Fb
[in]HaRegister value on MLX90632_EE_Ha
[in]HbRegister value on MLX90632_EE_Hb
[in]emissivityValue provided by user of the object emissivity
Returns
Calculated object temperature for current iteration in milliCelsius

Definition at line 244 of file mlx90632_extended_meas.c.

247 {
248  double calcedGa, calcedGb, calcedFa, first_sqrt;
249  // temp variables
250  double KsTAtmp, Alpha_corr;
251  double Ha_customer, Hb_customer;
252 
253  Ha_customer = Ha / ((double)16384.0);
254  Hb_customer = Hb / ((double)1024.0);
255  calcedGa = ((double)Ga * (prev_object_temp - 25)) / ((double)68719476736.0);
256  KsTAtmp = (double)Fb * (TAdut - 25);
257  calcedGb = KsTAtmp / ((double)68719476736.0);
258  Alpha_corr = (((double)(Fa * POW10)) * Ha_customer * (double)(1.0 + calcedGa + calcedGb)) /
259  ((double)70368744177664.0);
260  calcedFa = object / (emissivity * (Alpha_corr / POW10));
261 
262  first_sqrt = sqrt(calcedFa + TaTr4);
263 
264  return sqrt(first_sqrt) - 273.15 - Hb_customer;
265 }
#define POW10
static double emissivity
Definition: mlx90632.c:371
STATIC double mlx90632_calc_temp_object_iteration_reflected ( double  prev_object_temp,
int32_t  object,
double  TAdut,
double  TaTr4,
int32_t  Ga,
int32_t  Fa,
int32_t  Fb,
int16_t  Ha,
int16_t  Hb,
double  emissivity 
)

Iterative calculation of object temperature when the environment temperature differs from the sensor temperature.

DSPv5 requires 3 iterations to reduce noise for object temperature. Since each iteration requires same calculations this helper function is implemented.

Parameters
[in]prev_object_temppreviously calculated object temperature. If there is no previously calculated temperature input 25.0
[in]objectobject temperature from mlx90632_preprocess_temp_object
[in]TAdutambient temperature coefficient
[in]TaTr4compensation coefficient for reflected (environment) temperature. The compensation coefficient is calculated from ambient temperature either from a sensor different than the MLX90632 or acquired by other means.
[in]GaRegister value on MLX90632_EE_Ga
[in]FaRegister value on MLX90632_EE_Fa
[in]FbRegister value on MLX90632_EE_Fb
[in]HaRegister value on MLX90632_EE_Ha
[in]HbRegister value on MLX90632_EE_Hb
[in]emissivityValue provided by user of the object emissivity
Returns
Calculated object temperature for current iteration in milliCelsius

Definition at line 348 of file mlx90632.c.

351 {
352  double calcedGa, calcedGb, calcedFa, first_sqrt;
353  // temp variables
354  double KsTAtmp, Alpha_corr;
355  double Ha_customer, Hb_customer;
356 
357  Ha_customer = Ha / ((double)16384.0);
358  Hb_customer = Hb / ((double)1024.0);
359  calcedGa = ((double)Ga * (prev_object_temp - 25)) / ((double)68719476736.0);
360  KsTAtmp = (double)Fb * (TAdut - 25);
361  calcedGb = KsTAtmp / ((double)68719476736.0);
362  Alpha_corr = (((double)(Fa * POW10)) * Ha_customer * (double)(1 + calcedGa + calcedGb)) /
363  ((double)70368744177664.0);
364  calcedFa = object / (emissivity * (Alpha_corr / POW10));
365 
366  first_sqrt = sqrt(calcedFa + TaTr4);
367 
368  return sqrt(first_sqrt) - 273.15 - Hb_customer;
369 }
#define POW10
Definition: mlx90632.c:35
static double emissivity
Definition: mlx90632.c:371
double mlx90632_calc_temp_object_reflected ( int32_t  object,
int32_t  ambient,
double  reflected,
int32_t  Ea,
int32_t  Eb,
int32_t  Ga,
int32_t  Fa,
int32_t  Fb,
int16_t  Ha,
int16_t  Hb 
)

Calculation of object temperature when the environment temperature differs from the sensor temperature.

when the object has emissivity lower than 1 then it does not just emit InfraRed light, but also reflects it. That is why measurement of the ambient temperature around object is important to help calculating more precise object temperature. This function makes it possible to add object environment temperature and offset it with sensor's ambient temperature to calculate more precise object temperature. DSPv5 implementation of object temperature calculation with customer calibration data

Parameters
[in]objectobject temperature from mlx90632_preprocess_temp_object
[in]ambientsensor ambient temperature from mlx90632_preprocess_temp_ambient
[in]reflectedreflected (environment) temperature from a sensor different than the MLX90632 or acquired by other means
[in]EaRegister value on MLX90632_EE_Ea
[in]EbRegister value on MLX90632_EE_Eb
[in]GaRegister value on MLX90632_EE_Ga
[in]FbRegister value on MLX90632_EE_Fb
[in]FaRegister value on MLX90632_EE_Fa
[in]HaRegister value on MLX90632_EE_Ha
[in]HbRegister value on MLX90632_EE_Hb
Note
emissivity Value provided by user of the object emissivity using mlx90632_set_emissivity function.
Returns
Calculated object temperature in milliCelsius

Definition at line 410 of file mlx90632.c.

413 {
414  double kEa, kEb, TAdut;
415  double temp = 25.0;
416  double tmp_emi = mlx90632_get_emissivity();
417  double TaTr4;
418  double ta4;
419  int8_t i;
420 
421  kEa = ((double)Ea) / ((double)65536.0);
422  kEb = ((double)Eb) / ((double)256.0);
423  TAdut = (((double)ambient) - kEb) / kEa + 25;
424 
425  TaTr4 = reflected + 273.15;
426  TaTr4 = TaTr4 * TaTr4;
427  TaTr4 = TaTr4 * TaTr4;
428  ta4 = TAdut + 273.15;
429  ta4 = ta4 * ta4;
430  ta4 = ta4 * ta4;
431  TaTr4 = TaTr4 - (TaTr4 - ta4) / tmp_emi;
432 
433  //iterate through calculations
434  for (i = 0; i < 5; ++i)
435  {
436  temp = mlx90632_calc_temp_object_iteration_reflected(temp, object, TAdut, TaTr4, Ga, Fa, Fb, Ha, Hb, tmp_emi);
437  }
438  return temp;
439 }
double mlx90632_get_emissivity(void)
Read value of emissivity.
Definition: mlx90632.c:377
STATIC double mlx90632_calc_temp_object_iteration_reflected(double prev_object_temp, int32_t object, double TAdut, double TaTr4, int32_t Ga, int32_t Fa, int32_t Fb, int16_t Ha, int16_t Hb, double emissivity)
Iterative calculation of object temperature when the environment temperature differs from the sensor ...
Definition: mlx90632.c:348
int32_t mlx90632_calculate_dataset_ready_time ( void  )

Reads the refresh rate and calculates the time needed for a whole measurment table from the EEPROM settings.

The function is returning valid measurement time only for burst mode measurements. An error will be returned if it is called with a continuous measurement type parameter.

Return values
>=0Refresh time in ms
<0Something went wrong. Check errno.h for more details.

Definition at line 503 of file mlx90632.c.

504 {
505  int32_t ret;
506  int32_t refresh_time;
507 
508  ret = mlx90632_get_meas_type();
509  if (ret < 0)
510  return ret;
511 
513  return -EINVAL;
514 
515  if (ret == MLX90632_MTYP_MEDICAL_BURST)
516  {
518  if (ret < 0)
519  return ret;
520 
521  refresh_time = ret;
522 
524  if (ret < 0)
525  return ret;
526 
527  refresh_time = refresh_time + ret;
528  }
529  else
530  {
532  if (ret < 0)
533  return ret;
534 
535  refresh_time = ret;
536 
538  if (ret < 0)
539  return ret;
540 
541  refresh_time = refresh_time + ret;
542 
544  if (ret < 0)
545  return ret;
546 
547  refresh_time = refresh_time + ret;
548  }
549 
550  return refresh_time;
551 }
#define MLX90632_MTYP_MEDICAL_BURST
Definition: mlx90632.h:197
#define MLX90632_EE_MEDICAL_MEAS2
Medical measurement 2 16bit.
Definition: mlx90632.h:112
#define MLX90632_EE_MEDICAL_MEAS1
Medical measurement 1 16bit.
Definition: mlx90632.h:111
#define MLX90632_EE_EXTENDED_MEAS3
Extended measurement 3 16bit.
Definition: mlx90632.h:115
int32_t mlx90632_get_measurement_time(uint16_t meas)
Reads the refresh rate and calculates the time needed for a single measurment from the EEPROM setting...
Definition: mlx90632.c:488
#define MLX90632_MTYP_EXTENDED_BURST
Definition: mlx90632.h:198
int32_t mlx90632_get_meas_type(void)
Get the current measurement type set in the MLX90632.
#define MLX90632_EE_EXTENDED_MEAS2
Extended measurement 2 16bit.
Definition: mlx90632.h:114
#define EINVAL
From linux errno.h.
Definition: mlx90632.h:49
#define MLX90632_EE_EXTENDED_MEAS1
Extended measurement 1 16bit.
Definition: mlx90632.h:113
STATIC int32_t mlx90632_channel_new_select ( int32_t  ret,
uint8_t *  channel_new,
uint8_t *  channel_old 
)

Based on mlx90632_start_measurement return value fill channel_new and channel_old variables with proper values.

This is to provide a bit more flexibility in case other channels are returned and need a bit more mingeling than usual maths can provide.

So far there are just two use cases. If returned value is not 1 or 2, it will leave channel_new and channel_old unassigned.

Parameters
[in]retmlx90632_start_measurement return value
[out]*channel_newPointer to memory location where new channel value is stored
[out]*channel_oldPointer to memory location where old channel value is stored
Return values
0When both memory locations are updated as per ret
-EINVALchannel_new and channel_old were not updated

Definition at line 97 of file mlx90632.c.

98 {
99  switch (ret)
100  {
101  case 1:
102  *channel_new = 1;
103  *channel_old = 2;
104  break;
105 
106  case 2:
107  *channel_new = 2;
108  *channel_old = 1;
109  break;
110 
111  default:
112  return -EINVAL;
113  }
114  return 0;
115 }
#define EINVAL
From linux errno.h.
Definition: mlx90632.h:49
STATIC int32_t mlx90632_erase_eeprom ( uint16_t  address)

Definition at line 616 of file mlx90632.c.

617 {
618  int32_t ret = mlx90632_unlock_eeporm();
619 
620  if (ret < 0)
621  return ret;
622 
623  ret = mlx90632_i2c_write(address, 0x00);
624  if (ret < 0)
625  return ret;
626 
628  return ret;
629 }
STATIC int32_t mlx90632_unlock_eeporm()
Definition: mlx90632.c:598
STATIC int32_t mlx90632_wait_for_eeprom_not_busy()
Definition: mlx90632.c:603
int32_t mlx90632_i2c_write(int16_t register_address, uint16_t value)
Write value to register_address of the mlx90632.
double mlx90632_get_emissivity ( void  )

Read value of emissivity.

Definition at line 377 of file mlx90632.c.

378 {
379  if (emissivity == 0.0)
380  {
381  return 1.0;
382  }
383  else
384  {
385  return emissivity;
386  }
387 }
static double emissivity
Definition: mlx90632.c:371
int32_t mlx90632_get_meas_type ( void  )

Get the current measurement type set in the MLX90632.

Note
the available types are defined as MLX90632_MTYP_MEDICAL and MLX90632_MTYP_EXTENDED
Return values
=MLX90632_MTYP_MEDICAL - medical range measurement type
=MLX90632_MTYP_EXTENDED - extended range measurement type
<0Something went wrong. Consult errno.h for more details.

Definition at line 341 of file mlx90632_extended_meas.c.

342 {
343  int32_t ret;
344  uint16_t reg_ctrl;
345  uint16_t reg_temp;
346 
347  ret = mlx90632_i2c_read(MLX90632_REG_CTRL, &reg_temp);
348  if (ret < 0)
349  return ret;
350 
351  reg_ctrl = MLX90632_MTYP(reg_temp);
352 
353  if ((reg_ctrl != MLX90632_MTYP_MEDICAL) & (reg_ctrl != MLX90632_MTYP_EXTENDED))
354  return -EINVAL;
355 
356  reg_temp = MLX90632_CFG_PWR(reg_temp);
357 
358  if (reg_temp == MLX90632_PWR_STATUS_SLEEP_STEP)
359  return MLX90632_BURST_MEASUREMENT_TYPE(reg_ctrl);
360 
361  if (reg_temp != MLX90632_PWR_STATUS_CONTINUOUS)
362  return -EINVAL;
363 
364  return reg_ctrl;
365 }
int32_t mlx90632_i2c_read(int16_t register_address, uint16_t *value)
Read the register_address value from the mlx90632.
#define MLX90632_MTYP(reg_val)
Extract MTYP from Control register.
Definition: mlx90632.h:162
#define MLX90632_PWR_STATUS_SLEEP_STEP
Pwrmode sleep step.
Definition: mlx90632.h:155
#define MLX90632_MTYP_MEDICAL
Definition: mlx90632.h:195
#define MLX90632_MTYP_EXTENDED
Definition: mlx90632.h:196
#define MLX90632_BURST_MEASUREMENT_TYPE(meas_type)
The MSBit is only used in the software to indicate burst type measurement.
Definition: mlx90632.h:199
#define MLX90632_CFG_PWR(ctrl_val)
Extract the PowerMode bits.
Definition: mlx90632.h:144
#define MLX90632_PWR_STATUS_CONTINUOUS
Pwrmode continuous.
Definition: mlx90632.h:157
#define EINVAL
From linux errno.h.
Definition: mlx90632.h:49
#define MLX90632_REG_CTRL
Control Register address.
Definition: mlx90632.h:140
int32_t mlx90632_get_measurement_time ( uint16_t  meas)

Reads the refresh rate and calculates the time needed for a single measurment from the EEPROM settings.

Parameters
[in]measMeasurement to read the frefresh rate for
Return values
>=0Refresh time in ms
<0Something went wrong. Check errno.h for more details.

Definition at line 488 of file mlx90632.c.

489 {
490  int32_t ret;
491  uint16_t reg;
492 
493  ret = mlx90632_i2c_read(meas, &reg);
494  if (ret < 0)
495  return ret;
496 
498  reg = reg >> 8;
499 
500  return MLX90632_MEAS_MAX_TIME >> reg;
501 }
#define MLX90632_MEAS_MAX_TIME
Maximum measurement time in ms for the lowest possible refresh rate.
Definition: mlx90632.h:204
#define MLX90632_EE_REFRESH_RATE_MASK
Refresh Rate Mask.
Definition: mlx90632.h:131
int32_t mlx90632_i2c_read(int16_t register_address, uint16_t *value)
Read the register_address value from the mlx90632.
mlx90632_meas_t mlx90632_get_refresh_rate ( void  )

Gets the value in MLX90632_EE_MEAS_1 and converts it to the appropriate MLX90632_MEAS enum.

Return values
MLX90632_MEAS_HZ_ERRORif there is an error
refresh_rateas the mlx90632_meas_e

Definition at line 681 of file mlx90632.c.

682 {
683  int32_t ret;
684  uint16_t meas1;
685 
687  if (ret < 0)
688  return MLX90632_MEAS_HZ_ERROR;
689 
690  return MLX90632_REFRESH_RATE(meas1);
691 }
int32_t mlx90632_i2c_read(int16_t register_address, uint16_t *value)
Read the register_address value from the mlx90632.
#define MLX90632_EE_MEDICAL_MEAS1
Medical measurement 1 16bit.
Definition: mlx90632.h:111
#define MLX90632_REFRESH_RATE(ee_val)
Extract Refresh Rate from ee register.
Definition: mlx90632.h:133
int32_t mlx90632_init ( void  )

Initialize MLX90632 driver and confirm EEPROM version.

EEPROM version is important to match sensor EEPROM content and calculations. This is why this function checks for correct EEPROM version before it does checksum validation of the EEPROM content.

Note
EEPROM version can have swapped high and low bytes due to CPU or I2C. Please confirm that i2c read (16bit) is functioning as expected.
Return values
0Successfully initialized MLX90632 driver, extended range measurement not supported

Definition at line 441 of file mlx90632.c.

442 {
443  int32_t ret;
444  uint16_t eeprom_version, reg_status;
445 
446  ret = mlx90632_i2c_read(MLX90632_EE_VERSION, &eeprom_version);
447  if (ret < 0)
448  {
449  return ret;
450  }
451 
452  if ((eeprom_version & 0x00FF) != MLX90632_DSPv5)
453  {
454  // this here can fail because of big/little endian of cpu/i2c
455  return -EPROTONOSUPPORT;
456  }
457 
458  ret = mlx90632_i2c_read(MLX90632_REG_STATUS, &reg_status);
459  if (ret < 0)
460  return ret;
461 
462  // Prepare a clean start with setting NEW_DATA to 0
464  if (ret < 0)
465  return ret;
466 
467  if ((eeprom_version & 0x7F00) == MLX90632_XTD_RNG_KEY)
468  {
469  return ERANGE;
470  }
471 
472  return 0;
473 }
#define MLX90632_EE_VERSION
EEPROM version reg - assumed 0x101.
Definition: mlx90632.h:87
int32_t mlx90632_i2c_read(int16_t register_address, uint16_t *value)
Read the register_address value from the mlx90632.
#define EPROTONOSUPPORT
From linux errno.h.
Definition: mlx90632.h:52
#define MLX90632_XTD_RNG_KEY
Definition: mlx90632.h:192
int32_t mlx90632_i2c_write(int16_t register_address, uint16_t value)
Write value to register_address of the mlx90632.
#define ERANGE
From linux errno.h.
Definition: mlx90632.h:55
#define MLX90632_REG_STATUS
Device status register.
Definition: mlx90632.h:168
#define MLX90632_STAT_DATA_RDY
Data ready indicator.
Definition: mlx90632.h:173
#define MLX90632_DSPv5
Definition: mlx90632.h:184
double mlx90632_preprocess_temp_ambient ( int16_t  ambient_new_raw,
int16_t  ambient_old_raw,
int16_t  Gb 
)

Calculation of raw ambient output.

Preprocessing of the raw ambient value

Parameters
[in]ambient_new_rawambient temperature from MLX90632_RAM_3. The meas_num 1 or 2 is determined by value in MLX90632_STAT_CYCLE_POS
[in]ambient_old_rawambient temperature from MLX90632_RAM_3. The meas_num 1 or 2 is determined by value not in MLX90632_STAT_CYCLE_POS
[in]GbRegister value on MLX90632_EE_Gb
Returns
Calculated ambient raw output

Definition at line 242 of file mlx90632.c.

243 {
244  double VR_Ta, kGb;
245 
246  kGb = ((double)Gb) / 1024.0;
247 
248  VR_Ta = ambient_old_raw + kGb * (ambient_new_raw / (MLX90632_REF_3));
249  return ((ambient_new_raw / (MLX90632_REF_3)) / VR_Ta) * 524288.0;
250 }
#define MLX90632_REF_3
ResCtrlRef value of Channel 3.
Definition: mlx90632.h:191
double mlx90632_preprocess_temp_ambient_extended ( int16_t  ambient_new_raw,
int16_t  ambient_old_raw,
int16_t  Gb 
)

Calculation of raw ambient output for the extended range.

Preprocessing of the raw ambient value

Parameters
[in]ambient_new_rawambient temperature from MLX90632_RAM_3 from meas num 17
[in]ambient_old_rawambient temperature from MLX90632_RAM_3 from meas num 18
[in]GbRegister value on MLX90632_EE_Gb
Returns
Calculated ambient raw output

Definition at line 186 of file mlx90632_extended_meas.c.

187 {
188  double VR_Ta, kGb;
189 
190  kGb = ((double)Gb) / 1024.0;
191 
192  VR_Ta = ambient_old_raw + kGb * (ambient_new_raw / (MLX90632_REF_3));
193  return ((ambient_new_raw / (MLX90632_REF_3)) / VR_Ta) * 524288.0;
194 }
#define MLX90632_REF_3
ResCtrlRef value of Channel 3.
Definition: mlx90632.h:191
double mlx90632_preprocess_temp_object ( int16_t  object_new_raw,
int16_t  object_old_raw,
int16_t  ambient_new_raw,
int16_t  ambient_old_raw,
int16_t  Ka 
)

Calculation of raw object output.

Preprocessing of the raw object value

Parameters
[in]object_new_rawobject temperature from MLX90632_RAM_1 or MLX90632_RAM_2. The meas_number 1 or 2 is determined by value in MLX90632_STAT_CYCLE_POS
[in]object_old_rawobject temperature from MLX90632_RAM_1 or MLX90632_RAM_2. The meas_number 1 or 2 is determined by value not in MLX90632_STAT_CYCLE_POS
[in]ambient_new_rawambient temperature from MLX90632_RAM_3. The meas_number 1 or 2 is determined by value in MLX90632_STAT_CYCLE_POS
[in]ambient_old_rawambient temperature from MLX90632_RAM_3. The meas_number 1 or 2 is determined by value not in MLX90632_STAT_CYCLE_POS
[in]KaRegister value on MLX90632_EE_Ka
Returns
Calculated object raw output

Definition at line 252 of file mlx90632.c.

255 {
256  double VR_IR, kKa;
257 
258  kKa = ((double)Ka) / 1024.0;
259 
260  VR_IR = ambient_old_raw + kKa * (ambient_new_raw / (MLX90632_REF_3));
261  return ((((object_new_raw + object_old_raw) / 2) / (MLX90632_REF_12)) / VR_IR) * 524288.0;
262 }
#define MLX90632_REF_3
ResCtrlRef value of Channel 3.
Definition: mlx90632.h:191
#define MLX90632_REF_12
ResCtrlRef value of Channel 1 or Channel 2.
Definition: mlx90632.h:190
double mlx90632_preprocess_temp_object_extended ( int16_t  object_new_raw,
int16_t  ambient_new_raw,
int16_t  ambient_old_raw,
int16_t  Ka 
)

Calculation of raw object output for the extended range.

Preprocessing of the raw object value

Parameters
[in]object_new_rawobject temperature from MLX90632_RAM_1 and MLX90632_RAM_2 from meas_number 17, 18 and 19
[in]ambient_new_rawambient temperature from MLX90632_RAM_3 from meas num 17
[in]ambient_old_rawambient temperature from MLX90632_RAM_3 from meas num 18
[in]KaRegister value on MLX90632_EE_Ka
Returns
Calculated object raw output

Definition at line 196 of file mlx90632_extended_meas.c.

198 {
199  double VR_IR, kKa;
200 
201  kKa = ((double)Ka) / 1024.0;
202 
203  VR_IR = ambient_old_raw + kKa * (ambient_new_raw / (MLX90632_REF_3));
204  return ((object_new_raw / (MLX90632_REF_12)) / VR_IR) * 524288.0;
205 }
#define MLX90632_REF_3
ResCtrlRef value of Channel 3.
Definition: mlx90632.h:191
#define MLX90632_REF_12
ResCtrlRef value of Channel 1 or Channel 2.
Definition: mlx90632.h:190
STATIC int32_t mlx90632_read_temp_ambient_raw ( int16_t *  ambient_new_raw,
int16_t *  ambient_old_raw 
)

Read ambient raw old and new values based on mlx90632_start_measurement return value.

Two i2c_reads are needed to obtain necessary raw ambient values from the sensor, as they are then preprocessed before going to calculation functions. Because one value is newer than other (see mlx90632_start_measurement) this function provides dynamics based on return value of the mlx90632_start_measurement.

Parameters
[out]*ambient_new_rawPointer to memory location where new ambient value from sensor is stored
[out]*ambient_old_rawPointer to memory location where old ambient value from sensor is stored
Return values
0Successfully read both values
<0Something went wrong. Check errno.h for more details.

Definition at line 130 of file mlx90632.c.

131 {
132  int32_t ret;
133  uint16_t read_tmp;
134 
135  ret = mlx90632_i2c_read(MLX90632_RAM_3(1), &read_tmp);
136  if (ret < 0)
137  return ret;
138  *ambient_new_raw = (int16_t)read_tmp;
139 
140  ret = mlx90632_i2c_read(MLX90632_RAM_3(2), &read_tmp);
141  if (ret < 0)
142  return ret;
143  *ambient_old_raw = (int16_t)read_tmp;
144 
145  return ret;
146 }
#define MLX90632_RAM_3(meas_num)
Definition: mlx90632.h:178
int32_t mlx90632_i2c_read(int16_t register_address, uint16_t *value)
Read the register_address value from the mlx90632.
STATIC int32_t mlx90632_read_temp_ambient_raw_extended ( int16_t *  ambient_new_raw,
int16_t *  ambient_old_raw 
)

Read ambient raw old and new values for the extended range based on mlx90632_start_measurement return value.

Two i2c_reads are needed to obtain necessary raw ambient values from the sensor, as they are then preprocessed before going to calculation functions

Parameters
[out]*ambient_new_rawPointer to memory location where new ambient value from sensor is stored
[out]*ambient_old_rawPointer to memory location where old ambient value from sensor is stored
Return values
0Successfully read both values
<0Something went wrong. Check errno.h for more details.

Definition at line 54 of file mlx90632_extended_meas.c.

55 {
56  int32_t ret;
57  uint16_t read_tmp;
58 
59  ret = mlx90632_i2c_read(MLX90632_RAM_3(17), &read_tmp);
60  if (ret < 0)
61  return ret;
62  *ambient_new_raw = (int16_t)read_tmp;
63 
64  ret = mlx90632_i2c_read(MLX90632_RAM_3(18), &read_tmp);
65  if (ret < 0)
66  return ret;
67  *ambient_old_raw = (int16_t)read_tmp;
68 
69  return ret;
70 }
#define MLX90632_RAM_3(meas_num)
Definition: mlx90632.h:178
int32_t mlx90632_i2c_read(int16_t register_address, uint16_t *value)
Read the register_address value from the mlx90632.
STATIC int32_t mlx90632_read_temp_object_raw ( int32_t  start_measurement_ret,
int16_t *  object_new_raw,
int16_t *  object_old_raw 
)

Read object raw old and new values based on mlx90632_start_measurement return value.

Four i2c_reads are needed to obtain necessary raw object values from the sensor. These values are grouped per new and old and then averaged before return of the function. After that they are then preprocessed before going to calculation functions. Because one value is newer than other (see mlx90632_start_measurement) this function provides dynamics based on return value of the mlx90632_start_measurement.

Parameters
[in]start_measurement_retReturn value of mlx90632_start_measurement
[out]*object_new_rawPointer to memory location where average of new object values from sensor is stored
[out]*object_old_rawPointer to memory location where average of old object values from sensor is stored
Return values
0Successfully read both values
<0Something went wrong. Check errno.h for more details.

Definition at line 162 of file mlx90632.c.

164 {
165  int32_t ret;
166  uint16_t read_tmp;
167  int16_t read;
168  uint8_t channel, channel_old;
169 
170  ret = mlx90632_channel_new_select(start_measurement_ret, &channel, &channel_old);
171  if (ret != 0)
172  return -EINVAL;
173 
174  ret = mlx90632_i2c_read(MLX90632_RAM_2(channel), &read_tmp);
175  if (ret < 0)
176  return ret;
177 
178  read = (int16_t)read_tmp;
179 
180  ret = mlx90632_i2c_read(MLX90632_RAM_1(channel), &read_tmp);
181  if (ret < 0)
182  return ret;
183  *object_new_raw = (read + (int16_t)read_tmp) / 2;
184 
185  ret = mlx90632_i2c_read(MLX90632_RAM_2(channel_old), &read_tmp);
186  if (ret < 0)
187  return ret;
188  read = (int16_t)read_tmp;
189 
190  ret = mlx90632_i2c_read(MLX90632_RAM_1(channel_old), &read_tmp);
191  if (ret < 0)
192  return ret;
193  *object_old_raw = (read + (int16_t)read_tmp) / 2;
194 
195  return ret;
196 }
#define MLX90632_RAM_1(meas_num)
Definition: mlx90632.h:176
int32_t mlx90632_i2c_read(int16_t register_address, uint16_t *value)
Read the register_address value from the mlx90632.
#define MLX90632_RAM_2(meas_num)
Definition: mlx90632.h:177
STATIC int32_t mlx90632_channel_new_select(int32_t ret, uint8_t *channel_new, uint8_t *channel_old)
Based on mlx90632_start_measurement return value fill channel_new and channel_old variables with prop...
Definition: mlx90632.c:97
#define EINVAL
From linux errno.h.
Definition: mlx90632.h:49
STATIC int32_t mlx90632_read_temp_object_raw_extended ( int16_t *  object_new_raw)

Read object raw values for the extended range based on mlx90632_start_measurement return value.

Six i2c_reads are needed to obtain necessary raw object values from the sensor. These values are grouped and then averaged before return of the function. After that they are then preprocessed before going to calculation functions

Parameters
[out]*object_new_rawPointer to memory location where average of new object values from sensor is stored
Return values
0Successfully read values
<0Something went wrong. Check errno.h for more details.

Definition at line 83 of file mlx90632_extended_meas.c.

84 {
85  int32_t ret;
86  uint16_t read_tmp;
87  int32_t read;
88 
89  ret = mlx90632_i2c_read(MLX90632_RAM_1(17), &read_tmp);
90  if (ret < 0)
91  return ret;
92 
93  read = (int16_t)read_tmp;
94 
95  ret = mlx90632_i2c_read(MLX90632_RAM_2(17), &read_tmp);
96  if (ret < 0)
97  return ret;
98 
99  read = read - (int16_t)read_tmp;
100 
101  ret = mlx90632_i2c_read(MLX90632_RAM_1(18), &read_tmp);
102  if (ret < 0)
103  return ret;
104 
105  read = read - (int16_t)read_tmp;
106 
107  ret = mlx90632_i2c_read(MLX90632_RAM_2(18), &read_tmp);
108  if (ret < 0)
109  return ret;
110 
111  read = (read + (int16_t)read_tmp) / 2;
112 
113  ret = mlx90632_i2c_read(MLX90632_RAM_1(19), &read_tmp);
114  if (ret < 0)
115  return ret;
116 
117  read = read + (int16_t)read_tmp;
118 
119  ret = mlx90632_i2c_read(MLX90632_RAM_2(19), &read_tmp);
120  if (ret < 0)
121  return ret;
122 
123  read = read + (int16_t)read_tmp;
124 
125  if (read > 32767 || read < -32768)
126  return -EINVAL;
127 
128  *object_new_raw = (int16_t)read;
129 
130  return ret;
131 }
#define MLX90632_RAM_1(meas_num)
Definition: mlx90632.h:176
int32_t mlx90632_i2c_read(int16_t register_address, uint16_t *value)
Read the register_address value from the mlx90632.
#define MLX90632_RAM_2(meas_num)
Definition: mlx90632.h:177
#define EINVAL
From linux errno.h.
Definition: mlx90632.h:49
int32_t mlx90632_read_temp_raw ( int16_t *  ambient_new_raw,
int16_t *  ambient_old_raw,
int16_t *  object_new_raw,
int16_t *  object_old_raw 
)

Read raw ambient and object temperature.

Trigger and read raw ambient and object temperatures. This values still need to be pre-processed via mlx90632_preprocess_temp_ambient and mlx90632_preprocess_temp_object functions and then processed via mlx90632_calc_temp_ambient and mlx90632_calc_temp_object to retrieve values in milliCelsius

Parameters
[out]ambient_new_rawPointer to where new raw ambient temperature is written
[out]object_new_rawPointer to where new raw object temperature is written
[out]ambient_old_rawPointer to where old raw ambient temperature is written
[out]object_old_rawPointer to where old raw object temperature is written
Return values
0Successfully read both temperatures
<0Something went wrong. Check errno.h for more details

Read new and old ambient values from sensor

Read new and old object values from sensor

Definition at line 198 of file mlx90632.c.

200 {
201  int32_t ret, start_measurement_ret;
202 
203  // trigger and wait for measurement to complete
204  start_measurement_ret = mlx90632_start_measurement();
205  if (start_measurement_ret < 0)
206  return start_measurement_ret;
207 
209  ret = mlx90632_read_temp_ambient_raw(ambient_new_raw, ambient_old_raw);
210  if (ret < 0)
211  return ret;
212 
214  ret = mlx90632_read_temp_object_raw(start_measurement_ret, object_new_raw, object_old_raw);
215 
216  return ret;
217 }
STATIC int32_t mlx90632_read_temp_ambient_raw(int16_t *ambient_new_raw, int16_t *ambient_old_raw)
Read ambient raw old and new values based on mlx90632_start_measurement return value.
Definition: mlx90632.c:130
int mlx90632_start_measurement(void)
Trigger start measurement for mlx90632.
Definition: mlx90632.c:47
STATIC int32_t mlx90632_read_temp_object_raw(int32_t start_measurement_ret, int16_t *object_new_raw, int16_t *object_old_raw)
Read object raw old and new values based on mlx90632_start_measurement return value.
Definition: mlx90632.c:162
int32_t mlx90632_read_temp_raw_burst ( int16_t *  ambient_new_raw,
int16_t *  ambient_old_raw,
int16_t *  object_new_raw,
int16_t *  object_old_raw 
)

Read raw ambient and object temperature in sleeping step mode.

Trigger and read raw ambient and object temperatures. This values still need to be pre-processed via mlx90632_preprocess_temp_ambient and mlx90632_preprocess_temp_object functions and then processed via mlx90632_calc_temp_ambient and mlx90632_calc_temp_object to retrieve values in milliCelsius

Parameters
[out]ambient_new_rawPointer to where new raw ambient temperature is written
[out]object_new_rawPointer to where new raw object temperature is written
[out]ambient_old_rawPointer to where old raw ambient temperature is written
[out]object_old_rawPointer to where old raw object temperature is written
Return values
0Successfully read both temperatures
<0Something went wrong. Check errno.h for more details

Read new and old ambient values from sensor

Read new and old object values from sensor

Definition at line 219 of file mlx90632.c.

221 {
222  int32_t ret, start_measurement_ret;
223 
224  // trigger and wait for measurement to complete
225  start_measurement_ret = mlx90632_start_measurement_burst();
226  if (start_measurement_ret < 0)
227  return start_measurement_ret;
228 
230  ret = mlx90632_read_temp_ambient_raw(ambient_new_raw, ambient_old_raw);
231  if (ret < 0)
232  return ret;
233 
235  ret = mlx90632_read_temp_object_raw(2, object_new_raw, object_old_raw);
236 
237  return ret;
238 }
int32_t mlx90632_start_measurement_burst(void)
Trigger start of burst measurement for mlx90632.
Definition: mlx90632.c:553
STATIC int32_t mlx90632_read_temp_ambient_raw(int16_t *ambient_new_raw, int16_t *ambient_old_raw)
Read ambient raw old and new values based on mlx90632_start_measurement return value.
Definition: mlx90632.c:130
STATIC int32_t mlx90632_read_temp_object_raw(int32_t start_measurement_ret, int16_t *object_new_raw, int16_t *object_old_raw)
Read object raw old and new values based on mlx90632_start_measurement return value.
Definition: mlx90632.c:162
int32_t mlx90632_read_temp_raw_extended ( int16_t *  ambient_new_raw,
int16_t *  ambient_old_raw,
int16_t *  object_new_raw 
)

Read raw ambient and object temperature for extended range.

Trigger and read raw ambient and object temperatures. This values still need to be pre-processed via mlx90632_preprocess_temp_ambient_extended and mlx90632_preprocess_temp_object_extended functions and then processed via mlx90632_calc_temp_ambient_extended and mlx90632_calc_temp_object_extended to retrieve values in milliCelsius

Parameters
[out]ambient_new_rawPointer to where new raw ambient temperature is written
[out]object_new_rawPointer to where new raw object temperature is written
[out]ambient_old_rawPointer to where old raw ambient temperature is written
[out]object_old_rawPointer to where old raw object temperature is written
Return values
0Successfully read both temperatures
<0Something went wrong. Check errno.h for more details

Read new and old ambient values from sensor

Read new object value from sensor

Definition at line 133 of file mlx90632_extended_meas.c.

134 {
135  int32_t ret, start_measurement_ret;
136  int tries = 3;
137 
138  // trigger and wait for measurement to complete
139  while (tries-- > 0)
140  {
141  start_measurement_ret = mlx90632_start_measurement();
142  if (start_measurement_ret < 0)
143  return start_measurement_ret;
144 
145  if (start_measurement_ret == 19)
146  break;
147  }
148 
149  if (tries < 0)
150  {
151  // data not ready
152  return -ETIMEDOUT;
153  }
154 
156  ret = mlx90632_read_temp_ambient_raw_extended(ambient_new_raw, ambient_old_raw);
157  if (ret < 0)
158  return ret;
159 
161  ret = mlx90632_read_temp_object_raw_extended(object_new_raw);
162 
163  return ret;
164 }
STATIC int32_t mlx90632_read_temp_object_raw_extended(int16_t *object_new_raw)
Read object raw values for the extended range based on mlx90632_start_measurement return value...
STATIC int32_t mlx90632_read_temp_ambient_raw_extended(int16_t *ambient_new_raw, int16_t *ambient_old_raw)
Read ambient raw old and new values for the extended range based on mlx90632_start_measurement return...
#define ETIMEDOUT
From linux errno.h.
Definition: mlx90632.h:46
int mlx90632_start_measurement(void)
Trigger start measurement for mlx90632.
Definition: mlx90632.c:47
int32_t mlx90632_read_temp_raw_extended_burst ( int16_t *  ambient_new_raw,
int16_t *  ambient_old_raw,
int16_t *  object_new_raw 
)

Read raw ambient and object temperature for extended range sleeping step mode.

Trigger and read raw ambient and object temperatures. This values still need to be pre-processed via mlx90632_preprocess_temp_ambient_extended and mlx90632_preprocess_temp_object_extended functions and then processed via mlx90632_calc_temp_ambient_extended and mlx90632_calc_temp_object_extended to retrieve values in milliCelsius

Parameters
[out]ambient_new_rawPointer to where new raw ambient temperature is written
[out]object_new_rawPointer to where new raw object temperature is written
[out]ambient_old_rawPointer to where old raw ambient temperature is written
[out]object_old_rawPointer to where old raw object temperature is written
Return values
0Successfully read both temperatures
<0Something went wrong. Check errno.h for more details

Read new and old ambient values from sensor

Read new object value from sensor

Definition at line 166 of file mlx90632_extended_meas.c.

167 {
168  int32_t ret, start_measurement_ret;
169 
170  // trigger and wait for measurement to complete
171  start_measurement_ret = mlx90632_start_measurement_burst();
172  if (start_measurement_ret < 0)
173  return start_measurement_ret;
174 
176  ret = mlx90632_read_temp_ambient_raw_extended(ambient_new_raw, ambient_old_raw);
177  if (ret < 0)
178  return ret;
179 
181  ret = mlx90632_read_temp_object_raw_extended(object_new_raw);
182 
183  return ret;
184 }
int32_t mlx90632_start_measurement_burst(void)
Trigger start of burst measurement for mlx90632.
Definition: mlx90632.c:553
STATIC int32_t mlx90632_read_temp_object_raw_extended(int16_t *object_new_raw)
Read object raw values for the extended range based on mlx90632_start_measurement return value...
STATIC int32_t mlx90632_read_temp_ambient_raw_extended(int16_t *ambient_new_raw, int16_t *ambient_old_raw)
Read ambient raw old and new values for the extended range based on mlx90632_start_measurement return...
void mlx90632_set_emissivity ( double  value)

Set emissivity which is retained in single variable.

Parameters
[in]valueValue provided by user of object emissivity. Defaults to 1.0 and cannot be 0.0.
Warning
This is not suitable for multi-process calculations as we do not use instances

Definition at line 372 of file mlx90632.c.

373 {
374  emissivity = value;
375 }
static double emissivity
Definition: mlx90632.c:371
int32_t mlx90632_set_meas_type ( uint8_t  type)

Switch the measurement type of the MLX90632.

Parameters
[in]typemeasurement type to switch to
Note
the available types are defined as MLX90632_MTYP_MEDICAL and MLX90632_MTYP_EXTENDED
Return values
0Successfully swithed the meausurement mode
<0Something went wrong. Check errno.h for more details

Definition at line 299 of file mlx90632_extended_meas.c.

300 {
301  int32_t ret;
302  uint16_t reg_ctrl;
303 
305  return -EINVAL;
306 
307  ret = mlx90632_addressed_reset();
308  if (ret < 0)
309  return ret;
310 
311  ret = mlx90632_i2c_read(MLX90632_REG_CTRL, &reg_ctrl);
312  if (ret < 0)
313  return ret;
314 
315  reg_ctrl = reg_ctrl & (~MLX90632_CFG_MTYP_MASK & ~MLX90632_CFG_PWR_MASK);
317 
318  ret = mlx90632_i2c_write(MLX90632_REG_CTRL, reg_ctrl);
319  if (ret < 0)
320  return ret;
321 
322  ret = mlx90632_i2c_read(MLX90632_REG_CTRL, &reg_ctrl);
323  if (ret < 0)
324  return ret;
325 
326  reg_ctrl = reg_ctrl & ~MLX90632_CFG_PWR_MASK;
328  {
329  reg_ctrl |= MLX90632_PWR_STATUS_SLEEP_STEP;
330  }
331  else
332  {
333  reg_ctrl |= MLX90632_PWR_STATUS_CONTINUOUS;
334  }
335 
336  ret = mlx90632_i2c_write(MLX90632_REG_CTRL, reg_ctrl);
337 
338  return ret;
339 }
#define MLX90632_MEASUREMENT_TYPE_STATUS(mtyp_type)
Extract the measurement type from MTYP.
Definition: mlx90632.h:201
int32_t mlx90632_i2c_read(int16_t register_address, uint16_t *value)
Read the register_address value from the mlx90632.
#define MLX90632_MTYP_MEDICAL_BURST
Definition: mlx90632.h:197
#define MLX90632_CFG_MTYP_MASK
Meas select Mask.
Definition: mlx90632.h:146
#define MLX90632_MEASUREMENT_BURST_STATUS(mtyp_type)
Extract the measurement burst/continuous type from MTYP.
Definition: mlx90632.h:202
#define MLX90632_PWR_STATUS_SLEEP_STEP
Pwrmode sleep step.
Definition: mlx90632.h:155
#define MLX90632_MTYP_MEDICAL
Definition: mlx90632.h:195
#define MLX90632_MTYP_EXTENDED
Definition: mlx90632.h:196
#define MLX90632_MTYP_EXTENDED_BURST
Definition: mlx90632.h:198
int32_t mlx90632_i2c_write(int16_t register_address, uint16_t value)
Write value to register_address of the mlx90632.
#define MLX90632_PWR_STATUS_HALT
Pwrmode hold.
Definition: mlx90632.h:154
#define MLX90632_MTYP_STATUS(ctrl_val)
Definition: mlx90632.h:159
int32_t mlx90632_addressed_reset(void)
Trigger system reset for mlx90632.
Definition: mlx90632.c:475
#define MLX90632_PWR_STATUS_CONTINUOUS
Pwrmode continuous.
Definition: mlx90632.h:157
#define EINVAL
From linux errno.h.
Definition: mlx90632.h:49
#define MLX90632_CFG_PWR_MASK
PowerMode Mask.
Definition: mlx90632.h:143
#define MLX90632_REG_CTRL
Control Register address.
Definition: mlx90632.h:140
int32_t mlx90632_set_refresh_rate ( mlx90632_meas_t  measRate)

Sets the refresh rate of the sensor using the MLX90632_EE_MEAS_1 and MLX90632_EE_MEAS_2 registers.

Parameters
[in]measRaterefresh rate to set with mlx90632_meas_e
Return values
<0Something went wrong. Consult errno.h for more details.

Definition at line 650 of file mlx90632.c.

651 {
652  uint16_t meas1, meas2;
653 
654  int32_t ret = mlx90632_i2c_read(MLX90632_EE_MEDICAL_MEAS1, &meas1);
655 
656  if (ret < 0)
657  return ret;
658 
660 
661  if (meas1 != new_value)
662  {
664  if (ret < 0)
665  return ret;
666  }
667 
669  if (ret < 0)
670  return ret;
671 
673  if (meas2 != new_value)
674  {
676  }
677 
678  return ret;
679 }
int32_t mlx90632_i2c_read(int16_t register_address, uint16_t *value)
Read the register_address value from the mlx90632.
#define MLX90632_EE_MEDICAL_MEAS2
Medical measurement 2 16bit.
Definition: mlx90632.h:112
#define MLX90632_NEW_REG_VALUE(old_reg, new_value, h, l)
Definition: mlx90632.h:210
#define MLX90632_EE_MEDICAL_MEAS1
Medical measurement 1 16bit.
Definition: mlx90632.h:111
STATIC int32_t mlx90632_write_eeprom(uint16_t address, uint16_t data)
Definition: mlx90632.c:631
#define MLX90632_EE_REFRESH_RATE_SHIFT
Refresh Rate shift.
Definition: mlx90632.h:130
#define MLX90632_EE_REFRESH_RATE_START
Refresh Rate Start bit.
Definition: mlx90632.h:129
int mlx90632_start_measurement ( void  )

Trigger start measurement for mlx90632.

Trigger measurement cycle and wait for data to be ready. It does not read anything, just triggers and completes.

Return values
<0Something failed. Check errno.h for more information
>=0Channel position where new (recently updated) measurement can be found
Note
This function is using usleep so it is blocking!

Definition at line 47 of file mlx90632.c.

48 {
50  uint16_t reg_status;
51 
52  ret = mlx90632_i2c_read(MLX90632_REG_STATUS, &reg_status);
53  if (ret < 0)
54  return ret;
55 
57  if (ret < 0)
58  return ret;
59 
60  while (tries-- > 0)
61  {
62  ret = mlx90632_i2c_read(MLX90632_REG_STATUS, &reg_status);
63  if (ret < 0)
64  return ret;
65  if (reg_status & MLX90632_STAT_DATA_RDY)
66  break;
67  /* minimum wait time to complete measurement
68  * should be calculated according to refresh rate
69  * atm 10ms - 11ms
70  */
71  usleep(10000, 11000);
72  }
73 
74  if (tries < 0)
75  {
76  // data not ready
77  return -ETIMEDOUT;
78  }
79 
80  return (reg_status & MLX90632_STAT_CYCLE_POS) >> 2;
81 }
int32_t mlx90632_i2c_read(int16_t register_address, uint16_t *value)
Read the register_address value from the mlx90632.
#define MLX90632_MAX_NUMBER_MESUREMENT_READ_TRIES
Maximum number of read tries before quiting with timeout error.
Definition: mlx90632.h:205
#define MLX90632_STAT_CYCLE_POS
Data position in measurement table.
Definition: mlx90632.h:172
int32_t mlx90632_i2c_write(int16_t register_address, uint16_t value)
Write value to register_address of the mlx90632.
#define MLX90632_REG_STATUS
Device status register.
Definition: mlx90632.h:168
#define MLX90632_STAT_DATA_RDY
Data ready indicator.
Definition: mlx90632.h:173
void usleep(int min_range, int max_range)
Blocking function for sleeping in microseconds.
#define ETIMEDOUT
From linux errno.h.
Definition: mlx90632.h:46
int32_t mlx90632_start_measurement_burst ( void  )

Trigger start of burst measurement for mlx90632.

Trigger a single measurement cycle and wait for data to be ready. It does not read anything, just triggers and completes. The SOB bit is set so that the complete measurement table is re-freshed.

Note
The SOB bit is cleared internally by the mlx90632 immediately after the measurement has started.
Return values
<0Something failed. Check errno.h for more information
0New data is available and waiting to be processed
Note
This function is using usleep and msleep. Because of usleep it is blocking, while msleep implementation can have a thread switch! In case both are blocking expect up to 2 second freeze of CPU in worse case scenario (depending on Refresh rate setting), so you might also need to take care of Watch Dog.

Definition at line 553 of file mlx90632.c.

554 {
555  int32_t ret;
557  uint16_t reg;
558 
560  if (ret < 0)
561  return ret;
562 
564 
566  if (ret < 0)
567  return ret;
568 
570  if (ret < 0)
571  return ret;
572  msleep(ret); /* Waiting for refresh of all the measurement tables */
573 
574  while (tries-- > 0)
575  {
577  if (ret < 0)
578  return ret;
579  if ((reg & MLX90632_STAT_BUSY) == 0)
580  break;
581  /* minimum wait time to complete measurement
582  * should be calculated according to refresh rate
583  * atm 10ms - 11ms
584  */
585  usleep(10000, 11000);
586  }
587 
588  if (tries < 0)
589  {
590  // data not ready
591  return -ETIMEDOUT;
592  }
593 
594  return 0;
595 }
int32_t mlx90632_i2c_read(int16_t register_address, uint16_t *value)
Read the register_address value from the mlx90632.
#define MLX90632_START_BURST_MEAS
Definition: mlx90632.h:164
#define MLX90632_STAT_BUSY
Device busy indicator.
Definition: mlx90632.h:169
void msleep(int msecs)
Blocking function for sleeping in milliseconds.
#define MLX90632_MAX_NUMBER_MESUREMENT_READ_TRIES
Maximum number of read tries before quiting with timeout error.
Definition: mlx90632.h:205
int32_t mlx90632_i2c_write(int16_t register_address, uint16_t value)
Write value to register_address of the mlx90632.
#define MLX90632_REG_STATUS
Device status register.
Definition: mlx90632.h:168
int32_t mlx90632_calculate_dataset_ready_time(void)
Reads the refresh rate and calculates the time needed for a whole measurment table from the EEPROM se...
Definition: mlx90632.c:503
void usleep(int min_range, int max_range)
Blocking function for sleeping in microseconds.
#define MLX90632_REG_CTRL
Control Register address.
Definition: mlx90632.h:140
#define ETIMEDOUT
From linux errno.h.
Definition: mlx90632.h:46
STATIC int32_t mlx90632_unlock_eeporm ( )

Definition at line 598 of file mlx90632.c.

599 {
601 }
#define MLX90632_EEPROM_WRITE_KEY
EEPROM write key 0x55 and 0x4c.
Definition: mlx90632.h:186
int32_t mlx90632_i2c_write(int16_t register_address, uint16_t value)
Write value to register_address of the mlx90632.
STATIC int32_t mlx90632_wait_for_eeprom_not_busy ( )

Definition at line 603 of file mlx90632.c.

604 {
605  uint16_t reg_status;
606  int32_t ret = mlx90632_i2c_read(MLX90632_REG_STATUS, &reg_status);
607 
608  while (ret >= 0 && reg_status & MLX90632_STAT_EE_BUSY)
609  {
610  ret = mlx90632_i2c_read(MLX90632_REG_STATUS, &reg_status);
611  }
612 
613  return ret;
614 }
int32_t mlx90632_i2c_read(int16_t register_address, uint16_t *value)
Read the register_address value from the mlx90632.
#define MLX90632_STAT_EE_BUSY
Device EEPROM busy indicator.
Definition: mlx90632.h:170
#define MLX90632_REG_STATUS
Device status register.
Definition: mlx90632.h:168
STATIC int32_t mlx90632_write_eeprom ( uint16_t  address,
uint16_t  data 
)

Definition at line 631 of file mlx90632.c.

632 {
633  int32_t ret = mlx90632_erase_eeprom(address);
634 
635  if (ret < 0)
636  return ret;
637 
638  ret = mlx90632_unlock_eeporm();
639  if (ret < 0)
640  return ret;
641 
642  ret = mlx90632_i2c_write(address, data);
643  if (ret < 0)
644  return ret;
645 
647  return ret;
648 }
STATIC int32_t mlx90632_unlock_eeporm()
Definition: mlx90632.c:598
STATIC int32_t mlx90632_wait_for_eeprom_not_busy()
Definition: mlx90632.c:603
STATIC int32_t mlx90632_erase_eeprom(uint16_t address)
Definition: mlx90632.c:616
int32_t mlx90632_i2c_write(int16_t register_address, uint16_t value)
Write value to register_address of the mlx90632.

Variable Documentation

double emissivity = 0.0
static

Definition at line 371 of file mlx90632.c.

const char mlx90632version[] = { VERSION }
static

Definition at line 41 of file mlx90632.c.