NEC 78K0S/K 1+ Series Application Note
NEC 78K0S/K 1+ Series Application Note

NEC 78K0S/K 1+ Series Application Note

External event counter
Hide thumbs Also See for 78K0S/K 1+ Series:

Advertisement

Quick Links

Application Note
78K0S/Kx1+
Sample Program (16-bit Timer/Event Counter 00)
External Event Counter
This document describes an operation overview of the sample program and how to use it, as well as how to set and use
the external event counter function of 16-bit timer/event counter 00. In the sample program, the LED output is reversed
every fixed time the falling edge of the external pulse input is detected, by using the external event counter function of
16-bit timer/event counter 00.
Target devices
78K0S/KA1+ microcontroller
78K0S/KB1+ microcontroller
78K0S/KU1+ microcontroller
78K0S/KY1+ microcontroller
Document No.
U18888EJ1V0AN00 (1st edition)
Date Published December 2007 N
Printed in Japan
2007
CHAPTER 1 OVERVIEW....................................................................................... 3
1.1
Main Contents of the Initial Settings............................................................ 3
1.2
Contents Following the Main Loop.............................................................. 3
CHAPTER 2 CIRCUIT DIAGRAM ....................................................................... 4
2.1
Circuit Diagram ........................................................................................... 4
2.2
Peripheral Hardware ................................................................................... 4
CHAPTER 3 SOFTWARE .................................................................................... 5
3.1
File Configuration ........................................................................................ 5
3.2
Internal Peripheral Functions to Be Used ................................................... 6
3.3
Initial Settings and Operation Overview ...................................................... 6
3.4
Flow Charts ................................................................................................. 8
CHAPTER 4 SETTING METHODS...................................................................... 9
4.1
Counter 00 ................................................................................................. 9
5.1
Building the Sample Program ................................................................... 22
5.2
Operation with SM+................................................................................... 23
CHAPTER 6 RELATED DOCUMENTS ............................................................. 26
APPENDIX A PROGRAM LIST......................................................................... 27
APPENDIX B REVISION HISTORY .................................................................. 37
CONTENTS

Advertisement

Table of Contents
loading

Summary of Contents for NEC 78K0S/K 1+ Series

  • Page 1: Table Of Contents

    Application Note 78K0S/Kx1+ Sample Program (16-bit Timer/Event Counter 00) External Event Counter This document describes an operation overview of the sample program and how to use it, as well as how to set and use the external event counter function of 16-bit timer/event counter 00. In the sample program, the LED output is reversed every fixed time the falling edge of the external pulse input is detected, by using the external event counter function of 16-bit timer/event counter 00.
  • Page 2 NEC Electronics does not assume any liability for infringement of patents, copyrights or other intellectual property rights of third parties by or arising from the use of NEC Electronics products listed in this document or any other liability arising from the use of such products. No license, express, implied or otherwise, is granted under any patents, copyrights or other intellectual property rights of NEC Electronics or others.
  • Page 3: Chapter 1 Overview

    CHAPTER 1 OVERVIEW An example of using the external event counter function of 16-bit timer/event counter 00 is presented in this sample program. The LED output is reversed every 10 times (11 times only for the first reversal) the falling edge of the external pulse input is detected.
  • Page 4: Chapter 2 Circuit Diagram

    CHAPTER 2 CIRCUIT DIAGRAM This chapter describes a circuit diagram and the peripheral hardware to be used in this sample program. Circuit Diagram A circuit diagram is shown below. Note 1 RESET 78K0S/Kx1+ microcontroller External TI000 Note 2 clock pulse Notes 1.
  • Page 5: Chapter 3 Software

    CHAPTER 3 SOFTWARE This chapter describes the file configuration of the compressed file to be downloaded, internal peripheral functions of the microcontroller to be used, and initial settings and operation overview of the sample program, and shows a flow chart. File Configuration The following table shows the file configuration of the compressed file to be downloaded.
  • Page 6: Internal Peripheral Functions To Be Used

    CHAPTER 3 SOFTWARE Internal Peripheral Functions to Be Used The following internal peripheral functions of the microcontroller are used in this sample program. • External event counter function: 16-bit timer/event counter 00 • V < V detection: Low-voltage detector (LVI) •...
  • Page 7 CHAPTER 3 SOFTWARE The details are described in the status transition diagram shown below. Initial settings 1 • Referencing the option byte • Selecting the high-speed internal oscillator as the system clock source • The low-speed internal oscillator can be stopped by software •...
  • Page 8: Flow Charts

    CHAPTER 3 SOFTWARE Flow Charts The flow charts for the sample program are shown below. <Processing after reset release> <Vector interrupt INTTM000> Vector interrupt INTTM000 Reset start start Note Referencing the option byte Reversing the LED output Stack pointer setting Stopping watchdog timer operation Return...
  • Page 9: Chapter 4 Setting Methods

    CHAPTER 4 SETTING METHODS This chapter describes the external event counter function of 16-bit timer/event counter 00. For other initial settings, refer to the 78K0S/Kx1+ Sample Program (Initial Settings) LED Lighting Switch Control Application Note. For interrupt, refer to the 78K0S/Kx1+ Sample Program (Interrupt) External Interrupt Generated by Switch Input Application Note.
  • Page 10 CHAPTER 4 SETTING METHODS Note Set as follows, because the TI000 pin is used as the timer input when using the external event counter function. PMx Register PMCx Register 78K0S/KA1+ and 78K0S/KB1+ microcontrollers PM30 = 1 Setting not required 78K0S/KY1+ and 78K0S/KU1+ microcontrollers PM20 = 1 PMC20 = 0 <Example of the basic operation setting procedure when using 16-bit timer/event counter 00 as an external event...
  • Page 11 CHAPTER 4 SETTING METHODS (2) Setting the CR000 register This register has the functions of both a capture register and a compare register. Figure 4-2. Format of 16-bit Timer Capture/Compare Register 000 (CR000) CR000 When using CR000 as a compare register The value set to CR000 is constantly compared with the 16-bit timer counter 00 (TM00) count value, and an interrupt request (INTTM000) is generated if they match.
  • Page 12 CHAPTER 4 SETTING METHODS (3) Setting the PRM00 register This register is used to set the count clock of the TM00 counter and the valid edges of the TI000 and TI010 pin inputs. Figure 4-3. Format of Prescaler Mode Register 00 (PRM00) PRM00 ES110 ES100 ES010 ES000 PRM001 PRM000...
  • Page 13 CHAPTER 4 SETTING METHODS Cautions 4. To use the valid edge of TI000 with the count clock, it is sampled with f to eliminate noise. The capture operation is not performed until the valid edge is sampled and the valid level is detected twice, thus eliminating noise with a short pulse width.
  • Page 14 CHAPTER 4 SETTING METHODS Cautions 1. The operation of the TM00 counter starts when values other than 0 and 0 (operation stop mode) are set to TMC002 and TMC003, respectively. To stop the operation, set TMC002 and TMC003 to 0 and 0, respectively. 2.
  • Page 15 CHAPTER 4 SETTING METHODS [Example 1] Setting the count clock as the valid edge (falling edge) of the TI000 pin and generating an interrupt when the valid edge is detected for 10 times (11 times for the first interrupt) (Same contents as in this sample program source) (1) Register settings <1>...
  • Page 16 CHAPTER 4 SETTING METHODS <4> TMC00 Overflow detection of 16-bit timer counter 00 (TM00) Overflow not detected. Operation TO00 inversion Interrupt mode and clear timing selection request mode selection generation Clear & start Match between <When used as occurs upon TM00 and compare match between...
  • Page 17 CHAPTER 4 SETTING METHODS [Example 2] Setting the count clock as the valid edge (both rising and falling edges) of the TI000 pin and generating an interrupt when the valid edge is detected for 100 times (101 times for the first interrupt) (1) Register settings <1>...
  • Page 18 CHAPTER 4 SETTING METHODS <4> TMC00 Overflow detection of 16-bit timer counter 00 (TM00) Overflow not detected. Operation TO00 inversion Interrupt mode and clear timing selection request mode selection generation Clear & start Match between <When used as occurs upon TM00 and compare match between...
  • Page 19 CHAPTER 4 SETTING METHODS (2) Sample program In the example below, “x” in (1) Register settings is set to “0”. <1> Assembly language (when using the 78K0S/KA1+ and 78K0S/KB1+ microcontrollers) SET1 PM3.0 CRC00, #00000000B MOVW CR000, #99 PRM00, #00110011B TMC00, #00001100B <2>...
  • Page 20 CHAPTER 4 SETTING METHODS [Excerpt from this sample program source] An excerpt from APPENDIX A PROGRAM LIST, which is related to the 16-bit timer/event counter 00 function, is shown below (same contents as in [Example 1] mentioned above). (1) Assembly language EVENTCNT ;...
  • Page 21 CHAPTER 4 SETTING METHODS (2) C language #define eventCnt 10 /* Timer 00 external event counter compare value */ • • • void hdwinit(void){ unsigned char ucCnt200us; /* 8-bit variable for 200 us wait */ • Setting the external • Setting the operation mode of event counter CR000 as a compare register...
  • Page 22: Chapter 5 Operation Check Using System Simulator Sm

    CHAPTER 5 OPERATION CHECK USING SYSTEM SIMULATOR SM+ This chapter describes how the sample program operates with system simulator SM+ for 78K0S/Kx1+, by using the assembly language file (source files + project file) that has been downloaded by selecting the icon.
  • Page 23: Operation With Sm

    CHAPTER 5 OPERATION CHECK USING SYSTEM SIMULATOR SM+ ([Build → Debug] button). When the “main.asm” and “op.asm” source files are built normally, the (4) Click message “I3500: Build completed normally.” will be displayed. (5) Click the [OK] button in the message window to automatically start SM+. Click Click SM+ starts automatically.
  • Page 24 CHAPTER 5 OPERATION CHECK USING SYSTEM SIMULATOR SM+ When SM+ is started by clicking [Build → Debug] on PM+ (refer to 5.1), the following screen will be displayed. (This is a screen example when the assembly language source file is used.) (2) Click ([Restart] button).
  • Page 25 CHAPTER 5 OPERATION CHECK USING SYSTEM SIMULATOR SM+ (3) Click the [TI000] button in the I/O panel window, during program execution. The waveform of TI000 is as follows when the [TI000] button is clicked. Timing Chart Window 10 ms Goes from low level to high Goes from high level to low level by clicking level after 10 ms elapse.
  • Page 26: Chapter 6 Related Documents

    CHAPTER 6 RELATED DOCUMENTS Document Name Japanese/English 78K0S/KU1+ User’s Manual 78K0S/KY1+ User’s Manual 78K0S/KA1+ User’s Manual 78K0S/KB1+ User’s Manual 78K/0S Series Instructions User’s Manual RA78K0S Assembler Package User’s Manual Language Operation CC78K0S C Compiler User’s Manual Language Operation PM+ Project Manager User’s Manual SM+ System Simulator Operation User’s Manual 78K0S/KA1+ Simplified Flash Writing Manual MINICUBE2 Information Sample Program Startup Guide...
  • Page 27: Appendix A Program List

    APPENDIX A PROGRAM LIST As a program list example, the 78K0S/KB1+ microcontroller source program is shown below. main.asm (Assembly language version) ;*************************************************************************** NEC Electronics 78K0S/KB1+ ;*************************************************************************** 78K0S/KB1+ Sample program ;*************************************************************************** 16-bit timer 00 (external event counter) ;*************************************************************************** ;<<History>> 2007.7.-- Release ;***************************************************************************...
  • Page 28 APPENDIX A PROGRAM LIST Input: P30 Output: P00-P03, P20-P23, P31-P33, P40-P47, P120-P123, P130 # All unused ports are set as the output mode. ;*************************************************************************** ;=========================================================================== Define the symbol ;=========================================================================== EVENTCNT ; Timer 00 external event counter compare value ;=========================================================================== Vector table ;=========================================================================== XVCT CSEG 0000H...
  • Page 29 APPENDIX A PROGRAM LIST ;*************************************************************************** Initialization after RESET ;*************************************************************************** XMAIN CSEG UNIT RESET_START: ;--------------------------------------------------------------------------- Initialize the stack pointer ;--------------------------------------------------------------------------- MOVW #STACKTOP MOVW ; Set the stack pointer ;--------------------------------------------------------------------------- Initialize the watchdog timer ;--------------------------------------------------------------------------- WDTM, #01110111B ; Stop the watchdog timer operation ;--------------------------------------------------------------------------- Detect low-voltage + set the clock ;---------------------------------------------------------------------------...
  • Page 30 APPENDIX A PROGRAM LIST SET1 LVIMD that internal reset signal generated when VDD < VLVI ;----- Set the clock <2> ----- SET_CLOCK: PPCC, #00000000B ; The clock supplied to the peripheral hardware (fxp) = fx (= 8 MHz) -> The clock supplied to the CPU (fcpu) = fxp = 8 MHz ;--------------------------------------------------------------------------- Initialize the port 0...
  • Page 31 APPENDIX A PROGRAM LIST ;--------------------------------------------------------------------------- Set 16-bit timer 00 ;--------------------------------------------------------------------------- CRC00, #00000000B ; Use CR000 as a compare register MOVW #EVENTCNT-1 ; Set the compare value MOVW CR000, ; Set the compare value PRM00, #00000011B ; Set the count clock as the falling edge of the TI000 pin TOC00, #00000000B...
  • Page 32 APPENDIX A PROGRAM LIST main.c (C language version) /*************************************************************************** NEC Electronics 78K0S/KB1+ **************************************************************************** 78K0S/KB1+ Sample program **************************************************************************** 16-bit timer 00 (external event counter) **************************************************************************** <<History>> 2007.7.-- Release **************************************************************************** <<Overview>> This sample program presents an example of using the external event counter function of 16-bit timer 00.
  • Page 33 APPENDIX A PROGRAM LIST ***************************************************************************/ /*========================================================================== Preprocessing directive (#pragma) ==========================================================================*/ #pragma /* SFR names can be described at the C source level */ #pragma /* EI instructions can be described at the C source level */ #pragma /* NOP instructions can be described at the C source level */ #pragma interrupt INTTM000 fn_inttm000 Interrupt...
  • Page 34 APPENDIX A PROGRAM LIST LVION = 1; Enable low-voltage detector operation */ for (ucCnt200us = 0; ucCnt200us < 9; ucCnt200us++){ Wait about 200 us */ NOP(); while (LVIF){ /* Wait for VDD >= VLVI */ NOP(); LVIMD = 1; /* Set so that an internal reset signal is generated when VDD <...
  • Page 35 APPENDIX A PROGRAM LIST /*-------------------------------------------------------------------------- Initialize the port 12 --------------------------------------------------------------------------*/ = 0b00000000; /* Set output latches of P120-P123 as low PM12 = 0b11110000; /* Set P120-P123 as output mode */ /*-------------------------------------------------------------------------- Initialize the port 13 --------------------------------------------------------------------------*/ = 0b00000001; /* Set output latch of P130 as high */ /*-------------------------------------------------------------------------- Set 16-bit timer 00 --------------------------------------------------------------------------*/...
  • Page 36 APPENDIX A PROGRAM LIST /*************************************************************************** Interrupt INTTM000 ***************************************************************************/ __interrupt void fn_inttm000(){ P4 ^= 0b00000001; /* Reverse the LED output */ return; op.asm (Common to assembly language and C language versions) ;============================================================================= Option byte ;============================================================================= OPBT CSEG 0080H 10011100B ; Option byte area |||| |||+---------- Low-speed internal...
  • Page 37: Appendix B Revision History

    APPENDIX B REVISION HISTORY Edition Date Published Page Revision − − 1st edition December 2007 Application Note U18888EJ1V0AN...
  • Page 38 Kawasaki, Kanagawa 211-8668, Japan Tel: 044-435-5111 http://www.necel.com/ [Asia & Oceania] [America] [Europe] NEC Electronics (China) Co., Ltd NEC Electronics America, Inc. NEC Electronics (Europe) GmbH 7th Floor, Quantum Plaza, No. 27 ZhiChunLu Haidian 2880 Scott Blvd. Arcadiastrasse 10 District, Beijing 100083, P.R.China Santa Clara, CA 95050-2554, U.S.A.

This manual is also suitable for:

78k0s/ka1+78k0s/kb1+78k0s/ku1+78k0s/ky1+

Table of Contents