搜索
bottom↓
回复: 3

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

[复制链接]

出0入8汤圆

发表于 2023-5-29 20:26:14 | 显示全部楼层 |阅读模式
看网上开源的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)

阿莫论坛20周年了!感谢大家的支持与爱护!!

曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……

出0入42汤圆

发表于 2023-5-30 09:49:38 | 显示全部楼层
求三角函数可以用CORDIC或者微分方法均可实现,三角函数很多单片机缺函数库

出0入8汤圆

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

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

出0入0汤圆

发表于 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
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-8-15 18:07

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表