📄 emeter_3phase.h
字号:
#include <target_device.h> // Standard Definition Control Register
int sinne_gen(int *phase,int phaser_rate);
int FIR(int FIR_params[],int input);
extern long SIGNED_MUL(int operand1, int operand2);
extern int FRACTIONAL_SIGNED_MUL(int operand1, int operand2);
int power_conversion(long total_power, float scale_factor);
void extract_dc_bias(long* channel_long_params, int* channel_int_params, int* voltage, int* current);
void calibrate_starts(int* int_params, long* long_params);
double calc_phase_shift(double ratio);
void sync_with_reference(void);
void system_setup(void); // Initialization of System/Control Registers
//tell whether current AC value is POS or NEG
int calibrate_CT(int* int_params, long* long_params);
extern void DISPLAY_1DIGIT(int hex_number, int position);
extern void DISPLAY(int hex_number, int position);
//--------------------------------------------------------------------------
//long chan1_long_params[12]
#define V_accum 0 //accumulates voltage samples
#define logged_V_accum 1 //stores accumulator after a number of cycles
#define I_accum 2 //accumulates current samples
#define logged_I_accum 3 //stores accumulator after a number of cycles
#define P_accum 4 //accumulates power samples
#define logged_P_accum 5 //stores accumulator after a number of cycles
#define E_accum 6 //stores the current accumulated energy
#define E_accum_threshold 7 //stores the threshold when a pulse is issued
#define E_accum_count 8 //stores the electricity count.
#define PS_P_accum 9 //accumulates phase shifted power samples
#define logged_PS_P_accum 10 //stores phase shifted accumulator after a number of cycles
#define POWER_SCALE_FACTOR 11
//int chan1_int_params[22]
#define V_cycle_counter 0 // contains number of voltage cycles
#define I_cycle_counter 1 // contains number of current cycles
#define P_cycle_counter 2 // contains number of power cycles
#define V_count 3 // contains number of voltage samples accumulated
#define logged_V_count 4 // stores number of sampples after a number of cycles
#define I_count 5 // contains number of current samples accumulated
#define logged_I_count 6 // stores number of sampples after a number of cycles
#define P_count 7 // contains number of power samples accumulated
#define logged_P_count 8 // stores number of sampples after a number of cycles
#define V_bias 9 // contains uptodate voltage dc_bias level
#define I_bias 10 // contians uptodate current dc_bias level
#define channel_status 11 // contains status use for detecting a threshold
#define V_POS 0x1 // these are flags defined for channel_status
#define I_POS 0x2
#define NEW_V_LOG 0x4
#define NEW_I_LOG 0x8
#define NEW_P_LOG 0x10
#define E_TICK 0x20
#define CURRENT_HIGH_GAIN 0x40
#define PS_P_count 12 // contains number of phase shifted power samples accumulated
#define logged_PS_P_count 13 // stores number of phase shifted samples after a number of cycles
#define FIR_POINTER 14 // points to the FIR entrance in the table
// Use these levels to decide range switching
#define FIR_TAP 15
#define FIR_BETA 16
#define FIR_GAIN 17
#define I_above_threshold_counter 18
#define logged_I_above_threshold_counter 19
#define ENERGY_PERIOD 20
#define LAST_TAR 21
//int FIR_current1[3];
//#define TAP 0
//#define BETA 1
//#define GAIN 2
#define FIR_UNITY_LOAD 63*2 //element 63 is for no CT phase shift
//int voltage_buffer_chan1[64];
//int current_buffer_chan1[64];
#define SAMPLE_BUFFER_SIZE 64
//TIMER_B sample timing
//every 10 32768Hz clock generate interrupt routine
#define SAMPLE_PERIOD 9
//Start sampling at 8th clock
//This gives it 2 clock cycles for the conversion to be done
//this is 61us
//11 input conversion needs 11/200K = 55uS
#define RESULT_READY_TIME 7
//LED SETUP for power pulses
#define CHAN1_PULSE BIT0 //P3.0
#define CHAN2_PULSE BIT1 //P3.1
#define CHAN3_PULSE BIT2 //P3.2
//Flash programming
#define FSEG_A 0x01080 /* Flash Segment A start address */
#define FSEG_B 0x01000 /* Flash Segment B start address */
void Flash_wb( char *Data_ptr, char byte );
void Flash_ww( int *Data_ptr, int byte );
void Flash_wl( long *Data_ptr, long byte );
void Flash_clr( int *Data_ptr );
void Flash_secure(void);
void replace_flash_word(int *Data_ptr, int word );
void replace_flash_long(long *Data_ptr, long word );
#define FLASH_ADDRESS_CHAN1_E_ACCUM_THRESHOLD FSEG_A+2
//Display
#define D_CLEAR 16
#define D_MINUS 17
#define D_P 18
#define D_S 19
#define D_r 20
#define D_a 21
//Current gain Switching threshold
//Current changes from +2047 to -2048
//From Vref to external will change the gain by 4.
//So pk-pk for switching = 2048/4 * 1/3 = 170
#define I_SWITCHING_THRESHOLD 170
#define I_GAIN_LO_HI_THRESHOLD 240 //From high current to low current threshold is 0.05Vrms
#define I_GAIN_HI_LO_THRESHOLD 1800 //From low current to high current threshold is 0.1Vrms
//Global SIMULATE FLAG
#define SIMULATED_INPUT 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -