background image

RL78/G13 

Clock Generator (Clock Switching) CC-RL 

R01AN2831EJ0100  Rev. 1.00 

 

Page 39 of 51 

May 28, 2015 

 

5.8.15 

Getting Clock Status 

Figure 5.16 shows the flowchart for getting clock status. 

 

 

 

Figure 5.16      Getting Clock Status 

R_ CGC _GetClockStatus

R_CGC_Get_X1_Status()

Default 

HOCO clock 

R_CGC_Get_XT1_Status()

R_CGC_Get_HOCO_Status()

Clock status? 

Get X1 oscillation clock status 

Get XT1 oscillation clock status 

Get HOCO clock status 

X1 oscillation clock

X1 oscillation clock

return status 

[Argument]  

 Clock 

status 

Summary of Contents for RL78/G13

Page 1: ... 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 fCLK 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 ...

Page 2: ...xternal Interrupt Input 31 5 8 8 Main Processing 32 5 8 9 Setting to Start INTP0 External Interrupt Processing 33 5 8 10 Setting to Start Operation of Channel 0 of TAU0 34 5 8 11 Switching Clock 35 5 8 12 Switching from HOCO Clock to X1 Oscillation Clock 36 5 8 13 Switching from X1 Oscillation Clock to XT1 Oscillation Clock 37 5 8 14 Switching from XT1 Oscillation Clock to HOCO Clock 38 5 8 15 Get...

Page 3: ...L78 G13 Clock Generator Clock Switching CC RL R01AN2831EJ0100 Rev 1 00 Page 3 of 51 May 28 2015 7 Documents for Reference 51 Revision Record 52 General Precautions in the Handling of MPU MCU Products 53 ...

Page 4: ... X1 oscillation clock and the HOCO clock The XT1 oscillation clock is always generated The sample code also changes the LED blinking period on the target board as shown below according to the operating clock This allows the operating clock to be visually checked LED blinking period of the HOCO clock 32 MHz 0 5 seconds LED blinking period of the X1 oscillation clock 20 MHz 1 seconds LED blinking pe...

Page 5: ...51 May 28 2015 Figure 1 1 Outline of Clock Switching Switch input INTP0 RL78 G13 Change the LED blinking period ON Change the CPU peripheral hardware clock fCLK to one of the following clocks Switch clock HOCO clock 32 MHz X1 oscillation clock 20 MHz XT1 oscillation clock 32 768 kHz ...

Page 6: ... clock is selected 20 MHz When the XT1 oscillation clock is selected 32 768 kHz Operating voltage 5 0 V can run on a voltage range of 2 9 V to 5 5 V LVD operation VLVD Reset mode 2 81 V 2 76 V to 2 87 V Integrated development environment CS CS V3 01 00 from Renesas Electronics Corp C compiler CS CC RL V1 01 00 from Renesas Electronics Corp Integrated development environment e 2 studio e 2 studio V...

Page 7: ... When designing and implementing an actual circuit provide proper pin treatment and make sure that the hardware s electrical specifications are met connect the input only ports separately to VDD or VSS via a resistor 2 Connect any pins whose name begins with EVSS to VSS and any pins whose name begins with EVDD to VDD respectively 3 VDD must be held at not lower than the reset release voltage VLVD ...

Page 8: ...N2831EJ0100 Rev 1 00 Page 8 of 51 May 28 2015 4 2 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 I O Description P137 INTP0 Input Switch input P62 Output LED output ...

Page 9: ...llation clock 20 MHz 2 X1 oscillation clock 20 MHz XT1 oscillation clock 32 768 kHz 3 XT1 oscillation clock 32 768 kHz HOCO clock 32 MHz Subsequently steps 1 to 3 are repeated 4 Get the clock status The sample code gets the clock status If the clock status is found to have been changed the sample code takes one of the following actions according to the clock operating state When the high speed on ...

Page 10: ...external interrupt input module r_cg_intc_user c External interrupt input module INTP0 external interrupt r_cg_it c 12 bit interval timer module r_cg_it h External reference header file for the 12 bit interval timer module r_cg_it_user c Processing specific to the 12 bit interval timer module sample code Additional function R_IT_Wait_ms r_main c Main processing r_cg_macrodriver h Common header fil...

Page 11: ...on Byte Settings Address Value Description 000C0H 010C0H 11101111B Disables the watchdog timer Stops counting after the release from the reset status 000C1H 010C1H 01111111B LVD reset mode 2 81 V 2 76 V to 2 87 V 000C2H 010C2H 11101000B HS mode HOCO 32 MHz 000C3H 010C3H 10000100B Enables the on chip debugger Erases the data in the flash memory when on chip debugging security ID authentication fail...

Page 12: ...tus is operation on HOCO clock CHATTERING_WAIT 10 Wait time to deal with chattering is 10 ms HOCO_LED_SETTING_CHANNEL_PRESCAL ER 9 Frequency division ratio of channel 0 of TAU0 when HOCO clock is selected HOCO_LED_SETTING_CHANNEL_COUNT 15625 Count value of channel 0 of TAU0 when HOCO clock is selected X1_LED_SETTING_CHANNEL_PRESCALER 9 Frequency division ratio of channel 0 of TAU0 when X1 oscillat...

Page 13: ...P0 external interrupt processing R_TAU0_Channel0_Start Sets start of channel 0 of TAU0 R_CGC_ChangeClock Switches clocks R_CGC_HOCOToX1 Switches from HOCO clock to X1 oscillation clock R_CGC_X1ToXT1 Switches from X1 oscillation clock to XT1 oscillation clock R_CGC_XT1ToHOCO Switches from XT1 oscillation clock to HOCO clock R_CGC_GetClockStatus Gets clock status R_CGC_Get_X1_Status Gets X1 oscillat...

Page 14: ...Start Synopsis Sets start of channel 0 of TAU0 Header include r_cg_macrodriver h include r_cg_timer h include r_cg_userdefine h Declaration void R_TAU0_Channel0_Start void Explanation Releases mask of INTP0 interrupts to start counting Arguments None Return value None Remarks None Function Name R_CGC_ChangeClock Synopsis Switches clocks Header include r_cg_macrodriver h include r_cg_cgc h include ...

Page 15: ...psis Switches from X1 oscillation clock to XT1 oscillation clock Header include r_cg_macrodriver h include r_cg_cgc h include r_cg_userdefine h Declaration void R_CGC_X1ToXT1 void Explanation Switches the CPU peripheral hardware clock fCLK from X1 oscillation clock to XT1 oscillation clock Arguments None Return value None Remarks None Function Name R_CGC_XT1ToHOCO Synopsis Switches from XT1 oscill...

Page 16: ...ion Gets the clock status Gets the status of the clock specified in the argument so that the user can check if the clock oscillates Arguments First argument status Clock status 1 to 3 Set one of the following constants X1_STATUS Gets the status of X1 oscillation clock XT1_STATUS Gets the status of XT1 oscillation clock HOCO_STATUS Gets the status of HOCO clock Return value If the clock has not bee...

Page 17: ...XT1 oscillation clock status Header include r_cg_macrodriver h include r_cg_cgc h include r_cg_userdefine h Declaration uint8_t R_CGC_Get_XT1_Status void Explanation Gets the XT1 oscillation clock status Arguments None Return value When the clock has not been switched CLOCK_NOT_OSCILLATING 0x00 When the clock has been switched CLOCK_OSCILLATING 0x01 Remarks None Function Name R_CGC_Get_HOCO_Status...

Page 18: ...ants X1_STATUS Gets parameters for X1 oscillation clock XT1_STATUS Gets parameters for XT1 oscillation clock HOCO_STATUS Gets parameters for HOCO clock Second argument p_clkdiv Loaded with the frequency division ratio of the operation clock for channel 0 of TAU0 Third argument p_count Loaded with the count value of channel 0 of TAU0 Return value None Remarks p_clkdiv and p_count are the first and ...

Page 19: ...terval Synopsis Changes interval of channel 0 of TAU0 Header include r_cg_macrodriver h include r_cg_timer h include r_cg_userdefine h Declaration void R_TAU0_Channel0_ChangeInterval uint8_t clkdiv uint16_t count Explanation Changes the frequency division ratio of the operation clock for channel 0 of TAU0 to clkdiv Changes the count value of channel 0 of TAU0 to count Arguments First argument clkd...

Page 20: ...he function sets g_SwitchStatus to SWITCH_OFF 0x00 if it fails to detect two switch presses in succession The function sets g_SwitchStatus to SWITCH_ON 0x01 if it detects two switch presses in succession Updating the clock status This function sets g_ClockStatus to one of the following constants according to the number of switch presses HOCO_NEXT_STATUS_X1 X1_NEXT_STATUS_XT1 XT1_NEXT_STATUS_HOCO A...

Page 21: ...e 21 of 51 May 28 2015 5 8 Flowcharts Figure 5 1 shows the overall flow of the sample program described in this application note Figure 5 1 Overall Flow Start End Initialization function hdwinit main The option bytes are referenced before the initialization function is called ...

Page 22: ... R01AN2831EJ0100 Rev 1 00 Page 22 of 51 May 28 2015 5 8 1 Initialization Function Figure 5 2 shows the flowchart for the initialization function Figure 5 2 Initialization Function 0 IE hdwinit return System function r_systeminit Disable interrupts ...

Page 23: ...5 3 shows the flowchart for the system function Figure 5 3 System Function r_systeminit return Set up I O ports R_PORT_Create Set up CPU clock R_CGC_Create Disuse peripheral I O redirection function PIOR register 00000000B Set up TAU0 R_TAU0_Create Set up interval timer R_IT_Create Set up external interrupt input R_INTC_Create ...

Page 24: ...ts 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 any unused input only ports to VDD or VSS via a separate resistor 3 Set the I O port to a high level because the LED connected to P63 is always off R_PORT_Create Set up I O port for LED Set P62...

Page 25: ...AN2575E R_CGC_Create return Set up high speed system clock subsystem clock CMC register 51H X1 oscillation mode of high speed system clock XT1 oscillation mode of subsystem clock Low power consumption oscillation mode of XT1 oscillator X1 oscillator fx 10 MHz fx 20 MHz fx X1 clock oscillation frequency Set stop of X1 oscillator CSC register MSTOP 1 Set up XT1 oscillator Wait for XT1 oscillator to ...

Page 26: ...n mode Crystal ceramic resonator connection 1 0 Input port mode Input mode 1 1 External clock input mode Input mode External clock input Bits 5 and 4 EXCLKS OSCSELS Subsystem clock pin operation mode XT1 P123 pin XT2 EXCLKS P124 pin 0 0 Input port mode Input mode 0 1 XT1 oscillation mode Crystal resonator connection 1 0 Input port mode Input mode 1 1 External clock input mode Input mode External c...

Page 27: ...ral hardware clock fCLK 0 Main system clock fMAIN 1 Subsystem clock fSUB Bit 6 CSS Selection of CPU peripheral hardware clock fCLK 0 Main system clock fMAIN 1 Note2 Subsystem clock fSUB Bit 5 MCS Note 1 Status of main system clock fMAIN 0 High speed on chip oscillator clock fIH 1 High speed system clock fMX Bit 4 MCM0 Note 2 Main system clock fMAIN operation control 0 Selects the high speed on chi...

Page 28: ...illation mode External clock input mode Input port mode 0 X1 oscillator operating External clock from EXCLK pin is valid Input mode 1 X1 oscillator stopped External clock from EXCLK pin is invalid Bit 6 XTSTOP Subsystem clock operation control XT1 oscillation mode time External clock input mode Input port mode 0 XT1 oscillator operating External clock from EXCLKS pin is valid Input mode 1 XT1 osci...

Page 29: ...r clock 32 MHz Operation clock 0 CK00 62 5 MHz Operation clock 1 CK01 32 MHz Operation clock 2 CK02 16 MHz Operation clock 3 CK03 125 MHz Stop all TAU0 channels Disable TAU0 interrupts Clear TAU0 interrupt request flag Set TAU0 interrupt priority level to 3 TAU0EN bit 1 TPS0 register 0009H TT0 register 0AFFH TMMK00 bit 1 TMIF00 bit 0 TMPR100 bit 1 TMPR000 bit 1 Set up channel 0 of TAU0 Operation c...

Page 30: ...the flowchart for setting up the 12 bit interval timer Figure 5 7 12 bit Interval Timer Setup R_IT_Create return Supply clock to interval timer Stop interval timer Disable interval timer interrupts Set interval timer comparison value 1 ms Clear interval timer interrupt request flag RTCEN bit 1 ITMC register 0020H ITMC register 0000H ITMK bit 1 ITIF bit 0 ...

Page 31: ...nput Figure 5 8 shows the flowchart for setting up the external interrupt input Figure 5 8 External Interrupt Input Setup R_INTC_Create return PMK0 bit 1 PIF bit 0 PPR10 bit 1 PPR00 bit 1 EGN0 01H Disable INTP0 interrupts Clear INTP0 interrupt request flag Set INTP0 interrupt priority level to 3 Select falling edge as INTP0 valid edge ...

Page 32: ... Start operation of channel 0 of TAU0 YES Switch pressed status R_CGC_ChangeClock Change operation clock _ R_CGC_GetClockStatus Get clock status Operating on new clock Switch status Not pressed Transition to HALT mode Returned from HALT mode on an interval timer interrupt of channel 0 of TAU0 channel 0 R_TAU0_Channel0_Interrupt or INTP0 external interrupt input R_INTC0_Interrupt Enable interrupts ...

Page 33: ...o Start INTP0 External Interrupt Processing Figure 5 10 shows the flowchart for setting to start INTP0 external interrupt processing Figure 5 10 Setting to Start INTP0 External Interrupt Processing R_INTC0_Start return PIF0 bit 0 Clear interrupt request flag PMK0 bit 0 Enable INTP0 interrupts Start INTP0 operation ...

Page 34: ...hannel 0 of TAU0 Figure 5 11 shows the flowchart for setting to start the operation of channel 0 of TAU0 Figure 5 11 Setting to Start Operation of Channel 0 of TAU0 R_TAU0_Channel0_Start return TIMIF00 bit 0 Clear interrupt request flag TMMK00 bit 0 Enable TAU0 channel 0 interrupts TS0 register 0001H Start operation of channel 0 of TAU0 ...

Page 35: ...itching clocks Figure 5 12 Switching Clocks R_CGC_ChangeClock return R_CGC_HOCOToX1 Default R_CGC_X1ToXT1 R_CGC_XT1ToHOCO Argument Clock status Clock status Operating on X1 and next clock is XT1 Operating on XT1 and next clock is HOCO Operating on HOCO and next clock is X1 Change clock from HOCO to X1 Change clock from X1 to XT1 Change clock from XT1 to HOCO ...

Page 36: ... Figure 5 13 shows the flowchart for switching from HOCO clock to X1 oscillation clock Figure 5 13 Switching from HOCO Clock to X1 Oscillation Clock return R_CGC_HOCOToX1 MSTOP 0 Set up X1 oscillator Wait for X1 clock oscillation stabilization time while referring to OSTC register Select high speed clock fMX as main system clock fMAIN CKC register MCM0 1 ...

Page 37: ...ure 5 14 shows the flowchart for switching from X1 oscillation clock to XT1 oscillation clock Figure 5 14 Switching from X1 Oscillation Clock to XT1 Oscillation Clock return R_CGC_X1ToXT1 Set up HOCO Select HOCO as main system clock fMAIN Stop X1 oscillator Select subsystem clock fSUB as CPU peripheral hardware clock fCLK CKC register MCM0 0 MSTOP 1 CKC register CSS 1 ...

Page 38: ...m XT1 Oscillation Clock to HOCO Clock Figure 5 15 shows the flowchart for switching from XT1 oscillation clock to HOCO clock Figure 5 15 Switching from XT1 Oscillation Clock to HOCO Clock return R_CGC_XT1ToHOCO CKC register CSS 0 HIOSTOP 0 Set up HOCO Select main system clock fMAIN as CPU peripheral hardware clock fCLK ...

Page 39: ... flowchart for getting clock status Figure 5 16 Getting Clock Status R_CGC_GetClockStatus R_CGC_Get_X1_Status Default HOCO clock R_CGC_Get_XT1_Status R_CGC_Get_HOCO_Status Clock status Get X1 oscillation clock status Get XT1 oscillation clock status Get HOCO clock status X1 oscillation clock X1 oscillation clock return status Argument Clock status ...

Page 40: ...for getting X1 oscillation clock status Figure 5 17 Getting X1 Oscillation Clock Status R_CGC_Get_X1_Status NO YES Status Not oscillating fCLK CPU peripheral hardware clock fMAIN Main system clock fCLK status X1 oscillation clock Status Oscillating return status Conditions for the X1 oscillation clock status CLK CLS 0 fCLK status is fMAIN and CLK MCS 1 fMAIN status is fMX ...

Page 41: ...re 5 18 shows the flowchart for getting XT1 oscillation clock status Figure 5 18 Getting XT1 Oscillation Clock Status R_CGC_Get_XT1_Status YES NO Status Oscillating fCLK status subsystem clock Status Not oscillating return status fCLK CPU peripheral hardware clock Conditions for the subsystem clock status CLK CLS 1 fCLK status is subsystem clock ...

Page 42: ...art for getting HOCO clock status Figure 5 19 Getting HOCO Clock Status R_CGC_Get_HOCO_Status YES NO Status Not oscillating fCLK CPU peripheral hardware clock fMAIN Main system clock Conditions for establishing the HOCO clock status CLK CLS 0 fCLK status is fMAIN and CLK MCS 0 fMAIN status is HOCO clock Status Oscillating fCLK status HOCO clock return status ...

Page 43: ...Rev 1 00 Page 43 of 51 May 28 2015 5 8 19 Stopping Clock Figure 5 20 shows the flowchart for stopping clock Figure 5 20 Stopping Clock return R_CGC_StopClock HOCO clock Default HIOSTOP 1 X1 oscillation XT1 oscillation Current clock status HOCO clock Stop HOCO clock ...

Page 44: ...er HOCO default X1 oscillation XT1 oscillation Current clock status Set parameters for X1 oscillation Set up X1 oscillation time 20 MHz parameters as the frequency division ratio and count Set parameters for XT1 oscillation Set up XT1 oscillation time 32 768 kHz parameters as the frequency division ratio and count Set parameters for HOCO Set up HOCO 32 MHz parameters as the frequency division rati...

Page 45: ...AU0 Figure 5 22 shows the flowchart for restarting channel 0 of TAU0 Figure 5 22 Restarting Channel 0 of TAU0 R_TAU0_Channel0_Restart return R_TAU0_Channel0_ChangeInterval R_TAU0_Channel0_Stop R_TAU0_Channel0_Start Change the LED blinking interval Stop channel 0 of TAU0 Change interval of channel 0 of TAU0 Start channel 0 of TAU0 ...

Page 46: ...igure 5 23 Changing Interval of Channel 0 of TAU0 R_TAU0_Channel0_ ChangeInterval return NO YES Division ratio of operation clock 15 Division ratio of operation clock 15 Set up operation clock of channel 0 of TAU0 Set count value of channel 0 of TAU0 PS0 register PRS003 to PRS000 Division ratio of operation clock TDR00 register Count value Arguments Frequency division ratio of operation clock 0 to...

Page 47: ...ting to Stop Channel 0 of TAU0 Figure 5 24 shows the flowchart for setting to stopping channel 0 of TAU0 Figure 5 24 Setting to Stop Channel 0 of TAU0 R_TAU0_Channel0_Stop return Stop channel 0 of TAU0 TT0 register 0001H TMMK00 bit 1 Disable TAU0 channel 0 interrupts TMIF00 bit 0 Clear interrupt request flag ...

Page 48: ... 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 Figure 5 25 Processing Interval Timer Interrupt of Channel 0 of TAU0 r_tau0_channel0_interrupt return Invert LED output P62 bit 0 or 1 ...

Page 49: ...ure 5 26 Processing of INTP0 External Interrupt r_intc0_interrupt R_IT_Wait_ms YES NO YES NO g_ClockStatus g_ClockStatus 1 return Read switch input port Wait for 10 ms Wait to deal with chattering Read switch input port Detect two consecutive switch presses Update clock status Clock status value within valid range Set clock status to HOCO Switch status Not pressed Branch condition g_ClockStatus 3 ...

Page 50: ...f 1 ms Figure 5 27 Waiting in Units of 1 ms NO YES YES NO return R_IT_Wait_ms Start interval timer Argument Wait count Clear interval timer interrupt request flag Wait count 0 Decrement wait count Interval timer interrupt request present Clear interval timer interrupt request flag Stop interval timer ITMC register RINTE 1 ITIF bit 0 Clear interrupt request flag ITMC register RINTE 0 ...

Page 51: ...13 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 Website and Support Renesas Electronics Website http www renesas com index jsp Inquiries http www renesas c...

Page 52: ...sion Record RL78 G13 Clock Generator Clock Switching Rev Date Description Page Summary 1 00 May 28 2015 First edition issued All trademarks and registered trademarks are the property of their respective owners ...

Page 53: ...function are not guaranteed from the moment when power is supplied until the power reaches the level at which resetting has been specified 3 Prohibition of Access to Reserved Addresses Access to reserved addresses is prohibited The reserved addresses are provided for the possible future expansion of functions Do not access these addresses the correct operation of LSI is not guaranteed if they are ...

Page 54: ...r any other appropriate measures Because the evaluation of microcomputer software alone is very difficult please evaluate the safety of the final products or systems manufactured by you 8 Please contact a Renesas Electronics sales office for details as to environmental matters such as the environmental compatibility of each Renesas Electronics product Please use Renesas Electronics products in com...

Reviews: