NEC 78GK0S/K 1+ Series Application Note

Sample program (watchdog timer) 131 ms interval runaway detection

Advertisement

Quick Links

Application Note
78K0S/Kx1+
Sample Program (Watchdog Timer)
131 ms Interval Runaway Detection
This document describes an operation overview of the sample program, as well as how to use the sample program and
how to set and use the watchdog timer. In the sample program, a reset signal generated by an overflow of the
watchdog timer is generated at a 50% chance of occurrence during a switch input, by setting the runaway detection time
to 131 ms.
Target devices
78K0S/KA1+ microcontroller
78K0S/KB1+ microcontroller
78K0S/KU1+ microcontroller
78K0S/KY1+ microcontroller
Document No.
U18847EJ1V0AN00 (1st edition)
Date Published October 2007 N
Printed in Japan
2007
CHAPTER 1 OVERVIEW ...................................................................................3
1.1 Main Contents of Initial Settings ..............................................................4
1.2 Contents Following the Main Loop...........................................................4
CHAPTER 2 CIRCUIT DIAGRAM ....................................................................6
2.1 Circuit Diagram ........................................................................................6
2.2 Peripheral Hardware ................................................................................6
CHAPTER 3 SOFTWARE .................................................................................7
3.1 File Configuration.....................................................................................7
3.2 Internal Peripheral Functions to Be Used ................................................8
3.3 Initial Settings and Operation Overview...................................................8
3.4 Flow Chart..............................................................................................10
CHAPTER 4 SETTING METHODS ................................................................11
4.1 Watchdog Timer (WDT) Setting.............................................................11
CHAPTER 5 OPERATION CHECK USING THE DEVICE ..........................19
5.1 Building the Sample Program ................................................................19
5.2 Operation with the Device......................................................................21
CHAPTER 6 RELATED DOCUMENTS..........................................................23
APPENDIX A PROGRAM LIST......................................................................24
APPENDIX B REVISION HISTORY ...............................................................36
CONTENTS

Advertisement

Table of Contents
loading

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

  • Page 1: Table Of Contents

    Application Note 78K0S/Kx1+ Sample Program (Watchdog Timer) 131 ms Interval Runaway Detection This document describes an operation overview of the sample program, as well as how to use the sample program and how to set and use the watchdog timer. In the sample program, a reset signal generated by an overflow of the watchdog timer is generated at a 50% chance of occurrence during a switch input, by setting the runaway detection time to 131 ms.
  • 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 In this sample program, an example of using the watchdog timer (WDT) function is presented. The system clock is set as the operation clock of the watchdog timer and the runaway detection time is set to about 131 ms.
  • Page 4: Main Contents Of Initial Settings

    CHAPTER 1 OVERVIEW Main Contents of Initial Settings The contents of the initial settings are as follows. Note • Selecting the high-speed internal oscillator (8 MHz (TYP.)) as the system clock source Note • Setting so that oscillation of the low-speed internal oscillator can be stopped by using software •...
  • Page 5 CHAPTER 1 OVERVIEW Either of the following operations is performed at a 50% chance of occurrence (see the figure below), depending on the switch input timing. <1> If an overflow is not caused by the watchdog timer during interrupt servicing Due to the execution of interrupt servicing, LED1 blinks about every 60 ms during switch input.
  • Page 6: 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 LED2 LED1 INTP1 Note 2 Notes 1. Use this in a voltage range of 3.0 V ≤ V ≤...
  • Page 7: 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 8: 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. • Program runaway detection: Watchdog timer • V < V detection: Low-voltage detector (LVI) • Switch input: Note INTP1 (external interrupt)
  • Page 9 CHAPTER 3 SOFTWARE The details are described in the state transition diagram shown below. Initial settings 1 • Referencing the option byte • Selecting the high-speed internal oscillator (8 MHz (TYP.)) as the system clock source • The low-speed internal oscillator can be stopped by software •...
  • Page 10: Flow Chart

    CHAPTER 3 SOFTWARE Flow Chart A flow chart for the sample program is shown below. <Processing after reset release> <INTP1 (external interrupt) servicing> Start Interrupt servicing start Note Referencing the option byte Stack pointer setting Saving the AX register data Watchdog timer setting (overflow time: = 131.07 ms)
  • Page 11: Chapter 4 Setting Methods

    CHAPTER 4 SETTING METHODS This chapter describes the watchdog timer. 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 12 CHAPTER 4 SETTING METHODS (1) Setting the operation clock of the watchdog timer and overflow time The watchdog timer mode register (WDTM) is used to set the operation clock of the watchdog timer and overflow time. Writing to WDTM can be performed only once after reset release. Caution The operation clock of the watchdog timer and overflow time must be set in the initial settings.
  • Page 13 CHAPTER 4 SETTING METHODS (2) Watchdog timer counter control Writing “ACH” to the watchdog timer enable register (WDTE) clears the watchdog timer count and starts counting again. Figure 4-2. Format of Watchdog Timer Enable Register (WDTE) WDTE Caution If a value other than “ACH” is written to WDTE, an internal reset signal is generated. (3) Setting the oscillation control of the low-speed internal oscillator The operation clock of the watchdog timer that can be used depends on the oscillation control of the low-speed internal oscillator set by using the option byte.
  • Page 14 CHAPTER 4 SETTING METHODS [Example 1] Using the system clock (f ) as the watchdog timer operation clock, setting the overflow time to maximum cycle (2 ) (same content as the sample program setting) WDTM Overflow time setting Operation clock selection System clock (f The WDTM setting value is “01101111...
  • Page 15 CHAPTER 4 SETTING METHODS [Example 2] Using the low-speed internal oscillation clock (f ) as the watchdog timer operation clock, setting the overflow time to maximum cycle (2 ) (same content as the WDTM value after reset release) WDTM Note Note Overflow time setting Operation clock selection...
  • Page 16 CHAPTER 4 SETTING METHODS [Example 3] Stopping the watchdog timer WDTM Overflow time setting (Invalid setting due to watchdog timer operation stop) Operation clock selection Watchdog timer operation stop The WDTM setting value is “0111xxxx (x: don’t care, bits 7, 6, and 5 must be set to 0, 1, and 1, respectively)”.
  • Page 17 CHAPTER 4 SETTING METHODS • Assembly language program example (same content as in [Example 1] described above and the sample program) XMAIN CSEG UNIT RESET_START: MOVW #STACKTOP MOVW Set the stack pointer WDTM, #01101111B WDT overflow time = 2^20/fx = 131.07 ms •...
  • Page 18 CHAPTER 4 SETTING METHODS • C language program example (same content as in [Example 1] described above and the sample program) void hdwinit(void){ unsigned char ucCnt200us; /* 8-bit variable for 200 us wait WDTM = 0b01101111; WDT overflow time = 2^20/fx = 131.07 ms •...
  • Page 19: Chapter 5 Operation Check Using The Device

    CHAPTER 5 OPERATION CHECK USING THE DEVICE This chapter describes the flow from building to the operation check using the device, using the downloaded sample program. Building the Sample Program This section describes how to build sample programs, using the sample program (source files + project file) downloaded by clicking the icon.
  • Page 20 CHAPTER 5 OPERATION CHECK USING THE DEIVCE (3) Select [Project Settings] from the [Project] menu. When the [Project Settings] window opens, select the name of the device to be used (the device with the largest ROM or RAM size will be selected by default), and click [OK].
  • Page 21: Operation With The Device

    CHAPTER 5 OPERATION CHECK USING THE DEVICE Operation with the Device This section describes an example of an operation check using the device. The HEX file generated by executing build can be written to the flash memory of the device. For how to write to the flash memory of the device, refer to the 78K0S/Kx1+ Simplified Flash Writing Manual Information (being prepared).
  • Page 22 CHAPTER 5 OPERATION CHECK USING THE DEIVCE (2) Operation after pressing the switch (operation after interrupt servicing) If the switch is pressed for less than 10 ms, the switch input is identified as chattering and operation is returned to that described in (1). If the switch is pressed for longer than 10 ms, either of the following operations is performed at a 50% chance of occurrence (see the figure below), depending on the timing at which the switch is pressed.
  • Page 23: 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 78K0S/Kx1+...
  • Page 24: 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 ;***************************************************************************** Watchdog timer ;***************************************************************************** ;<<History>> 2007.6.-- Release ;***************************************************************************** ;<<Overview>> ;This sample program presents an example of using the watchdog timer function.
  • Page 25 APPENDIX A PROGRAM LIST | Blink every 120 ms | |-------|--------------------| | Blink every 60 ms +----------------------------+ # A reset is generated by WDT at a 50% chance of occurrence when SW is turned on. In that case, LED1 blinks every 120 ms even if SW is turned on. <RESET source and LED2>...
  • Page 26 APPENDIX A PROGRAM LIST XRAM DSEG SADDR CNT10: ; For 10 ms wait CNT60: ; For 60 ms wait CNT120: ; For 120 ms wait ;============================================================================= Define the memory stack area ;============================================================================= XSTK DSEG 0FEE0H STACKEND: ; Memory stack area = 32 bytes STACKTOP: ;...
  • Page 27 APPENDIX A PROGRAM LIST ; Assign the 200 us wait count value ;----- 200 us wait ----- WAIT_200US: $WAIT_200US ; 0.5[us/clk] x 10[clk] x 40[count] = 200[us] ;----- Wait for VDD >= VLVI ----- WAIT_LVI: WDTE, #0ACH ; Clear the watchdog timer LVIF, $WAIT_LVI ;...
  • Page 28 APPENDIX A PROGRAM LIST ; Enable vector interrupt ;***************************************************************************** Main loop ;***************************************************************************** MAIN_LOOP: ;----- Reverse LED1 ----- #00000001B ; Reverse output of LED1 CNT120, #120 ; Assign the 120 ms wait count value ;----- 120 ms wait ----- WAIT_120MS: CALL !WAIT_1MS ;...
  • Page 29 APPENDIX A PROGRAM LIST RETI ; Return from interrupt servicing ;----------------------------------------------------------------------------- Subroutine for a 1 ms wait (for 4 MHz operation) ;This is a subroutine for performing a rendezvous in ms units by using ;software. ;This subroutine is called by the number of times required when performing a ;rendezvous in ms units.
  • Page 30 APPENDIX A PROGRAM LIST main.c (C language version) /***************************************************************************** NEC Electronics 78K0S/KB1+ ****************************************************************************** 78K0S/KB1+ Sample program ****************************************************************************** Watchdog timer ****************************************************************************** <<History>> 2007.6.-- Release ****************************************************************************** <<Overview>> This sample program presents an example of using the watchdog timer function. The overflow time of the watchdog timer is set to 131.07 ms by counting the 8 MHz fx and runaway detection is performed.
  • Page 31 APPENDIX A PROGRAM LIST In that case, LED1 blinks every 120 ms even if SW is turned on. <RESET source and LED2> +------------------------+ RESET Source LED2 | | (P21) | |----------------|-------| | Other than WDT | |----------------|-------| | WDT +------------------------+ <<I/O port settings>>...
  • Page 32 APPENDIX A PROGRAM LIST LSRCM = 0b00000001; /* Stop the oscillation of the low-speed internal oscillator */ /* Initialize the port 2 */ = 0b00000011; /* Set output latches of P20, P21 as high (turn off LED1, LED2) and P22, P23 as low */ = 0b11110000;...
  • Page 33 APPENDIX A PROGRAM LIST = 0b00001000; /* Connect on-chip pull-up resistor to P43 = 0b00001000; /* Set P43 as input mode, P40-P42 and P44- P47 as output mode */ /*---------------------------------------------------------------------------- Initialize the port 12 ----------------------------------------------------------------------------*/ = 0b00000000; /* Set output latches of P120-P123 as low PM12 = 0b11110000;...
  • Page 34 APPENDIX A PROGRAM LIST for (unCnt = 0; unCnt < 555; unCnt++){ /* Wait of about 10 ms (for chattering removal) */ NOP(); PIF1 = 0; /* Clear the INTP1 interrupt request */ while (!P4.3){ /* Processing during SW input */ P2 ^= 0b00000001;...
  • Page 35 APPENDIX A PROGRAM LIST op.asm (Common to assembly language and C language versions) ;============================================================================= Option byte ;============================================================================= OPBT CSEG 0080H 10011100B ; Option byte area |||| |||+----------- Low-speed internal oscillator can be stopped by software |++------------ High-speed internal oscillation clock (8 MHz) is selected for system clock source +-------------- P34/RESET pin is used as RESET pin 11111111B...
  • Page 36: Appendix B Revision History

    APPENDIX B REVISION HISTORY Edition Date Published Page Revision − − 1st edition October 2007 Application Note U18847EJ1V0AN...
  • Page 37 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