SLYU064A June   2023  – December 2023 TMAG3001 , TMAG5170 , TMAG5170-Q1 , TMAG5170D-Q1 , TMAG5173-Q1 , TMAG5253 , TMAG5273

 

  1.   1
  2.   Abstract
  3.   Trademarks
  4. 1Introduction
  5. 2Joystick Design
    1. 2.1 Establishing Form Factor
      1. 2.1.1 Choosing Mechanical Implementation
      2. 2.1.2 Choosing Magnetic Implementation
    2. 2.2 Magnet Sensor Placement
    3. 2.3 Design Calculations
    4. 2.4 Post Processing
    5. 2.5 Prototyping and Bench Testing
    6. 2.6 Error Sources
      1. 2.6.1 Mechanical Hysteresis
      2. 2.6.2 Nearby Material Influence
      3. 2.6.3 Fulcrum Slippage
      4. 2.6.4 Offset
  6. 3Lever Design
    1. 3.1 Establishing a Form Factor
      1. 3.1.1 Choosing Mechanical Implementation
    2. 3.2 Magnet Sensor Placement
    3. 3.3 Design Calculations
    4. 3.4 Prototyping and Bench Testing
    5. 3.5 Error Sources
  7. 4Summary
  8. 5References
  9. 6Revision History

Post Processing

Regardless of whether the joystick is implemented with 1 magnet and 1 sensing device or 2 magnets and and 2 sensing devices, some post processing is required to translate measured data into position data relevant to the end user. Postprocessing takes measurements corresponding to the joystick pitching along x-axis and along the y-axis to extrapolate rotation angle and pitch angle.

For the 2 magnet, 2 device design, calibration involves finding the global maximum and minimum values for the z-axis field observed on both sensors. One device's z-field values relate to the joystick movement in the x-direction while the other device's z-field values relate to joystick movement in the y-direction. The bound measurements serve as a reference upon which future measurements can be compared. To find these bound values the user needs to move the joystick around the movement region perimeter as shown in Figure 2-14 and the device sampling rate is significantly faster than the user moving the joystick around the movement region perimeter. This increases spatial resolution in the calibration phase and ensure a higher probability of the ideal global maximum and minimums being detected by the sensor. These values are expected to be found at 0°, 90°, 180°, and 270°, which a user could easily miss by a few degrees if the user simply tried to calibrate by only moving to those visually perceived angles.

GUID-20230512-SS0I-GV0W-FTZX-6QX1PFLPSXRX-low.svg Figure 2-14 Circle Movement for Determining Global Maximums and Minimums

Because an unintended offset between device and sensor in the plane of rotation is expected to have influence on the linearity of the measurement, the default rest position and joystick bound measurements can be determined. This can be measured when the thumbstick is at the resting position. Alternatively, if the resting position is expected to have some tolerance, a calculation of the average position through the previously determined global maximums and minimums can be used.

With the x and y bound values calculated as well as the middle resting position, a rotation value can be calculated. The underlying concept leveraged is stated in Equation 1. However, in this case the all measured x and y values are normalized with respect to the global maximum and minimum values found during calibration like in Equation 2.

Equation 1. Angle   =   arctan ( y x )
Equation 2. Angle   =   arctan ( y_component x_component )   =   arctan ( Y_measured Y_Center Y_Bound Y_Center X_measured X_Center X_Bound X_Center )

As normalization leads to all x component and y component values ranging between 0 and 1, only angles between 0 and 90° are calculated. Therefore signs need to be assigned to the x_component and y_component. How signs are assigned depends on magnet polarity which can vary if there is not consistent assembly. Figure 2-15 shows that there are four different ways the magnets can be installed for the 2 magnet 2 sensor direction. Consequently, a function like in the following pseudo code can be used.

GUID-20230512-SS0I-DGPC-FGN8-Q8G5XPRWJRS8-low.svg Figure 2-15 Magnet Installation
float AngleComponent(const float measured, const float Left_Down_Bound, const float Right_Up_Bound, const float Center)
{
    float angleComponent;
    if(measured > Center)
    {
        if(Left_Down_Bound > Center)
        {
            angleComponent = -(measured-Center)/(Left_Down_Bound-Center);
        }
        else if(Right_Up_Bound > Center)
        {
            angleComponent = (measured-Center)/(Right_Up_Bound-Center);
        }
    }
    else if(measured < Center)
    {
        if(Left_Down_Bound < Center)
        {
            angleComponent = -(measured-Center)/(Left_Down_Bound-Center);
        }
        else if(Right_Up_Bound < Center)
        {
            angleComponent = (measured-Center)/(Right_Up_Bound-Center);
        }
    }
    return angleComponent;
}

One pitfall of the arc-tangent function, commonly abbreviated to atan(), is that this function calculates values between -90° and 90°. To get the entire range of angles in a circle, atan2() must be used. However, this function calculates values between -180° and 180°. Therefore, if angles are strictly desired in positive values, a ternary operator can be included in the calculation like in Equation 3.

Equation 3. Angle   =   atan2 ( y_component x_component ) + ( y_component < 0 ? 360 : 0 )

Joystick pitch can then be extrapolated from the measured data with Equation 4 so long as the movement region bounding pitch angle is known.

Equation 4. Angle   =   Pitch max × ( x 2 + y 2 x 2 max + y 2 max )