6 - Embedded System Programming
6 - Embedded System Programming
(RX63N-GR)
Embedded programming
« Learning Goals »
Memory allocation
With the general C language, the location of variables on memory is basically determined by compiler. With the
embedded C language, you can independently specify the fine allocation in the unit of variable by using #pragma
extension description.
Examples)
#pragma entry (vect=0) void PowerON_Reset (void) { /* function processing */}
_ _interrupt (vect=vector number) void function name (void) { /* interrupt processing function main body */ }
Defined items of
ANSI standard
Structure of control statements, variable
declaration, function definitions, etc.
char type
The default of char type (when unsigned or signed is not shown explicitly) is implementation dependent. Depending
on the CPU of microcomputer, the default of some is signed and, in some cases, you can select signed or unsigned.
You need to be very careful.
Return PC
Argument area
Allocated area for arguments
[CCRXM]
What is allocated to one general register is a variable with the length of 4 bytes or less such
as char and int.
A variable with 4 bytes or longer (such as long long and double) will be handled by 2
general registers.
What happens if initial values are set up for local variables of struct or array?
Initial value setting will be executed each time the declared function is called.
Initial values are secured also in the area other than stacks.
Local variables
Local variables not using stacks but using registers will effectively improve the performance of programs with no
read and write actions from/to memory.
Embedded C language does not always work on [ 1 ]. For this reason, memory
allocation and [ 2 ] will be basically done manually.
Since the rules for storing the arguments (area of allocating arguments) in embedded C
language is varied with microcomputers to microcomputers, special care needs to be paid
for rules for storing the arguments. For example, with the compiler for RX microcomputer
(CC-RX), the increased number of functions will cause the allocation to [ 3 ] rather than
to registers. Therefore the performance of program will be [ 4 ].
[ 5 ] with initial values are allocated to both ( 6 ) and RAM, and the initial values will be
copied from [ 6 ] to RAM at the power-on reset. [ 5 ] without initial values are allocated
RAM only, and the initial values will be set at [ 7 ] at the power-on reset.
<Options>
a. OS b. PC c. register
d. stack e. local variable f. global variable
g. ROM h. faster i. slower
j. initialization k. 0 l. 1
8
Answer Column
Correct
Question Answer
Answer
Summary
« Learning Goals »
10
This chapter describes various measures, designations and processing that need to be performed before main
function required before the execution of embedded C language that are different from the execution of general C
language programs. Though the contents described here are based on the particular RX microcomputers that are
used in the exercise, the notion, terms, mechanism, description unique to compiler and those things provided by the
integrated development environment are largely common to many microcomputers with some variations.
Since section D is the ROM portion of variables with initial values, the initialization of
copying the initial values stored in ROM to RAM is necessary.
According to ANSI language specification, section B even without initial values needs to set
the initial values to 0.
11
When a project is created, C language source files with the project name are created in
addition to startup program. In those files, main function is described.
12
+
{ • 68E305C8
• • 060003FB
• } EE000001
• FD68E005
main(); Link 9F060000
•
•
}
This is a program that is executed from Executes program After resetting, executes
the address indicated by the program from main function. programs sequentially from
counter after reset and, upon initialization the address indicated by the
of variables, calls the main function. program counter. 13
main();
main function calling
brk();
brkfunction calling }
stacksct.h
End #pragma stacksize su=0x100
#pragma stacksize si=0x300
14
brk function
After calling main function, user program will start working. In embedded systems, when main function is completed
in the state of power on, the control will never move to the next instruction. However, when such event should
happen, CPU will stop issuing instruction by using brk function.
Initialization of stack
For initialization of stack, entry function designation is used.
#pragma entry[(]< function name>[)]
The function designated by <function name> is treated as entry function.
With entry function, no output of register saving or return code will be executed by compiler.
When #pragma stacksize is declared, the initial setup code for stack pointer is outputted at the beginning
of function.
(2) When PowerON_Reset_PC function is built, initial setup of stack pointer is expanded to
top of the function by assembly language codes.
15
16
Include of machine.h
Since machine.h file is stored in the standard location to search by compiler CC-RX (the folder specified by
environment variable PATH),
#include <machine.h>
machine.h is enclosed by inequality sign "<" at left side and inequality sign ">" at right side.
Build
RTE
17
In the case of no OS
An initialization program written in assembly language is separately required.
18
<Options>
a. startup program b. static variable c. dynamic variable
d. prolog program e. block f. section
g. iodefine.h h. machine.h i. HardwareSetup function
j. embedded function k. register function l. flag function
m. #pragma interrupt n. #pragma inline o. PowerON_Reset_PC function
19
Answer Column
Correct
Question Answer
Answer
Summary
Explain the method to access the processor status word (PSW) from C language.
20
« Learning Goals »
21
Configuration of GR-SAKURA_eMboarD
GR-SAKURA_eMboarD consists of CPU board (GR-SAKURA) and the extension board
(eMboarD).
For the block diagram of RX63N, see p67 of RX63N User's Manual: Hardware.
Block diagram of GR-SAKURA
LAN Clock
12MHz
Switch
JTAG (CN6)
RX63N
Clock
32kHz
USB Boot mode
changeover switch
0 1 2 3 4 5 6 7 8 9 a b c d e f Optical
16x2 LCD Acceleration sensor
0 1 2 3 4 5 6 7 8 9 a b c d e f sensor
Temperature
sensor
Power switch
Power source LED
7 segment LED
12V power
supply
Connector
LED
Analog switch
GR-SAKURA
Volume Volume
Extension Extension
switchover switchover
Switch Switch
23
Switch Buzzer
UART Motor
LED
CAN
Power source circuit
LCD
24
In addition to above, more materials are stored in the folder. You are requested to see
them as necessary.
* The chapters hereafter will be described while doing the exercises. Exercise Volume: Read
Chapter 1 through Chapter 12 carefully.
25
<Options>
a. CPU board b. extension board c. general purpose board
d. memory board e. 12 f. 16
g. 32 h. 64 i. 96
j. 7 segment LED k. color LED l. RS232C connector
m. touch panel n. LCD o. LAN connector
26
Answer Column
Correct
Question Answer
Answer
Summary
27
« Learning Goals »
Understand the I/O control program using the general purpose I/O port of
RX63N.
28
29
RX63N Group
RX631 Group
Note: Pin allocation diagram shows power terminal and I/O port as well.
For the terminal configuration, see "Table 1.10 List of terminals by functions (100 pin LQFP)."
[UMH]
Table 1.9 Terminal allocation diagram (100 pin LQFP)
I/O port
Most of I/O ports can be selected from
using as a general purpose I/O port, or
using as a peripheral function (built-in I/O terminal, bus and bus control terminal, interrupt input
terminal).
At the initial state, I/O port is allocated to general purpose I/O port. (PMR=0x00)
Microcomputer
Switch
31
LED circuit
LED is a device that lights up by the flow of electric current. Connecting + (plus) of battery
to anode side and - (minus) to cathode side and applying electric current will light up the
LED. Resistor is inserted between battery and LED to restrict the electric current.
LED1
+ -
+3V
TLR114
LED1
-
A
R1 330
R1 330
K
TLR114
32
Anode
Anode is the electrode to which electric current flows from external circuit.
Low High
Port Port
33
330Ω×4 device
D4 D3 D2 D1
34
PDR
Value after reset
Port direction register
Pm0 dire ction control bit 0: Input (It functions as input port.)
PODR
1: Output (It functions as output port.)
Pm1 dire ction control bit Port output data register
Pm2 dire ction control bit
PMR
Pm3 dire ction control bit
m=0 to 9, A to G, J
[UMH]
35
PDR of PORTA
The PDR of PORTA connected to anode side of LED D1 is the address 0x0008C00A.
What value should be entered to set the bit 0 of PORTA to "output"?
PORTA.PDR 0x0008C00A
PDR
Value after reset
Port direction register
m=0 to 9, A to G, J
[UMH]
36
PODR of PORTA
The PODR of PORTA connected to LED D1 is the address 0x0008C02A.
What value should be entered to set the bit 0 of PORTA to "1"?
PORTA.PODR 0x0008C02A
void main(void)
{
/* variable declaration */
volatile char *porta_pdr =(char *)0x0008C00A;
volatile char *porta_podr=(char *)0x0008C02A;
/* port initialization */
*porta_podr = 0x00; /* Turn-off data is set at PORTA0 output data register. */
*porta_podr = 0x00; /* "1" (output) is set at PORTA0 direction register. */
/* Turn on LED */
*porta_podr=0x01; /* Turn-on data is set at PORTA0 output data register. */
while (1) {
/* termination loop */
}
}
37
4.7.1 iodefine.h
void main(void)
{
/* port initialization */
PORTA.PODR.BIT.B0 = 0; /* Turn-off data is set at PORTA0 output data register. */
PORTA.PDR.BIT.B0 = 1; /* "1" (output) is set at PORTA0 direction register. */
/* Turn on LED */
PORTA.PODR.BIT.B0 = 1; /* Turn-on data is set at PORTA0 output data register. */
while (1) {
/* termination loop */
}
}
-> "CS+ User's Guide" Program development procedure using CS+ <C language>
-> Practice
39
Practice
By using the programming development procedure <C language> using CS+, let's create a project and execute a
program by entering the program of the slide.
High High
Port1 Port1
Turning Turning
Port2 off Port2 on
High Low
40
Source driver
LED1
10kΩ
RX63N High High A K
PORTE0
High Low
PORTJ3
-> Exercise 1
41
VCC
10kΩ
SW3
RX63N PORT05
GND
42
PDR
Value after reset
Port direction register
Undefined
PODR
bit Symbol bit name Function
Pm3 bit
PIDR
Pm4 bit Input data register
Pm5 bit
Pm6 bit
Pm7 bit
m=0 to 9, A to G, J [UMH]
43
PDR of PORT0
The PDR of PORT0 connected to SW3 is the address 0x0008C000.
What value should be entered to PORT0 direction register to set up the bit 5 of PORT0 to "input"?
PORT0.PDR 0x0008C000
PIDR of PORT0
The PIDR (input data register) of PORT0 connected to SW3 is the address 0x0008C040.
Predict the value of PIDR (input data register) of PORT0 when SW3 is not pressed.
PORT0.PIDR 0x0008C040
#include "iodefine.h"
void main(void)
{
/* variable setup */
volatile char switch3;
/* port initialization */
PORT0.PDR.BIT.B5 = 0;
while (1) {
/* SW1 reading */
switch3 = PORT0.PIDR.BIT.B5;
}
}
44
VCC
PORTE0
10kΩ
10kΩ
SW3
PORTJ3
GND PORT05
-> Exercise 2
45
A control operation using bit operation or shift operation through BYTE access
rather than using bit field of I/O register defined by iodefine.h is also possible.
46
General I/O port is also called [ 1 ] and you can use it for both input and output
as the gate for [ 2 ] signals.
The general I/O port for RX63N is handled by the unit of [ 3 ] bits. Each port is
controlled by four registers, [ 4 ] (PDR), [ 5 ] (PODR), [ 6 ] (PIDR) and [ 7 ]
(PMR).
<Options>
a. peripheral I/O b. GPIO c. analog
d. digital e. port mode register f. 4
g. port input register h. port direction register i. 8
j. port output register k. 16 l. 32
47
Answer Column
Correct
Question Answer
Answer
Source driver is a transistor array from which electric current can [ 1 ] and sink
driver is a transistor array to which electric current can [ 2 ].
To turn on LED1 in the circuit of bottom right, you need to set the output of
source driver at [ 3 ] by setting the terminal voltage of PORTE0 [ 4 ], while
you need to set the output of sink driver at [ 5 ] by setting the terminal voltage
of PORTJ3 [ 6 ]. Therefore, you should set [ 7 ] to port direction register of
PORTE0, [ 8 ] to port output data register, [ 9 ] to port direction register of
PORTJ3 and [ 10 ] to port output data register.
Source driver
Sink driver
Answer Column
Correct
Question Answer
Answer
10
<Options>
a. 0 b. 1 c. PODR
d. PIDR e: high f: low
49
Answer Column
Correct
Question Answer
Answer
Summary
Explain the I/O control program that uses general I/O port of RX63N.
50
« Learning Goals »
51
On RX63N, following timers are mounted. In this chapter, "CMT (compare match timer)" is
described.
52
5.2 Clock
Clock
Clock generates the timing for microcomputer to work.
*On GR-SAKURA, a clock with 12MHz is mounted. By the setting to use external
clock, the signal of 12MHz from the clock is input to the terminal of RX63N.
Item
Time
EXTAL Channel
Clock
12MHz
XTAL
Cursor 1
Cursor 2
GR-SAKURA
Clock
53
Se le ctor
Syste m clock (ICLK)
To CPU, DM AC, DTC, ROM and RAM
Se le ctor
Se le ctor
De te c ting Peripheral module clock (PCLKA)
os c illa tion To ETHERC, EDMAC, DEU
s top
Peripheral module clock (PCLKB)
To peripheral modules other than
ETHERC, EDMAC, DEU
48MHz
M ain clock
Se le ctor
oscillator
M ain clock
12MHz
Se le ctor
Sub - clock
oscillator Sub -clock BCLK te rminal
Se le ctor
Exte rnal bus clock (BCLK)
High -speed To e xternal bus controller
on -chip
oscillator HOCO clock SDRAM clock (SDCLK)
To SDCLK te rminal
To be divided according to
Low -speed
setting and supplied to
on -chip
oscillator LOCO clock each clock [UMH]
54
Release of register write protection The maximum operating frequency of RX63N is 100MHz,
while XTAL of GR-SAKURA is 12MHz. Since the setting of
Setup for clock terminals frequency division by 1 is prohibited when multiplier circuit
(PLL) is selected, the clock is multiplied by 16 once to
Oscillator weight control 192MHz and then frequency-divided by 2 to 96MHz which is
then supplied to ICLK (instruction clock: CPU clock).
Startup of main clock oscillator
The clock used for timer is PCLKB (peripheral clock). The
Setup of PLL clock clock of 48MHz which is frequency-divided by 4 is supplied.
End
55
Clock selection
Comparator
Comparator
Bus interface
Unit 0
[UMH] Unit 1 56
57
*For the count value, the value to be counted minus 1 should be set up.
(This is to notify the event at the next clock of the matching.)
Interrupt controller
58
Specifications of CMT
The clock input to the timer is counted by CMCNT to measure the time. When the count
matches the value of CMCOR (the goal value), a compare match interrupt will develop, and
IR bit will turn to"1."
Value of CMCNT
(3) Compare match interrupt develops. -> IR is made to 1.
CMCOR
0000h
Time
(2) Matching of compare match
at CMCOR will reset the counter.
1
IR bit of CMT0
0
Specifications of CMT
(i) When frequency division clock is selected and start bit is set at"1," CMCNT counter will start counting up by
using the selected clock.
(ii) When the value of the CMCNT counter reaches that of the CMCOR register, the former will have "0000h."
(iii) At this timing, a compare match interrupt will develop and the corresponding interrupt status flag (IR) is set
at"1."
(iv) The CMCNT counter will restart counting up from "0000h."
Start
Counter initialization
Start counting
End
60
Polling
Polling refers to the action in the programming processing to monitor at certain interval and to detect any changes in
signal or status.
main *By making each processing by 1ms base, the combination will be
made more easily.
*The total of processing time needs to be standard time 1ms or less.
Initial setup It is important to write lean programs by considering the processing well.
of CNT0
1ms
NO
(only once
1ms elapsed?
IR=1?
at first)
1R setting 1R setting 1R setting
(1ms elapsed) (1ms elapsed) (1ms elapsed)
IR <- 0
Data processing
Output processing
Input processing
Data processing
Output processing
Input processing
Data processing
Output processing
1ms
(2nd time
Data processing and after)
Output processing
-> Exercise 3
61
By providing the reference time using the timer, time control becomes easy.
Generally 1ms cycle or 2ms cycle is often used, but the cycle may be set to longer period when there are much
contents of processing or sampling time can be prolonged.
In those cases where real-time property is demanded such as in communication or shorter sampling time is required
such as sound data, using interrupt can be a better solution. (-> Chapter 7)
Timer measures the time by [ 1 ] the basic clock. Since the clock for RX63N is
selected to [ 2 ] at the time of reset, switchover to external clock by initial
setup of program should be done and [ 3 ] of PLL and [ 4 ] for clock to be
supplied to each peripheral module need to be set up.
CMT (compare match timer) for RX63N measures the time by counting the
clock to be input to timer by using CMCNT. Comparing the clock count value
and the CMCOR that is set up, an interrupt will develop when they [ 5 ]. Since,
when the interrupt occurs, interrupt request flag (IR) will be [ 6 ], the time
control can be conducted by [ 7 ] in the program.
<Options>
a. frequency-division ratio b. counting c. multiplication ratio
d. larger e. smaller f. match
g. clear h. set i. sampling
j. polling k. interrupt l. reset
m. high-speed on-chip oscillator n. low-speed on-chip oscillator
62
Answer Column
Correct
Question Answer
Answer
Summary
63
« Learning Goals »
64
10kΩ RX63N
SW3
PORT05
GND
High level
Falling Rising
edge edge
Low level
GND voltage
GND voltage
Time Time 65
GND voltage
Time
Status of
switch
OFF ON OFF ON
Edge
processing 0 1 0 1
flag
(i) Processing (i) Processing
when switch is when switch is
Program pressed Edge flag clear pressed
(ii) Edge flag (ii) Edge flag
setting setting 66
Flag
As the memory location in a program to indicate that the processing has been completed, variables are prepared.
Since each of these variables uses the data "1"and"0" as the meaning of "set" and "clear" respectively, it is called
flag.
main
No
Is switch pressed?
Yes
Processing
-> Exercise 4a
67
What is chattering?
It refers to the phenomenon whereby such items as movable contact point creates very fast
and fine vibration when the point moves to connected state or to disconnected state. It is
caused by the bouncing of contact point.
The time duration varies with the type or structure of switches, but it lasts for the order of
100μsec to 10msec. The confirmation on specification or actual measurement is
necessary.
Voltage
In the case of edge sensing, multiple events of edge sensing in a short period are detected,
which can cause malfunctions.
There are solutions by hardware and by software to remove chattering.
68
VCC
R2
SW
(1) R1 (2) (3)
+
C1
GND GND
Input port
Sampling
Determined data
Input port
Sampling
Determined data
69
Read the status of switch at the interval longer than chattering time.
A
No
main 1ms elapsed?
Yes
Initialization of the clock No
Chattering time
elapsed?
LED initialization
Yes
Switch initialization
Reading switch
CMT0 initialization
No
Is switch pressed?
Yes
Processing
-> Exercise 4b 70
Method to read the status of switch at the interval longer than the chattering time
When a noise occurs, there can be a case where the switch status has wrongly been recognized to
have changed.
Noise
Input port
Sampling
Determined
data
Under this method, the switch status is read by the interval longer than the chattering time
and the data is recognized to be the determined data only when the data of reading twice
match.
Wrong detection cannot occur often even when noises occur.
Noise
Input port
Sampling
Determined
data
The status change will be reflected The status change will not take place because
because the data of reading twice match. the data of reading twice do not match. 71
The processing takes place only when the switch data is the same as the previous time
(matching twice). A
No
main 1ms elapsed?
Yes
Initialization of the clock No
Chattering time
elapsed?
LED initialization
Yes
Switch initialization Reading switch
CMT0 initialization No
Is the status of switch the
same as the previous time?
A
Yes Save the current status
No of switch to memory.
Is switch pressed?
Yes
Processing
-> Exercise 4c 72
For the method to detect [ sense ] the status change of switch, there are two
ways, [ 1 ] and [ 2 ].
[ 1 ] judges the status of port directly. [ 2 ] judges the change point of voltage.
The change point of voltage from High -> Low refers to [ 3 ] edge, and the
change point from Low -> High refers to [ 4 ] edge.
A switch is the device to create conduction by the contact of metal points. The
phenomenon whereby metal contact points bounce at the moment of contact is
called [ 5 ].
To avoid [ 5 ] by software, you need to apply sampling at the interval longer
than [ 5 ] time.
<Options>
a. sampling b. chattering c. polling
d. level sensing e. port sensing f. edge sensing
g. rising h. falling i. Schmitt trigger
73
Answer Column
Correct
Question Answer
Answer
Summary
74
« Learning Goals »
75
Exception handling
Exception handling refers to the handling whereby CPU, when in the middle of executing a
usual program it encounters some event, suspends the execution of the program and
executes some other program.
Mechanism of executing exception handling
The switchover to exception handling takes place by the mechanism whereby the top
address of a program is set up beforehand to the vector table and when some exception
occurs, the program counter is rewritten to such preset address.
RX63N exception handling
With RX63N CPU, there are following exceptions.
"Interrupt" is one of the exceptions.
void main(void)
{ void Excep_ICU_IRQ13(void)
・
・ {
・ ・
・ ・ ・
} }
The interrupt causing factor and the interrupt processing program are linked by the
vector table. When an interrupt occurs, the interrupt processing program is started
by replacing the program counter (PC) by the address preregistered to the vector
table.
77
The interrupt causing factor and the interrupt processing program are linked by the
vector table. When an interrupt occurs, the interrupt processing program is started
by replacing the program counter (PC) by the address preregistered to the vector
table.
There are two types of vector tables, fixed vector table and variable vector table.
The fixed vector table is the one with its all allocated addresses being fixed. In the
addresses FFFFFF80h to FFFFFFFFh, each vector of privileged exception, access
exception, undefined instruction exception, floating point exception, non-maskable interrupt
and reset that are the object of exceptional processing for the system is allocated.
The variable vector table is the one with its all allocated addresses allowing the
modification. In the area of 1024 bytes whose top address (IntBase) is shown by the
content of interrupt table register (INTB), each vector of unconditional trap and interrupt is
allocated.
To the variable vector table, numbers (0 to 255) are assigned for each vector.
With CC-RX, the top address of interrupt program is registered to the corresponding vector
of the variable vector table at the time of build by applying #pragma interrupt instruction to
interrupt function name handled as an interrupt program.
78
(Reserved area)
(Reserved area)
Access exception
(Reserved area)
(Reserved area)
(Reserved area)
(Reserved area)
(Reserved area)
(Reserved area)
Non-maskable interrupt
Reset
[UMH]
Fig. 2.4 Fixed vector table
Order whereby
interrupt vectors
are allocated
[UMH]
Fig. 2.5 Variable vector table
External
Terminal
IE
Interrupt
Responding to an interrupt
permission bit request, an interrupt program
preregistered to the
corresponding vector number
Peripheral modules
is executed.
79
ICUb
Comparison
(2) IEN is (4) I flag is set
set to "1." 1 to "1."
(1) IR is
set to "0."
IPL I
0000 1
PSW
0 1 0001
IR IEN IPR
CPU
Interrupt Interrupt Interrupt (3) IPR set
status flag request priority level
permission bit setting bit
80
Interrupt requests
Interrupt requests are managed by IR, IER and IPR of ICUb (interrupt controller) and finally only one interrupt
request is issued to CPU.
For this reason, when processing an interrupt, I bit of PSW needs to be set at "1."
Occurrence of an interrupt
(2) Interrupt
ICUb priority level is
judged.
(3) Comparison
with IPL
Comparison
1
Interrupt request
Occurrence of
an interrupt
(1) IR
becomes 1.
IPL I
0000 1
PSW
1 1 0001
IR IEN IPR
CPU
Interrupt Interrupt Interrupt
status flag request priority level
permission bit setting bit
81
Occurrence of an interrupt
When an interrupt occurs, IR flag of interrupt controller is set.
Execution of interrupt program (after interrupt (1) Replace the value of PC to the address
registered to the vector corresponding to
request being accepted) the accepted interrupt request.
82
void main(void) PC
{ void
・ Excep_ICU_IRQ13(void
) ISP Value of
・
{ PSW
・
・ Return
・
・ address
}
・
} ... (2) Execute RTE instruction. Restore the value of PSW
from the stack.
(3)
IRQ1
IRQ0
[Characteristics] [Characteristics]
• The response time to interrupt • The response time to interrupt
processing execution is fast. processing execution is slow.
• Weak at noises • Resistant to noises
• Clearance of request signal during
interrupt processing is necessary. 84
We give it a try to use input port PORT05 of SW3 for external terminal interrupt.
VCC
RX63N
SW3 10kΩ
PORT05/
GND IRQ13
OFF
SW 3 PORT05/IRQ13
ON
1
IR bit of IRQ13
0
Start
MPC write-protect
register permitted to be written
MPC write-protect
register prohibited to be written
Interrupt permission
End
86
Initialization of the
clock Interrupt handling
LED initialization
RTE
Initialization of
interrupt
Infinite loop
-> Exercise 5
87
(ii) Comment out the corresponding interrupt function of intprg.c, create a function with the same name as the
corresponding function of intprg.c in arbitrary C language file and include vect.h at the top of the file.
Value of CMCNT
(3) Compare match interrupt develops. -> IR is made to "1."
CMCOR
0000h
Time
(2) Matching of compare match at
CMCOR will reset the counter.
1
IR bit of CMT
0
Counter initialization
Interrupt permission
Start counting
End
89
main
CMT1
initialization
-> Exercise 6
90
While CPU is executing a usual program, it can encounter some event and has
to suspend the execution of the program to execute some other program. This
kind of events are generally called [ 1 ] and the processing to respond this is
called [ 1 ] handling.
Interrupt is one of [ 1 ] cases.
When ICUb [ interrupt controller ] receives multiple interrupt requests from
peripheral modules or external interrupt terminals, it judges [ 2 ] by using the
setup value of [ 3 ]. Furthermore, by comparing [ 4 ] of PSW in CPU and [ 3 ]
in ICUb, when [ 3 ] > [ 4 ] and the flag of [ 5 ] is 1, an interrupt request is
issued to CPU.
<Options>
a. reset b. exception c. polling
d. IPR e. priority level f. IR
g. IPL h. D i. I
91
Answer Column
Correct
Question Answer
Answer
When CPU receives an interrupt request while executing the main program, the
main program is [ 1 ] and the interrupt program is [ 2 ]. To execute the
interrupt program, it is necessary to preregister the top address of the interrupt
program to the corresponding address of the [ 3 ] table. When the interrupt
program is to be executed, the return address and [ 4 ] are saved to stack and
the top address of the interrupt program is set to program counter (PC).
<Options>
a. continued b. suspended c. executed
d. waiting e. ISP f. PSW
g. register h. memory i. vector
92
Answer Column
Correct
Question Answer
Answer
Summary
93
« Learning Goals »
94
Bus interface
comparison register
Successive
12 bit D/A
Interrup t signal
Comparator
Analog multiplexor
Asynchro no us trigger
[UMH]
Fig. 42.1 Block diagram of 12 bit A/D converter
96
Note 1: When temperature sensor output or internal reference voltage is selected, do not use the continuous scan mode.
Note 2: After the release of module stop status, wait 10ms before starting A/D conversion.
Note 3: For internal reference voltage, see "51. Electric characteristics."
Note 4: It depends on such factors as channels, signal source impedance and AVCC voltage.
97
Start
MPC write-protect
Register permitted to be written
MPC write-protect
Register prohibited to be written
-> Exercise 7
End
98
The module that converts the signal inputted from [ 1 ] to [ 2 ] value is called
[ 3 ]. [ 3 ] of RX63N is [ 4 ] type and determines the value by comparing
with the internal voltage for comparison sequentially.
For RX63N, there are two types of converters, 10 bit A/D converter and 12 bit
A/D converter.
The [ 5 ] the number of bits is, the higher precision of conversion is available.
<Options>
a. digital b. analog c. A/D converter
d. D/A converter e. parallel comparison f. successive comparison
g. follow-up comparison h. smaller i. larger
99
Answer Column
Correct
Question Answer
Answer
Summary
100
« Learning Goals »
101
Cycle
Pulse width
High
25%
Low
102
LED brightness: low (dark) LED brightness: medium (normal) LED brightness: high (bright) 103
Control logic
MTU3,4
[Input terminal]
[Clock input]
Control logic
Interna l clock:
Common
[A/D conversion start
request signal]
External clock:
[UMH]
104
[MTU0, 3, 4]
• Buffer operations can be set up.
• AC synchronous motor (brushless DC motor) driving mode using
complementary PWM and reset synchronous PWM can be set up, and two
types (chopping and level) of waveform output can be selected.
[MTU1, 2]
• Phase constant mode can be set up independently.
• Cascade connection operation
[MTU3, 4]
• Output of complementary PWM by continuous operations, and total 6 phases
from positive and negative of PWM 3 phases each are available.
[MTU5]
• Dead time compensation counter function
Complementary PWM mode • Interrupt at crest and trough of counter
• Thinning out function for conversion start trigger for A/D converter
Interrupt factors 28 types
Buffer operation Automatic transfer for register data
Trigger generation Output trigger for programmable pulse generator (PRG) can be generated.
Conversion start trigger for A/D converter can be generated.
Function of reducing power
consumption
Setup to module stop status is possible.
[UMH]
105
Time
[UMH]
106
Start A
The total time of High and Low of digital signal is called [ 1 ], the time of High
is called [ 2 ] and [ 2 ] divided by [ 1 ] is called [ 3 ].
The control method whereby the time of High and Low is changed while fixing
the [ 1 ] of digital signal is called [ 4 ].
[ 4 ] is often used for the speed control of [ 5 ].
<Options>
a. frequency b. cycle c. pulse width
d. duty ratio e. frequency ratio f. pulse ratio
g. PWM control h. PAM control i. PDM control
j. stepping motor l. DC motor
108
Answer Column
Correct
Question Answer
Answer
Summary
109
« Learning Goals »
110
MSB LSB
1 0 1 0 1 1 0 0 1 0
Transmitting Receiving
side side
111
Parity bit
In the start-stop synchronous serial communications, since there is no error correction function and error of 2 bits or
more cannot be detected, the error check is only conducted at the higher communication layer and it is often the
case that transmission with "no parity bit" is conducted.
Bus interface
Module data bus
Baud rate
generator
112
Item Contents
Serial communication method • Start-stop synchronous method
• Clock synchronization method
• Smart card interface
• Simple l2C bus
• Simple SPI bus
Transmission speed By the use of embedded baud generator, any bit rate can be set up.
Full duplex communication Transmission part: Continuous transmission by double-buffer configuration is
possible.
Receiving part: Continuous reception by double-buffer configuration is possible.
Input output terminal See Table 35.4 to 35.6.
Data transmission Selection between LSB first/MSB first is possible (Note 1).
Interrupt factors Transmission completion, Transmission data empty, Receiving data full,
Receiving error, Start-condition/restart-condition/Stop-condition generation
completion (For simple l2C mode)
Function of reducing power consumption Setting to module stop status for each channel is possible.
Start-stop Data length 7 bits/8 bits
synchronous mode Transmission stop bit 1 bit /2 bits
Parity function Even parity/odd parity/no parity
Receiving error detection Parity error, overrun error, framing error
function
Hardware flow control Sending/receiving control using CTSn terminal and RTSn terminal is possible.
Break detection Break can be detected by reading RXDn terminal level directly in case of framing
error.
Clock source Selectable from internal clock and external clock
Transfer rate clock input from TMR (SCI5, SCI6) is possible.
Multi-processor Serial communication function among multiple processors
communications function
Noise reduction The signal paths from input on the RXDn terminals incorporate digital noise
filters.
Clock synchronization Data length 8 bits
mode Receiving error detection Overrun errors
Hardware flow control Sending/receiving control using CTSn terminal and RTSn terminal is possible. [UMH]
113
Data length
For the data length of RX63N SCIc, you can select 7 bits or 8 bits.
Parity function
For the parity function of RX63N SCIc, you can select from even parity, odd parity and no parity.
Start
A
-> Exercise 9
114
<Options>
a. bps b. kbps c. Mgps
d. byte rate e. bit rate f. bit
g. byte h. 0 i. 1
j. 2 k. 7 l. 8
m. 9 n. 10 o. 11
p. 12 q. 13 r. 14
115
Answer Column
Correct
Question Answer
Answer
Summary
116