📄 emeter-structs.h
字号:
//--------------------------------------------------------------------------
//
// Software for MSP430 based e-meters.
//
// THIS PROGRAM IS PROVIDED "AS IS". TI MAKES NO WARRANTIES OR
// REPRESENTATIONS, EITHER EXPRESS, IMPLIED OR STATUTORY,
// INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR
// COMPLETENESS OF RESPONSES, RESULTS AND LACK OF NEGLIGENCE.
// TI DISCLAIMS ANY WARRANTY OF TITLE, QUIET ENJOYMENT, QUIET
// POSSESSION, AND NON-INFRINGEMENT OF ANY THIRD PARTY
// INTELLECTUAL PROPERTY RIGHTS WITH REGARD TO THE PROGRAM OR
// YOUR USE OF THE PROGRAM.
//
// IN NO EVENT SHALL TI BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
// CONSEQUENTIAL OR INDIRECT DAMAGES, HOWEVER CAUSED, ON ANY
// THEORY OF LIABILITY AND WHETHER OR NOT TI HAS BEEN ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGES, ARISING IN ANY WAY OUT
// OF THIS AGREEMENT, THE PROGRAM, OR YOUR USE OF THE PROGRAM.
// EXCLUDED DAMAGES INCLUDE, BUT ARE NOT LIMITED TO, COST OF
// REMOVAL OR REINSTALLATION, COMPUTER TIME, LABOR COSTS, LOSS
// OF GOODWILL, LOSS OF PROFITS, LOSS OF SAVINGS, OR LOSS OF
// USE OR INTERRUPTION OF BUSINESS. IN NO EVENT WILL TI'S
// AGGREGATE LIABILITY UNDER THIS AGREEMENT OR ARISING OUT OF
// YOUR USE OF THE PROGRAM EXCEED FIVE HUNDRED DOLLARS
// (U.S.$500).
//
// Unless otherwise stated, the Program written and copyrighted
// by Texas Instruments is distributed as "freeware". You may,
// only under TI's copyright in the Program, use and modify the
// Program without any charge or restriction. You may
// distribute to third parties, provided that you transfer a
// copy of this license to the third party and the third party
// agrees to these terms by its first use of the Program. You
// must reproduce the copyright notice and any other legend of
// ownership on each copy or partial copy, of the Program.
//
// You acknowledge and agree that the Program contains
// copyrighted material, trade secrets and other TI proprietary
// information and is protected by copyright laws,
// international copyright treaties, and trade secret laws, as
// well as other intellectual property laws. To protect TI's
// rights in the Program, you agree not to decompile, reverse
// engineer, disassemble or otherwise translate any object code
// versions of the Program to a human-readable form. You agree
// that in no event will you alter, remove or destroy any
// copyright notice included in the Program. TI reserves all
// rights not specifically granted under this license. Except
// as specifically provided herein, nothing in this agreement
// shall be construed as conferring by implication, estoppel,
// or otherwise, upon you, any license or other right under any
// TI patents, copyrights or trade secrets.
//
// You may not use the Program in non-TI devices.
//
// File: emeter-structs.h
//
// Steve Underwood <steve-underwood@ti.com>
// Texas Instruments Hong Kong Ltd.
//
// $Id: emeter-structs.h,v 1.23 2005/12/20 10:17:58 a0754793 Exp $
//
//--------------------------------------------------------------------------
#if !defined(_METER_STRUCTS_H_)
#define _METER_STRUCTS_H_
#if !defined(__GNUC__)
#if defined(DCO0)
#define __MSP430_HAS_DCO__
#endif
#if defined(FLL_DIV_1)
#define __MSP430_HAS_FLLPLUS_SMALL__
#define __MSP430_HAS_FLLPLUS__
#endif
#if defined(SD16SC)
#define __MSP430_HAS_SD16_3__
#endif
#if defined(ADC10SC)
#define __MSP430_HAS_ADC10__
#endif
#if defined(ADC12SC)
#define __MSP430_HAS_ADC12__
#endif
#if defined(CAIFG)
#define __MSP430_HAS_COMPA__
#endif
#if defined(SVSON)
#define __MSP430_HAS_SVS__
#endif
#if defined(TASSEL0)
#define __MSP430_HAS_TA3__
#define __MSP430_HAS_TA3_0__
#endif
#if defined(TA1SSEL0)
#define __MSP430_HAS_TA5_1__
#endif
#if defined(TBSSEL0)
#define __MSP430_HAS_TB7__
#endif
#if defined(UTCTL0_)
#define __MSP430_HAS_UART0__
#endif
#if defined(UTCTL1_)
#define __MSP430_HAS_UART1__
#endif
#if defined(BTSSEL)
#if defined(RTCBCD)
#define __MSP430_HAS_BT_RTC__
#else
#define __MSP430_HAS_BT__
#endif
#endif
#if defined(LCDON)
#if defined(VLCDREF0)
#define __MSP430_HAS_LCD_A__
#else
#define __MSP430_HAS_LCD4__
#endif
#endif
#if defined(RESLO_) && defined(RESHI_) && defined(MPYS_) && defined(OP2_)
#define __MSP430_HAS_MPY__
#endif
#if defined(P1OUT)
#define __MSP430_HAS_PORT1__
#endif
#if defined(P2OUT)
#define __MSP430_HAS_PORT2__
#endif
#if defined(P3OUT)
#define __MSP430_HAS_PORT3__
#endif
#if defined(P4OUT)
#define __MSP430_HAS_PORT4__
#endif
#if defined(P5OUT)
#define __MSP430_HAS_PORT5__
#endif
#if defined(P6OUT)
#define __MSP430_HAS_PORT6__
#endif
#endif
/* N.B.
When built for devices using the ADC12 converter, this e-meter software uses a
sampling rate of 3276.8/s. For a mains supply at exactly 50Hz, each sample is
5.4932 degrees of phase from the last.
When built for devices using the SD16 converter, this software uses a sampling
rate of 4096.0/s. For a mains supply at exactly 50Hz, each sample is
4.3945 degrees of phase from the last. */
#define FLASH_MAIN_PAGE_SIZE 512
#define FLASH_INFO_PAGE_SIZE 128
#if defined(__MSP430_HAS_SD16_3__)
#define SAMPLE_RATE_IS_4096 4096
#define ADC_BITS 16
#define SAMPLES_PER_10_SECONDS 40960
#define LIMP_SAMPLES_PER_10_SECONDS 10240
#define LIMP_SAMPLING_RATIO 4
#endif
#if defined(__MSP430_HAS_ADC12__)
#define SAMPLE_RATE_IS_3277 3277
#define ADC_BITS 12
#define SAMPLES_PER_10_SECONDS 32768
#define LIMP_SAMPLES_PER_10_SECONDS 8192
#define LIMP_SAMPLING_RATIO 4
#endif
#if defined(SINGLE_PHASE)
#define NUM_PHASES 1
#else
#define NUM_PHASES 3
#endif
#if NEUTRAL_MONITOR_SUPPORT
#define NUM_CURRENT_CHANNELS (NUM_PHASES + 1)
#define NEUTRAL_CURRENT_CHANNEL NUM_PHASES
#else
#define NUM_CURRENT_CHANNELS NUM_PHASES
#endif
/* This is the accumulated power value that represents one watt-hour
of energy. It is equal to 100 times the number of ADC samples per
hour. This results from the energy being accumulated at the same
rate as the ADC samples, and the power being in 1/100W increments. */
#define ENERGY_WATT_HOUR_THRESHOLD (SAMPLES_PER_10_SECONDS*36000L)
/* This is for the LED pulse */
#if defined(TOTAL_ENERGY_SUPPORT) || defined(TOTAL_REACTIVE_ENERGY_SUPPORT)
#if TOTAL_ENERGY_PULSES_PER_KW_HOUR >= 1000
#define TOTAL_ENERGY_PULSE_THRESHOLD (ENERGY_WATT_HOUR_THRESHOLD/TOTAL_ENERGY_PULSES_PER_KW_HOUR)*1000
#else
#define TOTAL_ENERGY_PULSE_THRESHOLD (ENERGY_WATT_HOUR_THRESHOLD/(16*TOTAL_ENERGY_PULSES_PER_KW_HOUR))*1000
#endif
#endif
#define PHASE_ENERGY_PULSE_THRESHOLD (ENERGY_WATT_HOUR_THRESHOLD/PHASE_ENERGY_PULSES_PER_KW_HOUR)*1000
/*! The following is the number of times an ADC may hit the endstops before
it is declared to be truly overloaded. A very low value makes the meter
less tolerant of noise spikes. A large value tends to ignore real overload. */
#define ENDSTOP_HITS_FOR_OVERLOAD 20
#if defined(__MSP430_HAS_ADC12__)
#define DEFAULT_V_DC_ESTIMATE 2230L
#define LOWER_TAMPER_V_DC_ESTIMATE 1500L
#define UPPER_TAMPER_V_DC_ESTIMATE 2500L
#define DEFAULT_LIMP_V_DC_ESTIMATE 1700L
#define LOWER_LIMP_TAMPER_V_DC_ESTIMATE 1200L
#define UPPER_LIMP_TAMPER_V_DC_ESTIMATE 2300L
//#define DEFAULT_I_DC_ESTIMATE 0L
#define DEFAULT_I_DC_ESTIMATE 2048L
#else
#define DEFAULT_V_DC_ESTIMATE 0L
#define LOWER_TAMPER_V_DC_ESTIMATE -1000L
#define UPPER_TAMPER_V_DC_ESTIMATE 1000L
#define DEFAULT_LIMP_V_DC_ESTIMATE 0L
#define LOWER_LIMP_TAMPER_V_DC_ESTIMATE -1000L
#define UPPER_LIMP_TAMPER_V_DC_ESTIMATE 1000L
#define DEFAULT_I_DC_ESTIMATE 0L
#endif
//--------------------------------------------------------------------------
#if !defined(__MSP430__)
#define __infomem__ /**/
#define __erasablemem__ /**/
#define _EINT() /**/
#define _DINT() /**/
#elif defined(__AQCOMPILER__)
#define __erasablemem__ _DMEM3
#elif defined(__GNUC__)
#define __erasablemem__ __attribute__ ((section(".erasabletext")))
#elif defined(__IAR_SYSTEMS_ICC__)
#define __infomem__ _Pragma("location=\"INFO\"")
#define __erasablemem__ /**/
#else
#define __infomem__ /**/
#define __erasablemem__ /**/
#endif
typedef struct
{
int32_t v2;
int32_t v3;
} goertzel_state_t;
/*! This structure contains the working parameters associated with a
single current sensor (e.g a shunt resistor or a current transformer). */
struct current_sensor_parms_s
{
/* Channel's DC estimates, accumulated powers, and the logged
accumulated power from the last measurement cycle. */
int32_t I_dc_estimate[GAIN_STAGES];
/*! The power dot product (i.e. V.I) currently in progress. */
int16_t P_accum[GAIN_STAGES][3];
/*! The most recently logged power dot product (i.e. V.I). */
int16_t /*volatile*/ P_accum_logged[GAIN_STAGES][3];
#if defined(REACTIVE_POWER_BY_QUADRATURE_SUPPORT)
int16_t P_reactive_accum[GAIN_STAGES][3];
int16_t /*volatile*/ P_reactive_accum_logged[GAIN_STAGES][3];
#endif
#if defined(IRMS_SUPPORT) || defined(POWER_FACTOR_SUPPORT)
/*! The current dot product (i.e. I.I) currently in progress. */
int16_t I_sq_accum[GAIN_STAGES][3];
/*! The most recently logged current dot product (i.e. I.I). */
/*! \brief The latest logged dot product of I.I */
int16_t /*volatile*/ I_sq_accum_logged[GAIN_STAGES][3];
#endif
/*! The number of ADC samples gathered at any moment for the dot products in
progress.
\brief The current number of accumulated samples. */
int16_t sample_count;
/*! The number of ADC samples gathered in the most recently logged set of dot
products. This number varies a little from block to block, as the blocks
are synchronised to the cycles of the mains waveform. However, the number
should be approximately the number of ADC samples in one second.
\brief The latest logged number of accumulated samples. */
int16_t /*volatile*/ sample_count_logged;
#if defined(__MSP430_HAS_SD16_3__)
int16_t sd16_preloaded_offset;
#else
/*! \brief The beta of the FIR/interpolator used for in-phase phase correction. */
int16_t in_phase_fir_beta[GAIN_STAGES];
int16_t in_phase_fir_gain[GAIN_STAGES];
#endif
/*! \brief The step into the history data used for phase correction. */
int16_t in_phase_phase_correction_step[GAIN_STAGES];
#if REACTIVE_POWER_BY_QUADRATURE_SUPPORT
/*! \brief The beta of the FIR/interpolator used for quadrature phase correction. */
int16_t quadrature_fir_beta;
int16_t quadrature_fir_gain;
/*! \brief The step into the history data used for phase correction. */
int16_t quadrature_phase_correction_step;
#endif
/*! \brief History of the current samples, for use when making large phase corrections */
int16_t I_history[GAIN_STAGES][2];
#if defined(MAINS_FREQUENCY_SUPPORT)
int16_t cycle_sample_count;
int32_t mains_period;
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -