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

📄 emeter-structs.h

📁 msp430F437三相电表DEMO(编译器 IAR 3.42A)
💻 H
📖 第 1 页 / 共 4 页
字号:
    monitoring of both the live and neutral leads for anti-tamper management. */
#define I_NEUTRAL_POS               0x0800

/*! This flag in a channel's status variable indicates the power has been declared to be
    reversed, after the anti-tamper logic has processed the raw indications. */
#define PHASE_REVERSED              0x1000  /* Live, neutral or both leads */

/*! This flag in a channel's status variable indicates the power (current in limp mode)
    has been declared to be unbalanced, after the anti-tamper logic has processed the
    raw indications. */
#define PHASE_UNBALANCED            0x2000

/* TIMER_B sample timing
   Every SAMPLE_PERIOD 32768Hz clocks generate interrupt.
   Start sampling at 8th clock
   This gives it 2 clock cycles for the conversion to be done,
   which is 61us
   8 input conversions needs 8/200K = 40uS
   11 input conversion needs 11/200K = 55uS */

#if defined(TOTAL_ENERGY_SUPPORT)
extern uint8_t total_energy_pulse_remaining_time;
extern int32_t total_power;
extern int32_t total_power_counter;
    #if TOTAL_ENERGY_PULSES_PER_KW_HOUR < 1000
extern int16_t extra_total_power_counter;
    #endif
extern uint32_t total_consumed_energy;
#endif

#if defined(TOTAL_REACTIVE_ENERGY_SUPPORT)
extern uint8_t total_reactive_energy_pulse_remaining_time;
extern int32_t total_reactive_power;
extern int32_t total_reactive_power_counter;
    #if TOTAL_ENERGY_PULSES_PER_KW_HOUR < 1000
extern int16_t extra_total_reactive_power_counter;
    #endif
extern uint32_t total_consumed_reactive_energy;
#endif

#if defined(SINGLE_PHASE)
extern struct phase_parms_s chan1;
#else
extern struct phase_parms_s chan[NUM_PHASES];
    #if NEUTRAL_MONITOR_SUPPORT
extern struct neutral_parms_s neutral;
    #endif
#endif
__infomem__ extern const struct info_mem_s nv_parms;
extern const struct nv_parms_s nv_def;

#if defined(SINGLE_PHASE)
#define phase                           (&chan1)
#define phase_nv                        (&nv_parms.seg_a.s.chan1)
#define phase_cal                       (&cal_info.chan1)
#endif

#if !defined(__MSP430__)
/*! The minimum value which the ADC can produce. */
#define ADC_MIN                         -32768
/*! The maximum value which the ADC can produce. */
#define ADC_MAX                         32767
#endif

#if defined(__MSP430__)
    #if defined(ADC12SC)
/*! This is the sampling period for normal operation. If limp mode is supported
    the sampling period in limp mode will be LIMP_SAMPLING_RATIO times as long. */
#define SAMPLE_PERIOD                   10

/*! The minimum value which the ADC12 can produce. */
#define ADC_MIN                         (0 + 400)
/*! The maximum value which the ADC12 can produce. */
#define ADC_MAX                         (4095 - 400)

        #if PWM_DITHERING_SUPPORT
/*! Period for the PWM based dithering signalling */
#define PWM_FREQ                        106 //50
/*! Maximum high interval for the PWM based dithering signalling */
#define PWM_UPPER_LIMIT                 90  //45
/*! Mid point for the high interval for the PWM based dithering signalling */
#define PWM_MID_POINT                   50  //25
/*! Minimum high interval for the PWM based dithering signalling */
#define PWM_LOWER_LIMIT                 10  //5
        #endif
    #elif defined(__MSP430_HAS_SD16_3__)
/*! The minimum value which the SD16 can produce. */
#define ADC_MIN                         -31000
/*! The maximum value which the SD16 can produce. */
#define ADC_MAX                         31000
/*! Set up meaningful names for the SD16 registers, to match the way we use it. */
    #if CURRENT_CH_2_IS_LIVE
#define SD16CCTL_LIVE       SD16CCTL1
#define SD16INCTL_LIVE      SD16INCTL1
#define SD16PRE_LIVE        SD16PRE1
#define SD16MEM_LIVE        SD16MEM1
#define SD16CCTL_NEUTRAL    SD16CCTL0
#define SD16INCTL_NEUTRAL   SD16INCTL0
#define SD16PRE_NEUTRAL     SD16PRE0
#define SD16MEM_NEUTRAL     SD16MEM0
    #else
#define SD16CCTL_LIVE       SD16CCTL0
#define SD16INCTL_LIVE      SD16INCTL0
#define SD16PRE_LIVE        SD16PRE0
#define SD16MEM_LIVE        SD16MEM0
#define SD16CCTL_NEUTRAL    SD16CCTL1
#define SD16INCTL_NEUTRAL   SD16INCTL1
#define SD16PRE_NEUTRAL     SD16PRE1
#define SD16MEM_NEUTRAL     SD16MEM1
    #endif
#define SD16CCTL_VOLTAGE    SD16CCTL2
#define SD16INCTL_VOLTAGE   SD16INCTL2
#define SD16PRE_VOLTAGE     SD16PRE2
#define SD16MEM_VOLTAGE     SD16MEM2
    #else
#error No known ADC available.
    #endif
#endif

#if defined(TEMPERATURE_SUPPORT)
extern uint16_t temperature;
#endif

#if !defined(RTC_SUPPORT)
/*! If there is not RTC support, this variable is incremented once a second, and is used
    to control the timing of display updates. */
extern uint8_t seconds;
#endif

/* ! This variable is used as a series of flag bits for various purposes in the meter. */
extern uint16_t meter_status;
#define TICKER                          0x0001

/*! This bit indicates the meter is in the power down state. */
#define POWER_DOWN                      0x0004
#define SKIP_A_SECOND                   0x0010
#define PWM_RAMPING_DOWN                0x0020

/*! This bit indicates the meter has received a valid access password. */
#define PASSWORD_OK                     0x0040

/*! This bit indicates the current status of the meter is "current flow is reversed", after
    all persistence checking, and other safeguards, have been used to check the validity of the
    reverse indication. */
#define STATUS_REVERSED                 0x0100

/*! This bit indicates the current status of the meter is "current flow is earthed", after
    all persistence checking, and other safeguards, have been used to check the validity of the
    earthed indication. */
#define STATUS_EARTHED                  0x0200

/*! This bit indicates the phase voltage is OK. */
#define STATUS_PHASE_VOLTAGE_OK         0x0400

/*! This bit indicates the battery condition is OK. If battery monitoring is not enabled, this bit
    is not used. */
#define STATUS_BATTERY_OK               0x0800

/*! This bit indicates the current status of the meter is "magnetic field tampering present", after
    all persistence checking, and other safeguards, have been used to check the validity of the
    high magnetic field condition. */
#define STATUS_HIGH_MAGNETIC_FIELD      0x1000

/*! This variable specifies the current operating mode of the meter. */
extern int8_t operating_mode;
#define OPERATING_MODE_NORMAL           0
#if defined(LIMP_MODE_SUPPORT)
#define OPERATING_MODE_LIMP             1
#define OPERATING_MODE_LIMP_BURST       2
#endif
#define OPERATING_MODE_LCD_ONLY         3
#define OPERATING_MODE_POWERFAIL        4

/*! This defines the number of times the power fail indication is checked before a positive decision on power
    failure is made. */
#define POWER_FAIL_DEBOUNCE             50

/*! This defines the number of times the power fail indication is checked before a positive decision on power
    restoration is made. */
#define POWER_RESTORE_DEBOUNCE          5

#if defined(BASIC_KEYPAD_SUPPORT)  ||  defined(CUSTOM_KEYPAD_SUPPORT)
/*! This variable tracks the current state of the user interface keys. */
extern uint8_t key_states;
#endif

#if defined(CORRECTED_RTC_SUPPORT)
/*! This value accumulates the error in the RTC. If it overflow in the positive direction, this
    represents the RTC being exactly one second too far in advance. If it overflows in the
    negative direction, this represents the RTC being exactly one second behind. */
extern int32_t rtc_correction;
#endif

#if defined(DYNAMIC_PHASE_CORRECTION_SUPPORT)
/*! This table, in a special section of flash memory, is constructed during the calibration of the
    meter. It defines the frequency dependant phase shift characteristics of the CTs. */
extern __erasablemem__ const int16_t frequency_phase_factor[NUM_CURRENT_CHANNELS];
/*! This table, in a special section of flash memory, is constructed during the calibration of the
    meter. It defines the frequency dependant gain characteristics of the CTs. */
extern __erasablemem__ const int16_t frequency_gain_factor[NUM_CURRENT_CHANNELS];

/*! This table, in a special section of flash memory, is constructed during the calibration of the
    meter. It defines the current dependant phase shift and gain characteristics of the CTs. The 77
    steps are based on a 60A meter, as follows:
    - 0.1A steps from 0.0A to 5.0A
    - 1A steps from 5.0A to 25.0A
    - 5A steps from 25.0A to 55.0A
    All currents above 55A use the 55A entry. This gives a total of 50 + 20 + 7 => 77 entries. Each entry
    consists of an 8 bit phase shift correction, and an 8 bit gain correction. */
extern __erasablemem__ const int8_t phase_corrections[77][NUM_CURRENT_CHANNELS][2];

#endif

#if defined(PHASE_CORRECTION_SUPPORT)
/*! The table of FIR coefficients to produce a range of phase shifts from -1/2 an ADC sample interval
    to +1/2 an ADC sample interval. When the SD16 is used, the hardware phase shifting capability of
    the ADC is used, instead of this table. */
extern const int16_t fir_coeffs[][2];

/*! The array element in fir_coeffs which represents zero phase shift. */
#define FIR_UNITY_LOAD              63
#endif

/*! The current sampling rate, in samples per second. If the meter supports a very
    low power limp mode, this value may change with the mode of the meter. */
extern int16_t samples_per_second;
/*! This value is set when a sampling of the battery voltage is initiated. It counts down
    the number of ADC samples which must occur before the battery voltage is actually
    tested. To conserve energy, the battery voltage is usually sampled infrequently (e.g.
    once per minute, or more). */
extern uint16_t battery_countdown;

#if defined(MAGNETIC_INTERFERENCE_SUPPORT)
extern uint16_t magnetic_sensor_count_logged;
#endif

//--------------------------------------------------------------------------

#if defined(__AQCOMPILER__)
extern void main(void);
#endif

#if !defined(__MSP430__)
/*! This function is the interrupt service routine for the ADC. It performs the phase
    corrections and calculation of dot products needed to measure the mains power
    parameters. It also assesses supplementary information, such as the mains frequency.
    It controls any energy pulse LEDs/display segments. It scans and debounces any keys.
    It monitors for power failure.
    \brief ADC interrupt service routine. */
extern void adc_interrupt(void);

/*! This function opens the data source file, when the software is built as a model running on a
    host computer. */
extern int start_host_environment(int argc, char *argv[]);

/*! This function gets the ADC values for a single sample of the mains waveforms, when the software
    is built as a model running on a host computer. */
extern void get_sample(int16_t adc_buffer[]);

/*! This function loads a set of non-volatile memory parameters from a text file, when the software
    is built as a model running on a host computer. */
extern int host_load_parms(struct nv_parms_s *nv);
extern int host_store_parms(struct nv_parms_s *nv);

/*! This function logs the set of non-volatile memory parameters being used, when the software
    is built as a model running on a host computer. */
extern void log_parms(struct nv_parms_s *nv);
#endif

/*! \brief Initialise all the data and peripherals, and prepare the machine to run
    after reset. */
extern void system_setup(void);

/*! This function updates the information displayed on the LCD each time it is called, stepping to the
    next item to be displayed, in a predetermined sequence. It should, therefore, be called at
    regular intervals, at the rate at which such cycling is required.
    \brief Update LCD display. */
extern void update_display(void);

/*! This function increments the RTC by one second.
    \brief Bump RTC by one second. */
extern void rtc_bumper(void);

/*! This function measures the speed of the RTC, by comparing MCLK, generated from the 32kHz RTC clock,
    with an external precision 32kHz signal.
    \brief Assess the speed at which the RTC is currently running, for RTC correction calibration. */
extern int32_t assess_rtc_speed(void);

/*! This function switches the meter to the normal operating state. It is usually used when the meter
    is in the low power state, or limp mode, and the conditions for normal operation have been detected.
    \brief Switch the meter to its normal operating mode. */
extern void switch_to_normal_mode(void);

/*! This function switches the meter to the limp, or live only, mode of operatiion. It is usually used
    the meter is running, but the measured voltage is too low to be valid.
    \brief Switch the meter to limp mode (also known as live only mode). */
extern void switch_to_limp_mode(void);

/*! This function switches the meter to the lowe power state, where only the RTC and power monitoring
    functions continue to operate within a timer interrupt routine. This is usually used when power

⌨️ 快捷键说明

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