ZHCUCC6 September 2024
由于 AMR 传感器在机械旋转一周过程中会生成两个正弦和余弦周期,需要额外的检测来区分 0° 至 180° 和 180° 至 360°。因此,TMAG6180 集成了两个 X、Y 霍尔开关,这有助于使用 Q0 和 Q1 输出将角度范围从 180° 扩展到 360°。角度计算流程图如图 3-6 所示,示例代码如下:
//----------------------------------------------------------------------
//Angle calculation
//----------------------------------------------------------------------
//comp0[0] = _IQ(0)
//comp0[1] = _IQ(1)
//comp1[0] = _IQ(1)
//comp1[1] = _IQ(0)
//----------------------------------------------------------------------
SinCosInput.SinCos.Sin = SinCosInput.SinCos.Sin - Adc16bitOffset;
SinCosInput.SinCos.Cos = SinCosInput.SinCos.Cos - Adc16bitOffset;
//ATAN2 calculation
DL_MathACL_startArcTan2Operation(MATHACL, &gAtanOpConfig, SinCosInput.SinCos.Sin, SinCosInput.SinCos.Cos);
DL_MathACL_waitForOperation(MATHACL);
SinCosOutput.PhasePU = DL_MathACL_getResultOne(MATHACL);
angle = _IQ(0.25) - (SinCosOutput.PhasePU>>1);
// Extend to 360 deg. 90 degree ~ 0.25, 45 degree ~ 0.125, 135 ~ 0.375
if((angle <= _IQ(0.375)) && (angle>_IQ(0.125)))
absangle=comp0[TMAG_Q0]+angle;
else
{
if (angle>_IQ(0.375))
absangle=comp1[TMAG_Q1]+angle;
else
absangle=_IQ(0.5)-comp1[TMAG_Q1]+angle;
}