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

📄 emeter_3ph_setup_44x.c

📁 基于MSPF449的三相电压表功率的开发程序
💻 C
📖 第 1 页 / 共 2 页
字号:
//**************************************************************************
//* 
//*   ADC and Timer_B setup for 3phase emeter program
//* 
//*   This program setups all system parameters
//*   It is hardware specific
//* 
//    Hardware requirements:
//
//    32KHz crystal attached to pin 8,9
//
//    T218010 LCD glass (same as the one used in EVK320), 
//
//           MSP430F449
//         ---------------
//     .  |               |
//    /|\ |           XIN |---
//     |  |               |    32768Hz
//     ---| RST      XOUT |---
//        |               |
//        |          A0   |<-- A0 I1
//        |          A1   |<-- A1 I2
//        |          A2   |<-- A2 I3
//        |          A3   |<-- A3 V1
//        |          A4   |<-- A4 V2
//        |          A5   |<-- A5 V3
//        |               |
//        |         P3.0  |-->CHANNEL 1 ENERGY PULSE
//        |         P3.1  |-->CHANNEL 2 ENERGY PULSE
//        |         P3.2  |-->CHANNEL 3 ENERGY PULSE
//        |               |
//        |      P1.2/TA1 |<-- Reference pulse input during calibration
//        |      P1.1/TA0 |<-- Local pulse input during calibration
//        |               |
//        |               |   Vcc
//        |               |     |
//        |               |    /
//        |               |    \ 30k
//        |           R32 |____/
//        |               |    /
//        |               |    \ 30k
//        |           R31 |____/
//        |               |    /
//        |               |    \ 30k
//        |           R30 |____/
//        |               |    |
//        |               |   GND
//        |               |
//        |               |          ____________LCD__T218010___________
//        |          COM3 |---------|2 COM4      __    __    __    __   |
//        |          COM2 |---------|1 COM3     |__|  |__|  |__|  |__|  |
//        |          COM1 |---------|3 COM2     |__|  |__|  |__|  |__|  |
//        |               |    _____|20 COM1     __    __    __    __   |
//        |          COM0 |___|_____|4  COM1                            |
//        |               |         |  S0            S14                |
//        |               |         |__19____________5__________________|
//        |               |            |             |
//        |      (28)S16  |------------              |
//        |           :   |   :                      |
//        |           :   |   :                      |
//        |      (42)S30  |-------------------------- 
//        |               |
//         ---------------
//
//    Operation of the software:
//
//    1)Sets the FLL to approx 4MHz
//    2)Sets ADC to scan 10 channels each conversion
//    3)Set TIMER_B1 to trigger sampling at 3276.8 samples/s
//      (positive edge starts conversion, negative edge cause interrupt
//        can adjust sample time by programming ADC and moving negative edge)
//    4)Will display a sampled channel every 0.5 second.
//    5)Setup LCD and basic timer. 
//    6)Display routine will convert to decimal and then display
//
//    Vincent Chan 
//    Texas Instruments Hong Kong Ltd
//    Date        Comments
//    =====================
//    01/09/19    Code Starts
//    01/10/07    Comments added
//    01/11/27    ADC is setup using external reference as default.
//**************************************************************************

#include "emeter_3phase.h"

#define  DEFAULT_USE_VREFPLUS 0
//--------------------------------------------------------------------------
extern int sinne_1,sinne_2;
extern int samples_write_index;
extern int samples_read_index;
extern int voltage_buffer_chan1[64];
extern int voltage_buffer_chan2[64];
extern int voltage_buffer_chan3[64];

extern int current_buffer_chan1[64];
extern int current_buffer_chan2[64];
extern int current_buffer_chan3[64];

extern int chan1_int_params[22];
extern int chan2_int_params[22];
extern int chan3_int_params[22];
extern long chan1_long_params[12];
extern long chan2_long_params[12];
extern long chan3_long_params[12];

extern const int FIR_COEFF[254];

extern unsigned int CH1_FLASH_INFO_FIR_PTR;
extern unsigned int CH2_FLASH_INFO_FIR_PTR;
extern unsigned int CH3_FLASH_INFO_FIR_PTR;

extern long CH1_FLASH_INFO_E_accum_threshold;
extern long CH2_FLASH_INFO_E_accum_threshold;
extern long CH3_FLASH_INFO_E_accum_threshold;

extern long CH1_FLASH_INFO_POWER_SCALE_FACTOR;
extern long CH2_FLASH_INFO_POWER_SCALE_FACTOR;
extern long CH3_FLASH_INFO_POWER_SCALE_FACTOR;

extern int  FLASH_INFO_average_VeREF_range;

extern long chan1_low_gain_threshold;
extern long chan2_low_gain_threshold;
extern long chan3_low_gain_threshold;

extern long chan1_high_gain_threshold;
extern long chan2_high_gain_threshold;
extern long chan3_high_gain_threshold;

extern int average_VeREF_range,average_temperature;

extern int ticker,seconds,minutes,hours,days;

void system_setup(void)
{
int i;
float* f_ptr;

//!!! This needs to be tested
//FLL_CTL0 = XCAP18PF;
//FLL_CTL0 = XCAP18PF;
SCFI0=FN_2+FLLD_8;                //range is 6 to 22.5 MHz set loop MPY factor D = 8
                                  //SCFQCTL is at its default
                                  //freq = 8 * (31+1) *32768 = 8.196Mhz
//SCFQCTL=SCFQ_4M;
FLL_CTL0+=DCOPLUS;                //activate loop MPY factor D.
                                  //FLL should now lock to 8.196MHz

WDTCTL = WDTPW + WDTHOLD;        // Stop watchdog timer

//Init test parameters
sinne_1=sinne_2=0;
//sinne_2+=0x6d;          //add 0.6 degree phase shift to simulate CT shift               
//sinne_2+=0x2aab;        //add 60degree phase lead to current 

                        //assume current leads voltage by 60 degree
                        // Inherent CT lead is 2 degrees. So overall lead is 62 degrees.
                        // phase = 10000hex * 62/360 = 0x2c17
//sinne_2=0x2c17;        //add 62degree phase lead to current 

//sinne_2=0x293F;        //add 58degree phase lead to current 

//system parameters
for(i=0;i<17;i++)
  {
  chan1_int_params[i]=0;
  chan2_int_params[i]=0;
  chan3_int_params[i]=0;    
  }
for(i=0;i<11;i++)
  {
  chan1_long_params[i]=0;
  chan2_long_params[i]=0;
  chan3_long_params[i]=0;    
  }

//CT compensation parameters using FIR

    #if SIMULATED_INPUT
chan1_int_params[FIR_POINTER]=FIR_UNITY_LOAD;
chan2_int_params[FIR_POINTER]=FIR_UNITY_LOAD;
chan3_int_params[FIR_POINTER]=FIR_UNITY_LOAD;
chan1_int_params[FIR_TAP]=0;
chan2_int_params[FIR_TAP]=0;
chan3_int_params[FIR_TAP]=0;
chan1_int_params[FIR_BETA]=0;    //no delay by default
chan2_int_params[FIR_BETA]=0;    //no delay by default
chan3_int_params[FIR_BETA]=0;    //no delay by default
chan1_int_params[FIR_GAIN]=0x7fff;   //gain = 1
chan2_int_params[FIR_GAIN]=0x7fff;   //gain = 1
chan3_int_params[FIR_GAIN]=0x7fff;   //gain = 1
    #else
if(CH1_FLASH_INFO_FIR_PTR>127*2)
  {
  chan1_int_params[FIR_POINTER]=FIR_UNITY_LOAD;
  }
else
  {
  chan1_int_params[FIR_POINTER]=CH1_FLASH_INFO_FIR_PTR;
  } 
if(CH2_FLASH_INFO_FIR_PTR>127*2)
  {
  chan2_int_params[FIR_POINTER]=FIR_UNITY_LOAD;
  }
else
  {
  chan2_int_params[FIR_POINTER]=CH2_FLASH_INFO_FIR_PTR;
  } 
if(CH3_FLASH_INFO_FIR_PTR>127*2)
  {
  chan3_int_params[FIR_POINTER]=FIR_UNITY_LOAD;
  }
else
  {
  chan3_int_params[FIR_POINTER]=CH3_FLASH_INFO_FIR_PTR;
  }      
chan1_int_params[FIR_BETA]=FIR_COEFF[chan1_int_params[FIR_POINTER]];

⌨️ 快捷键说明

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