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

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

?? calibration.c

?? TDK 6521 SOC 芯片 DEMO程序
?? C
?? 第 1 頁 / 共 2 頁
字號:
/***************************************************************************
 * 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 - Temperature Calibration.
// 
//  AUTHOR:  RGV / MTF
//
//  HISTORY: See end of file.
//**************************************************************************
// File: calibration.c
//               
#include "options.h"
// This calibration does not adjust phase, but it can handle
// all equations.  So, select the equations not handled by calphased.c
#if (CAL_SAVE || AUTOCAL) && \
    (EQUATION == _1ELEMENT_3WIRE \
     || EQUATION == _2ELEMENT_4WIRE_DELTA \
     || EQUATION == _2ELEMENT_4WIRE_WYE)
#include <math.h>
#include "mmath.h"
#include "meter.h"
#include "library.h"
#if NV_SELECT == NV_EEPROM
#include "eeprom.h"
#endif 
#if NV_SELECT == NV_FLASH
#include "flash.h"
#endif 
#if NV_SELECT == NV_FLASH || NV_SELECT == NV_EEPROM
#include "ce.h" // disable CE while writing flash
#endif
#include "calibration.h"

#define ZERO  0L
#if M6520
#define NUM_PARMS   0x80                 // Half of CE DATA ram.
#elif TRACE10
#define NUM_PARMS   0x100                // Half of CE DATA ram.
#else
#error unknown device
#endif

/*** External functions referenced by this module ***/
// Refer to include files.

/*** External variables referenced by this module ***/
extern const int32r_t CeData[];    // The default data for the analog front end.
extern const int8r_t NumCeData[2];

/*** Public functions referenced by this module ***/
/* See 'calibration.h' */

/*** Public variables referenced by this module ***/

/*** Private functions referenced by this module ***/
static int32_t adjust_gain (int32_t unitmax, int32_t actual, int32_t measured);
static uint32_t cal_checksum (void);
static void cal_end (void);
static void compensation (void);
bool memcpy_cepr (int32x_t * pDst, uint16_t pSrc, uint16_t len);
void memcpy_prce (uint16_t pDst, int32x_t * pSrc, uint16_t len);

#if AUTOCAL
/*** Private variables referenced by this module ***/
static int16i_t cs;   // Remaining accumulation intervals of calibration.

#if EQUATION == _1ELEMENT_2WIRE || EQUATION == _1ELEMENT_3WIRE 
#define CALIBRATIONS 3   
#elif EQUATION == _2ELEMENT_3WIRE_DELTA 
#define CALIBRATIONS 4   
#elif EQUATION == _2ELEMENT_4WIRE_DELTA || EQUATION == _2ELEMENT_4WIRE_WYE
#define CALIBRATIONS 5   
#elif EQUATION == _3ELEMENT_4WIRE_WYE
#define CALIBRATIONS 6   
#else
#error no such equation
#endif

#if EQUATION != _3ELEMENT_4WIRE_WYE
#define ADJUSTS 2
#else
#define ADJUSTS 3
#endif

static int32x_t cm[ CALIBRATIONS ];

static volatile int32p_t * code sqsum[] = 
#if EQUATION == _1ELEMENT_2WIRE || EQUATION == _1ELEMENT_3WIRE 
{ &v0sqsum, &i0sqsum, &i1sqsum };
#elif EQUATION == _2ELEMENT_3WIRE_DELTA 
{ &v0sqsum, &i0sqsum, &i1sqsum, &v1sqsum };
#elif EQUATION == _2ELEMENT_4WIRE_DELTA
{ &v0sqsum, &i0sqsum, &i1sqsum, &v2sqsum, &i2sqsum };
#elif EQUATION == _2ELEMENT_4WIRE_WYE
{ &v0sqsum, &i0sqsum, &i1sqsum, &v1sqsum, &i2sqsum };
#elif EQUATION == _3ELEMENT_4WIRE_WYE
{ &v0sqsum, &i0sqsum, &i1sqsum, &v1sqsum, &v2sqsum, &i2sqsum };
#else
#error no such equation
#endif

static const int32x_t * code cal[] =
#if EQUATION == _1ELEMENT_2WIRE || EQUATION == _1ELEMENT_3WIRE 
{ &cal_v0, &cal_i0, &cal_i1 };
#elif EQUATION == _2ELEMENT_3WIRE_DELTA 
{ &cal_v0, &cal_i0, &cal_i1, &cal_v1 };
#elif EQUATION == _2ELEMENT_4WIRE_DELTA
{ &cal_v0, &cal_i0, &cal_i1, &cal_v2, &cal_i2 };
#elif EQUATION == _2ELEMENT_4WIRE_WYE
{ &cal_v0, &cal_i0, &cal_i1, &cal_v1, &cal_i2 };
#elif EQUATION == _3ELEMENT_4WIRE_WYE
{ &cal_v0, &cal_i0, &cal_i1, &cal_v1, &cal_v2, &cal_i2 };
#else
#error no such equation
#endif

static const uint16x_t * code unitmax[] =
#if EQUATION == _1ELEMENT_2WIRE || EQUATION == _1ELEMENT_3WIRE 
{ &Vmax, &Imax, &Imax };
#elif EQUATION == _2ELEMENT_3WIRE_DELTA 
{ &Vmax, &Imax, &Imax, &Vmax };
#elif EQUATION == _2ELEMENT_4WIRE_DELTA
{ &Vmax, &Imax, &Imax, &Vmax, &Imax };
#elif EQUATION == _2ELEMENT_4WIRE_WYE
{ &Vmax, &Imax, &Imax, &Vmax, &Imax };
#elif EQUATION == _3ELEMENT_4WIRE_WYE
{ &Vmax, &Imax, &Imax, &Vmax, &Vmax, &Imax };
#else
#error no such equation
#endif

static const uint16x_t * code xcal[] =
#if EQUATION == _1ELEMENT_2WIRE || EQUATION == _1ELEMENT_3WIRE 
{ &Vcal, &Ical, &Ical };
#elif EQUATION == _2ELEMENT_3WIRE_DELTA 
{ &Vcal, &Ical, &Ical, &Vcal };
#elif EQUATION == _2ELEMENT_4WIRE_DELTA
{ &Vcal, &Ical, &Ical, &Vcal, &Ical };
#elif EQUATION == _2ELEMENT_4WIRE_WYE
{ &Vcal, &Ical, &Ical, &Vcal, &Ical };
#elif EQUATION == _3ELEMENT_4WIRE_WYE
{ &Vcal, &Ical, &Ical, &Vcal, &Vcal, &Ical };
#else
#error no such equation
#endif

void cal_begin (void)                   // Begin calibration.
{
    int32x_t *px;
    int8_t i;

    // MPU calibrations are omitted intentionally, because
    // all of them are more like configurations set by a user
    // to adapt the meter.

    // Sets default calibration for CE, including temperature compensations.
    px = &cal_i0;
    i = CALIBRATIONS;
    do  {   memset_ce (px++, UNITY);    } while (--i);

    i = ADJUSTS;
    do  {   memset_ce (px++, ZERO);     } while (--i);

    #if ADC_COMPENSATION
    // Start the calibration process, with 2 accumulation intervals
    // before temperature is collected, to clear the data pipeline.
    // Then, it collects data for another two seconds with the
    // temperature compensation running.
    cs = 4 + Scal;
    #else
    // Start the calibration process, with 2 accumulation intervals
    // before measurement begins, to clear the data pipeline.
    cs = 2 + Scal;
    #endif

    // set the global calibration flag
    Config |= CFG_CAL;
}

/* This the calibration state machine.
 * 1. Let the CE settle, then 
 * 2. Measure temperature for calibration, then 
 * 3. Measure the current for calibration, then 
 * 4. Perform the calibrations.
 * This only calibrates the gains, and assumes that the
 * phase calibrations are made another way.
 * It does not calibrate neutral current,
 * shunts, or other odd arrangements.
 */
void Calibrate (void)
{
    // Scal, Vcal and Ical are defined in 'defaults.c'.
    int8_t cnt;
    int32x_t *pcm;
    int32p_t * code *psqsum;
    int32_t rounding = Scal / 2;        // round to nearest LSB.

    #if ADC_COMPENSATION
    /* Need two (2) accumulation intervals before the
     * raw temperature will be correct.
     * At this point, it can set the nominal temperature,
     * and then begin to collect the data with
     * temperature compensation enabled. */
    if (cs == (Scal + 2))
        compensation ();                // Set temperature compensation values.
    #endif
    
    if (cs == Scal) // On the first accumulation interval of calibration.
        memset_x ((uint8x_t *) cm, 0, sizeof (cm)); // Initialize the data.

    // This code collects values averaged over several 
    // accumulation intervals, without loss of precision or overflow.
    // Collect the voltages and currents 
    // averaged over several accumulation intervals.
    pcm = cm;
    psqsum = sqsum;
    cnt = sizeof (cm) / sizeof (int32x_t);
    do
    {
        *pcm++ += (**psqsum++ + rounding) / Scal;                 
    } while (--cnt);
    
    if (0 == --cs)              // Count accumulation intervals.
    {                           // If the last accumulation interval, calibrate.
        cal_end ();             // Adjust calibration constants.
        cal_save();             // Save the new calibration.
        // Turn ON all the pulse outputs to show it's done.
        // This is a convenient indication because it works with
        // automatic calibration or manual operation.
        DIO &= 0xF3;            // The pulse outputs are DIOs.
        #if M6520
        CONFIG2 = 0x40 | (CONFIG2 & 0x3F); // Force TX_DIS to DIO_2.
        USER0 &= 0x3D;          // Drive the outputs to ground (LEDs on).
        DIR0 |= 0xC4;           // Change the DIOs 2, 6, 7 to outputs.
        #elif TRACE10                  
        USER0 &= 0x3F;          // Drive both outputs to ground (LEDs on).
        DIR0  |= 0xC0;          // Change the DIOs 6, 7 to outputs.
        #else
        #error unknown device
        #endif
        // clear the global calibration flag
        Config &= ~CFG_CAL;
    }
}

#if ADC_COMPENSATION
static void compensation (void)
{
    int32x_t tppmc1, tppmc2;
    int32x_t a, b;
    int32x_t tn;
    #if ENHANCED_TRIM 
    // These 51 bytes are dynamically allocated, so it doesn't waste RAM.
    int8x_t trimbga, trimbgb, trimm;
    int32x_t c, d;
    // temporary values correspond to letters in the design-spreadsheet.
    int32x_t td, tf, th, tj, tl;
    #endif

    // set temp_nom for calibration; note that the calibration
    // is with the temperature compensation on.
    temp_nom = temp_raw;
    tn = temp_nom;
    tppmc1 = 0; // the linear parts per million per degree C
    tppmc2 = 0; // the quadratic parts per million per degree C
    
    // code to add other components' temperature compensations 
    // to PPMC and PPMC2 goes here. tn is the calibration temperature.
    
    // calculate and add in the IC's temperature compensation
    #if ENHANCED_TRIM // compensate H-version (high-precision) parts
    // read a trim value
    trimbgb = Read_Trim (_TRIMBGB); // -128..127
    
    // if the chip has not been trimmed
    if (trimbgb == 0)
    {
    #endif // ENHANCED_TRIM.
        // Set untrimmed defaults for temperature compensations.
        a = -668;               // -6.68 * (ppm/c) * 1000
        b = -341000;            // -0.341 * (ppm/c^2) * 1000000
    #if ENHANCED_TRIM
    }
    else
    {   // Chip is trimmed, so calculate the..
        // ..temperature compensations, per the spreadsheet.
        // Constants are not abstracted because they are used only here..
        trimm   = Read_Trim (_TRIMM);   // -4..3
        trimbga = Read_Trim (_TRIMBGA); // -128..127
        #if M6520
        // c = [(temp_nom/2427.249249) - (bga * 500) - 370000]/900
        // 2427.249249 = (2^16)/(2^3)
        tn = (tn + 256L) / 512L; // tn = tn / 2^9
        td = ((tn * 27L) + 64L) / 128L; 
        th = ((int32_t)trimbga) * -500L;
        tj = th - 370000L;
        tf = td + tj;
        c = (tf + 5L)/9L;
        #elif TRACE11
        // c = [(temp_nom/4.74074) - (bga * 500) - 370000]/900
        // 4.74074 = 128/27
        td = ((tn * 27L) + 64L) / 128L; 
        th = ((int32_t)trimbga) * -500L;
        tj = th - 370000L;
        tf = td + tj;
        c = (tf + 5L)/9L;
        #elif TRACE13
        // Calculate c = [(temp_nom/2) - (bga * 500) - 370000]/900
        td = tn / 2L;
        th = ((int32_t)trimbga) * -500L;
        tj = th - 370000L;
        tf = td + tj;
        c = (tf + 5L)/9L;
        #else
        #error unknown configuration
        #endif
        // Calculate d = (bgb /10) - [(m + 0.5)*0.14]
        td =  ((int32_t)trimbgb) * 100L;
        th = (((int32_t)trimm) * 100L) + 50L;
        tj = ((th * 14L) + 5L) / 10L;
        d = td - tj;
    
        // a = (-0.28c+33)d+0.33c+7.9
        // calculate a
        td = -28L * c;
        tf = (td + (330000L + 5L)) / 10L;
        th = ((tf * d) + 5000L) / 10000L;
        tl = ((33L * c) + 50L) / 100L;
        tn = tl + 790L;
        a = th + tn;
    
        // b = (-0.0002c+0.02)d-0.46
        // Calculate b
        td = -2L * c;
        tf = td + 20000L;
        th = ((tf * d) + 500L) / 1000L;
        b = th - 460000L;
    } // end else chip has a trim
    #endif // ENHANCED_TRIM.
    tppmc1 += ((22463L * a) + 50000L)  / 100000L;    // a * 2.4632
    tppmc2 += ((1150L  * b) + 500000L) / 1000000L;   // b * 1150.1
    
    ppmc1 = tppmc1;
    ppmc2 = tppmc2;
}
#endif // compensation

static void cal_end (void)
{   // Note: Adjustments for shunts have to have different constants, 
    // and possibly a changed IMAX.
    int32x_t        *pcm    = cm;
    int32x_t * code *pcal   = cal;
    int16x_t * code *punit  = unitmax;
    int16x_t * code *pxcal  = xcal;
    int8_t cnt = sizeof (cm) / sizeof (int32x_t);

    do
    {      
        // Adjust the gain on each channel.
        memset_ce (
            *pcal++, 

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲欧洲成人自拍| 久久久99精品免费观看不卡| 日韩欧美成人午夜| 国产女人aaa级久久久级| 日日摸夜夜添夜夜添国产精品 | 99这里只有久久精品视频| 欧美日韩精品欧美日韩精品一| 久久日韩粉嫩一区二区三区 | 国产亚洲制服色| 亚洲成人免费在线| 成人av先锋影音| 精品久久人人做人人爽| 亚洲在线成人精品| 91在线国内视频| 国产亚洲欧美色| 精久久久久久久久久久| 欧美一级黄色片| 日韩激情一区二区| 欧美午夜片在线看| 亚洲综合色噜噜狠狠| 色综合亚洲欧洲| 自拍视频在线观看一区二区| 成人免费电影视频| 亚洲国产精品av| 国产成人啪免费观看软件| 日韩精品一区二区三区蜜臀| 日本不卡123| 欧美一级欧美三级| 韩国av一区二区三区| 538prom精品视频线放| 亚洲大片精品永久免费| 欧美日韩一区二区三区在线| 亚洲动漫第一页| 欧美人狂配大交3d怪物一区| 亚洲午夜私人影院| 3d成人h动漫网站入口| 丝袜脚交一区二区| 日韩美一区二区三区| 亚洲一级二级三级| 国产精品主播直播| 制服丝袜在线91| 日本不卡不码高清免费观看| www久久久久| 成人动漫精品一区二区| 日本一区二区视频在线| 成人av资源网站| 亚洲久本草在线中文字幕| 欧美日韩国产精品自在自线| 秋霞电影一区二区| 国产欧美日韩久久| 在线中文字幕一区| 视频精品一区二区| 欧美大片在线观看一区二区| 日韩不卡一二三区| 91精品国产综合久久精品麻豆| 久久9热精品视频| 久久久久久黄色| 黄页视频在线91| 欧美激情一区二区三区不卡| 色吧成人激情小说| 极品尤物av久久免费看| 中文字幕日韩欧美一区二区三区| 在线免费一区三区| 日产精品久久久久久久性色| 国产日产欧美一区二区视频| 欧美亚洲一区三区| 国产风韵犹存在线视精品| 亚洲精品国产精品乱码不99| 日韩欧美国产精品一区| eeuss国产一区二区三区| 日韩va欧美va亚洲va久久| 国产目拍亚洲精品99久久精品| 在线观看91精品国产入口| 国产精品一区二区三区网站| 亚洲三级在线播放| 欧美精品久久99久久在免费线| 国产精品自拍网站| 亚洲午夜久久久久久久久电影院 | 精品伦理精品一区| 91国产精品成人| 国产电影精品久久禁18| 五月激情综合网| 亚洲欧美国产高清| 欧美白人最猛性xxxxx69交| 色综合av在线| eeuss鲁片一区二区三区 | 欧美日韩一二三| 国产欧美一区二区精品忘忧草 | 国内精品视频666| 亚洲一区二区精品3399| 国产精品久久久久久久蜜臀| 精品久久久网站| 欧美中文字幕一区二区三区亚洲 | 亚洲一区影音先锋| 国产精品色哟哟网站| 日韩精品一区二区在线| 欧美日韩国产一级二级| 99久久99精品久久久久久| 中文字幕在线不卡国产视频| 国产精品视频一二三区| 欧美精品tushy高清| 色av一区二区| 欧美一区二区播放| 国产精品美女久久久久aⅴ国产馆 国产精品美女久久久久av爽李琼 国产精品美女久久久久高潮 | av中文字幕亚洲| 日韩精品一级中文字幕精品视频免费观看| 欧美三级一区二区| 波多野结衣在线一区| 国产一区二三区| 久久国产福利国产秒拍| 美日韩一级片在线观看| 麻豆精品一二三| 国产一区欧美一区| 国产精品亚洲一区二区三区在线| 国产在线不卡一卡二卡三卡四卡| 蜜臀av一区二区| 玖玖九九国产精品| 久久国产精品露脸对白| 精彩视频一区二区三区| 精品一区二区在线看| 国产一区 二区| 国产一本一道久久香蕉| 岛国精品在线观看| 99精品视频一区| 欧美视频在线观看一区| 欧美日韩久久不卡| 91精品国产综合久久婷婷香蕉| 6080日韩午夜伦伦午夜伦| 欧美日韩精品一区二区三区四区 | 国产精品自拍三区| 成人午夜精品在线| 成人国产免费视频| av亚洲精华国产精华精华| 福利电影一区二区三区| 丁香桃色午夜亚洲一区二区三区| 欧美一区二区在线不卡| 99精品欧美一区二区三区综合在线| 日本国产一区二区| 欧美日韩三级在线| 久久综合色婷婷| 亚洲欧洲日产国产综合网| 五月天精品一区二区三区| 国产在线视频一区二区| 色天天综合久久久久综合片| 91精品一区二区三区在线观看| 久久九九国产精品| 一区二区三区日本| 麻豆91小视频| eeuss鲁片一区二区三区在线观看| 欧美高清www午色夜在线视频| 精品日韩成人av| 亚洲日本va午夜在线影院| 日韩黄色免费网站| 国产99精品国产| 亚洲国产精品成人综合色在线婷婷 | 日韩电影在线观看网站| 欧美一区三区二区| 91精品国产欧美一区二区| 成人午夜激情影院| 成人av一区二区三区| 色嗨嗨av一区二区三区| 欧美日韩一区二区三区四区五区 | 波多野结衣欧美| 亚洲第一狼人社区| 成人免费毛片嘿嘿连载视频| 成人天堂资源www在线| 色www精品视频在线观看| 久久女同精品一区二区| 午夜视频在线观看一区| 97久久精品人人做人人爽| 日韩精品一区二区三区中文精品| 亚洲五月六月丁香激情| 国产ts人妖一区二区| 91精品国产手机| 亚洲一区日韩精品中文字幕| 国产成人综合视频| 日韩欧美成人午夜| 日韩中文字幕一区二区三区| 99久久er热在这里只有精品15| 久久综合丝袜日本网| 日本伊人色综合网| 欧美日韩一级二级三级| 亚洲激情成人在线| youjizz国产精品| 精品久久久久久久久久久院品网| 亚洲精品伦理在线| av亚洲精华国产精华| 国产欧美精品区一区二区三区 | av网站一区二区三区| 精品视频在线免费| 精品国产伦一区二区三区观看方式| 国产精品家庭影院| 成人蜜臀av电影| 国产三级久久久| 亚洲图片自拍偷拍| 精品污污网站免费看| 成人精品小蝌蚪| 国产欧美一区二区精品忘忧草| 国模套图日韩精品一区二区| 色噜噜夜夜夜综合网|