?? varh.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: VARH.C
//
#include "options.h"
#if VAR_ELEMENT
#include <math.h>
#include "mmath.h"
#include "lcd.h"
#include "meter.h"
#include "library.h"
#include "wh.h" // get wh_sum_*() routines
#include "varh.h" // test the fn prototypes
/*** Private functions declared within this module ***/
// None
static void varh_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_kVArH ();
}
void varh_lcd (uint8x_t *val)
{
varh_mission_to_lcd (wh_to_long (val));
}
#if DEMAND
static void var_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_kVAr ();
}
void var_lcd (uint32_t val)
{
var_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 VARh_Accumulate (void)
{
// If either net metering or calibration is present
// Signed VARhs are used in the autocalibration
#if NET_METER || AUTOCAL
#if PHASE_A_PRESENT
wh_sum_net (VARh_A, &var0sum); // VAR hours phase A.
#endif // element A
#if PHASE_B_CALCULATED
wh_sum_net (VARh_B, &var1sum); // VAR hours phase B.
#endif // element B
#if PHASE_C_CALCULATED
wh_sum_net (VARh_C, &var2sum); // VAR hours phase C.
#endif // element C
memcpy_xx (VARh, VARh_A, sizeof (VARh));// Clear total VARhs.
#if PHASE_B_PRESENT
add8_8 (VARh, VARh_B); // Sum up VARhs.
#endif // element B
#if PHASE_C_CALCULATED
add8_8 (VARh, VARh_C); // Sum up VARhs.
#endif // net metering and var sums
#endif // var sums
// absolute value metering is not used for vars...
#if IMPORT
#if PHASE_A_PRESENT
wh_sum_import (VARhi_A, &var0sum); // VAR hours phase A.
#endif // element A
#if PHASE_B_CALCULATED
wh_sum_import (VARhi_B, &var1sum); // VAR hours phase B.
#endif // element B
#if PHASE_C_CALCULATED
wh_sum_import (VARhi_C, &var2sum); // VAR hours phase C.
#endif // element C
#if !VAR_SUMS
if (i0sqsum > i1sqsum)
{
wh_sum_import (VARhi, &var0sum); // Watt hours phase A.
}
else
{
wh_sum_import (VARhi, &var1sum); // Watt hours phase B.
}
#else
memcpy_xx (VARhi, VARhi_A, sizeof (VARhi_A)); // Clear total VAR imports.
#if PHASE_B_PRESENT
add8_8 (VARhi, VARhi_B); // Sum up VAR imports.
#endif // element B
#if PHASE_C_CALCULATED
add8_8 (VARhi, VARhi_C); // Sum up VAR imports.
#endif // element C
#endif // VAR_SUMS
#endif // IMPORT
#if EXPORT
#if PHASE_A_PRESENT
wh_sum_export (VARhe_A, &var0sum); // VAR hours phase A.
#endif // element A
#if PHASE_B_CALCULATED
wh_sum_export (VARhe_B, &var1sum); // VAR hours phase B.
#endif // element B
#if PHASE_C_CALCULATED
wh_sum_export (VARhe_C, &var2sum); // VAR hours phase C.
#endif // element C
#if !VAR_SUMS
if (i0sqsum > i1sqsum)
{
wh_sum_export (VARhe, &var0sum); // Watt hours phase A.
}
else
{
wh_sum_export (VARhe, &var1sum); // Watt hours phase B.
}
#else // var sums
memcpy_xx (VARhe, VARhe_A, sizeof (VARhe_A)); // Clear out VAR exports.
#if PHASE_B_PRESENT
add8_8 (VARhe, VARhe_B); // Sum up VAR exports.
#endif // element B
#if PHASE_C_CALCULATED
add8_8 (VARhe, VARhe_C);
#endif // element C
#endif // VAR_SUMS
#endif // EXPORT
}
#endif // equation
/***************************************************************************
* History
* $Log: varh.c,v $
* Revision 1.16 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.15 2006/10/03 00:33:58 tvander
* Turned off WATT_SUMS and VAR_SUMS, so that maximum of elements is calculated instead of sums. Assured that Wh exports and VARh imports and exports both have a "maximum of A and B" behavior when WATT_SUMS and VAR_SUMS are turned off.
*
* Revision 1.14 2006/09/14 00:41:09 tvander
* Spaces for tabs (pretty printing)
*
* Revision 1.13 2006/09/13 21:39:07 gmikef
* *** empty log message ***
*
* Revision 1.12 2006/09/12 02:45:19 gmikef
* *** empty log message ***
*
* Revision 1.11 2006/09/10 00:28:39 Michael T. Fischer
* First version to support DGM0915 LCD.
*
* Revision 1.10 2006/09/09 01:15:00 gmikef
* *** empty log message ***
*
* Revision 1.9 2006/09/08 07:37:49 Michael T. Fischer
* *** empty log message ***
*
* Revision 1.8 2006/06/06 05:15:20 tvander
* clean build
*
* Revision 1.7 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.6 2006/04/25 01:09:56 tvander
* Integrated improved RTC. Compensates for time off, has default constant
* compensation. Computes true hours of operation.
*
* Revision 1.5 2006/04/12 00:27:50 tvander
* Debugged compilation with equations 3 and 4, on 6513
*
* Revision 1.4 2006/03/06 03:41:20 Michael T. Fischer
* More 6530 prep.
*
* Revision 1.3 2006/01/04 04:47:54 gmikef
* Switched RMS and VA calculations to use floating point. (and Calibration).
*
* 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.
*
* 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. *
***************************************************************************/
#endif // VAR_ELEMENT
/* varh.c */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -