亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? emeter.c

?? MSP430電能測量程序,用的是電力線載波通訊.即PLC
?? C
?? 第 1 頁 / 共 2 頁
字號:
//#define WFS

/** \file 
  * ESP430CE1 Application Program Example
  *
  * This file shows exemplarily the usage of the ESP430CE1 module for
  * a single-phase emeter with two current sensors (one shunt and one
  * current transformer).
  *
  * \author Volker Rzehak
  * \date   04/08/2003
  *
  * \Modified Stefan Schauer
  * \date   04/29/2003
    Changes:
     - added Temp. calibration Parameters
     - fixed bouncing of Idle Key
  */
//====================================================================

#include "device.h"
#include "emeter.h"
#include "parameter.h"
#include "display.h"
#include "calibration.h"
#include "emeter-toolkit.h"


#if __VER__ < 200
sfrb    SD16CONF0          = 0xB7;
sfrb    SD16CONF1          = 0xBF;
#else
#define SD16CONF0_                (0xB7)  
DEFC(   SD16CONF0               , SD16CONF0_)
#define SD16CONF1_                (0xBF)  
DEFC(   SD16CONF1               , SD16CONF1_)
#endif

// const and var definition
#define TIMEOUT	0xFFFF		// Huge timeout
//#define TIMEOUT	0x0FFF			// Shorter timeout
unsigned char ZXLDFGedge = 0;

/// Saves firmware version during initialization.
unsigned int firmware_version; 
/// Cumulated active energy.
float total_energy;
/// Last temperature measurement result.
unsigned int temperature;

// buffer to save RET values
//unsigned int savedRET[(RET31_ - RET0_)/2];

//union tu_ulong_word intlevel = {pSET_INTRPTLEVL_LO, pSET_INTRPTLEVL_HI};
struct ts_parameters s_parameters;

#ifdef __IAR_SYSTEMS_ICC__
#if __VER__ < 200
#pragma memory=constseg(INFOA)
#else
#pragma constseg=INFOA
#endif
#endif

#ifdef __CROSSWORKS__
 #pragma constseg("INFOA")
#endif

const struct ts_parameters s_parameters_flash = 
           {
              defVRatio,
              defIRatio,
              defEnergieRatio,
              defSET_PHASECORR1,
              defSET_PHASECORR2,
              defSET_V1OFFSET,
              defSET_I1OFFSET,
              defSET_I2OFFSET,
              defSET_STARTCURR_INT,
              defSET_STARTCURR_FRAC,
              {defSET_INTRPTLEVL_LO,
               defSET_INTRPTLEVL_HI},
              def_togglelevel,
              defTempGain,
              defTempOffset
           };

const long SerialNumber_flash = 0xDEAFC0C0;	// System serial number stored in FLASH

#ifdef __IAR_SYSTEMS_ICC__
#if __VER__ < 200
#pragma memory=default
#else
#pragma constseg=default
#endif
#endif

#ifdef __CROSSWORKS__
#pragma dataseg(default)
#endif
	
unsigned int CalCyclCnt = 0;     // Register for Cycle calculation of Calibration
unsigned int wfs1;
unsigned int wfs2;
unsigned int wfs3;
union tu_long_word energy;
union ts_long_word tempenergy;

signed long sumenergy= 0;
signed long maxenergy= 0;

void display_error(void) 
{;}


//====================================================================
/**
  * Analog front-end initialization routine.
  *
  * Configures the sigma-delta ADC module as analog front-end for
  * a tamper-resistant meter using a current transformer and a
  * shunt as current sensors (see configuration of channel 0 and 1).
  */
void init_analog_front_end(void)
{
/**
  * First it makes sure that the Embedded Signal Processing is 
  * disabled, otherwise it wouldn't be possible to modify the 
  * SD16 registers.
  */
  ESPCTL &= ~ESPEN;

/**
  * Then the general configurations of the analog front-end are done
  * that apply to all channels: clock selection (SMCLK) and divider
  * settings (depending on SMCLK frequency) and reference voltage
  * selections.
  */
  
//  SD16CTL= SD16SSEL_1  // Clock selection: SMCLK
  SD16CTL = 0x800 + SD16SSEL_1  // Clock selection: SMCLK + (Amp: )
#if (MCLK_FREQ == 2)
         | SD16DIV_1   // divide by 2 => ADC clock: 1.094MHz
#endif         
#if (MCLK_FREQ == 4)
         | SD16DIV_2   // divide by 4 => ADC clock: 1.094MHz
#endif         
#if (MCLK_FREQ == 8)
         | SD16DIV_3   // divide by 8 => ADC clock: 1.094MHz
#endif         
         | SD16REFON;  // Use internal reference


  SD16CCTL0 = INCH_0;  // I1
  SD16CCTL1 = INCH_0;  // I2
  SD16CCTL2 = INCH_0;  // V

  SD16CONF1 |= 0x40;   // Delay of ADC clock = 40ns
  

// -------------------------------------------------------------------
/** 
  * - Selection of ADC gain:
  *   - VIN,MAX(GAIN = 1) = 0.5V  > VCT(Peak)
  *   - VIN,MAX(GAIN = 2) = 0.25V < VCT(Peak)
  *   - VIN,MAX(GAIN = 16) = 0.031V  > VShunt(Peak)
  *   - VIN,MAX(GAIN = 32) = 0.015V  < VShunt(Peak)
  */
  // -----------------------------------------------------------
  // Configure analog front-end channel 2 - Current 1
   SD16INCTL0= I1_Gain; // Set gain for channel 0 (I1)
//  SD16INCTL0= GAIN_1; // Set gain for channel 0 (I1) to 1
//  SD16INCTL0= GAIN_2; // Set gain for channel 0 (I1) to 2
//  SD16INCTL0= GAIN_32; // Set gain for channel 0 (I1) to 32
  SD16CCTL0 |= OSR_0;  // Set oversampling ratio to 256 (default)

  // -----------------------------------------------------------
  // Configure analog front-end channel 1 - Current 2
  SD16INCTL1= I2_Gain; // Set gain for channel 1 (I2)
//  SD16INCTL1= GAIN_1; // Set gain for channel 1 (I2) to 1
//  SD16INCTL1= GAIN_2; // Set gain for channel 1 (I2) to 2
//  SD16INCTL1= GAIN_16; // Set gain for channel 1 (I2) to 16
  SD16CCTL1 |= OSR_0;  // Set oversampling ratio to 256 (default)

  // -----------------------------------------------------------
  // Configure analog front-end channel 2 - Voltage
 //!!!TEMP!!!	SetAFEGain2(calVoltage);
	SD16INCTL2= GAIN_1; //!!!TEMP!!! Set gain for channel 2 (V) to 1

	SD16CCTL2 |= OSR_0;  // Set oversampling ratio to 256 (default)
  
/**
  * \note 
  * Please note, that the oversampling ratio should be identical 
  * for all channels. Default is 256.
  */       

} // End of init_analog_front_end()


//====================================================================
void SetAFEGain2(int lineVoltage)
{
// Configure analog front-end channel 2 - Voltage
  if (lineVoltage <= 125)
  	{ SD16INCTL2= GAIN_2; }// Set gain for channel 2 (V) to 2
  else
    { SD16INCTL2= GAIN_1; }// Set gain for channel 2 (V) to 1
}



//====================================================================
/**
  * Sets one parameter of the ESP430CE1 module.
  *
  * The parameter \a param is loaded with \a data.
  *
  * \param param Parameter to be set.
  * \param data Data to be loaded into parameter.
  */
void set_parameter(unsigned int param, unsigned int data)
{
  volatile unsigned int timeout= TIMEOUT;  
  //  /\  Prevent variable from being "optimized".
  MBOUT1= data;
  MBOUT0= param;
  
  do
  { 
    while (((MBCTL & IN0IFG) == 0) && ((--timeout) > 0)) ;
    if (timeout == 0) { display_error(); return; }
  } while ((MBIN0 != mPARAMSET) || (MBIN1 != param));
}

//====================================================================
/**
  * Initializes ESP430CE1.
  *
  */
void init_esp_parameter(unsigned char flashvars)
{
  volatile unsigned int timeout;
  //  /\  Prevend variable from being "optimized".

  // copy predefined init values to RAM
  if (flashvars)
  {
	s_parameters = s_parameters_flash;
	_NOP();
  }
  
/**
  * Makes sure that the Embedded Signal Processing 
  * is enabled, 
  */
  ESPCTL |= ESPEN;
  MBCTL = 0;
    
/**
  * that it is not in measurement or calibration mode,
  */
  if ((RET0 & 0x8000) != 0) 
  { 
    // Set Embedded Signal Processing into "Idle" mode
    MBOUT1= modeIDLE; // ESP_IDLE;
    MBOUT0= mSET_MODE;
    timeout= TIMEOUT;
    while (((RET0 & 0x8000) != 0) && (--timeout > 0)) ;
  }

/**
  * and that it is ready to receive messages by requesting the
  * firmware version.
  */
  MBOUT0= mSWVERSION;
  timeout= TIMEOUT;
  do
  { 
    while (((MBCTL & IN0IFG) == 0) && (--timeout > 0)) ;
    if (timeout == 0) { display_error(); return; }
  } while (MBIN0 != mSWRDY);
  firmware_version= MBIN1; // Save firmware version.
  
/**
  * Then the parameters are initialized.
  *
  * \par Control 0: make settings for :
  * - Use current channel I2 - tamper-detection
  * - Count absolute active energy 
  *   (negative energy is considered as tampering)
  * - Switch DC removal alorithm on for I1
  * - Switch DC removal alorithm on for I2
  */
  set_parameter(mSET_CTRL0, defSET_CTRL0);

/**
  * \Set Number of Measurement: 
  *    e.g.  4096 * 50Hz. => int after 1sec
  */
  set_parameter(mSET_INTRPTLEVL_LO, s_parameters.pSET_INTRPTLEVL.w[0]);
  set_parameter(mSET_INTRPTLEVL_HI, s_parameters.pSET_INTRPTLEVL.w[1]);


/**
  * \par Nominal Mains Frequency: 
  *    e.g.  50Hz.
  */
  set_parameter(mSET_NOMFREQ, calFreq);
  
/**
  * \par Phase Error Correction:
  * Sets phase error for current 1/2 at nominal mains frequency for 
  * current transformer according to its specification
  * The phase error of the shunt is zero.
  */
  set_parameter(mSET_PHASECORR1, (int)s_parameters.pSET_PHASECORR1);
  set_parameter(mSET_PHASECORR2, (int)s_parameters.pSET_PHASECORR2);
  
/** \par Adjustment parameters for the two currents:
  * Current Transformer:
  * \par
  * There are two possibilties to adjust the two current
  * values:
  * -# Only one current value is scaled with a factor > 1
  *    to fit the others current's value. The factor
  *    for the later is set to 1.\n
  *    In this example current I1 would be scaled by 0.32/0.30 = 1.06667.
  *    (The RMS values at the maximum current are used to calculate the
  *     factor.)
  *    The current transformer's value is scaled to fit with 
  *    shunt's value, because the shunt's values are bigger, 
  *    so the current transformer's values are multiplied with 
  *    a factor > 1 - otherwise the shunt's values would be 
  *    multiplied with a factor < 1 and this would result
  *    in degraded accuracy.
  * -# Both currents are scaled with a factor > 1 to use the maximum FSR
  *    (Full Scale Range) at the maximum current Imax.\n

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美老年两性高潮| 久久久精品影视| 国产一区二区三区在线观看免费视频 | 国产精品一区二区三区网站| 中文字幕一区在线观看视频| 中文字幕亚洲在| 这里是久久伊人| 色综合中文字幕国产| 日本不卡123| 一区二区三区电影在线播| 久久久久久免费毛片精品| 欧美探花视频资源| 成人国产电影网| 经典三级在线一区| 亚洲高清免费在线| 1024精品合集| 国产精品麻豆一区二区 | 中文字幕av一区 二区| 欧美精品第1页| 欧美日韩一级片网站| 97久久久精品综合88久久| 国产成人精品亚洲日本在线桃色| 欧美aaaaa成人免费观看视频| 亚洲国产欧美一区二区三区丁香婷| 国产精品久久毛片av大全日韩| 久久久久久久久久美女| 91精品国产欧美一区二区| 欧美日韩不卡一区| 在线观看国产一区二区| 成人的网站免费观看| 成人高清免费观看| 国产成人8x视频一区二区| 国产一区在线精品| 久久精品国产一区二区三| 奇米777欧美一区二区| 日本系列欧美系列| 丝袜a∨在线一区二区三区不卡 | 日韩专区中文字幕一区二区| 亚洲一区二区三区在线播放| 亚洲精品久久久久久国产精华液| 1024亚洲合集| 亚洲免费高清视频在线| 亚洲精品视频自拍| 一区二区免费在线播放| 亚洲宅男天堂在线观看无病毒| 亚洲免费资源在线播放| 亚洲一区中文在线| 亚洲成av人影院在线观看网| 亚洲国产精品一区二区www| 一区二区成人在线视频| 亚洲午夜日本在线观看| 午夜电影一区二区| 肉肉av福利一精品导航| 久久99蜜桃精品| 国产夫妻精品视频| av激情亚洲男人天堂| 色综合色综合色综合色综合色综合| 91碰在线视频| 欧美日韩一二三| 91精品福利在线一区二区三区| 日韩精品资源二区在线| 国产亚洲精品aa| 亚洲丝袜美腿综合| 天天影视色香欲综合网老头| 国产一区二区三区四区五区美女| 丁香网亚洲国际| 色综合久久综合网97色综合| 欧美日韩国产欧美日美国产精品| 欧美一区二区三区性视频| 久久久蜜桃精品| 亚洲精品国产品国语在线app| 91一区二区在线观看| 欧美日韩你懂得| www国产精品av| 亚洲日本护士毛茸茸| 日本伊人精品一区二区三区观看方式| 国产在线国偷精品产拍免费yy| 99国产麻豆精品| 日韩免费看网站| 亚洲天堂a在线| 韩国毛片一区二区三区| 99精品欧美一区二区蜜桃免费| 在线91免费看| 亚洲欧美在线aaa| 免费成人在线播放| 99久久99久久精品国产片果冻| 欧美一区永久视频免费观看| 国产精品欧美精品| 日韩国产在线观看| 91欧美激情一区二区三区成人| 日韩欧美成人一区| 亚洲最新视频在线播放| 国产在线一区观看| 欧美日韩一区二区三区高清 | 久久久久久亚洲综合| 亚洲激情六月丁香| 国产二区国产一区在线观看| 这里只有精品视频在线观看| 亚洲手机成人高清视频| 国产综合色在线| 欧美日韩一区三区| 亚洲欧洲成人自拍| 国产一区激情在线| 欧美区视频在线观看| 中文字幕一区二区视频| 国精品**一区二区三区在线蜜桃| 欧美吻胸吃奶大尺度电影| 国产情人综合久久777777| 日韩av在线发布| 欧美羞羞免费网站| 国产精品高清亚洲| 国产一区二区不卡在线| 日韩一卡二卡三卡国产欧美| 亚洲制服丝袜在线| 色综合天天狠狠| ㊣最新国产の精品bt伙计久久| 国产一二三精品| 日韩午夜av一区| 亚洲一二三四在线观看| 91丨porny丨蝌蚪视频| 国产亚洲一区二区三区四区 | 久久蜜桃一区二区| 另类成人小视频在线| 91麻豆精品国产| 午夜视频一区二区| 91国偷自产一区二区使用方法| 亚洲品质自拍视频| av午夜精品一区二区三区| 欧美国产精品一区二区三区| 国产夫妻精品视频| 久久久久久一二三区| 国产麻豆视频一区| 欧美精品一区二区三区高清aⅴ| 久久9热精品视频| 精品国产乱码久久久久久夜甘婷婷 | 精品国产一区a| 男女激情视频一区| 欧美一区二区在线免费观看| 五月天激情综合| 亚洲男人的天堂av| 一本久久a久久免费精品不卡| 综合亚洲深深色噜噜狠狠网站| 不卡的av在线播放| 自拍偷自拍亚洲精品播放| 99re热视频精品| 亚洲最新在线观看| 欧美精品免费视频| 玖玖九九国产精品| 久久青草国产手机看片福利盒子| 国内不卡的二区三区中文字幕 | 五月婷婷久久丁香| 日韩欧美国产wwwww| 韩国三级电影一区二区| 国产日韩精品视频一区| av一区二区三区四区| 亚洲精品视频免费观看| 欧美日韩国产精品成人| 久久精品国产精品亚洲红杏| 国产三级一区二区| 97国产精品videossex| 图片区小说区国产精品视频| 日韩欧美一区中文| 国产成人一级电影| 亚洲三级电影网站| 这里只有精品视频在线观看| 国产精品亚洲第一区在线暖暖韩国 | 欧美专区日韩专区| 蜜臀a∨国产成人精品| 国产人成亚洲第一网站在线播放| 色噜噜偷拍精品综合在线| 日韩高清一级片| 久久久精品日韩欧美| 在线观看日韩一区| 激情图区综合网| 亚洲区小说区图片区qvod| 欧美一区二区三区啪啪| 成人aaaa免费全部观看| 午夜一区二区三区在线观看| 久久你懂得1024| 在线免费不卡视频| 国产乱对白刺激视频不卡| 一区二区三区在线高清| 久久久五月婷婷| 欧美探花视频资源| 高清成人在线观看| 日产国产高清一区二区三区| 国产精品成人免费精品自在线观看| 欧美日韩在线三区| 丰满放荡岳乱妇91ww| 青青草一区二区三区| 亚洲激情五月婷婷| 久久久久久久久岛国免费| 欧美视频一区二区在线观看| 国产成人亚洲综合a∨猫咪| 亚洲成人在线免费| 日韩美女视频一区二区| 久久影音资源网| 欧美精品vⅰdeose4hd| 99国内精品久久| 国产精品一区二区久激情瑜伽|