TIDUF78 May 2024
The linear position over the four equidistant spaced TMAG5170 is calculated in every interrupt service routine at a 4kHz rate sample rate per below flow-chart in Figure 3-7.
The Z-axis and X-axis data of the four TMAG5170 are read. If none of the Z-axis magnitude exceeds a minimum field strength, the moving magnet is out of range. If not, the TMAG5170 with the highest magnitude in the Z-axis is identified. A hysteresis can be used to avoid switching between two adjacent TMAG5170. This happens when the sense magnet position is in the center between two adjacent TMAG5170, hence both TMAG5170 measure similar Z-axis magnetic field strengths.
The angle calculation is only continued for the TMAG5170 with the highest magnetic field strength in the Z-axis.
In the first step the offset and gain of the Z-axis are corrected as identified during the system calibration. Then the angle with respect to the X position of the Hall-effect element with the corresponding TMAG5170 is calculated using the atan2 function of the calibrated Z-axis and X-axis, as per Equation 1.
In the second step, the linear position is calculated per Equation 2. Depending on the TMAG5170 number, the corresponding linear position offset is added too.
In the third step, the error due to the off-axis measurement is compensated using the absolute magnitude of the X-axis with a compensation factor identified during system calibration as per Equation 3.
The source code, which was used for calculating the linear position with the reference design is shown below.
//-------------------------------------------------------
// Angle calculation
//-------------------------------------------------------
// z_max_num
// 0: Out of range (Z-field too small)
// 3: TMAG5170[0] has highest Z-field
// 5: TMAG5170[1] has highest Z-field
// 7: TMAG5170[2] has highest Z-field
// 9: TMAG5170[3] has highest Z-field
//-------------------------------------------------------
void calcLinPos(int16_t zmax_num_index)
{
float tnom;
float tdenom;
PositionRead.LinPosRef_cm = LC415LinPos_cm; // Absolute linear position reference
if (zmax_num_index==0) // Magnet is out of range
{
PositionRead.LinPos_cm = 0; // Measured absolute linear position
PositionRead.LinPosError_cm = 0; // Measured position error
}
else
{
// Gain and offset compensated Z-axis
tnom = TMAGS_ARRAY[(zmax_num_index-3)/2].Z_mT-PositionCalc.OffsetZ_mT[(zmax_num_index-3)/2];
tnom = tnom*PositionCalc.GainComp[(zmax_num_index-3)/2];
tdenom = TMAGS_ARRAY[(zmax_num_index-3)/2].X_mT; // X-axis
PositionRead.Angle_deg = (180/3.1415)*atan2f(tdenom,tnom);
PositionRead.LinPos_cm = PositionRead.Angle_deg/90*PositionCalc.DistanceTMAG5170_cm/2;
PositionRead.LinPos_cm += PositionCalc.DistanceTMAG5170_cm * ((zmax_num_index-3)/2);
PositionRead.LinPos_cm += -PositionCalc.RefOffset_cm;
// Nonlinear position error compensation using X-field
PositionRead.LinPos_cm += PositionCalc.PosXfieldComp * abs(TMAGS_ARRAY[(zmax_num_index-3)/2].X_mT);
// calculate position error versus reference
PositionRead.LinPosError_cm = PositionRead.LinPos_cm - PositionRead.LinPosRef_cm;
}
}
For more information on angle and linear position calculation algorithms refer to the application reports Achieving Highest System Angle Sensing Accuracyand Magnet Selection for Linear Position Applications (Rev. A).