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...
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...
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) ...
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.
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...
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.
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.
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...
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.)
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.
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...
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)
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.
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...
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()
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...
(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...
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 ...
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 ...
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...
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.
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...
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...
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 ...
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...
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...
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...
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...
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.
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)
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...
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 ...
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.
Need help?
Do you have a question about the RL78/G13 and is the answer not in the manual?
Questions and answers