mkliop 发表于 2023-5-29 20:26:14

一些开源的LCR电桥源码里为什么不用三角函数运算就可以?

看网上开源的LCR电桥核心代码里不用算阻抗角的三角函数也可以测量电阻和电抗是什么原理呢?
本论坛开源的代码也是类似
在https://www.amobbs.com/thread-5152439-1-1.html
比如如下的代码.

IF.Btn3=1                  ;Calibrate - Test OPEN?
    H=A^2 + B^2                  ;Denom of Zin = Vc / Io
    VarE=((A * C) + (B * D)) / H   ;Re of Zin
    VarI=((A * D) - (B * C)) / H   ;Im of Zin
    R=VarE                         ;Copy for cal display
    X=VarI
ELSE.                      ;Else normal run
    H=VarE^2 + VarI^2
    A=A - ((VarE * C) + (VarI * D)) / H   ;Re of Io - Iin
    B=B - ((VarE * D) - (VarI * C)) / H   ;Im of Io - Iin
    H=A^2 + B^2               ;Denom of Zc = Vc / (Io - Iin)
    R=((A * C) + (B * D)) / H   ;Re of Zc
    X=((B * C) - (A * D)) / H   ;Im of Zc
ENDIF.

IF.Btn5=1                  ;Calibrate - Test SHORT?
    VarG=R                     ;Re of ground voltage drop Vg
    VarH=X                     ;Im of Vg
ELSE.                      ;Else normal run
    R=R - VarG               ;Deduct ground drop
    X=X - VarH
ENDIF.

D=(R/X)^2                  ;Dissipation factor (squared)

老母鸡火箭筒 发表于 2023-5-30 09:49:38

求三角函数可以用CORDIC或者微分方法均可实现,三角函数很多单片机缺函数库

mkliop 发表于 2023-5-30 12:43:17

老母鸡火箭筒 发表于 2023-5-30 09:49
求三角函数可以用CORDIC或者微分方法均可实现,三角函数很多单片机缺函数库 ...
(引用自2楼)

有好多源码里面都是复数运算,不了解其中原理

TINXPST 发表于 2023-5-30 14:56:21

mkliop 发表于 2023-5-30 12:43
有好多源码里面都是复数运算,不了解其中原理
(引用自3楼)

Keil中支持复数的运算,其实就是定义了几个复数运算的函数。就像这个样子的:

//-----------------------------------------------------------------------------
// Div_Complex
//-----------------------------------------------------------------------------
//
// Return Value : true if no error in a floating-point number operation
// Parameters   : A, B and pointer on C (real and imaginary parts)
//
//C = A / B
//If an error is detected the operation is not performed.
//Usage:float Rsm,Xsm;
//          Div_Complex(Vp, Vq, Ip, Iq, &Rsm, &Xsm); // measured values: Zxm = (Vp+jVq)/(Ip+jIq) = Rsm + jXsm
//
void Div_Complex(float A_Real, float A_Imag, float B_Real, float B_Imag, float *C_Real, float *C_Imag)
{
   // u8 a, b;
    float CR, CI;
        float Y = B_Real * B_Real + B_Imag * B_Imag;

    if (fabs(Y) < MINFLOAT)
      Y = MINFLOAT;

    CR = (A_Real * B_Real + A_Imag * B_Imag) / Y;
    CI = (A_Imag * B_Real - A_Real * B_Imag) / Y;

//    a = chkfloat(CR); // >= 2 if there is an error
//    b = chkfloat(CI);

//    if (a >= 2 || b >= 2)
//      return false;

    *C_Real = CR;
    *C_Imag = CI;
   // return true;
} // Div_Complex


//-----------------------------------------------------------------------------
// Mul_Complex
//-----------------------------------------------------------------------------
//
// Return Value : true if no error in a floating-point number operation
// Parameters   : A, B and pointer on C (real and imaginary parts)
//
//C = A * B
//If an error is detected the operation is not performed.
//
void Mul_Complex(float A_Real, float A_Imag, float B_Real, float B_Imag, float *C_Real, float *C_Imag)
{
   // u8 a, b;
    float CR, CI;

        CR = (A_Real * B_Real - A_Imag * B_Imag);
        CI = (A_Imag * B_Real + A_Real * B_Imag);

//    a = chkfloat(CR); // >= 2 if there is an error
//    b = chkfloat(CI);

//    if (a >= 2 || b >= 2)
//      return false;

    *C_Real = CR;
    *C_Imag = CI;
   // return true;
} // Mul_Complex
页: [1]
查看完整版本: 一些开源的LCR电桥源码里为什么不用三角函数运算就可以?