mtb-pmbus
Helper Functions

General Description

Functions

float32_t mtb_pmbus_lin11_to_float (uint16_t linear_11)
 Converts the argument "linear11" to floating point and returns it. More...
 
uint16_t mtb_pmbus_float_to_lin11 (float32_t float_var)
 Takes the argument "floatvar" (a floating point number) and converts it to a 16-bit LINEAR11 value (11-bit mantissa + 5-bit exponent), which it returns. More...
 
float32_t mtb_pmbus_lin16_to_float (uint16_t linear_16, int8_t int_exp)
 Converts the argument "linear16" to floating point and returns it. More...
 
uint16_t mtb_pmbus_float_to_lin16 (float32_t float_var, int8_t out_exp)
 Takes the argument "floatvar" (a floating point number) and converts it to a 16-bit LINEAR16 value (16-bit mantissa), which it returns. More...
 

Function Documentation

◆ mtb_pmbus_lin11_to_float()

float32_t mtb_pmbus_lin11_to_float ( uint16_t  linear_11)

Converts the argument "linear11" to floating point and returns it.

Parameters
linear_11A number in LINEAR11 format
Returns
float32_t The linear11 parameter converted to floating point

◆ mtb_pmbus_float_to_lin11()

uint16_t mtb_pmbus_float_to_lin11 ( float32_t  float_var)

Takes the argument "floatvar" (a floating point number) and converts it to a 16-bit LINEAR11 value (11-bit mantissa + 5-bit exponent), which it returns.

Parameters
float_varA floating point number
Returns
uint16_t float_var converted to LINEAR11
Note
Conversion to LINEAR11 may result in the loss of precision, because LINEAR11 uses less bits to represent the floating point number and mantissa is not normalized.

◆ mtb_pmbus_lin16_to_float()

float32_t mtb_pmbus_lin16_to_float ( uint16_t  linear_16,
int8_t  int_exp 
)

Converts the argument "linear16" to floating point and returns it.

Parameters
linear_16The 16-bit mantissa of a LINEAR16 number
int_expThe 5-bit exponent of a LINEAR16 number. Packed in the lower 5 bits. 2's Complement.
Returns
float32_t The parameters converted to floating point

◆ mtb_pmbus_float_to_lin16()

uint16_t mtb_pmbus_float_to_lin16 ( float32_t  float_var,
int8_t  out_exp 
)

Takes the argument "floatvar" (a floating point number) and converts it to a 16-bit LINEAR16 value (16-bit mantissa), which it returns.

Parameters
float_varA floating point number to be converted to LINEAR16
out_expUser provided 5-bit exponent to use in the conversion.
Returns
uint16_t The parameters converted to LINEAR16.
Note
Conversion to LINEAR16 may result in loss of precision, because LINEAR16 use less bits to represent the floating point number and mantissa is not normalized.
Providing mismatched exponent lead to incorrect conversion:
Incorrect conversion examples:
float_var = 10.5f, out_exp = 0 -> 0x000B LIN16 mantissa -> 11.0f when converted back to float with the same exponent.
float_var = 65535.0f, out_exp = -1 -> 0xFFFE LIN16 mantissa -> 32767.0f when converted back to float with the same exponent.
Correct conversion examples:
float_var = 10.5f, out_exp = -1 -> 0x0015 LIN16 mantissa -> 10.5f when converted back to float with the same exponent.
float_var = 65535.0f, out_exp = 0 -> 0xFFFF LIN16 mantissa -> 65535.0f when converted back to float with the same exponent.