Renesas Technology announced in late March he start of a design challenge for engineers around the world: develop an innovative, low-power application using the RL78 MCU and IAR Systems toolchain. To get started, you need to familiarize yourself with the RL78. Clemens Valens, Editor-in-Chief of Elektor online, introduces the RL78 in a comprehensive “The RL78 Microcontroller: An MCU Family for Low-Power Applications” (Circuit Cellar 261, 2012).
I’ve worked with Valens in various occasions, and had the pleasure of meeting him in 2011. He’s truly “an engineer’s engineer”: extremely embedded tech savvy, well-read, and inquisitive. Furthermore, I edited Circuit Cellar articles Valens wrote about diverse design projects, such as a virtual instrument interface and a scrolling LED message board. Thus, it’s clear to me that Valens understands the importance of designing high-quality, energy-efficient, systems—and doing so within budget. I trust you’ll find his introduction to the RL78 insightful and immediately applicable.
The RL78 Microcontroller: An MCU Family for Low-Power Applications
By Clemens Valens (Circuit Cellar 261, 2012)
The low-power 8/16-bit microcontroller (MCU) market is a bit of a warzone with several MCU manufacturers proposing “the industry’s lowest power solution.” In a YouTube video, Texas Instruments boasts a best active figure of 160 μA/MIPS for their MSP430 family. In application note AN1267, Microchip Technology claims 110 μA at “1 MHz Run” for their PIC16LF72X. And Renesas Electronics announced 70 μA at “1-MHz normal operation” on their RL78 product website.[1, 2, 3] The absence of justification on how exactly these figures were obtained makes comparing them rather useless. But then again, you don’t really have to because, as most low-power developers know from experience, if you don’t get the hardware and software design right, you will never attain the promised 20-year battery lifetime no matter how low the MCU’s active, sleep, or standby current may be. In this article, I will take a closer look at Renesas’s quickly expanding RL78 family to see what they offer that may help you create a low-power design.
Photo 1 - The Renesas RL78
THE RL78 FAMILY
The RL78 family of 16-bit MCUs currently has two branches, “generic” and “application specific,” but a third “display” branch is forthcoming. The generic branch contains the subfamilies G12, G13, and G1A, all based on the 78K core, and the G14, which is based on the R8C core. In the application-specific branch there is the 1A and F12. I am not sure about their core origins as these products are still very new and, at the time of writing, documentation is missing. It doesn’t really matter; from now on it is the new RL78 core for all. Since they share the same core, I will concentrate on the G13 for which I have a nice evaluation board (see Photo 1 and “The Renesas Demonstration Kit for RL78” sidebar).
Sidebar: Renesas Demonstration Kit
This family comes in a large number of variants (I counted 182), with devices having from 20 up to 128 pins (see Figure 1). Note that the parts themselves are labelled R5F10xx. The differences between all these variants are, besides the package type, the amounts of flash memory (program and data) and RAM. Program flash memory starts at 16 KB and currently ends at 512 KB, data flash sizes can be 0, 4, or 8 KB and RAM is 2 KB for the small devices and up to 32 KB for the big ones.
Figure 1 - Diagram of 128-pin RL78/G13 devices
The CPU is 16-bit, but the internal memory architecture is 8 bit. Its 32 general-purpose registers are organized in four banks of eight and can be used as 8- or 16-bit registers. The memory-mapped special function registers (SFRs) that control the on-chip peripherals can be addressed per bit, per byte, or as 16-bit registers, depending on the register. A second set of SFRs, the extended or second SFRs, are available too, but they need longer instructions to be accessed.
For those who need to squeeze the maximum out of MCU performance, it may be interesting to know that the CPU offers a short addressing mode enabling you to access a page of 256 bytes with a minimum amount of code.
The maximum clock frequency of the processor is 32 MHz, but the hardware user’s manual, which is almost 1,100 pages, interestingly also boasts about the ultra-low-speed capabilities of the processor as it can run from a 32.768-kHz clock.
The RL78 core features 15 I/O ports, most of which are 8-bit wide. Port 13 is 2-bit wide and ports 10 and 15 are 7-bit wide. The port pins that are actually available depend on the device. Inputs and outputs are highly configurable. Inputs can be analog, CMOS, or TTL. Outputs can be CMOS or N-channel open drain. Pull-up resistors are available too. The exact configuration possibilities depend on the port pin, so consult the datasheet. Because of the many configuration options, it is possible to use the MCU in multi-voltage systems without level-shifting circuitry except for the occasional external pull-up resistor. The chip can be powered from 1.6 V to 5.5 V, the core itself runs from 1.8 V provided by an internal voltage regulator.
Several options are available for the MCU clock. When clock precision is not too important, the MCU can be run from its internal clock, up to 32 MHz, otherwise it is possible to connect an external crystal, resonator, or oscillator. An internal low-speed clock (15 kHz) is also available, but not for the CPU, only for the watchdog timer (WDT), the real-time clock (RTC), and the interval timer.
The timers of the RL78 are flexible and offer many functions. Depending on the pin size of the device, you can have up to 16 16-bit timers, grouped in two arrays of eight. Each timer (called a “channel”) can function as an interval timer, square-wave generator, event counter, frequency divider, pulse-interval timer, pulse-duration timer, and delay counter. For even more possibilities, timers can be combined to create monostable multivibrators or to do pulse-width modulation (PWM). This way, up to seven PWM signals can be generated from one master timer. If you need more timers but resolution is less important, you can split some 16-bit timers in two 8-bit timers (this is not possible with all timers). Timer 7 of array 0 is extra special as it features local interconnect network (LIN) network support (see below).
Aside from date and time keeping with alarms, the RTC also provides constant period interrupts at 2 Hz and 1 Hz and also every minute, hour, day, or month. A 1-Hz output is available on devices with 40 or more pins. For extra precision, the RTC offers a correction register for fine tuning the 32,768-kHz clock. Unsurprisingly, the RTC continues operation when the MCU is stopped.
Now that I mentioned Stop mode, a special interval timer peripheral enables wakeup from this mode at periodic intervals. This timer is also used for the analog-to-digital converter’s (ADC’s) Snooze mode. More on that later. With a clock frequency of 32,768 Hz, the lowest interval rate is 8 Hz (0.125 ms).
Yet another time-related peripheral on the RL78 is the buzzer controller (not available on 20-pin devices). This is a clock output destined at IR comms carrier generation, to clock other chips in a system or to produce sound from a buzzer. A gate bit enables modulation of this output in such a way that pulses always have the same width.
Finally, a WDT completes the timing peripherals. It has a special Window mode that limits the time frame during which you can reset the watchdog to a fraction of the watchdog interval (50%, 75%, or 100%). Resetting the watchdog counter outside the window results in a reset. The window is open in the second part of the interval. An interrupt can be generated when the WDT reaches 75% of its time-out value, (i.e., when the watchdog reset window is known to be open in all cases). Figure 2 illustrates the mechanism.
Figure 2 - Trying to reset the watchdog counter when the window is closed results in an internal reset signal
The ADC is of the 10-bit successive approximation type and can have up to 26 inputs. Several triggering options are provided, hardware and software, where hardware triggering means triggering by a timer module (timer channel 1 end of count or capture, interval timer, or RTC). The time it takes to do a conversion depends partly on the triggering mode. When input stabilization is not too much of an issue (i.e., when you don’t switch inputs) you can achieve conversion times of just over 2 μs.
Two registers enable comparing the ADC’s output to maximum and minimum values, producing an interrupt when the new value is either in or out of bounds. This function is also available in Snooze mode. In this mode, the processor itself is stopped and consumes very little power, but ADC conversions continue under control of the hardware trigger. When a conversion triggers an ADC interrupt, the processor can then wake up from Snooze mode and resume normal operation.
The RL78 features multifunction serial units. The devices with 25 pins or less have one such unit, the others have two. Only serial unit 2 provides LIN bus support.
A serial unit can function in asynchronous UART mode, in synchronous CSI mode (three-wire bus with clock, data in and data out signals, master and slave mode supported), and in simplified (master-only) I²C mode. Again, depending on the device, you can have up to four UARTs or eight CSI and/or simplified I²C ports. Of course a mix is also possible. Full I²C is possible with the specialized I²C unit.
UART0 and UART2, CSI00 and CSI20 provide Snooze mode functionality similar to the ADC. In Snooze mode, these ports can be made to wake up on the arrival of incoming data without waking up the CPU. If the received data is interesting enough, it is also possible to wake up the CPU.
LIN communications are possible with UART2 together with Timer 7 of Array 0. The LIN bus is an inexpensive alternative to the CAN bus in automotive systems to control simple devices like switches, sensors, and actuators. LIN only uses one wire and is rather low speed (20 Kbps maximum). The timer takes care of the LIN synchronization issues and the UART performs the (de)serialisation of the data.
Full blown I²C communication is possible with the specialized I²C peripheral IICA. The 80-pin and more devices have two channels, the others only one. Communication speeds up to 20 MHz are permitted to enable I²C “fast mode” (3.5 MHz) and “fast mode plus” (10 MHz). This module is capable of waking up the CPU from Stop mode.
Of interest is the hardware multiplier and divider module intended for filtering and FFT functions. This module is capable of 16 × 16 bits signed and unsigned multiplications and divisions producing 32-bit results. It can also do 16 × 16 bit multiply-accumulate. We are talking about a module here, not an instruction, meaning that you have to load the operands yourself in special registers and get the result from yet another. The multiplication itself is done in one clock cycle, a division takes 16. The accumulate operation adds another cycle.
Another special math function is the binary-coded decimals (BCD) correction register that enables you to easily transform binary calculation results into BCD results.
DIRECT MEMORY ACCESS
To speed up data transport without loading the CPU, the RL78 core features direct memory access (DMA), up to four channels. DMA transfers up to 1,024 words of data (8 or 16 bit) to and from SFRs and RAM and they can be started by a range of interrupts (e.g., ADC, serial, timer). Although DMA transfers are done in parallel with normal CPU operation, it does slow down the CPU. For time-critical situations, it is possible to put a DMA transfer on hold for a number of clock cycles and let the CPU finish its job first.
Interrupts are pretty standard on the RL78 and many sources are available. The “key interrupt” function on the other hand is less common. It provides up to eight (depending on the device, you guessed it) key or push button inputs that are ORed together to generate an interrupt on a key press (active low).
OPERATING MODES & SECURITY
Besides the aforementioned Stop and Snooze modes, the RL78 also provides a Halt mode. In this mode, the CPU is stopped but the clocks keep running, making a fast resume possible. In Stop mode, the clocks are stopped too reducing power consumption more than in Halt mode. Snooze mode is like Stop mode, but with one or more peripherals in a snoozing state, ready to wake up when something interesting happens. Interrupts can be used to wake up from Snooze, Stop, or Halt mode. A reset usually works too.
Reset, by the way, can have seven origins, three of which are related to safety functions: illegal instruction, RAM parity, and illegal memory access. Two others involve the power supply: power-on reset (POR) and low-voltage detection (LVD). All these reset options are needed to conform to the International Electrotechnical Commission (IEC) 60730-1 (“Automatic Electrical Controls for Household and Similar Use; Part 1: General Requirements”) and IEC 61508-SER (“Functional Safety of Electrical/Electronic/Programmable Electronic Safety-Related Systems”) safety standards. Since the RL78 is compliant, it also implements flash memory CRC checking, protections to prevent RAM and SFRs to be modified when the CPU stops functioning, an oscillator frequency-detection circuit, and an ADC self-test function.
The hardware used for the flash memory CRC check is also available as a general-purpose CRC module for user programs. It implements the standard CCITT CRC-16 polynomial (X^16 + X^12 + X^5 + 1).
The RAM guard function protects only up to 512 bytes, so be careful where you put your sensitive data.
FLASH & FUSES
Those familiar with the fuse bytes of PIC and AVR processors will be happy to know that the RL78 contains four of them, the option bytes that configure such things as the WDT, low-voltage detection, flash memory modes, clock frequencies, and debugging modes.
Flash memory is divided into two parts, program memory and data memory, and it can be programmed in-circuit over a serial interface. A boot partition is available too. This partition uses a kind of ping-pong mechanism called “boot swapping” to ensure that a valid bootloader is always programmed into the boot partition so that even power failures during bootloader programming will not harm the boot partition. A flash window function protects the memory against unintentionally reprogramming parts of it.
This concludes our voyage through the Renesas RL78 core. As you have seen, the RL78 offers many interesting peripherals all combined in a flexible low-power optimized design. Thanks to the integrated oscillator and other functions, an RL78 MCU can be used with very little external hardware, enabling inexpensive and compact designs. Once you master its Snooze mode and your low-power design skills, you can use this MCU family in battery-operated metering applications, for instance, but I am sure you can think of something more surprising.
Clemens Valens (firstname.lastname@example.org) is Editor-in-Chief of Elektor Online. He has more than 15 years of experience in embedded systems design. Clemens is currently interested in sound synthesis techniques, rapid prototyping, and the popularization of technology.
 Texas Instruments, Inc., “Ultra-Low Power MSP430 – The World’s Lowest Power MCU,” 201.
 Microchip Technology, Inc., “AN1267: nanoWatt and nanoWatt XLP Technologies: An Introduction to Microchip’s Low-Power Devices,” 2009.
 Renesas Electronics Corp., “RL78 Family,” www.renesas.com/pr/mcu/rl78/index.html.
International Electrotechnical Commission (IEC), “60730-1, Automatic Electrical Controls for Household and Similar Use; Part 1: General Requirements,” 2002.
———, “61508-SER, Functional Safety of Electrical/
Electronic/Programmable Electronic Safety-Related Systems,” 2010.
Renesas Electronics Corp., Renesas Rulz, “RL78/G13 Demonstration Kit,” www.renesasrulz.com/community/demoboards/rdkrl78g13.