📄 vah.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 - Accumulation Routines.
//
// AUTHOR: RGV
//
// HISTORY: See end of file.
//**************************************************************************
// File: VAH.C
//
#include "options.h"
#include <math.h>
#include "mmath.h"
#include "meter.h"
#include "lcd.h"
#include "library.h"
#include "wh.h" // wh_sum_* () routines
#include "vah.h" // test the fn prototypes
/*** External variables referenced by this module ***/
// va0sum..va2sum are in meter\meter.h
// See "math.h"
/*** Public variables declared within this module ***/
// None
/*** Private functions declared within this module ***/
#if RMS_VALUES
static int32_t VAh_VA (int32_t xdata *v0, int32_t xdata *i0);
#endif
/*** Private variables declared within this module ***/
// None
/*** Public functions declared within this module ***/
// function used in meter.c to figure creep
int32_t VAh_WVAR (int32p_t *w0, int32p_t *v0)
{
float w, v;
w = (float)(*w0);
v = (float)(*v0);
return (lroundf(sqrt (w * w + v * v)));
}
#if VA_ELEMENT
#if RMS_VALUES
// Figure VAh from Irms and Vrms
static int32_t VAh_VA (int32_t xdata *v0, int32_t xdata *i0)
{
float v, i;
v = ((float)(*v0))/65536.0;
i = ((float)(*i0))/65536.0;
return (lroundf(v * i));
}
#endif
static void vah_mission_to_lcd (uint32_t l)
{
LCD_Number (l, 6, 3); // Display up to six digits (x % 1,000,000).
LCD_3DP (); // Three (3) Decimal Points.
LCD_kVAH ();
}
void vah_lcd (uint8x_t *val)
{
vah_mission_to_lcd (wh_to_long (val));
}
#if DEMAND
static void va_mission_to_lcd (uint32_t l)
{
LCD_Number (l, 6, 3); // Display up to six digits (x % 1,000,000).
LCD_3DP (); // Three (3) Decimal Points.
LCD_kVA ();
}
void va_lcd (uint32_t val)
{
va_mission_to_lcd (w_to_long (val));
}
#endif // DEMAND.
#ifdef EQUATION
#define PHASE_B_CALCULATED (PHASE_B_PRESENT || EQUATION == _1ELEMENT_3WIRE)
#define PHASE_C_CALCULATED (EQUATION == _2ELEMENT_4WIRE_DELTA || EQUATION == _3ELEMENT_4WIRE_WYE)
void VAh_Accumulate (void)
{
// Note that va0sum..va1sum are already calculated for creep
// detection using sqrt(wh*wh + varh*varh), in meter.c
// Those values are in meter.h (va0sum..va2sum), and are just
// used here, unless the calculation from RMS values is required.
#if RMS_VALUES
if (Config & CFG_VAH_SELECT) // VA hours phase A.
{ // VA hours phase B.
#if PHASE_A_PRESENT
va0sum = VAh_VA (&Vrms_A, &Irms_A);
#else
va0sum = 0;
#endif // element A
#if PHASE_B_CALCULATED
#if EQUATION == _2ELEMENT_3WIRE_DELTA || EQUATION == _2ELEMENT_4WIRE_WYE || EQUATION == _3ELEMENT_4WIRE_WYE
va1sum = VAh_VA (&Vrms_B, &Irms_B);
#else
va1sum = VAh_VA (&Vrms_A, &Irms_B);
#endif
#else
va1sum = 0;
#endif // element B
#if PHASE_C_CALCULATED
va2sum = VAh_VA (&Vrms_C, &Irms_C);
#endif // element C
}
#endif // RMS_VALUES.
#if PHASE_A_PRESENT
wh_sum_net (VAh_A, &va0sum); // VA hours phase A.
#endif // element A
#if PHASE_B_CALCULATED
wh_sum_net (VAh_B, &va1sum); // VA hours phase B.
#endif // element B
#if PHASE_C_CALCULATED
wh_sum_net (VAh_C, &va2sum); // VA hours phase C.
#endif // element C
#if VA_SUMS
vasum = va0sum;
memcpy_xx (VAh, VAh_A, sizeof (VAh)); // Clear out overall VAhs.
#if PHASE_B_PRESENT
vasum += va1sum;
add8_8 (VAh, VAh_B); // Sum up overall VAhs.
#endif // element B
#if PHASE_C_CALCULATED
vasum += va2sum;
add8_8 (VAh, VAh_C); // Sum up overall VAhs.
#endif // element C
#endif // VA_SUMS
}
#endif // EQUATION.
/***************************************************************************
* History
* $Log: vah.c,v $
* Revision 1.19 2006/10/11 20:46:48 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.18 2006/09/14 00:40:29 tvander
* Adds up vasum
*
* Revision 1.17 2006/09/13 21:39:05 gmikef
* *** empty log message ***
*
* Revision 1.16 2006/09/12 02:45:16 gmikef
* *** empty log message ***
*
* Revision 1.15 2006/09/10 00:28:30 Michael T. Fischer
* First version to support DGM0915 LCD.
*
* Revision 1.14 2006/09/09 02:29:45 gmikef
* *** empty log message ***
*
* Revision 1.13 2006/09/09 01:14:56 gmikef
* *** empty log message ***
*
* Revision 1.12 2006/09/08 07:37:32 Michael T. Fischer
* *** empty log message ***
*
* Revision 1.11 2006/05/18 23:18:54 tvander
* 16K and 32K
* First cut at new requirements.
* 32K 6521 is grossly tested.
* All others have a clean compile with C51 8.02
*
* Revision 1.10 2006/04/12 00:27:50 tvander
* Debugged compilation with equations 3 and 4, on 6513
*
* Revision 1.9 2006/03/06 03:41:03 Michael T. Fischer
* More 6530 prep.
*
* Revision 1.8 2006/02/10 03:13:21 tvander
* Fixed VAh calculations and display, date display
*
* Revision 1.7 2006/01/16 20:11:29 tvander
* Clean Keil build, all versions
*
* Revision 1.5 2006/01/10 04:08:22 gmikef
* Added PDATA support for CE Outputs.
*
* Revision 1.4 2006/01/04 04:47:54 gmikef
* Switched RMS and VA calculations to use floating point. (and Calibration).
*
* Revision 1.3 2005/12/23 01:27:46 tvander
* Meter.c would not compile for 6513 because a table was wrong.
* A few style issues.
*
* Revision 1.1 2005/10/08 04:41:28 tvander
* Fixed priority inversion.
* Rewrote watchdog to work in brownout, but of course it doesn't work.
* Watchdog can now be defeated by clearing watchdog option to 0.
* Reorganized watt hour modules (at last!).
* Disabled reading of STATUS in 6521_cli because the CE's status is always SAG.
* Tested with 6521_CLI; measurements seem to work.
* Fixed other builds.
*
*
* As accumulate.c:
* Revision 1.9 2005/09/22 23:45:13 tvander
* Clean build all models and unit tests, updated copyright to be fore Teridian
*
* Revision 1.8 2005/09/11 00:34:04 tvander
* Clean compiles
*
* Revision 1.7 2005/08/30 18:14:00 gmikef
* *** empty log message ***
*
* Revision 1.6 2005/06/18 00:58:12 tvander
* Refactored accumulate_energy, squashed a bunch of bugs.
*
* Revision 1.5 2005/06/17 22:54:44 tvander
* Separated imports and exports.
* Some imports and exports were not being updated.
*
* Revision 1.4 2005/06/14 00:14:42 tvander
* Error in accumulation- it was checking a pointer for its sign.
*
* Revision 1.3 2005/04/30 02:12:59 gmikef
* *** empty log message ***
*
* Revision 1.6 2005/04/29 00:01:58 gmikef
* *** empty log message ***
*
* Revision 1.5 2005/04/27 21:38:06 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. *
***************************************************************************/
/* vah.c */
#endif // VA_ELEMENT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -