Infineon One Point Calibration Library  1.0.1
Data Structures | Macros | Typedefs | Functions
onecalib.h File Reference
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
Include dependency graph for onecalib.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ANALOG_SENSOR_DATA
 
struct  ROTATION_DATA_STORE
 
struct  CALIB_DATA
 

Macros

#define RAD2DEGFACTOR   (180.00 / M_PI)
 
#define DEG2RADFACTOR   (M_PI / 180.00)
 
#define ANGLE_TOLERANCE   0.25
 
#define ANGLE_TOLERANCE_RAD   (ANGLE_TOLERANCE * DEG2RADFACTOR)
 
#define ANGLE180_RAD   (180.00 * DEG2RADFACTOR)
 
#define ANGLE45   45.00
 
#define ANGLE135   135.00
 
#define ANGLE225   -135.00
 
#define ANGLE315   -45.00
 
#define ANGLE45_H   ((ANGLE45 + ANGLE_TOLERANCE) * DEG2RADFACTOR)
 
#define ANGLE45_L   ((ANGLE45 - ANGLE_TOLERANCE) * DEG2RADFACTOR)
 
#define ANGLE135_H   ((ANGLE135 + ANGLE_TOLERANCE) * DEG2RADFACTOR)
 
#define ANGLE135_L   ((ANGLE135 - ANGLE_TOLERANCE) * DEG2RADFACTOR)
 
#define ANGLE225_H   ((ANGLE225 + ANGLE_TOLERANCE) * DEG2RADFACTOR)
 
#define ANGLE225_L   ((ANGLE225 - ANGLE_TOLERANCE) * DEG2RADFACTOR)
 
#define ANGLE315_H   ((ANGLE315 + ANGLE_TOLERANCE) * DEG2RADFACTOR)
 
#define ANGLE315_L   ((ANGLE315 - ANGLE_TOLERANCE) * DEG2RADFACTOR)
 

Typedefs

typedef double float64_t
 
typedef struct ANALOG_SENSOR_DATA ANALOG_SENSOR_DATA_t
 
typedef struct ROTATION_DATA_STORE ROTATION_DATA_STORE_t
 
typedef struct CALIB_DATA CALIB_DATA_t
 

Functions

void ONECALIB_InitSensorData (uint32_t cosP_in_LSB, uint32_t cosN_in_LSB, uint32_t sinP_in_LSB, uint32_t sinN_in_LSB)
 Function used for ANALOG_SENSOR_DATA_t data assignment. More...
 
void ONECALIB_InitCalibData (CALIB_DATA_t *param_store)
 Function used for CALIB_DATA_t data initialization. The pointer of type CALIB_DATA_t will be used to store calibration parameters. More...
 
float64_t ONECALIB_GetAngle (const CALIB_DATA_t *calib_param)
 Calculates the calibrated angle if calibration has been performed, else the uncalibrated angle. More...
 
float64_t ONECALIB_GetUncalibAngle (void)
 Calculates the uncalibrated angle. More...
 
float64_t ONECALIB_GetCalibAngle (const CALIB_DATA_t *calib_param)
 Calculates the calibrated angle. More...
 
void ONECALIB_CalibrationFindParam (CALIB_DATA_t *param_store, bool rotate_CW, bool rotate_CCW)
 This function is used to extract the calibration parameters. It should called until calib_param.full_calibration_performed is true. To extract the correct rotation, the input parameter rotate_CW should be true until calib_param.rotation_data_CW.calibration_done is true(while the magnet is spinning in CW direction). Same for the CCW direction. While calib_param.full_calibration_performed is false only the differential uncalibrated angle is available. More...
 

Macro Definition Documentation

◆ ANGLE135

#define ANGLE135   135.00

angle position used for the calibration process.

Definition at line 37 of file onecalib.h.

◆ ANGLE135_H

#define ANGLE135_H   ((ANGLE135 + ANGLE_TOLERANCE) * DEG2RADFACTOR)

angle position limit in radians used for the calibration process.

Definition at line 43 of file onecalib.h.

◆ ANGLE135_L

#define ANGLE135_L   ((ANGLE135 - ANGLE_TOLERANCE) * DEG2RADFACTOR)

angle position limit in radians used for the calibration process.

Definition at line 44 of file onecalib.h.

◆ ANGLE180_RAD

#define ANGLE180_RAD   (180.00 * DEG2RADFACTOR)

angle position in radians used for the calibration process.

Definition at line 34 of file onecalib.h.

◆ ANGLE225

#define ANGLE225   -135.00

angle position used for the calibration process.

Definition at line 38 of file onecalib.h.

◆ ANGLE225_H

#define ANGLE225_H   ((ANGLE225 + ANGLE_TOLERANCE) * DEG2RADFACTOR)

angle position limit in radians used for the calibration process.

Definition at line 45 of file onecalib.h.

◆ ANGLE225_L

#define ANGLE225_L   ((ANGLE225 - ANGLE_TOLERANCE) * DEG2RADFACTOR)

angle position limit in radians used for the calibration process.

Definition at line 46 of file onecalib.h.

◆ ANGLE315

#define ANGLE315   -45.00

angle position used for the calibration process.

Definition at line 39 of file onecalib.h.

◆ ANGLE315_H

#define ANGLE315_H   ((ANGLE315 + ANGLE_TOLERANCE) * DEG2RADFACTOR)

angle position limit in radians used for the calibration process.

Definition at line 47 of file onecalib.h.

◆ ANGLE315_L

#define ANGLE315_L   ((ANGLE315 - ANGLE_TOLERANCE) * DEG2RADFACTOR)

angle position limit in radians used for the calibration process.

Definition at line 48 of file onecalib.h.

◆ ANGLE45

#define ANGLE45   45.00

angle position used for the calibration process.

Definition at line 36 of file onecalib.h.

◆ ANGLE45_H

#define ANGLE45_H   ((ANGLE45 + ANGLE_TOLERANCE) * DEG2RADFACTOR)

angle position limit in radians used for the calibration process.

Definition at line 41 of file onecalib.h.

◆ ANGLE45_L

#define ANGLE45_L   ((ANGLE45 - ANGLE_TOLERANCE) * DEG2RADFACTOR)

angle position limit in radians used for the calibration process.

Definition at line 42 of file onecalib.h.

◆ ANGLE_TOLERANCE

#define ANGLE_TOLERANCE   0.25

tolerance angle used for calibration process.

Definition at line 32 of file onecalib.h.

◆ ANGLE_TOLERANCE_RAD

#define ANGLE_TOLERANCE_RAD   (ANGLE_TOLERANCE * DEG2RADFACTOR)

tolerance angle in radians used for the calibration process.

Definition at line 33 of file onecalib.h.

◆ DEG2RADFACTOR

#define DEG2RADFACTOR   (M_PI / 180.00)

Definition at line 31 of file onecalib.h.

◆ RAD2DEGFACTOR

#define RAD2DEGFACTOR   (180.00 / M_PI)

Definition at line 30 of file onecalib.h.

Typedef Documentation

◆ ANALOG_SENSOR_DATA_t

◆ CALIB_DATA_t

typedef struct CALIB_DATA CALIB_DATA_t

◆ float64_t

typedef double float64_t

Definition at line 50 of file onecalib.h.

◆ ROTATION_DATA_STORE_t

Function Documentation

◆ ONECALIB_CalibrationFindParam()

void ONECALIB_CalibrationFindParam ( CALIB_DATA_t *  calib_param,
bool  rotate_CW,
bool  rotate_CCW 
)

This function is used to extract the calibration parameters. It should called until calib_param.full_calibration_performed is true. To extract the correct rotation, the input parameter rotate_CW should be true until calib_param.rotation_data_CW.calibration_done is true(while the magnet is spinning in CW direction). Same for the CCW direction. While calib_param.full_calibration_performed is false only the differential uncalibrated angle is available.

This function will extract the maximum, minimum voltage levels, amplitude, offset, and orthogonality. Based on the found values, it will calculate the necessary calibration parameters.

Usage example:

------------------- CALIBRATION FOR CW DIRECTION -------------------------------
while (!calibration_store_params.rotation_data_CW.calibration_done) {
// read sensor data
ONECALIB_CalibrationFindParam(&calibration_store_params, true,
false);
}
------------------- CALIBRATION FOR CCW DIRECTION -------------------------------
UART_Transmit(&UART_0, message_ccw, sizeof(message_ccw) - 1);
while (!calibration_store_params.rotation_data_CCW.calibration_done) {
// read sensor data
ONECALIB_CalibrationFindParam(&calibration_store_params,
false, true);
}
------------------- GET CALIBRATED ANGLE DATA ----------------------------------
if (calibration_store_params.full_calibration_performed) {
angle_read = ONECALIB_GetCalibAngle(&calibration_store_params);
}
Parameters
[in]calib_paramis a pointer of type CALIB_DATA_t, this structure holds the current sensor calibration parameters.
[in]rotate_CWis a bool that is true if the rotation is in clockwise direction.
[in]rotate_CCWis a bool that is true if the rotation is in counter-clockwise direction.
Returns
Nothing

Definition at line 468 of file onecalib.c.

References ROTATION_DATA_STORE::calibration_done, and CALIB_DATA::rotation_data_CW.

◆ ONECALIB_GetAngle()

float64_t ONECALIB_GetAngle ( const CALIB_DATA_t *  calib_param)

Calculates the calibrated angle if calibration has been performed, else the uncalibrated angle.

This function checks the stored calibration parameters and returns a angle value, no matter if the calibration procedure has been performed.

Parameters
[in]calib_paramis a pointer of type CALIB_DATA_t, this structure holds the current sensor calibration parameters.
Returns
Returns the calibrated or uncalibrated angle in degrees.

Definition at line 372 of file onecalib.c.

◆ ONECALIB_GetCalibAngle()

float64_t ONECALIB_GetCalibAngle ( const CALIB_DATA_t *  calib_param)

Calculates the calibrated angle.

Don't use this if the calibration procedure has not been performed. This function dosen't check the stored calibration parameters and returns the calibrated angle value.

Parameters
[in]calib_paramis a pointer of type CALIB_DATA_t, this structure holds the current sensor calibration parameters.
Returns
Returns the calibrated angle in degrees.

Definition at line 414 of file onecalib.c.

◆ ONECALIB_GetUncalibAngle()

float64_t ONECALIB_GetUncalibAngle ( void  )

Calculates the uncalibrated angle.

This function uses differential sensor data to extract the angle.

Returns
Returns the uncalibrated angle in degrees.

Definition at line 397 of file onecalib.c.

◆ ONECALIB_InitCalibData()

void ONECALIB_InitCalibData ( CALIB_DATA_t *  calib_param)

Function used for CALIB_DATA_t data initialization. The pointer of type CALIB_DATA_t will be used to store calibration parameters.

This function must be called once before ONECALIB_CalibrationFindParam(..).

Parameters
[in]calib_paramis a pointer of type CALIB_DATA_t.
Returns
Nothing

Definition at line 301 of file onecalib.c.

◆ ONECALIB_InitSensorData()

void ONECALIB_InitSensorData ( uint32_t  sinP_in_LSB,
uint32_t  cosP_in_LSB,
uint32_t  sinN_in_LSB,
uint32_t  cosN_in_LSB 
)

Function used for ANALOG_SENSOR_DATA_t data assignment.

This function must be called after the data readout.

The initialized pointer will be used in the angle calculation and calibration process.

Parameters
[in]cosP_in_LSBis the sensor value in LSB corresponding to the positive cosinus.
[in]cosN_in_LSBis the sensor value in LSB corresponding to the negative cosinus.
[in]sinP_in_LSBis the sensor value in LSB corresponding to the positive sinus.
[in]sinN_in_LSBis the sensor value in LSB corresponding to the negative sinus.
Returns
Nothing

Definition at line 242 of file onecalib.c.