📄 ce652x.h
字号:
/***************************************************************************
* 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. *
* this program is fully protected by the United States copyright *
* laws and is the property of Teridian Semiconductor Corporation. *
***************************************************************************/
//**************************************************************************
// DESCRIPTION: 71M652x POWER METER - Compute Engine Program/Data.
//
// AUTHOR: MTF
//
// HISTORY: See end of file
//**************************************************************************
// File: CE652x.H
//
#ifndef CE652X_H
#define CE652X_H
#define CE_DATA_BASE 0x1000 // Base of CE Data RAM (4-byte wide elements).
#define CE_DATA_SIZE 0x0080 // Length of CE Data RAM in double words.
#define CE_PARM_BASE 0x1020 // Start of parameters for configuration
#define CE_PARM_SIZE 0x0018 // Length of parameters for configuration
// -1100 counts/ degree-C (from data sheet, but the code does the
// subtraction NOM-ACTUAL, rather than ACTUAL-NOM, so the sign is opposite),
// The ADC left-shifts the value by 9 bits (i.e. by a factor of 512)
// two successive samples are added by the
// CE to average both chop values,
// The result is about 8.878e-6 per LSB from the CE, or if you prefer,
// 0.1C = 112640 counts of temp_raw_x
#define DEG_SCALE (10.0/(2.0 * 1100.0 * 512.0))
// CE ADC data.
struct ADC_t
{
int32_t A_i0_raw; // Raw current element 0.
int32_t A_v0_raw; // Raw voltage element 0.
int32_t A_i1_raw; // Raw current element 1.
int32_t A_v1_raw; // Raw voltage element 1.
int32_t A_rsvrd_0; // Reserved.
int32_t A_temp_old; // Temperature previous mux cycle.
int32_t A_temp; // Temperature.
int32_t A_vbat; // Battery.
};
// CE constants.
struct Constants_t
{ // Defaults.
int32_t C_cal_i0; // 16384 Calibration constants.
int32_t C_cal_v0; // 16384 Calibration constants.
int32_t C_cal_i1; // 16384 Calibration constants.
int32_t C_cal_v1; // 16384 Calibration constants.
int32_t C_phadj_0; // 0 is ideal phase shift for 50 and 60Hz
int32_t C_phadj_1; // 0 is ideal phase shift for 50 and 60Hz
int32_t C_apulsew; // 0 Alternate Wh pulse data. Ignored if zero.
int32_t C_apulser; // 0 Alternate VARh pulse data. Ignored if zero.
int32_t C_cestate; // 0x5000 CE state.
int32_t C_wrate; // 2334 ;2334 for 1 Whr/pulse, if 2520 samples/SUM.
int32_t C_gain_adj; // 16384 Scales voltage and current values -- 16384 is unity.
int32_t C_quant; // 0 Compensation for 2's complement truncation.
int32_t C_sagthr; // 40108694 Vx must be above this to prevent sag alarm.
int32_t C_quant_var; // 0 Compensation for 2's complement truncation in VAR channel
int32_t C_quant_i; // 0 Compensation for 2's complement truncation in I^2 channel.
int32_t C_kvar; // 6448 VAR scale factor
}; // 0 is a legal value.
// Note that pulse output is normally high, with negative pulse.
// Definitions for 'cestate'.
#define CE_SAG_CNT 0xFF00
#define CE_FREQSEL 0x00C0
#define CE_EXT_PULSE BIT5
#define CE_I0_SHUNT BIT3
#define CE_I1_SHUNT BIT2
#define CE_PULSE_FAST BIT1
#define CE_PULSE_SLOW BIT0
#define CE_FREQ_ALIGN 6
// CE outputs.
struct Outputs_t
{
#if IMAX2
int32_t O_var1sum_ce; // Sum of output samples from var meter element 1.
int32_t O_w1sum_ce; // Sum of output samples from wattmeter element 1.
int32_t O_i1sqsum_ce; // Sum of I1^2 samples.
#else
int32_t O_var1sum; // Sum of output samples from var meter element 1.
int32_t O_w1sum; // Sum of output samples from wattmeter element 1.
int32_t O_i1sqsum; // Sum of I1^2 samples.
#endif
int32_t O_v1sqsum; // Sum of V1^2 samples.
int32_t O_var0sum; // Sum of output samples from var meter element 0.
int32_t O_w0sum; // Sum of output samples from wattmeter element 0.
int32_t O_i0sqsum; // Sum of I0^2 samples.
int32_t O_v0sqsum; // Sum of V0^2 samples.
int32_t O_freq; // The frequency of V[0-1] = FREQ * FS / 2^32.
int32_t O_cestatus; // CE Status word.
int32_t O_temp_raw; // Filtered raw temperature.
int32_t O_main_edge_cnt; // Number of edges (either direction, debounced) in pre};
};
extern volatile struct Outputs_t xdata CE_Outputs;
#define temp_raw_x CE_Outputs.O_temp_raw
#if IMAX2
#define MPU_Outputs (uint8p_t *) &var1sum_ce // Outputs from CE.
#else
#define MPU_Outputs (uint8p_t *) &var1sum // Outputs from CE.
#endif
extern volatile int32x_t cal_i0;
extern volatile int32x_t cal_v0;
extern volatile int32x_t cal_i1;
extern volatile int32x_t cal_v1;
extern volatile int32x_t phadj_0;
extern volatile int32x_t phadj_1;
extern volatile int32x_t apulsew;
extern volatile int32x_t apulser;
extern volatile int32x_t cestate;
extern volatile int32x_t wrate;
extern volatile int32x_t gain_adj;
extern volatile int32x_t quant;
extern volatile int32x_t sagthr;
extern volatile int32x_t quant_var;
extern volatile int32x_t quant_i;
extern volatile int32x_t kvar;
extern volatile int32x_t wsum_accum;
extern volatile int32x_t vsum_accum;
extern volatile int32x_t vbat;
#if IMAX2
extern volatile int32_t pdata var1sum_ce; // Sum of output samples from var meter element 1.
extern volatile int32_t pdata w1sum_ce; // Sum of output samples from wattmeter element 1.
extern volatile int32_t pdata i1sqsum_ce; // Sum of I1^2 samples.
#endif
extern volatile int32_t pdata var1sum; // Sum of output samples from var meter element 1.
extern volatile int32_t pdata w1sum; // Sum of output samples from wattmeter element 1.
extern volatile int32_t pdata i1sqsum; // Sum of I1^2 samples.
extern volatile int32_t pdata v1sqsum; // Sum of V1^2 samples.
extern volatile int32_t pdata var0sum; // Sum of output samples from var meter element 0.
extern volatile int32_t pdata w0sum; // Sum of output samples from wattmeter element 0.
extern volatile int32_t pdata i0sqsum; // Sum of I0^2 samples.
extern volatile int32_t pdata v0sqsum; // Sum of V0^2 samples.
extern volatile int32_t pdata freq;
extern volatile int32_t pdata cestatus;
extern volatile int32_t pdata temp_raw;
extern volatile int32_t pdata main_edge_cnt;
extern int32_t pdata va0sum; // Sum of output samples from VA meter element 0.
extern int32_t pdata va1sum; // Sum of output samples from VA meter element 1.
extern int32_t xdata deltaT; // Deviation from 22C, TEMP_NOM - TEMP; LSB 0.1 degrees C.
// Need in XRAM for battery backup.
// Definitions for 'cestatus'.
#define CE_F0 BIT28
#define CE_SAG_B BIT26
#define CE_SAG_A BIT25
#define CESTATUS (CE_F0 | CE_SAG_A | CE_SAG_B)
/****************************************************************************
* History:
* $Log: ce652x.h,v $
* Revision 1.32 2006/10/06 03:16:23 tvander
* Comment
*
* Revision 1.31 2006/10/06 03:05:47 tvander
* Fixed the constant DEG_SCALE. Again.
*
* Revision 1.30 2006/10/06 02:03:03 tvander
* Changed sign of DEG_SCALE, so the temperature increases when the chip is warmer.
*
* Revision 1.29 2006/10/06 01:37:26 tvander
* Corrected DEG_SCALE
*
* Revision 1.28 2006/09/09 01:13:19 gmikef
* *** empty log message ***
*
* Revision 1.27 2006/06/14 02:44:05 tvander
* Makes the vbat from the CE available.
*
* Revision 1.26 2006/06/10 01:55:07 tvander
* Updated DEG_SCALE to as-measured.
*
* Revision 1.25 2006/06/08 20:54:42 tvander
* Made CE parm seizes as large as possible, to accomodate changes.
*
* Revision 1.24 2006/06/06 03:59:27 tvander
* Added constants to save and restore CE parameters.
*
* Revision 1.23 2006/05/18 23:18:51 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.22 2006/03/17 00:28:35 tvander
* Added IMAX2
*
* Revision 1.21 2006/03/06 03:37:45 Michael T. Fischer
* More 6530 prep.
*
* Revision 1.20 2006/02/08 03:43:25 tvander
* Made "import" the default power measurement mode, rather than net-metering
*
* Revision 1.19 2006/01/25 01:04:46 tvander
* Added DEG_SCALE
*
* Revision 1.18 2006/01/16 20:11:27 tvander
* Clean Keil build, all versions
*
* Revision 1.17 2006/01/11 00:51:18 gmikef
* *** empty log message ***
*
* Revision 1.16 2006/01/10 04:06:04 gmikef
* Added PDATA support for CE Outputs.
*
* Revision 1.14 2005/12/09 19:42:10 tvander
* Calibration save and restore now work in flash, and save and restore temp_nom
* in the 6520's temp_raw value for the CE variables.
*
* Revision 1.13 2005/10/08 04:41:24 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.12 2005/09/22 23:45:15 tvander
* Clean build all models and unit tests, updated copyright to be fore Teridian
*
* Revision 1.11 2005/08/30 18:15:54 gmikef
* *** empty log message ***
*
* Revision 1.10 2005/08/18 20:44:45 tvander
* Added temperature measurement to GUI-available fields.
* FIxed memory-space problem in add8_8
* Added temp_x, temp_nom, ppmc and ppmc2 to register def. file.,
* moved many other registers, whcih where in the way.
*
* Revision 1.9 2005/08/12 06:01:40 gmikef
* Added MPU temperature compensation for GAIN_ADJ.
* Added changes to support new CE 6521 code.
*
* Revision 1.8 2005/08/10 02:02:01 gmikef
* *** empty log message ***
*
* Revision 1.7 2005/08/02 22:36:29 tvander
* Optional software pulse logic.
* Fixed build in 6511B and 6521B
*
* Revision 1.6 2005/07/14 20:15:51 tvander
* ce code concentrated in ce.c
* ce interface concentrated in ce652x.c, .h
* Fixed 0-length read or write using flag protocol.
* display.c is out of the build
* kwh_initialize now reads the LRC.
*
* Revision 1.5 2005/06/18 00:58:13 tvander
* Refactored accumulate_energy, squashed a bunch of bugs.
*
* Revision 1.4 2005/06/16 19:00:22 tvander
* Makes "get_ce_constants" available.
*
* Revision 1.3 2005/06/09 00:01:24 tvander
* Flag reads and writes work for power registers, the real time clock and CE RAM.
*
* Revision 1.2 2005/05/26 21:54:38 tvander
* Flag is grossly working with GUI: signs on, reads, writes both xdata and idata, interlocks with CE cycle, and timeouts work.
*
* Revision 1.1 2005/05/04 00:58:37 gmikef
* *** empty log message ***
*
* Revision 1.19 2005/05/03 02:18:54 gmikef
* *** empty log message ***
*
* Revision 1.18 2005/05/02 18:03:16 gmikef
* *** empty log message ***
*
* Revision 1.6 2005/04/30 02:16:48 gmikef
* *** empty log message ***
*
* Revision 1.17 2005/04/30 00:18:47 gmikef
* *** empty log message ***
*
* Revision 1.16 2005/04/29 00:01:59 gmikef
* *** empty log message ***
*
* Revision 1.15 2005/04/27 21:38:13 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 /* ce652x.h */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -