TIDUF78 May   2024

 

  1.   1
  2.   Description
  3.   Resources
  4.   Features
  5.   Applications
  6.   Design Images
  7. 1System Description
    1. 1.1 Key System Specifications
  8. 2System Overview
    1. 2.1 Block Diagram
    2. 2.2 Design Considerations
    3. 2.3 Highlighted Products
  9. 3System Design Theory
    1. 3.1 Hardware Design
    2. 3.2 Software Design
      1. 3.2.1 TMAG5170 SPI Frame
        1. 3.2.1.1 Serial Data In 32-Bit Frame
        2. 3.2.1.2 Serial Data Out 32-Bit Frame
      2. 3.2.2 TMAG5170 Register Configuration
      3. 3.2.3 SPI and Start-of-Conversion Timing
      4. 3.2.4 Linear Position Calculation
  10. 4Hardware, Software, Testing Requirements, and Test Results
    1. 4.1 Hardware
      1. 4.1.1 PCB Overview
      2. 4.1.2 MCU Interface Connector
    2. 4.2 Test Setup
    3. 4.3 Test Results
      1. 4.3.1 Magnetic Z and X Field Measurement
      2. 4.3.2 Linear Position Measurement
      3. 4.3.3 SPI Signal Measurement
  11. 5Design and Documentation Support
    1. 5.1 Design Files
      1. 5.1.1 Schematics
      2. 5.1.2 BOM
      3. 5.1.3 PCB Layout
        1. 5.1.3.1 Layout Prints
        2. 5.1.3.2 Layout Guidelines
    2. 5.2 Tools and Software
    3. 5.3 Documentation Support
    4. 5.4 Support Resources
    5. 5.5 Trademarks
  12. 6About the Author

Linear Position Calculation

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.

TIDA-060045 Simplified Position
                    Calculation Flowchart Figure 3-7 Simplified Position Calculation Flowchart

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.

Equation 1. Angledegnum=180°πatanZnum,Xnum

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.

Equation 2. LinPoscmnum=Angledegnum90°1.25cm+num2.5cm+RefOffsetcm

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.

Equation 3. LinPoscmnum=LinPoscmnum+absXnumCompFactorcmmT

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).