71M6521D/71M6521F 71M6521B Energy Meter IC Family SOFTWARE USER’S GUIDE 8/6/2008 Revision 1.7 TERIDIAN Semiconductor Corporation 6440 Oak Canyon Rd., Suite 100 Irvine, CA 92618-5201 Ph: (714) 508-8800 ▪ Fax: (714) 508-8878 Meter.support@teridian.com http://www.teridian.
71M652X Software User’s Guide TERIDIAN Semiconductor Corporation makes no warranty for the use of its products, other than expressly contained in the Company’s warranty detailed in the TERIDIAN Semiconductor Corporation standard Terms and Conditions.
71M652X Software User’s Guide 71M652X Energy Meter IC FAMILY SOFTWARE USER’S GUIDE Revision 1.
71M652X Software User’s Guide Table of Contents 1 ............. INTRODUCTION 13 1.1 Using this Document ............................................................................................................................. 13 1.2 Related Documentation ......................................................................................................................... 14 1.3 Compatibility Statement ............................................................................................
71M652X Software User’s Guide 5.3 Program Flow ......................................................................................................................................... 46 5.3.1 5.4 Startup and Initialization 46 Basic Code Architecture........................................................................................................................ 49 5.4.1 Initialization 49 5.4.2 Foreground 50 Timer Interrupt .................................................................
71M652X Software User’s Guide 5.17.1 Memory Use 96 5.17.2 CE Code Location 96 5.17.3 Battery Modes 96 5.17.4 Three-Wire EEPROM Hardware 98 Temperature Compensation 99 5.17.5 5.18 TEST Modules ........................................................................................................................................ 99 5.18.1 6513 CE Example 99 5.18.2 Serial Port Tests 99 5.18.3 Timer Tests 99 5.18.4 EEPROM Tests 99 5.18.5 Generating DIO Pulses on Reset 99 5.18.
1M652X Software User’s Guide Program Counter................................................................................................................. 120 Ports 120 Timers 0 and 1 .................................................................................................................... 120 Timer/Counter Mode Control Register (TMOD) .................................................................. 121 Timer/Counter Control Register (TCON) .................................................
71M652X Software User’s Guide List of Figures Figure 2-1: Software Structure ....................................................................................................................................... 16 Figure 3-1: Port Speed and Handshake Setup ............................................................................................................... 21 Figure 5-1: STARTUP.A51 .................................................................................................................
71M652X Software User’s Guide Table 5-4: Current Sensing Options ............................................................................................................................... 42 Table 5-5: Compensation Features ................................................................................................................................ 42 Table 5-6: Power Registers and Pulse Output Features ................................................................................................
71M652X Software User’s Guide Table 6-30: Serial 1 Modes .......................................................................................................................................... 124 Table 6-31: The S1CON Register ................................................................................................................................ 124 Table 6-32: The S1CON Bit Functions ................................................................................................................
71M652X Software User’s Guide LIMITED USE LICENSE AGREEMENT Acceptance: By using the Application Programming Interface and / or other software described in this document (“Licensed Software”) and provided by TERIDIAN Semiconductor Corporation (“TSC”), the recipient of the software (“Licensee”) accepts, and agrees to be bound by the terms and conditions hereof.
71M652X Software User’s Guide Revision 1.
71M652X Software User’s Guide 1 1 INTRODUCTION TERIDIAN Semiconductor Corporation’s (TSC) 71M652X single chip Energy Meter Controllers are a family of Systemson-Chip that supports all functionalities required to build a low-cost power meter. Demo Boards are available for each chip (71M6521DE/FE, 71M6521BE) to allow development of embedded application, in conjunction with an In-Circuit Emulator.
71M652X Software User’s Guide 1.2 RELATED DOCUMENTATION Please refer to the following documents for further information: • 71M6521 Demo Board User’s Manual • 71M6521DE/FE or 71M6521BE Data Sheet • Signum Systems ADM-51 In-Circuit Emulator Manual • Keil Compiler Manual (Version 7.5 or later) • μVision2 (Version 2.20a or later) Manual TERIDIAN’s web site (http://www.teridian.com) should be frequently checked for updates, application notes and other helpful information.
71M652X Software User’s Guide 2 2 DESIGN GUIDE This section provides designers with some basic guidance in developing power meter applications utilizing the TSC 71M652X devices. There are two types of applications that can be developed: 2.1 • Embedded application using the sources provided by TERIDIAN, or • Embedded application using only customer generated functions. HARDWARE REQUIREMENTS The following are the minimum hardware requirements for developing custom programs: 2.
71M652X Software User’s Guide In order to generate and test software, the Keil compiler and the Signum in-circuit emulator (ICE) must be installed per the instructions in section 4. The include files and header files must also be present on the development PC. Typically, a design session consists of the following steps: 2.
71M652X Software User’s Guide The Demo Code is highly modular. Each device in the chip and on the Demo Board has a corresponding set of driver software in the Hardware Layer. These driver software modules are very basic, enabling customers to easily locate and reuse the logic. For the serial devices and for the CE, the buffer handling has been abstracted and separated from the driver modules. Where there are several similar devices (e.g.
71M652X Software User’s Guide Revision 1.
71M652X Software User’s Guide 3 3 DESIGN REFERENCE As depicted in Figure 1 of section 2, the 71M652X provides a great deal of design flexibility for the application developer. Programming details are described below. 3.1 PROGRAM MEMORY The embedded 80515 MPU within the 71M652X has separate program (32K, 16K, or 8K bytes) and data memory (2K bytes). The code for the Compute Engine program resides in the MPU program memory (flash).
71M652X Software User’s Guide 3.3 PROGRAMMING OF THE 71M652X CHIPS There are two ways to download a hex file to the 71M652X Flash Memory: • Using a Signum Systems ADM-51 ICE. • Using the TERIDIAN Semiconductor Flash Programmer Module (FDBM) or the TERIDIAN Semiconductor Flash Download FDBM-TFP1 Stand-Alone Module Note: For both programming and debugging code it is important that the hardware watchdog timer is disabled. See the Demo Board User’s Manual for details.
71M652X Software User’s Guide 3.5.1 Running the 652X_Demo.hex Program This object file is the 71M652X embedded application developed by TERIDIAN to exercise all low-level function calls using a serial interface. Demo Boards ship pre-installed with this program. To run this program: • Connect a serial cable between the serial port of the Debug Board RS232 and a COM port of a Windows PC.
71M652X Software User’s Guide 3.5.2 CLI Commands The Demo Board User’s Manual (DBUM) for the 71M6521 contains a complete list of the available commands. Note: Only the 71M6521FE chip has enough memory to support a serial command line interface in addition to its metering functions. Communication with the 71M6521BE and 71M6521DE chips is implemented with a simpler interface, based on Intel hex records. This interface is also described in the Demo Board User’s Manual. 3.5.
71M652X Software User’s Guide 4 4 TOOL INSTALLATION GUIDE This section provides detailed installation instructions for the Signum ADM-51 in-circuit emulator and for the Keil compiler. 4.1 INSTALLING THE PROGRAMS FOR THE ADM51 EMULATOR The AMD51 ICE interfaces with the PC is via the USB serial interface. The installation process consists of the following steps: 1. 2. 3. 4. 4.
71M652X Software User’s Guide 4.3 INSTALLING THE ADM51 USB DRIVER The Wemu51 program communicates with the emulator ADM51 via the USB interface of the PC. The USB driver for the ADM51 has to be installed prior to using the emulator. After plugging in the USB cable into the PC and the ADM51 ICE the status light of the ADM51 emulator should come on. A dialog box will appear, asking you to install the ADM51 driver. Click Next. Another dialog box will appear, asking how to search for the driver.
71M652X Software User’s Guide Click Finish. Click Finish again. Note: USB 1.1 is sufficient for operation of the ADM51. If higher performance is desired and no USB 2.0 port is available on the host PC, a USB 2.0 card can be installed as an option. 4.4 INSTALLING UPDATES TO THE EMULATOR PROGRAM AND HARDWARE If the Wemu51 program is revision 3.07 or later, no special precautions have to be taken. Otherwise, the program should be updated using the Signum Systems web site (www.signum.com).
71M652X Software User’s Guide 4.5 CREATING A PROJECT Double click on the WEMU51 icon to start the Chameleon debugger. Click Project/Create New Project. The following screen will appear: Follow the instructions of the Create Project Wizard by selecting Next. Revision 1.
71M652X Software User’s Guide When prompted for the project name to be used, type a convenient project name. Click Next. When prompted for the project directory to be used, select an existing folder on the PC. Do NOT select any folder in the Wemu51 installation directory! Click Next. When prompted for the emulator to be used, select ADM51 Emulator. Click Next. Revision 1.
71M652X Software User’s Guide When prompted for the communication device to be used, select USB ADM51. Click Next. When prompted for the processor to be used, select either 71M6521. Click Next. Click Finish. Revision 1.
71M652X Software User’s Guide 4.6 INSTALLING THE KEIL COMPILER After inserting the Keil CD-ROM into the CD drive of the PC, the on-screen instructions should be followed to install the Keil compiler. Note: For PCs that can only use one type of drive at a time (CD-ROM drive, floppy drive, such as certain laptops), it is helpful to copy the contents of the floppy labeled “Add-On Disk” to the hard drive of the PC. That way, drives do not have to be swapped out during the installation.
71M652X Software User’s Guide 4.7 CREATING A PROJECT FOR THE KEIL COMPILER 4.7.1 Directory Structure The following directory structure is established when the files from the archive 652X_Demo.
71M652X Software User’s Guide The Project Workspace screen on the left side of the window shows the main components of the source (CE, CLI, IO, Main, Meter, Utils) in folders. Folders can be opened by clicking on the plus sign next to them. Opening the folders will display the source files associated with them. It should be noted that not all header files are physically present in the project directory. The files absacc.h, string.h, ctype.h, and setjmp.
71M652X Software User’s Guide 4.7.3 Manually Controlling the Keil Compiler Settings If the method described in section “Adjusting the Keil Compiler Settings” is not used, the Keil compiler settings can also be controlled manually. The target options should be selected in order to adapt the compiler controls properly to the target. The uVision compiler environment is started by selecting Programs Æ Keil Æ uVision2.
71M652X Software User’s Guide For older versions of the Keil compiler, select the TERIDIAN folder (labeled “TDK”), open it by clicking on the + sign and select 73M2910L as the target device. Confirm by clicking OK. Under Project Æ Options for Target1, select the Target tab and enter the values in the fields as shown above. Confirm by clicking OK. Revision 1.
71M652X Software User’s Guide Under the Output tab, select a name for the executable (object) file with .abs extension’ in the field labeled “Name of the executable” and check the fields by “Debug Information”, “Browse Information” and “Create HEX File”. This will guarantee that high-level source information will be embedded in the output file. Select HEX-80 as the output format, as shown below: Under the C51 tab, provide path names for the source files to be included, as shown below.
71M652X Software User’s Guide 4.8 PROJECT MANAGEMENT TOOLS With large software projects involving a multitude of source, object, list and other files in various revisions, it is very helpful to use a version control tool. To manage file versions under Windows, Tortoise CVS, a free version control utility, might be useful. This utility can be found at http://www.tortoisecvs.org/ . 4.9 ALTERNATIVE COMPILERS The Demo Code was written for the Keil compiler.
71M652X Software User’s Guide Some editors to be considered are: • VIM, see http://www.vim.org/ a free VI editor. VIM is available in full-featured versions for Windows. VI is part of the POSIX standard, so using it is a portable skill. VIM wins awards for usability. • UltraEdit http://www.ultraedit.com/ , an inexpensive (not free), professional Windows programming editor. This editor works like all other Windows applications, with extra features to support programming languages.
71M652X Software User’s Guide 5 5 DEMO CODE DESCRIPTION 5.1 80515 DATA TYPES AND COMPILER-SPECIFIC INFORMATION 5.1.1 Data Types The 80515 MPU core is an 8-bit micro controller (MPU); thus operations that use 8-bit data types such as “char” or “unsigned char” work more efficiently than operations that use multi-byte types, such as “int” or “long”. The Keil C51 compiler supports ANSI C data types as well as data types that are unique to the generic 8051 controller family.
71M652X Software User’s Guide General data type definitions: typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned long uint32_t; typedef signed char int8_t; typedef signed short int16_t; typedef signed long int32_t Type definitions for internal data, lower 128 bytes, addressed directly: typedef unsigned char data uint8d_t; typedef unsigned short data uint16d_t; typedef unsigned long data uint32d_t; typedef signed char data int8d_t; typedef signed short data
71M652X Software User’s Guide Type definitions for internal data, 256 bytes, in the upper 128 bytes addressed indirectly: typedef unsigned char idata uint8i_t; typedef unsigned short idata uint16i_t; typedef unsigned long idata uint32i_t; typedef signed char idata int8i_t; typedef signed short idata int16i_t; typedef signed long idata int32i_t; This is fairly fast, not battery-backed-up memory, slower than the data in the lower 128 bytes of internal memory. Competes with data for space.
71M652X Software User’s Guide Note: Throughout the Demo Code, an attempt has been made to put the most frequently used variables in the fastest memory space.
71M652X Software User’s Guide There is a known defect in version 7.50a of the Keil compiler: Memory types must be explicitly defined in local variables. Using a predefined type is not explicit enough, i.e. "char xdata c;" is ok. "typedef char int8_t; ... int8_t data c;" is OK, but "typedef char data int8d_t; ... int8d_t c;" is not OK. 5.
71M652X Software User’s Guide Feature Code Size 8KB 16KB 32KB Description CT and shunt resistors 1KB to 2.5KB Y Y Y Configurations include one element, one phase, and neutral current, as well as two elements with two phases Rogowski coils 2.5KB N N N Needs special CE code Table 5-4: Current Sensing Options Feature Code Size 8KB 16KB 32KB Description Chopping of VREF 0.06KB Y Y Y Control of the chopping bit Temperature compensation of VREF 0.
71M652X Software User’s Guide Feature Code Size 8KB 16KB 32KB Description Wh equation 1 0.2KB N N/opt N/opt Wh equation 2 0.2KB N/opt N/opt N/opt Frequency register 0.1KB N Y Y Inhibited if freq > 70Hz or voltage is below the threshold Wh net metering 0.4KB N N/opt Y Used only for automatic calibration. No display is provided. Wh export register 0.25KB N N/opt N/opt Wh exported, display reads “3 999999” Wh export pulse output 0.
71M652X Software User’s Guide Feature Feature Code Size 8KB 16KB 32KB 0.37KB Y Y Y Adjustable at calibration. If abs(W) < Creep threshold, then creep mode. Zero accumulator of CE N/A Y Y Y The pulse accumulation register in the CE is cleared to prevent spurious pulses from low current noise. Current threshold N/A Y Y Y Adjustable at calibration. Set If max(abs(IA2), abs(IB2)) < Current threshold then creep mode. Current is calculated from RMS if possible, or, if below 0.
71M652X Software User’s Guide Feature Feature Code Size 8KB 16KB 32KB Description FLAG interface protocol 2.5KB N N/opt N/opt Implements the FLAG protocol stack (see the FLAG specification). The FLAG protocol reads and writes registers in the meter and responds to all ports. Reception of calibration parameters via the serial interface 2.0KB Y Y Y Simple serial calibration system that supports reading data and writing calibration values, including CE data, MPU calibration and RTC settings.
71M652X Software User’s Guide Feature Code Size 8KB 16KB 32KB Description Error recording and saving 0.4KB N/opt N/opt N/opt Errors are recorded in 16 bit words, one bit per error. All error collection is reset when the magnetic tamper DIO is asserted for 1 second. Error data is protected by a checksum. The time stamp (hour, day and month of assertion) and the bit number of the five most recent errors are saved. Microwire EEPROM 0.2KB N/opt N/opt N/opt I2C EEPROM 0.
71M652X Software User’s Guide Before the MPU gets to execute the main() program, it will execute the startup instructions contained in the STARTUP.A51 assembly program (Figure 5-1). Upon completion, STARTUP.A51 causes a jump to the label C_START, which is contained in the second startup assembly program named init.A51 (Keil/C51/LIB directory, see Figure 5-2). Init.A51 finally causes the jump to main(). The startup files are described in section 5.10 .
71M652X Software User’s Guide main_init() Initialize battery mode management Initialize LCD Remove software watchdogs Display "HELLO" Reset RTC meter_initialize() Set default values Enable RTC interrupt Restore calibration values Initialize pulse counting restore OK? no yes autocal request? Enable CE Apply calibration defaults Create SW watchdog for main loop no Enable interrupts yes END Perform autocal Figure 5-4: main_init() Function Revision 1.
71M652X Software User’s Guide main_run() main_background() main_background() Reset SW watchdog for main loop Command pending? no Neutralize potential flash erase from EMI yes Run software timers Process command Run metering Process flag protocol (0) Detect and manage battery modes Process flag protocol (1) END END Figure 5-5: main_run() Function 5.4 BASIC CODE ARCHITECTURE The TERIDIAN 71M652X firmware can be divided into two code parts.
71M652X Software User’s Guide 5.4.2 Foreground There are total 12 interrupts available for the 80515, and the revision 4.7a Demo Code uses a total of 11 interrupts. Table 5-10 shows the interrupt service routines (ISRs), the corresponding vectors (Table 6-58 in section 6.3.5.4) and their priority, as assigned by the MPU using the IP0 and IP1 registers (see section 6.3.5.2).
71M652X Software User’s Guide the interrupt of the EEPROM (external interrupt 5), currently unused (code is available in Io\eeprom.c). Timer 0 shares its interrupt priority bits with FWCOL, the flash write timing interrupt, also unused (flash code is in Util\flash.c). The lowest priority is xfer_busy_isr() (Meter\ce.c) and the rtc_isr() interrupts (Io\rtc.c; both share external interrupt 6, Meter\io652x.c). These can usually wait up to half a second.
71M652X Software User’s Guide tmr0_isr() tmr1_isr() no Restart timer? Restart timer? yes no yes Reload with TH0, TL0 Stop timer Reload with TH1, TL1 no application needs timer0? application needs timer1? yes Stop timer no yes Run timer routine for application Run timer routine for application Reset tmr0 SW watchdog Reset tmr1 SW watchdog END END Figure 5-6: Timer ISRs stm_run() pTimers = &Timers[NUM_TIMERS) tick_cnt<>0 pTimers = &Timers[NUM_TIMERS) i = NUM_TIMERS i = NUM_TIMERS N
71M652X Software User’s Guide CE_BUSY Interrupt CE_BUSY interrupt is used for handling the outputs of the CE that are refreshed every 396µs, i.e. SAG detection. ce_busy_isr() Disable CE interrupts Stretch clock 5 times Read CE status Normal clock Execute Timer Expired function.
71M652X Software User’s Guide XFER_busy_rtc_int() IE_XFER? no yes Clear IE_XFER yes no alt mux cycle? yes Configure for alt mux cycle yes no Not first CE pass? yes Copy data from CE DRAM to IRAM Decrement ce_first_pass Apply creep threshold ce_first_pass = 0? no yes Enable pulses Reset XFER_BUSY watchdog IE_RTC? no yes Clear IE_RTC Accumulate pulse counts Clock compensation Watchdog reset IE_RTC or IE_XFER? END Figure 5-9: XFER_BUSY/RTC ISR The interrupt service routine includes a loo
71M652X Software User’s Guide RTC interrupt happens, and then the XFER interrupt happens after the IE_XFER flag is already tested, but before the RTC interrupt is cleared. In this case, the signal to EXT6 will remain set, and never have an edge to cause another interrupt 6. Therefore, the XFER_BUSY interrupt will hang forever, thus preventing delivery of the data to the meter.
71M652X Software User’s Guide 5.4.
71M652X Software User’s Guide meter_LCD meter_lcd() ce_active = FALSE & RTC_Tic() =TRUE? no yes LCD Clear Display " CE OFF" ce_totals_rdy() = TRUE no yes beat != my_beat? ce_totals_ready=FALSE yes my_beat = beat Save accumulated energy to BROWNOUT cache arrange for blinking of decimal point no no select_total >= MAX_TOTAL? beat? yes yes decimal point on meter_totals (select_total, select_phase) Clear display no date display M_DATE != select_scroll? yes, display other than date LCD_mode
71M652X Software User’s Guide Command Line Interpreter cli() U08 data d; cli_result = NULL N cli_result = NULL & done(&d) = FALSE? Y toupper(d) = '/' ? Y cli_result = OK_ID N toupper(d) = ']' ? Y cmd_ce_data_access() N toupper(d) = ')' ? Y cmd_mpu_data_access() N toupper(d) = 'C' ? Y cmd_ce() N toupper(d) = 'E' ? Y cmd_eeprom() N toupper(d) = 'I' ? Y cmd_i() N toupper(d) = 'M' ? Y cmd_meter) N toupper(d)= 'P' ? Y N toupper(d) = 'PS' ? Y cmd_power_save() N cmd_profile() toupper
71M652X Software User’s Guide Auto-Calibration The auto-calibration option (not compiled in the executable Demo Code) is a simplified calibration procedure based on voltage, real energy and reactive energy measurements. Before the calibration starts, the desired accumulation time (SCAL) and the applied (ideal) voltage and current have to be entered by the user in the MPU memory locations VCAL and ICAL.
71M652X Software User’s Guide 3) If 0 <= cs <= Scal: For two accumulation intervals, prorated measurements of current and voltage are added to the variables. Using two accumulation intervals covers both chop polarities of temperature measurements. 4) If cs = 0: This signals the end of the calibration. Cumulative current and voltage measurements are then used to calculate and set the calibration coefficients for voltage and currents in CE DRAM. See the source file calphased.c for details.
71M652X Software User’s Guide set_tc1_tc2() temperature compensation for adc fppmc1 = ppmc1 from CE fppmc2 = ppmc2 from CE tn = calibration temperature from CE tn==0? a calibration temperature exists? Y constants are not set? tppmc1 == 0L && tppmc2 == 0L tppmc1 = 0; tppmc2 = 0; trimbgb = Read_Trim (_TRIMBGB) no temperature compensation read a trim value untrimmed? trimbgb == 0 N trimm = Read_Trim (_TRIMM); trimbga = Read_Trim (_TRIMBGA); // -128..
71M652X Software User’s Guide Command Pending cmd_pending() N N len = 0? no entry Y !(len = Serial_CRx (port, cb, CMD_BUFF_SIZE)) Y return (FALSE) UART0 echo echo0? N Y cp = cb c = len i=0 i = ' ' (CLI_BASE == cli_index) && (',' == c) put_char (&c) N Y cli_buff[ cli_index ] && cli_i
71M652X Software User’s Guide EEPROM Read/Write EEDATA= 0xA0 (write command) EECTRL = 0x03 (transmit data command) interrupt rcvd? (INT5) EEDATA= address of MSB EECTRL = 0x03 (transmit data command) interrupt rcvd? (INT5) EEDATA= address of LSB EECTRL = 0x03 (transmit data command) interrupt rcvd? (INT5) READ write or read? WRITE EEDATA= 0xA1 (read command) EECTRL = 0x03 (transmit data command) EEDATA= *destination EECTRL = 0x03 (transmit data command) interrupt rcvd? (INT5) interrupt rcvd? (IN
71M652X Software User’s Guide Registers and memory locations: • EEDATA = SFR 0x9E • EECTRL = SFR 0x9F • *source = pointer to EEPROM address for read or write • *destination = pointer to XRAM address • count = byte count for multiple read/write If the EEPROM interrupt service routine (INT5) returns the value 0x80 (illegal command), the loop should be exited, all registers should be refreshed and the operation should be restarted.
71M652X Software User’s Guide Start NO count==0? EEDATA= *(destination++) EECTRL = 0x03 (multiple write with ACK command) count- EECTRL = 0x05 (stop command) Clear all registers interrupt rcvd? (INT5) End Figure 5-20: Multi-Byte Write Notes: • For larger EEPROMs, 1010xxR can be the first command (R=1 for read, R = 0 for write operation).
71M652X Software User’s Guide Power Factor Measurement The power-factor option (not compiled in the executable Demo Code) provides both instantaneous and accumulated (over fractions of an hour) display of power factor by phase. All power factor calculations are performed using floating point variables. The power factor (PF = cosϕ) calculation is based on the equations: P = S * cosϕ = S * PF ==> PF = P/S, with P = real energy, S = apparent energy, PF = power factor or VAh divided by Wh. 5.4.
71M652X Software User’s Guide 5.5 MANAGING MISSION AND BATTERY MODES After a reset or power up, the processor must first decide what mode it is in and then take the appropriate action. It is useful to concentrate all activities related to power modes and reset into one centralized module. The Demo Code revision 4.7a does the switching of modes in the main() routine, based on decisions made in batmodes_20.c.
71M652X Software User’s Guide Precautions when adding a battery: When a battery or other DC supply is added to a Demo Board that is powered down, the 71M6521 Demo Code will cause the chip to enter Brownout mode and stay in Brownout mode.
71M652X Software User’s Guide At the end of each accumulation interval, an MPU interrupt, the "xfer_interrupt" occurs (see ce.c, xfer_busy_isr()) occurs. This is the signal for the MPU to copy the above data to stable storage for further use. At this time, the MPU performs creep detection (meter.c Apply_Creep() ). If the measured voltage, current and/or power is below the minimum, no results for volts, current or watts are reported.
71M652X Software User’s Guide When compiled without the on-line help option (help.c), CLI.C takes about 14Kbytes of program space. Adding the on-line help will use another 5Kbytes. When designing a real meter, CLI.C can easily be removed without major changes to the software. 2. FLAG flag0.c flag1.c flag.c Basic FLAG AMR Protocol implements a basic FLAG AMR protocol for SER0 implements a basic FLAG AMR protocol for SER1 code shared shared by flag0.c and flag1.c 3. IO: cal_ldr.c eep24C08.c eeprom.
M652X Software User’s Guide flag0test.c modetest.c ser0test.c ser1test.c stmtest.c tmr0test.c tmr1test.c 7. a test for a FLAG system a simple test of the 6520’s battery modes tests the serial driver for SER0 tests the serial driver for SER1 tests the software timers tests the driver for TMR0 tests the driver for TMR1 Util: Utilities dead.c defines unused flash space for the boot loader dio.h defines high-level access to DIO pins flash.
71M652X Software User’s Guide 5.11 INCLUDE/HEADER FILES In line with common industry practice, each C file in the Demo Code source code has a corresponding header file that ends in .H and that provides the interface to the C file’s code. A number of include files are special cases, and provide global data or hardware definitions. • Main_6521B\options.h selects the features used by the code that is less than 8K • Main_6521D\options.
71M652X Software User’s Guide 5.11.3 Other Include/Header Files Other Include/Header files are: • CLI.H - Result code and Common ASCII code definition used for CLI • HELP.H - HELP message prototype declarations • IO.H – I/O subroutines for CLI • SER0CLI.H, SER1CLI.H – hardware access layer for UART0/UART1 • SERCLI.H – include definitions for UART 0/1 debug routines • FLAG0.H, FLAG1.H, FLAG.H – shared logic for all FLAG interfaces • EEPROM.H – EEPROM • II2.H – I2C Interface • LCD.
71M652X Software User’s Guide 5.12 CE IMAGE FILES The CE code uses pre-designed, pre-validated algorithms and calculations, which are accurate to the noise floor of the integrated circuit, saving substantial engineering and development time. The source code for the CE is proprietary. Only the code and data images (binary images) are available to the user. The code image must be merged with the MPU code residing in flash memory. Teridian provides two files for each ce code.
71M652X Software User’s Guide Name Purpose Function or LSB Value CLI Format L in bits XDATA IThrshldA Starting current, element A LSB = 216 I 0SQSUM )0 unsigned 32 0x0000 )1 N/A 8 0x0004 0 in this position disables creep logic for both element A and B. Config Configure meter operation on the fly.
71M652X Software User’s Guide Name Purpose Function or LSB Value CLI Format L in bits XDATA Ical Current value to be used for autocalibration** Nominal RMS current applied to all elements during auto-calibration (LSB = 0.1V). Power factor must be 1. )11 unsigned 16 0x0023 VThrshld Voltage at which to measure frequency, zero crossing, etc. LSB = 216 V 0 SQSUM )12 unsigned 16 0x0025 This feature is approximated using the CE’s sag detection.) PulseWidth Maximum time pulse is on.
71M652X Software User’s Guide Name Purpose Function or LSB Value CLI Format L in bits XDATA Vrms_A Vrms, element A 216 V 0 SQSUM )23 unsigned 32 0x004B Irms_A Irms, element A 216 I 0SQSUM )24 unsigned 32 0x004F Vrms_B Vrms, element B**,† 216 V1SQSUM )25 unsigned 32 0x0053 Irms_B Irms, element B 216 I1SQSUM )27 unsigned 32 0x0057 STATUS Status of meter See table for STATUS register )2A unsigned 32 0x0063 CAI Count of accumulation intervals since reset, or last clea
71M652X Software User’s Guide Name Purpose Function or LSB Value CLI Format L in bits XDATA Whn Net metered Wh, all elements A, LSB of W0SUM )54 signed 64 0x010B Whn_A* Net metered Wh, element A, for autocalibration LSB of W0SUM )56 signed 64 0x0113 Whn_B* Net metered Wh, element B, for autocalibration “ )58 signed 64 0x011B VARhn* Net metered VARh, all elements LSB of w0sum )5C signed 64 0x012B VARhn_A* Net metered VARh, element A, for autocalibration LSB of w0sum )5E
71M652X Software User’s Guide 5.14 FIRMWARE APPLICATION INFORMATION 5.14.1 Sag Detection A sag is defined as an undervoltage condition that persists for more than one period. A shorter undervoltage condition is called a dip (see Figure Figure 5-22). The occurrence of sags can announce an impending loss of power. Since accumulated energy values etc. in the meter will have to be saved to non-volatile memory in the case of loss of power, a sag can be used to initiate data saving operations.
71M652X Software User’s Guide 5.14.3 Temperature Compensation for Measurements The internal voltage reference of the 652X ICs is calibrated during device manufacture. Trim data is stored in on-chip fuses. The temperature coefficients TC1 and TC2 are given as constants that represent typical component behavior. The bandgap temperature is provided to the embedded MPU, which then may digitally compensate the power outputs.
71M652X Software User’s Guide One method to correct the temperature characteristics of the crystal is to obtain coefficients from the curve in Figure 31 by curve-fitting the PPM deviations A fairly close curve fit is achieved with the coefficients a = 10.89, b = 0.122, and c = –0.00714 (see Figure 32). f = fnom * (1 + a/106 + T * b/106 + T2* c/106) When applying the inverted coefficients, a curve (see Figure 5-25) will result that effectively neutralizes the original crystal characteristics.
71M652X Software User’s Guide 5.15 ALPHABETICAL FUNCTION REFERENCE Function/Routine Name Description Input Output File Name abs_x() x = abs(x0); Take absolute value of n-byte 'x0'. uint8_tx *x, uint8_tx *x0, n none math.c add() *x += y; where 'x' & 'y' are 'n' bytes wide. uint8_tx *x, uint8_tx *y, n uint8_t math.c add_1() *x += y; where 'x' is 'n' bytes wide, 'y' is single byte. uint8_tx *x, y, n uint8_t math.
71M652X Software User’s Guide Function/Routine Name Description Input Output File Name calibrate() processes measurements during auto-calibration none none calphased.c ce_active() returns CE status none bool ce.c ce_enable() Enables or disables the CE bool enable none ce.c ce_init() Initializes the CE none bool ce.c ce_reset() resets the CE none none ce.c cli () command Line Interpreter none none cli.c cli_init() Initializes the SLI's interface to any serial port.
71M652X Software User’s Guide Function/Routine Name Description Input Output File Name LRC_Calc_NVR() calculates longitudinal parity on NVRAM uint8_tx *ptr, uint16_t len, U01 set bool library.c ctoh() converts ascii hex character to hexadecimal digit uint8_t c uint8_t load.c date_lcd () Displays the current date. void void rtc.c Delta_Time () Figure the elapsed time between two times. struct RTC_t start, struct RTC_t end int32_t seconds rtc.
71M652X Software User’s Guide Function/Routine Name Description Input Output File Name flag1_out() Output interrupt for FLAG AMR module on SER1 none none flag1.c flag1_run() Run main loop logic for FLAG AMR module on SER1 none none flag1.c frequency_lcd () Displays the frequency on the LCD. void void freq.c get_ce_constants() Copies CE configuration constants to a data structure so they can be viewed in the emulator. void void ce.
71M652X Software User’s Guide Function/Routine Name Description Input Output File Name IICStart() IIC bus's start condition none none iiceep.c IICStop() IIC bus's stop condition none none iiceep.c init_meter() Initializes meter to default values none none defaults.c IRQ_DEFINES Defines variables used by macros to enable and disable interrupts. n/a n/a irq.h irq_disable() Disables interrupts. void void irq.c IRQ_DISABLE() The fastest way to disable interrupts.
71M652X Software User’s Guide Function/Routine Name Description Input Output File Name LCD_Number() Displays a number on the LCD. int32_t number uint8_t num_digits_before_deci mal_point, uint8_t num_digits_after_decim al_point none lcd.c lmax() returns maximum of unsigned long 'a' and 'b'. U32 a, U32 b U32 math.c lmin() returns minimum of unsigned long 'a' and 'b'. U32 a, U32 b U32 math.c log2() returns binary logarithm uint16_t k uint8_t math.
71M652X Software User’s Guide Function/Routine Name Description Input Output File Name memcmp_xx() compares xdata to xdata uint8_tx *xsrc1, uint8_tx *xsrc2, uint16_t len S08 library.c memcpy_ix() copies xdata to idata uint8_ti *dst, uint8_tx *src, uint8_t len none library.c memcpy_px() Copies data to serial EEPROM U32 Dst, uint8_tx *pSrc, uint16_t len enum eeprom.c, eepromp.c, eepromp3.c memcpy_rce() reads from or writes to flash int32_tr *dst, int32_tx *src, uint8_t len none flash.
71M652X Software User’s Guide Function/Routine Name Description Input Output File Name normalize() puts a register into normal form, in which the major count of Wh is greater than or equal to zero, and less than 1,000,000,000. The minor count of ce counts (e.g. from w0sum) is made to be less than 1 Wh and positive, by transfering larger amounts into the major count. uint8x_t *register_ptr none math.c operating_lcd () Displays the number of hours of operation. void void rtc.
71M652X Software User’s Guide Function/Routine Name Description Input Output File Name psoft_update () The inputs are watt hours, as generated by the CE, and set the extra pulse generators to blink at the same rate as CE pulse outputs, with the same units. This should be called each time a new accumulation interval has data. int32_t pulse3_in, int32_t pulse4_in void psoft.c put_char() puts character into CLI buffer uint8_t idata *c none io.
71M652X Software User’s Guide Function/Routine Name Description Input Output File Name send_help() sends text in code at specified location to serial port uint8_tr * code *s none cli.c send_hex() sends byte out SERIAL0 in HEX uint8_t n none io.c send_long() sends a [0, 9,999,999,999] value to DTE. int32_t n none io.c send_long_hex() sends a [0, FFFFFFFF] value to DTE U32 n none io.c send_num() sends a [0, 9,999,999,999] value to DTE int32_t n, uint8_t size none io.
71M652X Software User’s Guide Function/Routine Name Description Input Output File Name ser_xmit_rdy() Returns true if the serial port can send another byte. void bool ser0.h, ser1.h Serial_CRx() Receive a string up to a maximum length. enum SERIAL_PORT port, uint8x_t *buffer, uint16_t len uint16_t length-received sercli.c3 Serial_CTx() Transmit a string up to a maximum length. enum SERIAL_PORT port, uint8x_t *buffer, uint16_t len uint16_t length-sent sercli.
71M652X Software User’s Guide Function/Routine Name Description Input Output File Name Serial1_CTx() Transmit a string up to a maximum length. uint8x_t *buffer, uint16_t len uint16_t length-sent ser1cli.c Serial1_Rx() Receive a string of any length. uint8x_t *buffer, uint16_t len none ser1cli.c Serial1_RxFlowOff( ) Force an XOFF to be sent on this port. none none ser1cli.c Serial1_RxFlowOn() Force an XON to be sent on this port. none none ser1cli.
71M652X Software User’s Guide Function/Routine Name Description Input Output File Name stm_wait() Waits for the passed number of clock ticks. uint16_t void stm.c strlen_r () returns length of string in flash code uint8_tr *src uint16_t library.c strlen_x() returns length of string in xdata uint8_tx *src uint16_t library.c sub8_4() (uint64_t) x -= (uint32_t) y uint8_tx *x, uint8_tx *y none math.c sub8_8() (uint64_t) x -= (uint64_t) y uint8_tx *x, uint8_tx *y none math.
71M652X Software User’s Guide Function/Routine Name Description VAh_Accumulate() Calculates VAh void void vah.c VARh_Accumulate() Calculates VARh void void varh.c voltage_phase_lcd( ) Display voltage phases on LCD. uint8_t select void vphase.c wd_create() Creates a software watchdog. uint8_t wd void wd.c wd_destroy() Destroys a software watchdog. uint8_t wd void wd.c wd_reset() Resets a software watchdog. If all software watchdogs have been reset, the hardware watchdog is reset.
71M652X Software User’s Guide 5.17 PORTING 71M6511/6513 CODE TO THE 71M6521 5.17.1 Memory Use The biggest issue when moving code from the 6511/6513 to the 71M6521 is the reduced program memory. While the 71M6511 and 6513 have 64K, the 6521 has 32K, 16K and 8K versions. The standard 6521 CE code has 414 bytes, and takes up space in flash.
71M652X Software User’s Guide RESET MISSION V3P3SYS falls IE_PLLRISE -> 1 V3P3SYS rises V1 > VBIAS V1 <= VBIAS IE_PLLFALL -> 1 V3P3SYS rises LCD_ONLY BROWNOUT V3P3SYS rises RESET & VBAT_OK IE_PB -> 1 IE_WAKE -> 1 PB SLEEP or VBAT_OK timer LCD timer PB VBAT _OK VBAT _OK RESET & VBAT_OK SLEEP Figure 5-26: Operation Modes State Diagram The wake-up timer is a little trickier to use than the pushbutton.
71M652X Software User’s Guide The demo software is designed so that the serial port always runs at 300 bd, in both mission mode and brownout mode. The 6521 has special clock-interpolation logic in the baud rate generation so that 300 baud works in brownout mode. The designers chose this 300 bd especially because it is compatible with some AMR applications, such as FLAG, and it was achievable in the chip.
71M652X Software User’s Guide 5.17.5 Temperature Compensation When operating with “internal” temperature compensation, the 71M6511 and 71M6513 ICs use the CE as the compensation mechanism. Compensation is then based on the temperature deviation from nominal and the PPMC and PPMC2 factors that are either derived from the on-chip fuses (71M6511H/6513H) or standard values (71M6511/6513) that apply to the average chip. In the 71M6521, the CE is no longer in charge of temperature compensation.
71M652X Software User’s Guide The Keil project file is RESET_READ_SE.UV2. 5.18.7 Software Timer Test This project, consisting of several files, demonstrates the use and test of the software timer using a hardware timer that is multiplexed into many slower timers. The Keil project file is stmtest.uv2. 5.18.8 Interrupt Test This Test Module is written in 8051 assembler and can be used for testing the function of the INT0, INT1, TMR0, and TMR1 control using DIO_Rx.
71M652X Software User’s Guide 6 1 6 80515 MPU REFERENCE An 80515 core is implemented on the TERIDIAN 71M652X chips. This section is intended for software engineers who plan to use the 80515. 6.1 80515 OVERVIEW The 80515 is a fast single-chip 8-bit micro controller (MPU) core. It is a fully functional 8-bit embedded controller that executes all ASM51 instructions and has the same instruction set as the 80C31.
71M652X Software User’s Guide 6.1.
71M652X Software User’s Guide 6.2 80515 ARCHITECTURAL OVERVIEW 6.2.1 Memory organization The 80515 MPU core incorporates the Harvard architecture with separate code and data spaces. Memory organization in the 80515 is similar to that of the industry standard 8051. There are three memory areas: program memory (External Flash), external data memory (External RAM), and internal data memory (Internal RAM).
71M652X Software User’s Guide CKCON register Stretch Value CKCON.2 CKCON.1 CKCON.
71M652X Software User’s Guide Address 0xFF 0x80 Direct addressing Indirect addressing Special Function Registers (SFRs) RAM 0x7F Byte-addressable area 0x30 0x2F Bit-addressable area 0x20 0x1F Register banks R0…R7 0x00 Table 6-3: Internal Data Memory Map Special Function Registers Location A map of the Special Function Registers is shown in Table 6-4. Only a few addresses are occupied, the others are not implemented.
71M652X Software User’s Guide Generic Special Function Register Overview All generic SFRs are explained in detail in section 6.3.2. Register Symbol Description Program status word Accumulator PSW The PSW contains program status information ACC B register B Stack pointer SP Data pointer DPL, DPH Secondary data pointer DPL1, DPH1 Data pointer select register Port registers Serial data buffer DPS The accumulator register.
71M652X Software User’s Guide Generic Special Function Registers Location and Reset Values Table 6-5 shows the location of the SFRs and the value they assume at reset or power-up.
71M652X Software User’s Guide Special Function Registers Specific to the 652X Register Alternative Name SFR Address R/W Description Register for port 0 read and write operations (pins DIO0…DIO7) Data direction register for port 0. Setting a bit to 1 means that the corresponding pin is an output. Register for port 1 read and write operations (pins DIO8…DIO15) Data direction register for port 1. Setting a bit to 1 means that the corresponding pin is an output.
71M652X Software User’s Guide WDI 0xE8 R/W R/W W INTBITS INT0…INT6 0xF8 R Only byte operations on the whole WDI register should be used when writing. This multi-purpose register contains the following bits: Bit 0 (IE_XFER): XFER Interrupt Flag: This flag monitors the XFER_BUSY interrupt. It is set by hardware and must be cleared by the interrupt handler Bit 1 (IE_RTC): RTC Interrupt Flag: This flag monitors the RTC_1SEC interrupt.
71M652X Software User’s Guide Instructions Ordered by Function Mnemonic ADD A,Rn Description Add register to accumulator ADD A,direct Add direct byte to accumulator ADD A,@Ri Add indirect RAM to accumulator ADD A,#data Add immediate data to accumulator ADDC A,Rn Add register to accumulator with carry flag ADDC A,direct Add direct byte to A with carry flag Code 28-2F Bytes 1 Cycles 1 25 2 2 26-27 1 2 24 2 2 38-3F 1 1 35 2 2 ADDC A,@Ri Add indirect RAM to A with carry flag ADD
71M652X Software User’s Guide Mnemonic ANL A,Rn Description AND register to accumulator ANL A,direct AND direct byte to accumulator ANL A,@Ri AND indirect RAM to accumulator Code 58-5F Bytes 1 Cycles 1 55 2 2 56-57 1 2 ANL A,#data AND immediate data to accumulator 54 2 2 ANL direct,A AND accumulator to direct byte 52 2 3 ANL direct,#data AND immediate data to direct byte ORL A,Rn OR register to accumulator ORL A,direct OR direct byte to accumulator ORL A,@Ri OR indirect RAM
71M652X Software User’s Guide Mnemonic MOV A,Rn Description Move register to accumulator Code E8-EF Bytes 1 Cycles 1 MOV A,direct Move direct byte to accumulator E5 2 2 MOV A,@Ri Move indirect RAM to accumulator E6-E7 1 2 MOV A,#data Move immediate data to accumulator 74 2 2 MOV Rn,A MOV Rn,direct Move accumulator to register F8-FF 1 2 Move direct byte to register A8-AF 2 4 MOV Rn,#data Move immediate data to register 78-7F 2 2 MOV direct,A Move accumulator to direct byte
71M652X Software User’s Guide Mnemonic ACALL addr11 Description Absolute subroutine call Code xxx11 Bytes 2 Cycles 6 LCALL addr16 Long subroutine call 12 3 6 RET Return from subroutine 22 1 4 RETI Return from interrupt AJMP addr11 Absolute jump 32 1 4 xxx01 2 3 LJMP addr16 SJMP rel Long jump 02 3 4 Short jump (relative addr.
71M652X Software User’s Guide Instructions Ordered by Opcode (Hexadecimal) Opcode 0x00 Mnemonic NOP Opcode 0x20 Mnemonic JB bit.
71M652X Software User’s Guide Opcode 0x60 Mnemonic JZ rel Opcode 0x80 Mnemonic SJMP rel Opcode 0xA0 Mnemonic ORL C,bit 0x61 0x62 AJMP addr11 0x81 XRL direct,A 0x82 AJMP addr11 0xA1 AJMP addr11 ANL C,bit 0xA2 MOV C,bit 0x63 XRL direct,#data 0x64 XRL A,#data 0x83 MOVC A,@A+PC 0xA3 INC DPTR 0x84 DIV AB 0xA4 MUL AB 0x65 0x66 XRL A,direct 0x85 MOV direct,direct 0xA5 Reserved XRL A,@R0 0x86 MOV direct,@R0 0xA6 MOV @R0,direct 0x67 XRL A,@R1 0x87 MOV direct,@R1 0xA7 MOV
71M652X Software User’s Guide Opcode 0xC0 Mnemonic PUSH direct Opcode 0xD0 Mnemonic POP direct 0xC1 AJMP addr11 0xD1 ACALL addr11 0xC2 CLR bit 0xD2 SETB bit 0xC3 CLR C 0xD3 SETB C 0xC4 SWAP A 0xD4 DA A 0xC5 XCH A,direct 0xD5 DJNZ direct,rel 0xC6 XCH A,@R0 0xD6 XCHD A,@R0 0xC7 XCH A,@R1 0xD7 XCHD A,@R1 0xC8 XCH A,R0 0xD8 DJNZ R0,rel 0xC9 XCH A,R1 0xD9 DJNZ R1,rel 0xCA XCH A,R2 0xDA DJNZ R2,rel 0xCB XCH A,R3 0xDB DJNZ R3,rel 0xCC XCH A,R4 0xDC DJNZ R4,rel 0
71M652X Software User’s Guide Instructions that Affect Flags Affected Flag Instruction C OV Affected Flag Instruction AC C ADD X X X CLR C 0 ADDC X X X CPL C X SUBB X X X MUL 0 X DIV 0 X ORL C, bit X DA X ORL C, /bit X RRC X MOV C, bit X RLC X CJNE X SETB C 1 ANL C, bit X ANL C, /bit X OV AC Table 6-17: Instructions Affecting Flags Note: Operations affecting the PSW or bits in the PSW will also affect flag settings 6.
71M652X Software User’s Guide 6.3.
71M652X Software User’s Guide 6.3.2 80515 MPU The 80515 MPU is composed of four components: 1. Control unit 2. Arithmetic-logic unit 3. Memory control unit 4. RAM and SFR control unit The 80515 MPU allows instruction fetch from program memory and instruction execution using RAM or SFR. The following chapter describes the main MPU registers. Accumulator ACC is the accumulator register. Most instructions use the accumulator to hold the operand.
71M652X Software User’s Guide The state of bits RS1 and RS0 select the working registers bank as follows: RS1/RS0 00 Bank selected Bank 0 Location (00H – 07H) 01 Bank 1 (08H – 0FH) 10 Bank 2 (10H – 17H) 11 Bank 3 (18H – 1FH) Table 6-20: Register Bank Location Stack Pointer The stack pointer is a 1-byte register initialized to 07H after reset. This register is incremented before PUSH and CALL instructions, causing the stack to begin at location 08H.
71M652X Software User’s Guide Timer/Counter Mode Control Register (TMOD) MSB GATE C/T M1 M0 GATE Timer 1 C/T M1 LSB M0 Timer 0 Table 6-21: The TMOD Register Bit TMOD.7 TMOD.3 Symbol Gate Function If set, enables external gate control (pin int0 or int1 for Counter 0 or 1, respectively). When int0 or int1 is high, and trx bit is set (see TCON register), a counter is incremented every falling edge on t0 or t1 input pin TMOD.6 TMOD.2 C/T Selects Timer or Counter operation.
71M652X Software User’s Guide Bit Symbol Function TCON.7 TF1 TCON.6 TR1 Timer 1 Run control bit. If cleared, Timer 1 stops. TCON.5 TF0 Timer 0 overflow flag set by hardware when Timer 0 overflows. This flag can be cleared by software and is automatically cleared when an interrupt is processed. TCON.4 TR0 Timer 0 Run control bit. If cleared, Timer 0 stops. TCON.3 IE1 Interrupt 1 edge flag is set by hardware when the falling edge on external pin int1 is observed.
71M652X Software User’s Guide Mode 1 Pin rxd0 serves as an input, and txd0 serves as a serial output. No external shift clock is used. 10 bits are transmitted: a start bit (always 0), 8 data bits (LSB first), and a stop bit (always 1). On receive, a start bit synchronizes the transmission. 8 data bits are available by reading S0BUF, and the stop bit sets the flag RB80 in the Special Function Register S0CON. In mode 1 either the internal baud rate generator or timer 1 can be use to specify the baud rate.
71M652X Software User’s Guide SM0 0 SM1 0 Mode 0 Description shift register Baud Rate Fclk/12 0 1 1 8-bit UART Variable 1 0 2 9-bit UART Fclk/32 or /64 1 1 3 9-bit UART Variable Table 6-29: Serial Port 0 Modes Note: The speed in Mode 2 depends on the SMOD bit in the Special Function Register PCON when SMOD = 1, Fclk/32.
71M652X Software User’s Guide Bit Symbol Function S1CON.7 SM S1CON.5 SM21 Enables the multiprocessor communication feature (see description above). Sets baud rate S1CON.4 REN1 If set, enables serial reception. Cleared by software to disable reception. S1CON.3 TB81 The 9th transmitted data bit in Mode A. Set or cleared by the MPU, depending on the function it performs (parity check, multiprocessor communication etc.) S1CON.2 RB81 In Modes 2 and 3, it is the 9th data bit received.
71M652X Software User’s Guide 6.3.4 Software Watchdog Timer The watchdog timer is a 16-bit counter that is incremented once every 24 or 384 clock cycles. After an external reset, the watchdog timer is disabled and all registers are set to zero. Software Watchdog Timer structure The watchdog consists of a 16-bit counter (wdt), a reload register (WDTREL), prescalers (by 2 and by 16), and control logic.
71M652X Software User’s Guide Refreshing the WD Timer The watchdog timer must be refreshed regularly to prevent the reset request signal from becoming active. This requirement imposes an obligation on the programmer to issue two instructions. The first instruction sets WDT and the second instruction sets SWDT. The maximum delay allowed between setting WDT and SWDT is 12 clock cycles.
71M652X Software User’s Guide IP0.6 WDTS Watchdog timer status flag. Set by hardware when the watchdog timer was started. Can be read by software. Table 6-38: The IP0 Bit Functions Note: The remaining bits in the IP0 register are not used for watchdog control Watchdog Timer Reload Register (WDTREL): MSB 7 LSB 6 5 4 3 2 1 0 Table 6-39: The WDTREL Register Bit WDTREL.7 Symbol 7 Function Prescaler select bit. When set, the watchdog is clocked through an additional divide-by-16 prescaler WDTREL.
71M652X Software User’s Guide EAL WDT ES0 ET1 EX1 ET0 EX0 Table 6-41: The IEN0 Register Bit Symbol Function IEN0.7 EAL EAL=0 – disable all interrupts IEN0.6 WDT Not used for interrupt control IEN0.5 - IEN0.4 ES0 ES0=0 – disable UART 0 interrupt IEN0.3 ET1 ET1=0 – disable timer 1 overflow interrupt IEN0.2 EX1 EX1=0 – disable external interrupt 1 IEN0.1 ET0 ET0=0 – disable timer 0 overflow interrupt IEN0.
71M652X Software User’s Guide Timer/Counter Control Register (TCON) MSB TF1 TR1 TF0 TR0 IE1 IT1 IE0 LSB IT0 Table 6-47: The TCON Register Bit Symbol Function TCON.7 TF1 Timer 1 overflow flag TCON.6 TR1 Not used for interrupt control TCON.5 TF0 Timer 0 overflow flag TCON.4 TR0 Not used for interrupt control TCON.3 IE1 External interrupt 1 flag TCON.2 IT1 External interrupt 1 type control bit TCON.1 IE0 External interrupt 0 flag TCON.
71M652X Software User’s Guide Interrupt Request register (T2CON) MSB LSB I3FR I2FR Table 6-51: The T2CON Register Bit Symbol Function T2CON.7 T2CON.6 I3FR This bit controls the polarity of external interrupt 3 T2CON.5 I2FR This bit controls the polarity of external interrupt 2 T2CON.4 T2CON.3 T2CON.2 T2CON.1 T2CON.0 Table 6-52: The T2CON Bit Functions 6.3.5.4 Interrupt Priority Level Structure All interrupt sources are combined in groups, as shown in Table 6-52.
71M652X Software User’s Guide 4 Comparator rising automatic 5 EEPROM busy falling automatic 6 XFER_BUSY OR RTC_1SEC falling manual Table 6-54: External MPU Interrupts Enable Bit EX0 Description Enable external interrupt 0 Flag Bit IE0 Description External interrupt 0 flag EX1 EX2 Enable external interrupt 1 IE1 External interrupt 1 flag Enable external interrupt 2 IEX2 External interrupt 2 flag EX3 Enable external interrupt 3 IEX3 External interrupt 3 flag EX4 Enable external in
71M652X Software User’s Guide External interrupt 1 External interrupt 3 Timer 1 interrupt External interrupt 4 UART 0 interrupt External interrupt 5 External interrupt 6 Table 6-59: Polling Sequence 6.3.5.5 Interrupt Sources and Vectors The vectors associated with each interrupt source are displayed in Table 6-59.
71M652X Software User’s Guide DIO Int ernal Int errupt F lags Logi c and Pol arity Select ion Int errupt Control Regis ter I nterrupt Enabl e IEN0. 7 IEN0.0 Priorit y As signm ent IE 0 IEN2.0 R I1 UART1 (optical) IP 1.0/ I P0. 0 P o l l i ng Se q u e n c e Sourc e External I nterrupt Flags > =1 TI 1 IEN0.1 Tim er 0 Com parators TF0 I EN1.1 I2 FR INT2 I P1. 1/ IP 0.1 I nterrupt Ve c tor IR C ON. 1 I EN0.2 D IO IE1 I3 FR C E_BUSY IEN1.2 INT3 IP 1.2/ I P0. 2 IR C ON. 2 I EN0.
71M652X Software User’s Guide 7 7 APPENDIX 7.1 ACRONYMS AC Alternating Current – current with changing polarity AMR Automated Meter Reading, usually performed via an optical port or modem ANSI American National Standardization Institution, part of ISO ANSI C C Programming Language, standardized by ANSI in 1983. Keil C, used throughout this User’s Guide is not strictly ANSI compliant.
71M652X Software User’s Guide LSB Least Significant Bit MB Megabyte(s) – 1,024 kilobytes MPU Microprocessor/microcontroller Unit MSB Most Siginificant Bit NV Non-Volatile PC Personal Computer, Program Counter PSU Power Supply Unit PSW Program Status Word RAM Random Access Memory SFR Special Function Register (of the 8051 MPU) TOU Time-of-Use (variable metering tariffs usually based on time of day) TSC TERIDIAN Semiconductor Corporation USB Universal Serial Bus VA Volt-Amperes (app
71M652X Software User’s Guide Revision 1.
71M652X Software User’s Guide Software User Guide: This User Guide contains proprietary product definition information of TERIDIAN Semiconductor Corporation (TSC) and is made available for informational purposes only. TERIDIAN assumes no obligation regarding future manufacture, unless agreed to in writing.