Renesas RL78/G13 Operation

Renesas RL78/G13 Operation

Clock generator (clock switching) cc-rl
Hide thumbs Also See for RL78/G13:

Advertisement

APPLICATION NOTE
RL78/G13
R01AN2831EJ0100
Rev. 1.00
Clock Generator (Clock Switching) CC-RL
May 28, 2015
Introduction
This application note explains how to use the clock generator of the RL78/G13.
The clock from the clock generator is switched when a switch is pressed. The clock generator uses the high-speed
on-chip oscillator clock, (32 MHz), X1 oscillation clock (20 MHz), or XT1 oscillation clock (32.768 kHz) as the
CPU/peripheral hardware clock (f
).
CLK
Target Device
RL78/G13 (40 pins or more)
When applying the sample program covered in this application note to another microcomputer, modify the program
according to the specifications for the target microcomputer and conduct an extensive evaluation of the modified
program.
R01AN2831EJ0100 Rev. 1.00
Page 1 of 51
May 28, 2015

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the RL78/G13 and is the answer not in the manual?

Questions and answers

Summary of Contents for Renesas RL78/G13

  • Page 1 May 28, 2015 Introduction This application note explains how to use the clock generator of the RL78/G13. The clock from the clock generator is switched when a switch is pressed. The clock generator uses the high-speed on-chip oscillator clock, (32 MHz), X1 oscillation clock (20 MHz), or XT1 oscillation clock (32.768 kHz) as the...
  • Page 2: Table Of Contents

    RL78/G13 Clock Generator (Clock Switching) CC-RL Contents Specifications ............................4 Operation Check Conditions ......................... 6 Related Application Note........................6 Description of the Hardware ......................... 7 4.1 Hardware Configuration Example ......................7 4.2 List of Pins to be Used ......................... 8 Software Description ..........................
  • Page 3 RL78/G13 Clock Generator (Clock Switching) CC-RL Documents for Reference ........................51 Revision Record ............................52 General Precautions in the Handling of MPU/MCU Products ................ 53 R01AN2831EJ0100 Rev. 1.00 Page 3 of 51 May 28, 2015...
  • Page 4: Specifications

    RL78/G13 Clock Generator (Clock Switching) CC-RL Specifications The sample code covered in this application note switches its operating clock when the switch on the target board is pressed according to the sequence below. (1) High-speed on-chip oscillator clock (32 MHz)  X1 oscillation clock (20 MHz) (2) X1 oscillation clock (20 MHz) ...
  • Page 5 RL78/G13 Clock Generator (Clock Switching) CC-RL Change the LED blinking period Switch input Switch clock (INTP0) RL78/G13 Change the CPU/peripheral hardware clock ) to one of the following clocks:  HOCO clock (32 MHz)  X1 oscillation clock (20 MHz) ...
  • Page 6: Operation Check Conditions

    5.0 V (can run on a voltage range of 2.9 V to 5.5 V.) LVD operation (V ): Reset mode 2.81 V (2.76 V to 2.87 V) CS + V3.01.00 from Renesas Electronics Corp. Integrated development environment (CS+) C compiler (CS+) CC-RL V1.01.00 from Renesas Electronics Corp.
  • Page 7: Description Of The Hardware

    RL78/G13 Clock Generator (Clock Switching) CC-RL Description of the Hardware Hardware Configuration Example Figure 4.1 shows an example of hardware configuration that is used for this application note. 10 k RESET P137/INTP0 RL78/G13 20 MHz For on-chip debugger P40/TOOL0 REGC 32.768 kHz...
  • Page 8: List Of Pins To Be Used

    RL78/G13 Clock Generator (Clock Switching) CC-RL List of Pins to be Used Table 4.1 lists the pins to be used and their functions. Table 4.1 Pins to be Used and their Functions Pin Name Description P137/INTP0 Switch input Input LED output Output R01AN2831EJ0100 Rev.
  • Page 9: Software Description

    RL78/G13 Clock Generator (Clock Switching) CC-RL Software Description Operation Overview The sample code covered in this application note switches its operating clock when the switch on the target board is pressed. (1) Initialize the clock generator. The sample code initializes the I/O ports, clock generator, timer array unit 0 (TAU0), 12-bit interval timer, and external interrupt input hardware.
  • Page 10: File Configuration

    RL78/G13 Clock Generator (Clock Switching) CC-RL File Configuration Table 5.1 lists the files that are used in this sample code. This table excludes files which are automatically generated by the integrated development environment. Table 5.1 File Configuration File Name Description Remarks r_cg_cgc.c...
  • Page 11: List Of Option Byte Settings

    RL78/G13 Clock Generator (Clock Switching) CC-RL List of Option Byte Settings Table 5.2 summarizes the settings of the option bytes. Table 5.2 Option Byte Settings Address Value Description 000C0H/010C0H 11101111B Disables the watchdog timer. (Stops counting after the release from the reset status.)
  • Page 12: List Of Constants

    RL78/G13 Clock Generator (Clock Switching) CC-RL List of Constants Table 5.3 lists the constants that are used in this sample program. Table 5.3 Constants for Sample Program Constant Setting Description HOCO_NEXT_STATUS_X1 Clock status : Operating on the HOCO clock and the next clock is the X1 oscillation clock.
  • Page 13: List Of Variables

    RL78/G13 Clock Generator (Clock Switching) CC-RL List of Variables Table 5.4 lists the global variables that are used in this sample program. Table 5.4 Global Variable Type Variable Name Contents Function Used uint8_t g_ClockStatus Clock status main() r_intc0_interrupt uint8_t g_TAU0_Channel0_C...
  • Page 14: Function Specifications

    RL78/G13 Clock Generator (Clock Switching) CC-RL Function Specifications This section describes the specifications for the functions that are used in the sample code. [Function Name R_INTC0_Start Sets start of INTP0 external interrupt processing. Synopsis #include "r_cg_macrodriver.h" Header #include "r_cg_intc.h" #include "r_cg_userdefine.h"...
  • Page 15 RL78/G13 Clock Generator (Clock Switching) CC-RL [Function Name] R_CGC_HOCOToX1 Switches from HOCO clock to X1 oscillation clock. Synopsis Header #include "r_cg_macrodriver.h" #include "r_cg_cgc.h" #include "r_cg_userdefine.h" void R_CGC_HOCOToX1 (void) Declaration Switches the CPU/peripheral hardware clock (f ) from the HOCO clock to the X1 oscillation Explanation clock.
  • Page 16 RL78/G13 Clock Generator (Clock Switching) CC-RL [Function Name] R_CGC_GetClockStatus Gets clock status. Synopsis Header #include "r_cg_macrodriver.h" #include "r_cg_cgc.h" #include "r_cg_userdefine.h" uint8_t R_CGC_GetClockStatus(uint8_t status) Declaration Gets the clock status. Explanation Gets the status of the clock specified in the argument so that the user can check if the clock oscillates.
  • Page 17 RL78/G13 Clock Generator (Clock Switching) CC-RL [Function Name] R_CGC_Get_X1_Status Gets X1 oscillation clock status. Synopsis Header #include "r_cg_macrodriver.h" #include "r_cg_cgc.h" #include "r_cg_userdefine.h" uint8_t R_CGC_Get_X1_Status(void) Declaration Gets the X1 oscillation clock status. Explanation Arguments None  Return value When the clock has not been switched: CLOCK_NOT_OSCILLATING (0x00) ...
  • Page 18 RL78/G13 Clock Generator (Clock Switching) CC-RL [ Function Name ] R_CGC_StopClock Stops clock. Synopsis #include "r_cg_macrodriver.h" Header #include "r_cg_cgc.h" #include "r_cg_userdefine.h" Declaration void R_CGC_StopClock(uint8_t status) Stops the clock specified in the argument. Explanation  First argument: status : Clock to stop (1 to 3)
  • Page 19 RL78/G13 Clock Generator (Clock Switching) CC-RL [Function Name] R_TAU0_Channel0_Restart Restarts channel 0 of TAU0. Synopsis Header #include "r_cg_macrodriver.h" #include "r_cg_timer.h" #include "r_cg_userdefine.h" void R_TAU0_Channel0_Restart(uint8_t clkdiv, uint16_t count) Declaration  Explanation Stops the interval timer for channel 0 of TAU0 temporarily.
  • Page 20 RL78/G13 Clock Generator (Clock Switching) CC-RL [Function Name] r_tau0_channel0_interrupt Processes an interval timer interrupt of channel 0 of TAU0. Synopsis Header #include "r_cg_macrodriver.h" #include "r_cg_timer.h" #include "r_cg_userdefine.h" static void __near r_tau0_channel0_interrupt(void) Declaration Inverts the LED output (P62) at transition to this interrupt processing.
  • Page 21: Flowcharts

    RL78/G13 Clock Generator (Clock Switching) CC-RL Flowcharts Figure 5.1 shows the overall flow of the sample program described in this application note. Start The option bytes are referenced before Initialization function the initialization function is called. hdwinit() main() Figure 5.1 Overall Flow R01AN2831EJ0100 Rev.
  • Page 22: Initialization Function

    RL78/G13 Clock Generator (Clock Switching) CC-RL 5.8.1 Initialization Function Figure 5.2 shows the flowchart for the initialization function. hdwinit() IE  Disable interrupts System function r_systeminit() return Figure 5.2 Initialization Function R01AN2831EJ0100 Rev. 1.00 Page 22 of 51 May 28, 2015...
  • Page 23: System Function

    RL78/G13 Clock Generator (Clock Switching) CC-RL 5.8.2 System Function Figure 5.3 shows the flowchart for the system function. r_ s ysteminit  00000000B PIOR Disuse peripheral I/O register redirection function Set up I/O ports R_PORT_Create() Set up CPU clock R_CGC_Create()
  • Page 24: I/O Port Setup

    Figure 5.4 I/O Port Setup Cautions: 1. Refer to the section entitled "Flowcharts" in RL78/G13 Initialization Application Note (R01AN2575E) for the configuration of the unused ports. 2. Provide proper treatment for unused pins so that their electrical specifications are met. Connect each of...
  • Page 25: Cpu Clock Setup

    (about 1 second). This period is specified with constant CGC_SUBWAITTIME in r_cg_cgc.h. Caution: For details on the procedure for setting up the CPU clock (R_CGC_Create ()), refer to the section entitled "Flowcharts" in RL78/G13 Initialization Application Note (R01AN2575E). R01AN2831EJ0100 Rev. 1.00 Page 25 of 51 May 28, 2015...
  • Page 26 Control of X1 clock oscillation frequency 1 MHz  fx  10 MHz 10 MHz < fx  20 MHz Caution: For details on the register setup procedures, refer to RL78/G13 User's Manual: Hardware. R01AN2831EJ0100 Rev. 1.00 Page 26 of 51 May 28, 2015...
  • Page 27 Notes: 1. Bits 7 and 5 are read-only. 2. Changing the value of the MCM0 bit is prohibited while the CSS bit is set to 1. Caution: For details on the register setup procedures, refer to RL78/G13 User's Manual: Hardware. R01AN2831EJ0100 Rev. 1.00 Page 27 of 51...
  • Page 28 Bit 0 HIOSTOP High-speed on-chip oscillator clock operation control High-speed on-chip oscillator operating. High-speed on-chip oscillator stopped. Caution: For details on the register setup procedures, refer to RL78/G13 User's Manual: Hardware. R01AN2831EJ0100 Rev. 1.00 Page 28 of 51 May 28, 2015...
  • Page 29: Timer Array Unit 0 (Tau0) Setup

    RL78/G13 Clock Generator (Clock Switching) CC-RL 5.8.5 Timer Array Unit 0 (TAU0) Setup Figure 5.6 shows the flowchart for setting up the timer array unit 0 (TAU0). R_TAU0_Create Supply clock signals to timer array TAU0EN bit  1 unit Set up TAU0 operation TPS0 register ...
  • Page 30: Setting Up 12-Bit Interval Timer

    RL78/G13 Clock Generator (Clock Switching) CC-RL 5.8.6 Setting up 12-bit Interval Timer Figure 5.7 shows the flowchart for setting up the 12-bit interval timer. R_IT_Create Supply clock to interval timer RTCEN bit  1 ITMC register  0000H Stop interval timer ITMK bit ...
  • Page 31: Setting Up External Interrupt Input

    RL78/G13 Clock Generator (Clock Switching) CC-RL 5.8.7 Setting up External Interrupt Input Figure 5.8 shows the flowchart for setting up the external interrupt input. R_INTC_Create PMK0 bit  1 Disable INTP0 interrupts PIF bit  0 Clear INTP0 interrupt request flag PPR10 bit ...
  • Page 32: Main Processing

    RL78/G13 Clock Generator (Clock Switching) CC-RL 5.8.8 Main Processing Figure 5.9 shows the flowchart for the main processing. main IE  Enable interrupts Start INTP0 operation R_INTC0_Start() Start operation of channel 0 of TAU0 R_TAU0_Channel0_Start() The switch status is set on...
  • Page 33: Setting To Start Intp0 External Interrupt Processing

    RL78/G13 Clock Generator (Clock Switching) CC-RL 5.8.9 Setting to Start INTP0 External Interrupt Processing. Figure 5.10 shows the flowchart for setting to start INTP0 external interrupt processing. R_INTC0_Start PIF0 bit  0: Clear interrupt request flag. Start INTP0 operation PMK0 bit  0: Enable INTP0 interrupts.
  • Page 34: Setting To Start Operation Of Channel 0 Of Tau0

    RL78/G13 Clock Generator (Clock Switching) CC-RL 5.8.10 Setting to Start Operation of Channel 0 of TAU0 Figure 5.11 shows the flowchart for setting to start the operation of channel 0 of TAU0. R_TAU0_Channel0_Start TIMIF00 bit  0: Clear interrupt request flag.
  • Page 35: Switching Clock

    RL78/G13 Clock Generator (Clock Switching) CC-RL 5.8.11 Switching Clock Figure 5.12 shows the flowchart for switching clocks. [Argument] R_CGC_ChangeClock  Clock status Clock status? Operating on HOCO and next clock is X1 Change clock from HOCO to X1 R_CGC_HOCOToX1() Operating on X1 and next clock is XT1...
  • Page 36: Switching From Hoco Clock To X1 Oscillation Clock

    RL78/G13 Clock Generator (Clock Switching) CC-RL 5.8.12 Switching from HOCO Clock to X1 Oscillation Clock. Figure 5.13 shows the flowchart for switching from HOCO clock to X1 oscillation clock. R_CGC_HOCOToX1 MSTOP  0 Set up X1 oscillator Wait for X1 clock oscillation stabilization...
  • Page 37: Switching From X1 Oscillation Clock To Xt1 Oscillation Clock

    RL78/G13 Clock Generator (Clock Switching) CC-RL 5.8.13 Switching from X1 Oscillation Clock to XT1 Oscillation Clock Figure 5.14 shows the flowchart for switching from X1 oscillation clock to XT1 oscillation clock. R_CGC_X1ToXT1 Set up HOCO CKC register Select HOCO as main system clock MCM0 ...
  • Page 38: Switching From Xt1 Oscillation Clock To Hoco Clock

    RL78/G13 Clock Generator (Clock Switching) CC-RL 5.8.14 Switching from XT1 Oscillation Clock to HOCO Clock Figure 5.15 shows the flowchart for switching from XT1 oscillation clock to HOCO clock. R_CGC_XT1ToHOCO Set up HOCO HIOSTOP  0 Select main system clock (f...
  • Page 39: Getting Clock Status

    RL78/G13 Clock Generator (Clock Switching) CC-RL 5.8.15 Getting Clock Status Figure 5.16 shows the flowchart for getting clock status. [Argument] R_ CGC _GetClockStatus  Clock status Clock status? X1 oscillation clock Get X1 oscillation clock status R_CGC_Get_X1_Status() X1 oscillation clock...
  • Page 40: Getting X1 Oscillation Clock Status

    RL78/G13 Clock Generator (Clock Switching) CC-RL 5.8.16 Getting X1 Oscillation Clock Status Figure 5.17 shows the flowchart for getting X1 oscillation clock status. = CPU/peripheral hardware clock R_CGC_Get_X1_Status = Main system clock MAIN Status  Not oscillating status = X1...
  • Page 41: Getting Xt1 Oscillation Clock Status

    RL78/G13 Clock Generator (Clock Switching) CC-RL 5.8.17 Getting XT1 Oscillation Clock Status Figure 5.18 shows the flowchart for getting XT1 oscillation clock status. = CPU/peripheral hardware clock R_CGC_Get_XT1_Status Conditions for the subsystem clock status: CLK.CLS = 1: f status is subsystem clock.
  • Page 42: Getting Hoco Clock Status

    RL78/G13 Clock Generator (Clock Switching) CC-RL 5.8.18 Getting HOCO Clock Status Figure 5.19 shows the flowchart for getting HOCO clock status. = CPU/peripheral hardware clock R_CGC_Get_HOCO_Status = Main system clock MAIN Status  Not oscillating Conditions for establishing the HOCO clock...
  • Page 43: Stopping Clock

    RL78/G13 Clock Generator (Clock Switching) CC-RL 5.8.19 Stopping Clock Figure 5.20 shows the flowchart for stopping clock. R_CGC_StopClock Current clock status? X1 oscillation XT1 oscillation HOCO clock HIOSTOP  1 Stop HOCO clock HOCO clock Default return Figure 5.20 Stopping Clock R01AN2831EJ0100 Rev.
  • Page 44: Getting Parameters Of Channel 0 Of Tau0

    RL78/G13 Clock Generator (Clock Switching) CC-RL 5.8.20 Getting Parameters of Channel 0 of TAU0 Figure 5.21 shows the flowchart for getting parameters of channel 0 of TAU0. [Argument]  Clock status R_TAU0_Channel0_GetParameter  Frequency division ratio and count of channel 0...
  • Page 45: Restarting Channel 0 Of Tau0

    RL78/G13 Clock Generator (Clock Switching) CC-RL 5.8.21 Restarting Channel 0 of TAU0 Figure 5.22 shows the flowchart for restarting channel 0 of TAU0. R_TAU0_Channel0_Restart Stop channel 0 of TAU0 R_TAU0_Channel0_Stop() Change interval of channel 0 of TAU0 Change the LED blinking interval.
  • Page 46: Changing Interval Of Channel 0 Of Tau0

    RL78/G13 Clock Generator (Clock Switching) CC-RL 5.8.22 Changing Interval of Channel 0 of TAU0 Figure 5.23 shows the flowchart for changing the interval of channel 0 of TAU0. [Arguments] R_TAU0_Channel0_ : Frequency division ratio of operation clock (0 to 15)
  • Page 47: Setting To Stop Channel 0 Of Tau0

    RL78/G13 Clock Generator (Clock Switching) CC-RL 5.8.23 Setting to Stop Channel 0 of TAU0 Figure 5.24 shows the flowchart for setting to stopping channel 0 of TAU0. R_TAU0_Channel0_Stop TT0 register  0001H TMMK00 bit  1: Disable TAU0 channel 0 interrupts.
  • Page 48: Processing Of Interval Timer Interrupt Of Channel 0 Of Tau0

    RL78/G13 Clock Generator (Clock Switching) CC-RL 5.8.24 Processing of Interval Timer Interrupt of Channel 0 of TAU0 Figure 5.25 shows the flowchart for processing an interval timer interrupt of channel 0 of TAU0. r_tau0_channel0_interrupt P62 bit  0 or 1...
  • Page 49: Processing Of Intp0 External Interrupt

    RL78/G13 Clock Generator (Clock Switching) CC-RL 5.8.25 Processing of INTP0 External Interrupt Figure 5.26 shows the flowchart for processing INTP0 external interrupt. r_intc0_interrupt Read switch input port Wait to deal with chattering Wait for 10 ms R_IT_Wait_ms() Read switch input port...
  • Page 50: Waiting In Units Of 1 Ms

    RL78/G13 Clock Generator (Clock Switching) CC-RL 5.8.26 Waiting in Units of 1 ms Figure 5.27 shows the flowchart for waiting in units of 1 ms. [Argument] R_IT_Wait_ms Wait count ITMC register Start interval timer RINTE = 1 Clear interval timer interrupt ITIF bit ...
  • Page 51: Sample Code

    RL78/G13 User's Manual: Hardware (R01UH0146E) RL78 Family User's Manual: Software (R01US0015E) (The latest versions of the documents are available on the Renesas Electronics Website.) Technical Updates/Technical Brochures (The latest versions of the documents are available on the Renesas Electronics Website.)
  • Page 52 Revision Record RL78/G13 Clock Generator (Clock Switching) Description Rev. Date Page Summary First edition issued 1.00 May 28, 2015 — All trademarks and registered trademarks are the property of their respective owners.
  • Page 53 General Precautions in the Handling of MPU/MCU Products The following usage notes are applicable to all MPU/MCU products from Renesas. For detailed usage notes on the products covered by this document, refer to the relevant sections of the document as well as any technical updates that have been issued for the products.
  • Page 54 10. It is the responsibility of the buyer or distributor of Renesas Electronics products, who distributes, disposes of, or otherwise places the product with a third party, to notify such third party in advance of the contents and conditions set forth in this document, Renesas Electronics assumes no responsibility for any losses incurred by you or third parties as a result of unauthorized use of Renesas Electronics products.

Table of Contents