⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 phase_angle.c

📁 TDK 6521 SOC 芯片 DEMO程序
💻 C
字号:
/***************************************************************************
 * This code and information is provided "as is" without warranty of any   *
 * kind, either expressed or implied, including but not limited to the     *
 * implied warranties of merchantability and/or fitness for a particular   *
 * purpose.                                                                *
 *                                                                         *
 * Copyright (C) 2005 Teridian Semiconductor Corp. All Rights Reserved.    *
 ***************************************************************************/
//**************************************************************************
//  DESCRIPTION: 71M652x POWER METER - Phase Angle Calculation.
// 
//  AUTHOR:  MTF
//
//  HISTORY: See end of file
//**************************************************************************
// File: PHASE_ANGLE.C 
//
#include "options.h"
#if PHASE_ANGLES
#include "lcd.h"
#include "meter.h"

#define PHASE_B_CALCULATED (PHASE_B_PRESENT || EQUATION == _1ELEMENT_3WIRE)

// External functions used by this module.
uint32_t latan2 (int32_t y, int32_t x); // Returns arcTangent (y/x) in mDegrees.

static void Display_Phase_Angle (int32_t d);

void phase_angle_lcd (uint8_t select_phase)
{
    int32_t d;
    switch (select_phase)
    {
       #if PHASE_A_PRESENT
       case 1:
          d = IPhase_A;
          break;
       #endif

       #if PHASE_B_CALCULATED
       case 2:
          d = IPhase_B;
          break;
       #endif

       #if PHASE_C_PRESENT
       case 3:
          d = IPhase_C;
          break;
       #endif

       default:
          d = 0;
          break;
    }
    Display_Phase_Angle (d);
}
 
static void Display_Phase_Angle (int32_t d)
{
    if (d > 359500l )
        d = 0;
    LCD_Number ((d + 500) / 1000, 4, 0);  // meter upto four digits (rounded).
}                                                         

void Compute_Phase_Angle (void)
{
#if PHASE_A_PRESENT
    if(Irms_A < VThrshld)
        IPhase_A = 0;
#if STATUS
    else if (SAGA & Status)
        IPhase_A = 0;
#endif
    else
        IPhase_A = latan2 (var0sum, w0sum);
#endif
#if PHASE_B_CALCULATED
    if(Irms_A < VThrshld)
        IPhase_B = 0;
#if STATUS
    else if (SAGB & Status)
        IPhase_B = 0;
#endif
    else
        IPhase_B = latan2 (var1sum, w1sum);
#endif
#if PHASE_C_PRESENT
    if(Irms_C < VThrshld)
        IPhase_C = 0;
#if STATUS
    else if (SAGC & Status)
        IPhase_C = 0;
#endif
    else
        IPhase_C = latan2 (var2sum, w2sum);
#endif
}
#endif
/***************************************************************************
 * History:
 * $Log: phase_angle.c,v $
 * Revision 1.14  2006/10/11 20:46:47  tvander
 * Fixed phase B accumulation and measurement for equation 1.
 * Phase B is not part of the equation, but is very useful for calibration.
 *
 * Revision 1.13  2006/09/29 08:57:44  tvander
 * Phase calculation ought to be smaller.
 *
 * Revision 1.12  2006/09/09 01:14:36  gmikef
 * *** empty log message ***
 *
 * Revision 1.11  2006/06/14 02:46:38  tvander
 * Faster LCD display.
 *
 * Revision 1.10  2006/05/25 03:31:45  tvander
 * Renamed variables so nonvolatile variables can be switched to other definitions
 * of watt-hours (e.g. from absolute value to volt-amps or imports)
 * (meter.c, meter.h, pulse_src.c)
 * FIxed power factors so they zero correctly.
 * Fixed RMS to work with different accumulation interval.
 *
 * Revision 1.9  2006/03/06 03:40:28  Michael T. Fischer
 * More 6530 prep.
 *
 * Revision 1.8  2006/01/16 20:11:28  tvander
 * Clean Keil build, all versions
 *
 * Revision 1.6  2005/09/28 20:54:03  tvander
 * V/I phase displays for all phases,
 * main edge count displays for both types,
 * rewrote setup from defaults to group related functions.
 *
 * Revision 1.5  2005/09/22 23:45:19  tvander
 * Clean build all models and unit tests, updated copyright to be fore Teridian
 *
 * Revision 1.4  2005/08/30 18:19:27  gmikef
 * *** empty log message ***
 *
 * Revision 1.3  2005/04/30 02:14:58  gmikef
 * *** empty log message ***
 *
 * Revision 1.5  2005/04/27 21:38:09  gmikef
 * *** empty log message ***
 *
 * Copyright (C) 2005 Teridian Semiconductor Corp. All Rights Reserved.    *
 * this program is fully protected by the United States copyright          *
 * laws and is the property of Teridian Semiconductor Corporation.         *
 ***************************************************************************/
/* phase angle.c */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -