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

📄 freq.c

📁 TDK 6521 SOC 芯片 DEMO程序
💻 C
字号:
/***************************************************************************
 * 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 - Frequency Validity.
// 
//  AUTHOR:  MTF
//
//  HISTORY: See end of file
//**************************************************************************
// File: FREQ.C 
//
#include "options.h"
#include "irq.h"  // interrupt control
#include "lcd.h"
#include "meter.h"
#include "freq.h"

enum FREQ_SRC  { SELECT_A, SELECT_B, SELECT_C };

#if FREQUENCY
/*** Public functions declared in the module. ***/
// See "meter.h".

#define SEVENTY_HZ 0x71B9DF9L           // Maximum allowable frequency.

// Scale factors.
#define TENTH_HZ (0x001A0000l / 10)   // 13 * 2^17 / 10 = (2^32 / (2^15 / 13)) / 10.
#define TWENTIETH_HZ (0x001A0000l / 20)
#define convert_frequency(d) ((d + TWENTIETH_HZ) / TENTH_HZ)

void frequency_lcd (void)
{
    LCD_Number (convert_frequency (Frequency), 5, 1);
    LCD_1DP ();             // One (1) decimal place.
}
#endif // FREQUENCY.

#if MAIN_EDGE_COUNT
static void Display_Main_Edge_Count (uint32_t d);

void main_edge_cnt_lcd (uint8_t select)
{
    switch (select)
    {
       default:
       #if !RTC_LINE_LOCKED
       case 1:
          Display_Main_Edge_Count (MainEdgeCount);
          break;
       #endif
       case 2:
          Display_Main_Edge_Count (main_edge_cnt);
          break;
    }
}

static void Display_Main_Edge_Count (uint32_t d)
{
    d %= 1000000L; 
    LCD_Number (d, 6, 0);               // Display up to six digits.
}
#endif

#if FREQUENCY || MAIN_EDGE_COUNT || RTC_LINE_LOCKED
void Determine_Frequency (void)
{
    // read which element is being measured
    // The 6520 only reads element A
    #if M6520 || TRACE11 
    bool clear = FALSE;
    if(Status & MINVA) // the only possible element
        clear = TRUE;
    #elif TRACE13
    bool clear = FALSE;
    enum FREQ_SRC element;    
    element = (enum FREQ_SRC) memget_ce (&freqsel);
    #elif M6515
    bool clear = FALSE;
    enum FREQ_SRC element;    
    element = (enum FREQ_SRC) freqsel;
    #else
    #error unknown device type
    #endif

    #if !M6520 && !TRACE11
    // decide if it's ok to use its frequency and edge counts
    switch(element)
    {
    default: // fall through to the first available case
    case SELECT_A:  // always present
        if(Status & MINVA)
            clear = TRUE;
        break;

    // Is the voltage present?
    #if EQUATION != _1ELEMENT_2WIRE && EQUATION != _1ELEMENT_3WIRE
    case SELECT_B:
        if(Status & MINVB)
            clear = TRUE;
        break;
    #endif

    // Is the voltage present?
    #if EQUATION == _2ELEMENT_4WIRE_DELTA || EQUATION == _3ELEMENT_4WIRE_WYE 
    case SELECT_C:
        if(Status & MINVC)
            clear = TRUE;
        break;
    #endif
    }
    #endif // EQUATION != _1_ELEMENT_2WIRE

    // This is a critical region.
    // 1. Because the inputs come from the CE.
    // 2. because these values can be used
    // to lock the real-time-clock to the line frequency.
    // See rtc.c
    irq_disable();
    if (clear)
    { 
        // If the RTC line lock option is selected, then if
        // the nominal count is not cleared, it will stop the clock...
        #if MAIN_EDGE_COUNT || RTC_LINE_LOCKED
        main_edge_cnt_nom = 0;       // disable usage before clearing count
        main_edge_cnt = 0;           // The edge count is not valid
        #endif
        #if FREQUENCY                // The frequency source is not valid,
        Frequency = 0;
        #endif                            
    }
    else
    { // The frequency source is valid.
        #if FREQUENCY
        Frequency = freq;
        #endif
        #if MAIN_EDGE_COUNT || RTC_LINE_LOCKED
        MainEdgeCount += main_edge_cnt;
        // Set the nominal edge cnt automatically if possible
        // Setting enables usage
        #if FREQUENCY
        main_edge_cnt_nom = (freq > (long)(55. / 0.587e-6)) ? 120 : 100;
        #else
        // define line frequency in options.h
        main_edge_cnt_nom = (LINE_FREQ*2);
        #endif
        #endif
    }
    irq_enable();
}
#endif // FREQUENCY || MAIN_EDGE_COUNT || RTC_LINE_LOCKED

/***************************************************************************
 * History:
 * $Log: freq.c,v $
 * Revision 1.32  2006/10/13 00:51:10  tvander
 * Removed compile options for 6530, 6515;
 * renamed 6511 and 6513 to trace11 and trace13;
 * Binary verified unchanged from previous version.
 *
 * Revision 1.31  2006/10/06 01:39:11  tvander
 * Changed so that if the RTC is locked to the line, main_edge count is measured.
 * The edge-count display routines are still enabled only by the main-edge-count flag.
 *
 * Revision 1.30  2006/09/14 00:38:32  tvander
 * Spaces for tabs
 *
 * Revision 1.29  2006/09/13 21:38:51  gmikef
 * *** empty log message ***
 *
 * Revision 1.28  2006/09/12 02:44:52  gmikef
 * *** empty log message ***
 *
 * Revision 1.27  2006/09/09 01:13:50  gmikef
 * *** empty log message ***
 *
 * Revision 1.26  2006/08/18 23:24:00  tvander
 * Fixed compile switches
 *
 * Revision 1.25  2006/08/08 18:46:13  tvander
 * Added an option for 6515 test PCB
 *
 * Revision 1.24  2006/07/27 00:58:01  tvander
 * Fixed code to lock RTC to line frequency.  Added a single byte to the shared
 * data structure.
 *
 * Revision 1.23  2006/07/25 00:29:42  tvander
 * Drop display of main edge count when it is being used to lock the clock to the line.
 *
 * Revision 1.22  2006/07/13 22:33:20  tvander
 * Fixed anomalies with counting.
 *
 * Revision 1.21  2006/06/14 02:46:37  tvander
 * Faster LCD display.
 *
 * Revision 1.20  2006/06/09 22:40:02  tvander
 * Redesigned to use status information from the redesigned creep.
 *
 * Revision 1.19  2006/06/08 20:56:31  tvander
 * Fixed "determine freq" so it only measures voltage sensors that are active.
 * Also disables interrupts only fo rthe feature that actually needs it.
 *
 * Revision 1.18  2006/05/18 23:18:52  tvander
 * 16K and 32K
 * First cut at new requirements.
 * 32K 6521 is grossly tested.
 * All others have a clean compile with C51 8.02
 *
 * Revision 1.17  2006/04/25 01:09:55  tvander
 * Integrated improved RTC.  Compensates for time off, has default constant
 * compensation.  Computes true hours of operation.
 *
 * Revision 1.16  2006/03/06 03:38:22  Michael T. Fischer
 * More 6530 prep.
 *
 * Revision 1.15  2006/03/03 11:30:08  Michael T. Fischer
 * Prep for 6530 LCD, etc.
 *
 * Revision 1.14  2006/01/16 20:11:27  tvander
 * Clean Keil build, all versions
 *
 * Revision 1.12  2005/12/21 01:35:27  tvander
 * 6513
 *
 * Revision 1.11  2005/10/08 04:41:24  tvander
 * Fixed priority inversion.
 * Rewrote watchdog to work in brownout, but of course it doesn't work.
 * Watchdog can now be defeated by clearing watchdog option to 0.
 * Reorganized watt hour modules (at last!).
 * Disabled reading of STATUS in 6521_cli because the CE's status is always SAG.
 * Tested with 6521_CLI; measurements seem to work.
 * Fixed other builds.
 *
 * Revision 1.10  2005/09/28 20:54:02  tvander
 * V/I phase displays for all phases,
 * main edge count displays for both types,
 * rewrote setup from defaults to group related functions.
 *
 * Revision 1.9  2005/09/28 00:53:34  tvander
 * Fixed freq and temperature displays
 *
 * Revision 1.8  2005/09/22 23:45:15  tvander
 * Clean build all models and unit tests, updated copyright to be fore Teridian
 *
 * Revision 1.7  2005/08/30 18:16:11  gmikef
 * *** empty log message ***
 *
 * Revision 1.6  2005/08/12 06:01:56  gmikef
 * Added MPU temperature compensation for GAIN_ADJ.
 * Added changes to support new CE 6521 code.
 *
 * Revision 1.5  2005/08/10 02:02:18  gmikef
 * *** empty log message ***
 *
 * Revision 1.4  2005/07/01 00:32:37  tvander
 * Changed the nomenclature on the Status register so that it could be accessed in a byte-wise way.
 *
 * Revision 1.3  2005/04/30 02:13:45  gmikef
 * *** empty log message ***
 *
 * Revision 1.6  2005/04/27 21:38:08  gmikef
 * *** empty log message ***
 *
 * Copyright (C) 2005 Teridian Semiconductor Corp. All Rights Reserved.    *
 * this program is fully protected by the United States copyright          *
 * laws and is the property of Teridian Semiconductor Corporation.         *
 ***************************************************************************/
/* freq.c */

⌨️ 快捷键说明

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