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

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

?? meter.c

?? TDK 6521 SOC 芯片 DEMO程序
?? C
?? 第 1 頁 / 共 4 頁
字號:
/***************************************************************************
 * This code and information is provided "as is" without warranty of any   *
 * kind, either expressed or implied, including but not limited to the     *
 * implied warranties of merchantability and/or fitness for a particular   *
 * purpose.                                                                *
 *                                                                         *
 * Copyright (C) 2005 Teridian Semiconductor Corp. All Rights Reserved.    *
 ***************************************************************************/
//**************************************************************************
//  DESCRIPTION: 71M652x POWER METER - Display Routines. 
// 
//  AUTHOR:  MTF
//
//  HISTORY: See end of file.
//**************************************************************************
// File: METER.C
//               
#include "options.h"
#include <ctype.h>             // Need for 'toupper' function.
//#include "OSCOPE.h"
#include "calibration.h"
#include "ce.h"
#include "batmodes.h"          // battery modes
#include "battest.h"           // battery test
#include "eeprom.h"
#include "cli.h"
#include "defaults.h"
#include "freq.h"              // select, condition and display frequency
#include "io.h"
#include "lcd.h"
#include "library.h"
#include "irq.h"
#include "mmath.h"
#include "peak_alerts.h"       // detect overvoltages and overcurrents
#include "pwrfact.h"           // calculate & display power factors
#include "phase_angle.h"       // calculate & display V/I phase angles
#include "vphase.h"            // calculate & display V/V phase angles:w
#include "pulse_src.h"
#include "psoft.h"
#include "pcnt.h"
#include "rms.h"               // manage Irms and Vrms
#include "rtc.h"
#include "wh.h"
#include "varh.h"
#include "vah.h"
#include "meter.h"             // Test API for consistency

/*** Public variables declared within this module ***/
bool ce_totals_ready;           // Enables update only if changed.
int32_t pdata va0sum, va1sum;   // volt-amps, scaled like w0sum
#if VA_SUMS
int32_t pdata vasum;
#endif
#if PHASE_C_PRESENT
int32_t pdata va2sum;
#endif

#if FLAG
bool register_available = FALSE;        // false = registers are invalid
bool register_locked = FALSE;           // false = update registers
bool register_write = FALSE;            // true = registers written by FLAG

struct Totals_t  xdata Registers _at_ (0x0000); // Flag registers.
struct Totals_t  xdata Totals;          // Need to be in XDATA to be non-volatile store?
#else                    
struct Totals_t  xdata Totals _at_ (0x0000);  
#endif                            // Need to be in XDATA to be non-volatile store?

/*** Private functions declared within this module ***/
static void RescalePhaseB(void);
static void Gain_Compensation (void);
static void Compute_Small_Irms (void);
static void Apply_Creep_Threshold (void);

/*** Private variables used within this module ***/
extern const uint8x_t * code LcdSrc[];

//===========================================================================//
//---------------------------------------------------------------------------//
#if CLI
void cmd_meter (void)
{
    uint8_t data c, d, r;

    select_total = M_NONE;
    select_phase = 0;

    c = toupper (get_char_d (&d));

    if ('R' == c) // detection of bad command when RMS not defined- see below
    {
       c = get_num_decimal ();    
       switch (c)
       {
       case 1: select_total = M_IRMS; break;
       case 2: select_total = M_VRMS;
       default: break;
       }
    }
    else
    {
       cli_index = d;                   // Unget last character.
       select_total = r = get_num_decimal ();    
    }

    done (&c);                          // Skip delimiter, if any.
    switch(select_total)
    {    
    default:
        cli_result = ERROR_ID;
    case M_NONE:
        select_total = M_WH;
        break;
    #if TEMPERATURE
    case M_TEMP:
    #endif
    #if FREQUENCY
    case M_FREQ:
    #endif
    #if OPERATING_TIME
    case M_HOURS:
    #endif
    #if REAL_TIME_DATE
    case M_TIME:
    case M_DATE:
    #endif
    #if BATTERY_TEST
    case M_BATTEST:
    #endif
       break;

    #if WATT_ELEMENT
    case M_WH:
    #if EXPORT
    case M_WHE:
    #endif
    #endif
    #if VAR_ELEMENT
    #if IMPORT
    case M_VARH:
    #endif
    #if EXPORT
    case M_VARHE:
    #endif
    #endif
    #if VA_ELEMENT
    #if IMPORT
    case M_VAH:
    #endif
    #endif
    #if POWER_FACTOR
    case M_PF:
    #endif
    #if PHASE_ANGLES
    case M_VI_ANGLE:
    #endif
    #if VOLTAGE_PHASES
    case M_VPHASE:
    #endif
    #if RMS_VALUES
    case M_IRMS:
    case M_VRMS:
    #endif
    #if PHASE_ANGLES || VOLTAGE_PHASES || POWER_FACTOR || RMS_VALUES
       select_phase = get_num_decimal ();    
       break;
    #endif
    #if PULSE_CNT
    case M_PULSE:
       c = get_num_decimal ();    
       select_pulse = min (c, MAX_PULSE);
       done (&c);                          // Skip delimiter, if any.
       c = get_num_decimal ();    
       select_interval = min (c, MAX_INTERVAL);
       break;
    #endif
    #if MAIN_EDGE_COUNT
    case M_EDGE_CNT:
       c = get_num_decimal ();    
       select_phase = min (c, MAX_EDGE_TYPE);
       break;
    #endif
    }    

    if (!(CE_ACTIVE))
        ce_totals_ready = TRUE;             // force a redisplay
}
#endif // CLI

void meter_initialize (void)
{
    memset_x ((uint8x_t *) &Totals.Sums, 0x00, sizeof (Totals.Sums));       

    // read the revenue registers from the EEPROM
    // There are two sets just in case the power failure occurs while
    // one of the sets is being calculated.
    // The two sets are the structures Totals.Acc and Totals.AccB
    // In Totals, AccB follows Acc, so a single read reads both.
    #if EEPROM
    eeprom_enable();
    memcpy_xpr (
        (uint8x_t*)&Totals.Acc, // The start of the data
        EEPROM_REGISTERS,
        (2 * sizeof (Totals.Acc)) );  // get the revenue registers
    #endif
          
    // validate the saved revenue registers
    if (!LRC_Calc_NVR ((uint8x_t *) &Totals.Acc, sizeof (Totals.Acc), FALSE))
    {   // Copy A is Invalid.  Try to fix it.
        if (!LRC_Calc_NVR ((uint8x_t *) &Totals.AccB, sizeof (Totals.Acc), FALSE))
        {
            // Both copies are bad... so there's no recovery
            Status |= POWER_BAD;
            memset_x ((uint8x_t *) &Totals.Acc, 0x00, sizeof (Totals.Acc));
        }
        else
        {
            memcpy_xx ((uint8x_t *) &Totals.Acc, (uint8x_t *) &Totals.AccB, sizeof (Totals.Acc));
        }
    }
 
#if FLAG
    register_available = FALSE;         // false = registers are invalid.
    register_locked = FALSE;            // false = update registers.
    register_write = FALSE;          // true = registers written by FLAG.
#endif
#if PULSE_SOURCE && PULSE_SOFT
    psoft_init ();                      // initialize software pulse outputs.
#endif
}       
//===========================================================================//
// Perform the calculations for data just imported from the CE to the MPU
// This should be called from the main loop.  It runs the electric-power-meter
// part of the logic.
uint8_t xdata count_errors = 0;
void meter_run (void)
{
    if (xfer_update)                    // Did the CE transfer interrupt run recently?
    {
       if (CFG_CLEAR_ACC == (Config & CFG_CLEAR_ACC))
       {                          // Clear all accumulated values.
          memset_x ((uint8x_t *) &Totals.Acc, 0, sizeof (Totals.Acc));  
          memset_x ((uint8x_t *) &Totals.Sums, 0, sizeof (Totals.Sums));  
          Config &= ~CFG_CLEAR_ACC;
       }

       cai += 1;  // count accumulation intervals

       while (xfer_update)  // repeat this logic if a xfer-busy int happens
       {
           xfer_update = FALSE;

           #if IMAX2
           RescalePhaseB();
           #endif

           #if RMS_VALUES
           Compute_RMS ();         // compute the voltage and current
           #endif

           Compute_Small_Irms ();  // figures VA to figure small Irms

           Apply_Creep_Threshold ();
       }
//       OSCOPE_ZERO; OSCOPE_ONE;
       // xfer update is set here and cleared at the end,
       // because the flag protocol uses it to decide if the 
       // totals can be copied.  At this point, the totals begin to change
       xfer_update = TRUE;

       #if WATT_ELEMENT
       wh_accumulate ();
       #endif

       #if VAR_ELEMENT
       VARh_Accumulate ();
       #endif

       #if VA_ELEMENT
       VAh_Accumulate ();
       #endif

       #if PULSE_SOURCE
       SelectPulses ();              // for software generated pulse outputs
       #endif

       #if POWER_FACTOR
       Compute_Power_Factor ();     // computes the power factor for elements
       #endif

       #if PHASE_ANGLES
       Compute_Phase_Angle ();       // computes the V/I phase angle for each conductor
       #endif

       #if FREQUENCY || MAIN_EDGE_COUNT || RTC_LINE_LOCKED
       Determine_Frequency ();
       #endif

       #if PEAKS
       Determine_Peaks ();           // Check if the voltage or current are too high
       #endif

       #if VOLTAGE_PHASES
       Calc_Voltage_Phase ();        // Calculate the angle between voltage inputs
       #endif

       Gain_Compensation ();         // quadratic temperature compensation of the meter

       #if RTC_COMPENSATION && (REAL_TIME_DATE || OPERATING_TIME)
       RTC_Compensation ();          // Do temperature compensation of the RTC. 
       #endif
       #if REAL_TIME_DATE
       RTClk_Read ();                // Get current time.
       #endif

       #if BATTERY_TEST
       battest_run ();               // Run the battery test at midnight
       #endif

       // precalculate the value to be displayed in the autosleep mode
       // This value is saved by the sag logic in ce.c
       // The second copy is made when the accumulators are copied, below
       #if AUTOSLEEP
       brownout_cache_valid = 0;
       #if WATT_SUMS
       // save total kWh
       brownout_cache = wh_to_long (LcdSrc[ 0 ]);
       #else
       // save kWh on phase A
       brownout_cache = wh_to_long (LcdSrc[ 1 ]);
       #endif
       #if MODE_DISPLAY
       brownout_cache_mode = M_WH;
       #endif
       brownout_cache_valid = YES;
       #endif // autosleep

       // keep interrupting clock stuff out
       irq_disable();
       LRC_Calc_NVR ((uint8x_t *) &Totals.Acc, sizeof (Totals.Acc), TRUE);
       memcpy_xx (
           (uint8x_t *) &Totals.AccB, 
           (uint8x_t *) &Totals.Acc, 
           sizeof (Totals.Acc));
       irq_enable();

       #if AUTOCAL
       // cal flag is set in main.c if pin 3 of the debug
       // connector is grounded, and watt hours are zero
       if (Config & CFG_CAL)
           // this call performs a state machine that
           // measures volts and amps for a period,
           // then adjusts the CE's calibration gains
           // and saves them to nonvolatile memory
           // After that, the LCD says "HELLO"
           // to indicate completion.
           Calibrate ();
       #endif

       #if FLAG
       if (!register_locked)         // If a flag interface is not signed on,
           Update_register ();       // move data in or out of the FLAG interface
       #endif
       xfer_update = FALSE;          // The transfer interrupt's data is available
       ce_totals_ready = TRUE;

//       OSCOPE_ZERO;
    }
    #if WATCHDOG // if the watchdog hierarchy is enabled, fix up meter settings
    else
    {
        // If the bits are set, but there's no interrupt, handle it.
        // This happens in rare instances when high-voltage electromagnetic
        // interference is inadequately handled by the PCB.  In these cases,
        // status bits in the controller can be inverted by noise.  This
        // interrupt is so crucial that it's worth handling it in this way.
        // 
        // The interrupts are reenabled because that is one possible failure.
        if (IE_RTC)
        {
            CLR_IE_RTC();          // Just clear IE_RTC bit.

            #if REAL_TIME_DATE || OPERATING_TIME
            rtc_isr ();            // Compensate the clock
            #endif // REAL_TIME_DATE.

            #if 1 == PULSE_CNT
            pcnt_accumulate ();    // Sum timed counts of pulses
            #endif

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
中文字幕一区av| 欧美一卡2卡3卡4卡| 国产精品久久久久久亚洲毛片| 精品一区二区精品| 久久久久久一二三区| 国产iv一区二区三区| 中文字幕二三区不卡| 一本色道久久综合亚洲91| 亚洲精品一卡二卡| 欧美久久久久免费| 黑人巨大精品欧美黑白配亚洲| 欧美激情一区二区三区不卡| 99vv1com这只有精品| 亚洲欧美乱综合| 日韩一区二区三区免费看| 国产福利一区在线| 亚洲人123区| 91精品婷婷国产综合久久竹菊| 麻豆一区二区99久久久久| 日本一区二区三区在线不卡| 色婷婷综合视频在线观看| 蜜臀91精品一区二区三区| 国产精品午夜久久| 91精品国产麻豆| 成人夜色视频网站在线观看| 亚洲成av人片www| 国产日本一区二区| 337p亚洲精品色噜噜噜| 国产一区激情在线| 日日夜夜一区二区| 中文字幕一区二区不卡| 日韩三级视频中文字幕| 成人av网站在线| 免费高清在线一区| 亚洲精品亚洲人成人网| 精品久久人人做人人爰| 一本色道亚洲精品aⅴ| 黄色精品一二区| 夜色激情一区二区| 国产欧美在线观看一区| 91精品在线一区二区| 99精品国产一区二区三区不卡| 青青国产91久久久久久| 亚洲乱码国产乱码精品精98午夜| 日韩免费一区二区| 欧美写真视频网站| 不卡大黄网站免费看| 蜜臀av性久久久久蜜臀aⅴ| 亚洲精品日韩综合观看成人91| 欧美大胆人体bbbb| 欧美久久免费观看| 色欧美片视频在线观看| 成人高清免费观看| 国产九色精品成人porny| 日韩激情av在线| 亚洲第四色夜色| 亚洲精品免费在线观看| 国产精品久久久久影院老司| 久久综合视频网| 在线不卡免费av| 在线一区二区三区| 一本到不卡免费一区二区| 成人精品gif动图一区| 国产激情一区二区三区四区| 久久精品国产精品亚洲精品| 奇米一区二区三区| 免费在线观看精品| 日本视频免费一区| 偷拍日韩校园综合在线| 亚洲一区欧美一区| 亚洲精品久久7777| 亚洲美女视频在线| 亚洲精品老司机| 亚洲一区二区三区爽爽爽爽爽| 国产精品成人免费在线| 日本一二三不卡| 欧美国产成人精品| 1000部国产精品成人观看| 国产精品久久久久久久第一福利| 国产精品看片你懂得| 中文字幕中文字幕中文字幕亚洲无线| 国产亚洲婷婷免费| 国产欧美精品一区二区三区四区 | 2022国产精品视频| 日韩免费性生活视频播放| 日韩精品一区二区三区蜜臀| 欧美激情中文字幕一区二区| 久久久久国产一区二区三区四区| 久久久99久久| 国产精品久久久久aaaa樱花| 自拍偷自拍亚洲精品播放| 亚洲精品中文在线观看| 亚洲超碰精品一区二区| 奇米精品一区二区三区在线观看一| 免费av成人在线| 国产福利精品一区| 99视频热这里只有精品免费| 日本韩国精品在线| 91精品国产黑色紧身裤美女| 欧美一级久久久| 日本一区二区三区久久久久久久久不| 中文字幕成人网| 亚洲一区二区三区四区的| 美女性感视频久久| 国产98色在线|日韩| 欧美在线制服丝袜| 精品国产露脸精彩对白| 1024亚洲合集| 蜜桃视频一区二区三区在线观看| 国产精品一区在线观看你懂的| 成人黄色在线网站| 欧美日韩一级片网站| 欧美精品一区男女天堂| 亚洲欧美综合在线精品| 日韩黄色一级片| 99麻豆久久久国产精品免费 | 中文字幕精品一区二区精品绿巨人| 日韩理论片一区二区| 日韩成人精品在线| 丁香婷婷综合色啪| 7777精品伊人久久久大香线蕉的| 久久奇米777| 亚洲第一在线综合网站| 国产xxx精品视频大全| 欧美三级电影网| 国产精品视频一二三| 日韩影院免费视频| 91影视在线播放| 日韩欧美的一区| 亚洲国产日韩精品| 国产不卡在线播放| 日韩一级二级三级精品视频| 国产精品二三区| 精品一区二区在线免费观看| 色综合久久88色综合天天6| 久久久久久久久一| 奇米综合一区二区三区精品视频| 色综合天天综合色综合av| 欧美一区二区高清| 一二三四社区欧美黄| 国产999精品久久久久久绿帽| 制服.丝袜.亚洲.另类.中文| 亚洲黄色性网站| 成人午夜视频免费看| xnxx国产精品| 日本成人在线看| 一本色道综合亚洲| 一区在线播放视频| 成人一区在线看| 久久婷婷久久一区二区三区| 日本欧美一区二区在线观看| 欧美丰满少妇xxxbbb| 亚洲一区二区在线免费观看视频 | 欧美最新大片在线看| 国产精品久久久久天堂| 国产激情91久久精品导航| 精品久久久久久久久久久久久久久久久 | 国产一区二三区好的| 555夜色666亚洲国产免| 一区二区免费看| 色综合天天性综合| 日韩理论在线观看| 色婷婷综合久色| 亚洲制服欧美中文字幕中文字幕| 丰满放荡岳乱妇91ww| 久久午夜国产精品| 国产麻豆视频精品| 日本一区二区三区高清不卡| 国产精品1区二区.| 亚洲国产高清在线| bt欧美亚洲午夜电影天堂| 一区二区中文字幕在线| 91麻豆国产香蕉久久精品| 亚洲欧美日韩久久精品| 色综合天天性综合| 亚洲一区二区三区在线看| 欧美日韩精品一区二区天天拍小说 | 亚洲成人资源网| 欧美精品电影在线播放| 奇米影视一区二区三区小说| 欧美成人bangbros| 国产乱码精品一区二区三| 国产欧美一区二区精品性| 成人av网在线| 一区二区三区加勒比av| 欧美日本免费一区二区三区| 美女在线视频一区| 国产人久久人人人人爽| 97久久精品人人澡人人爽| 亚洲一卡二卡三卡四卡五卡| 91精品在线免费观看| 国产乱妇无码大片在线观看| 国产精品热久久久久夜色精品三区 | 久久99深爱久久99精品| 久久久久久久久久久久久久久99 | 欧美三片在线视频观看 | 久久久久综合网| 成人av电影免费在线播放| 亚洲图片自拍偷拍| 日韩欧美国产一区二区在线播放|