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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? 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++, 

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美亚洲图片小说| 欧美精品一区二区三区很污很色的| 精品视频999| 精品国产乱码久久久久久浪潮| 中文字幕一区二区三区乱码在线 | 色综合久久久久综合体桃花网| 欧美精品在线一区二区三区| 国产精品久久三区| 精品一区中文字幕| 91.麻豆视频| 亚洲欧美欧美一区二区三区| 日韩电影一二三区| 欧洲一区在线观看| 欧美日韩一本到| 一区二区三区在线免费播放| 国产成人精品免费视频网站| 日韩视频免费观看高清完整版 | 99视频精品全部免费在线| 欧美一区二区三区思思人| 亚洲色图在线看| 不卡一区二区中文字幕| 337p粉嫩大胆色噜噜噜噜亚洲| 日韩国产精品久久久久久亚洲| 色8久久人人97超碰香蕉987| 国产精品不卡在线| 国产精品亚洲成人| 久久综合色综合88| 蜜臀av一区二区在线免费观看 | 欧美xxxxxxxx| 丝袜亚洲另类欧美| 欧美人与禽zozo性伦| 性做久久久久久免费观看欧美| 26uuu久久天堂性欧美| 日本视频一区二区| 91精品午夜视频| 丝袜亚洲精品中文字幕一区| 7777女厕盗摄久久久| 亚洲国产视频网站| 欧美日韩在线观看一区二区 | 亚洲精品综合在线| 99热这里都是精品| 亚洲丝袜制服诱惑| 91搞黄在线观看| 午夜电影一区二区| 5月丁香婷婷综合| 男女视频一区二区| 欧美精品一区二区在线观看| 国产美女视频一区| 亚洲国产精品成人综合 | 欧美国产丝袜视频| 高清日韩电视剧大全免费| 欧美经典一区二区三区| www..com久久爱| 一区二区三区.www| 欧美军同video69gay| 久久精品国产亚洲a| 国产午夜精品久久久久久免费视 | 久久91精品国产91久久小草| 欧美精品一区二区精品网| 国产精品亚洲一区二区三区在线| 中文字幕亚洲一区二区av在线| 欧美在线观看禁18| 久久激情五月激情| 国产精品嫩草影院av蜜臀| 色婷婷综合久久| 麻豆成人免费电影| 国产精品久久久久7777按摩| 欧美日韩你懂的| 国产在线精品一区二区| 中文字幕一区二区三区精华液 | 色婷婷av一区二区三区软件| 日本特黄久久久高潮| 国产精品日产欧美久久久久| 欧美精品777| 国产成人aaa| 舔着乳尖日韩一区| 欧美国产综合一区二区| 在线成人免费视频| www..com久久爱| 毛片av一区二区| 一区二区三区日韩欧美| 中文字幕欧美一区| 日韩一级高清毛片| 高清成人免费视频| 日本不卡一二三| 伊人一区二区三区| 国产亚洲欧美一区在线观看| 欧美日韩国产成人在线免费| 成人免费的视频| 天天色图综合网| 亚洲女人****多毛耸耸8| 欧美www视频| 欧美人牲a欧美精品| 97久久精品人人做人人爽| 精品一二三四区| 日韩电影一区二区三区四区| 亚洲综合视频网| 国产精品不卡一区二区三区| 久久久亚洲欧洲日产国码αv| 欧美久久高跟鞋激| 一本大道久久a久久精品综合| 国产91色综合久久免费分享| 久久99精品一区二区三区| 日日夜夜一区二区| 亚洲国产精品天堂| 亚洲视频一区二区在线| 国产亚洲污的网站| 精品国产3级a| 精品电影一区二区| 精品乱人伦小说| 日韩精品在线一区二区| 91精品国产91久久久久久最新毛片| 欧美中文一区二区三区| 91网站黄www| 粉嫩av一区二区三区在线播放| 美脚の诱脚舐め脚责91| 丝袜亚洲精品中文字幕一区| 日韩精品久久理论片| 亚洲综合一区在线| 亚洲国产视频a| 婷婷成人激情在线网| 婷婷六月综合网| 麻豆久久一区二区| 免费高清不卡av| 久久99精品久久只有精品| 久久成人18免费观看| 国产在线一区观看| 国产精品888| 色综合天天性综合| 欧美日韩中文精品| 日韩一区二区三区在线观看| 精品久久久久久久一区二区蜜臀| 精品久久久久香蕉网| 日韩一区二区三区观看| 欧美精品一区二区三区蜜臀| 欧美一二三在线| 国产精品私房写真福利视频| 欧美激情艳妇裸体舞| 夜夜揉揉日日人人青青一国产精品| 亚洲国产日产av| 老汉av免费一区二区三区 | 免费精品视频在线| 蜜桃视频第一区免费观看| 国产精品一区二区免费不卡| 91美女视频网站| 欧美精品日韩一本| 国产午夜精品美女毛片视频| 亚洲视频网在线直播| 一区二区三区在线视频观看58| 美女网站在线免费欧美精品| 免费在线看一区| 成人永久免费视频| 欧美综合天天夜夜久久| 精品欧美一区二区久久| 亚洲欧美日韩国产手机在线| 综合久久久久久| 美女免费视频一区| 国产成人亚洲综合a∨猫咪| 一本到三区不卡视频| 亚洲精品一区二区三区99| 久久精品欧美一区二区三区不卡| 日本麻豆一区二区三区视频| 欧美一区二区三区四区五区| 2023国产一二三区日本精品2022| 亚洲欧美在线另类| 天天影视网天天综合色在线播放| 国产一区二区精品在线观看| 色婷婷综合久久| 国产网站一区二区| 首页综合国产亚洲丝袜| 成人午夜电影网站| 欧美一区二区三级| 国产精品午夜在线| 免费亚洲电影在线| 99re8在线精品视频免费播放| 欧美成人国产一区二区| 国产婷婷色一区二区三区在线| 亚洲国产cao| 成人精品视频一区二区三区| 欧美成人激情免费网| 性做久久久久久免费观看 | 91成人免费在线| 精品国产sm最大网站免费看| 天天影视色香欲综合网老头| 91成人网在线| 中文字幕视频一区| 国产成人免费xxxxxxxx| 欧美日韩国产经典色站一区二区三区| 亚洲欧美偷拍三级| 国产精品18久久久久久久久久久久 | 精品国产一区二区三区久久久蜜月 | 亚洲欧美偷拍三级| 国产成人精品免费视频网站| 日韩欧美国产三级| 日韩二区三区在线观看| 欧美色图一区二区三区| 欧美国产一区视频在线观看| 粉嫩绯色av一区二区在线观看| 精品欧美一区二区三区精品久久| 蜜桃在线一区二区三区|