This module provides support for all features of the 12-bit A/D Converter on the RX110, RX111, RX113, RX130,
RX210, RX230, RX231, RX631, RX63N, RX64M, RX65N and RX71M.
Target Device
The following is a list of devices that are currently supported by this API:
• RX110, RX111, RX113, RX130 Groups
• RX210 Group
• RX230, RX231 Groups
• RX631, RX63N Groups
• RX64M Group
• RX65N Group
• RX71M Group
When using this application note with other Renesas MCUs, careful evaluation is recommended after making
modifications to comply with the alternate MCU.
5.7 Adding a Demo to a Workspace ..................................................................................................... 73
R01AN1666EJ0220 Rev. 2.20 Page 2 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
1. Overview
This A/D Converter (ADC) driver supports the S12ADa peripheral on the RX63x, the S12ADb peripheral on the
RX11x/RX210, the S12ADC peripheral on the RX64M/RX71M, the S12ADE peripheral on the RX130/RX230/RX231
and the S12ADFa peripheral on the RX65x.
Depending on the MCU chosen, some features include, but are not limited to single scans, grouped single scans, and
continuous scanning. Peripheral features include register left or right alignment, clearing data after register reads,
summation and average of conversion results, and the ability to store data on alternate triggers of a channel. Channel,
temperature and internal reference voltage sensor specific features include setting sampling time using state counts, and
opting out of summation of samples. There is no dependency on any other software except for the board support
package (r_bsp module).
The ADC begins conversion when it receives a trigger. When the conversion is complete, a flag is set and an interrupt
issued if enabled. If the ADC is operating in a single scan mode, only one scan takes place per trigger. If the ADC is
operating in a continuous mode, scans continue indefinitely after the initial trigger occurs.
The trigger source may be synchronous from an MTU peripheral, Event Link Controller (ELC), or a TPU peripheral
(non-RX11x); asynchronous from an external trigger on ADTRG#, or from setting a bit in software. Note that even
though a software trigger is an asynchronous action, the hardware manual reserves the term “asynchronous trigger” to
refer to asynchronous external hardware triggers. Additionally, although the temperature sensor on the RX210 has its
own independent trigger, the driver hides this operation and the application should be written as if the standard software
trigger is being used.
The driver provides a Control() command for polled applications which checks to see if a scan completed after a trigger
occurs. If interrupts are in use, the interrupt will call a Callback function specified in the Open() function. The only
argument to the Callback function specifies whether the default scan has completed or a Group B scan has completed.
In general, the peripheral operates on a single trigger source. However, in a group mode, two different trigger sources
are used. Each group can contain one or more unique channels and may be scanned at different trigger intervals.
The majority of the driver serves to initialize the A/D peripheral and provide functions to read conversion results.
Settings which are common to all channels such as conversion alignment or addition count are set in the Open() call.
Specific channel enabling is done via a Control() command. Two Read() functions are provided- one which retrieves a
single conversion value and another which retrieves all conversion registers whether the channel is enabled or not.
For the RX11x/RX21x/RX63x there are 13 to 24 channels available for conversion depending upon the MCU chosen.
All MCUs include a Temperature and an Internal Reference Voltage sensor. Each has its own conversion register. In
addition, in non-RX63x MCUs, a single channel can be designated as a “double trigger”. This means the scan-complete
flag/interrupt occurs on every other scan. On an odd scan, the conversion result is placed in its normal data register. On
an even scan, the result is placed in a special register. Double trigger cannot be used with sensors or other channels
(unless the other channels are in Group B), and a sensor can only be scanned by itself.
For the RX64M/RX71M/RX65x there are 8 channels on Unit 0, 21 channels and two sensors (Temperature and Internal
Reference Voltage) on Unit 1. In addition, a single channel on each unit can be designated as a “double trigger”
channel. This means that the scan-complete flag/interrupt occurs on every other scan. On an odd scan, the conversion
result is placed in its normal data register. On an even scan, the result is placed in a special register. Double trigger
cannot be used with sensors or other channels (unless the other channels are in other Groups.). Sensors and channels
may be scanned together on Unit 1. A built-in level and window comparator is available for channels and sensors. The
sensors are available on unit 1 and a Sample & Hold feature is available on unit 0 for sampling up to 3 channels
simultaneously. A virtual channel is available for Self-Diagnosis against various voltages, and a Disconnect Detection
Assist feature allows for an initial charging or discharging of the internal capacitor. This 12-bit converter may also be
configured for 8 or 10-bit resolution for slightly faster conversion if desired, and an input is available for an external
amplifier (positive or negative gain) for up to 8 channels on unit 1.
R01AN1666EJ0220 Rev. 2.20 Page 3 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
2. API Information
This Driver API follows the Renesas API naming standards.
2.1 Hardware Requirements
This driver requires your MCU support the following features:
•S12ADa, S12ADb, S12ADC, S12ADE or S12ADFa peripheral
2.2 Hardware Resource Requirements
This section details the hardware peripherals that this driver requires. Unless explicitly stated, these resources must be
reserved for the driver and the user cannot use them.
2.2.1 S12ADa/S12ADb/S12ADC/S12ADE/S12ADFa
This driver makes use of all features available on these peripherals.
2.2.2 GPIO
This driver utilizes port pins corresponding to each individual analog channel. These pins may not be used for GPIO.
2.3 Software Requirements
This driver is dependent upon the following packages:
•Renesas Board Support Package (r_bsp)
2.4 Limitations
Registers, settings, or usage notes vary depending on the mode used in the 12-bit A/D converter. APIs in this
application note must be used according to the 12-bit A/D converter chapter in the User's Manual: Hardware for the
MCU used.
2.5 Supported Toolchains
This driver is tested and working with the following toolchains:
•Renesas RX Toolchain v2.05.00
2.6 Header Files
Compile time configurable options are located in r_s12ad_rx\ref\r_s12ad_rx_config_reference.h. This file should be
copied into the r_config subdirectory of the project and renamed to r_s12ad_rx_config.h. It is this renamed file that
should be modified if needed and the original kept as a reference.
All API calls and their supporting interface definitions are located in r_s12ad_rx\r_s12ad_rx_if.h. Both this file and
r_s12ad_rx_config.h should be included by the User’s application.
2.7 Integer Types
This project uses ANSI C99 “Exact width integer types” in order to make the code clearer and more portable. These
types are defined in stdint.h.
R01AN1666EJ0220 Rev. 2.20 Page 4 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
If this equate is set to 1, parameter checking is included
utilizes the system default setting.
// 1.8V <= AVcc0 < 2.7V
This equate is for the Temperature Sensor gain
2.8 Configuration Overview
All configurable options that can be set at build time are located in the file “r_s12ad_rx_config.h”. A summary of these
settings are provided in the following table:
in the build. If the equate is set to 0, the parameter
checking is omitted from the build. Setting this equate
to BSP_CFG_PARAM_CHECKING_ENABLE
amplifier on the RX210. The default is a value of 0
which is good for all target voltages. For best
temperature resolution, the voltage range which most
accurately reflects the AVcc0 should have its #define
uncommented.
2.9 Code Size
The code size is based on optimization level 2 and optimization type for size for the RXC toolchain in Section 2.5. The
ROM (code and constants) and RAM (global data) sizes are determined by the build-time configuration options set in
the module configuration header file.
With Parameter CheckingWithout Parameter Checking
ROM: 1354 bytes ROM: 983 bytes
RX110
RAM: 12 bytes RAM: 12 bytes
ROM: 1234 bytes ROM: 950 bytes
RX111
RAM: 124 bytes RAM: 124 bytes
ROM: 1471 bytes ROM: 1100 bytes
RX113
RAM: 12 bytes RAM: 12 bytes
ROM: 2560 bytes ROM: 1879 bytes
RX130
RAM: 12 bytes RAM: 12 bytes
ROM: 1671 bytes ROM: 1200 bytes
RX210
RAM: 12 bytes RAM: 12 bytes
ROM and RAM code sizes
R01AN1666EJ0220 Rev. 2.20 Page 5 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
ROM: 2327 bytes ROM: 1616 bytes
RX230, RX231
RAM: 12 bytes RAM: 12 bytes
ROM: 1030 bytes ROM: 792 bytes
RX63N
RAM: 12 bytes RAM: 12 bytes
ROM: 3277 bytes ROM: 2464 bytes
RX64M
RAM: 32 bytes RAM: 32 bytes
ROM: 5176 bytes ROM: 4114 bytes
RX65N
RAM: 40 bytes RAM: 40 bytes
ROM: 3277 bytes ROM: 2464 bytes
RX71M
RAM: 32 bytes RAM: 32 bytes
Table 2: ROM and RAM code size
2.10 API Data Structures
This section details the data structures that are used with the driver’s API functions.
To provide strong type checking and reduce errors, many parameters used in API functions require arguments to be
passed using the provided type definitions. Allowable values are defined in the public interface files:
/* ADC_OPEN() ARGUMENT DEFINITIONS */
typedef enum e_adc_mode
{
ADC_MODE_SS_TEMPERATURE, // single scan temperature sensor
ADC_MODE_SS_INT_REF_VOLT, // single scan internal ref voltage sensor
ADC_MODE_SS_ONE_CH, // single scan one channel
ADC_MODE_SS_MULTI_CH, // 1 trigger source, scan multiple channels
ADC_MODE_CONT_ONE_CH, // continuous scan one channel
ADC_MODE_CONT_MULTI_CH, // continuous scan multiple channels
ADC_MODE_SS_ONE_CH_DBLTRIG, // on even trig save to ADDBLDR & interrupt
ADC_MODE_SS_MULTI_CH_GROUPED, // 2 trigger sources, scan multiple channels
ADC_MODE_SS_MULTI_CH_GROUPED_DBLTRIG_A,
ADC_MODE_MAX // This definition DO NOT USE for R_ADC_Open() argument
} adc_mode_t;
typedefenum e_adc_trig // trigger sources (set to TRSA bit or TRSB bit)
{
ADC_TRIG_ASYNC_ADTRG = 0, // ext asynchronous trigger; not for
// Group modes nor double trigger modes
ADC_TRIG_SYNC_TRG0AN = 1, // MTU0 TRGA
ADC_TRIG_SYNC_TRG0BN = 2, // MTU0 TRGB
ADC_TRIG_SYNC_TRGAN = 3, // MTUx TRGA
R01AN1666EJ0220 Rev. 2.20 Page 7 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
adc_add_t add_cnt;
adc_align_t alignment; // ignored if addition used
adc_clear_t clearing;
adc_speed_t conv_speed;
adc_trig_t trigger; // default and Group A trigger source
adc_trig_t trigger_groupb; // valid only for group modes
uint8_t priority; // for S12ADIO int; 1=lo 15=hi 0=off/polled
uint8_t priority_groupb; // GBADI interrupt priority; 0-15
} adc_cfg_t;
/* ADC_CONTROL() ARGUMENT DEFINITIONS */
typedefenume_adc_cmd
{
// Commands for special hardware configurations
ADC_CMD_SET_SAMPLE_STATE_CNT,
// Commands to enable channels or sensors
ADC_CMD_ENABLE_CHANS, // enables chans and A & B INT if pri != 0
ADC_CMD_ENABLE_TEMP_SENSOR, // enables sensor and INT if priority != 0
ADC_CMD_ENABLE_VOLT_SENSOR, // enables sensor and INT if priority != 0
// Commands to enable hardware triggers or cause software trigger
ADC_CMD_ENABLE_TRIG, // ADCSR.TRGE=1 for sync/async triggers
ADC_CMD_SCAN_NOW, // software trigger start scan
R01AN1666EJ0220 Rev. 2.20 Page 8 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
// Commands to poll for scan completion
ADC_CMD_CHECK_SCAN_DONE, // for Normal or GroupA scan
ADC_CMD_CHECK_SCAN_DONE_GROUPA,
ADC_CMD_CHECK_SCAN_DONE_GROUPB,
/* ADC_OPEN() ARGUMENT DEFINITIONS */
typedef enum e_adc_mode
{
ADC_MODE_SS_TEMPERATURE, // single scan temperature sensor
ADC_MODE_SS_INT_REF_VOLT, // single scan internal ref voltage sensor
ADC_MODE_SS_ONE_CH, // single scan one channel
ADC_MODE_SS_MULTI_CH, // 1 trigger source, scan multiple channels
ADC_MODE_CONT_ONE_CH, // continuous scan one channel
ADC_MODE_CONT_MULTI_CH, // continuous scan multiple channels
ADC_MODE_SS_ONE_CH_DBLTRIG, // on even trig save to ADDBLDR & interrupt
ADC_MODE_SS_MULTI_CH_GROUPED, // 2 trigger sources, scan multiple channels
ADC_MODE_SS_MULTI_CH_GROUPED_DBLTRIG_A,
ADC_MODE_MAX // This definition DO NOT USE for R_ADC_Open() argument
} adc_mode_t;
typedef enum e_adc_trig // trigger sources (set to TRSA bit or TRSB bit)
{
ADC_TRIG_ASYNC_ADTRG = 0, // ext asynchronous trigger; not for Group modes// nor double trigger modes
R01AN1666EJ0220 Rev. 2.20 Page 10 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
adc_add_t add_cnt;
adc_align_t alignment; // ignored if addition used
adc_clear_t clearing;
adc_speed_t conv_speed;
adc_trig_t trigger; // default and Group A trigger source
adc_trig_t trigger_groupb; // valid only for group modes
uint8_t priority; // for S12ADIO int; 1=lo 15=hi 0=off/polled
uint8_t priority_groupb;// GBADI interrupt priority; 0-15
} adc_cfg_t;
/* ADC_CONTROL() ARGUMENT DEFINITIONS */
typedefenume_adc_cmd
{
// Commands for special hardware configurations
ADC_CMD_SET_SAMPLE_STATE_CNT,
R01AN1666EJ0220 Rev. 2.20 Page 11 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
// Commands to enable channels or sensors
ADC_CMD_ENABLE_CHANS, // enables chans and A & B INT if pri != 0
ADC_CMD_ENABLE_TEMP_SENSOR, // enables sensor and INT if priority != 0
ADC_CMD_ENABLE_VOLT_SENSOR, // enables sensor and INT if priority != 0
// Commands to enable hardware triggers or cause software trigger
ADC_CMD_ENABLE_TRIG, // ADCSR.TRGE=1 for sync/async triggers
ADC_CMD_SCAN_NOW, // software trigger start scan
// Commands to poll for scan completion
ADC_CMD_CHECK_SCAN_DONE, // for Normal or GroupA scan
ADC_CMD_CHECK_SCAN_DONE_GROUPA,
ADC_CMD_CHECK_SCAN_DONE_GROUPB,
adc_add_t add_cnt;
adc_align_t alignment; // ignored if addition used
adc_clear_t clearing;
adc_speed_t conv_speed;
adc_trig_t trigger; // default and Group A trigger source
adc_trig_t trigger_groupb; // valid only for group modes
uint8_t priority; // for S12ADIO int; 1=lo 15=hi 0=off/polled
uint8_t priority_groupb; // GBADI interrupt priority; 0-15
R01AN1666EJ0220 Rev. 2.20 Page 14 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
} adc_cfg_t;
/* ADC_CONTROL() ARGUMENT DEFINITIONS */
typedefenume_adc_cmd
{
// Commands for special hardware configurations
ADC_CMD_USE_INT_VOLT_AS_HVREF,
ADC_CMD_SET_SAMPLE_STATE_CNT,
// Commands to enable channels or sensors
ADC_CMD_ENABLE_CHANS, // enables chans and A & B INT if pri != 0
ADC_CMD_ENABLE_TEMP_SENSOR, // enables sensor and INT if priority != 0
ADC_CMD_ENABLE_VOLT_SENSOR, // enables sensor and INT if priority != 0
// Commands to enable hardware triggers or cause software trigger
ADC_CMD_ENABLE_TRIG, // ADCSR.TRGE=1 for sync/async triggers
ADC_CMD_SCAN_NOW, // software trigger start scan
// Commands to poll for scan completion
ADC_CMD_CHECK_SCAN_DONE, // for Normal or GroupA scan
ADC_CMD_CHECK_SCAN_DONE_GROUPA,
ADC_CMD_CHECK_SCAN_DONE_GROUPB,
R01AN1666EJ0220 Rev. 2.20 Page 16 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
typedefstructst_adc_data
{
uint16_t chan[ADC_REG_ARRAY_MAX]; // chnls/indexes used depends upon MCU
uint16_t temp;
uint16_t volt;
uint16_t dbltrig; // Not used on RX63x
} adc_data_t;
2.10.5 RX130 Interface Types (r_s12ad_rx130_if.h)
/***** ADC_OPEN() ARGUMENT DEFINITIONS *****/
typedef enum e_adc_mode
{
ADC_MODE_SS_TEMPERATURE, // single scan temperature sensorADC_MODE_SS_INT_REF_VOLT, // single scan internal ref voltage sensorADC_MODE_SS_ONE_CH, // single scan one channelADC_MODE_SS_MULTI_CH, // 1 trigger source, scan multiple channelsADC_MODE_CONT_ONE_CH, // continuous scan one channelADC_MODE_CONT_MULTI_CH, // continuous scan multiple channelsADC_MODE_SS_ONE_CH_DBLTRIG, // on even triggers save to ADDBLDR &
ADC_TRIG_SOFTWARE = 10, // software trigger; not for Group modes// nor double trigger modes // This is not set to TRSA or TRSB
ADC_TRIG_NONE = 0x3F
} adc_trig_t;
adc_trig_ttrigger; // ADSTRGR.TRSA, default and Group A
trigger source
adc_trig_ttrigger_groupb; // valid only for group modesuint8_tpriority; // for S12ADIO int; 1=lo 15=hi 0=off/polleduint8_tpriority_groupb; // S12GBADI interrupt priority; 0-15
} adc_cfg_t;
/***** ADC_CONTROL() ARGUMENT DEFINITIONS *****/
typedef enum e_adc_cmd
{
// Commands for special hardware configurationsADC_CMD_USE_VREFL0, // Low reference. Default is to use AVSS0.ADC_CMD_USE_VREFH0, // High reference. Default is to use AVCC0.ADC_CMD_SET_DDA_STATE_CNT, // For Disconnect Detection AssistADC_CMD_SET_SAMPLE_STATE_CNT, // Set the conversion time
// Command to configure channels, sensors, and comparatorADC_CMD_ENABLE_CHANS, // Configure channels to scanADC_CMD_ENABLE_TEMP_SENSOR, // "configure" temperature sensorADC_CMD_ENABLE_VOLT_SENSOR, // "configure" internal ref voltage sensorADC_CMD_EN_COMPARATOR_LEVEL, // Enable comparator for threshold compareADC_CMD_EN_COMPARATOR_WINDOW, // Enable comparator for range compare
// Commands to enable hardware triggers or cause software triggerADC_CMD_ENABLE_TRIG, // ADCSR.TRGE=1 for sync/asynchronous
triggers
ADC_CMD_SCAN_NOW, // Software trigger start scan
// Commands to poll for scan completion and comparator results
R01AN1666EJ0220 Rev. 2.20 Page 18 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
ADC_CMD_CHECK_SCAN_DONE, // For Normal or GroupA scanADC_CMD_CHECK_SCAN_DONE_GROUPA,
ADC_CMD_CHECK_SCAN_DONE_GROUPB,
ADC_CMD_CHECK_CONDITION_MET, // comparator condition
{
adc_sst_reg_treg_id;
uint8_tnum_states; // ch16-21, 24-26 use the same value
} adc_sst_t;
R01AN1666EJ0220 Rev. 2.20 Page 19 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
/* for ADC_CMD_CONFIGURE_SCAN */
// Bitwise OR these masks together for desired channels and sensors
// Used for all commands containing a "mask" or "flags" field
{
ADC_ELC_SCAN_DONE = 0, // normal scan or Group A scan completeADC_ELC_GROUPB_SCAN_DONE,
ADC_ELC_ALL_SCANS_DONE,
} adc_elc_t;
typedef struct st_adc_ch_cfg
{
uint32_tchan_mask; // channels/bits 0-7, 16-21, 24-26uint32_tchan_mask_groupb; // valid for group modesadc_grpa_tpriority_groupa; // valid for group modes
R01AN1666EJ0220 Rev. 2.20 Page 20 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
uint32_tadd_mask; // valid if add enabled in Open()adc_diag_tdiag_method; // self-diagnosis virtual channeladc_elc_tsignal_elc; //
} adc_ch_cfg_t;
/* for ADC_CMD_EN_COMPARATOR_LEVEL and ADC_CMD_EN_COMPARATOR_WINDOW */
typedef struct st_adc_cmpwin_cfg // bit-OR ADC_MASK_xxx to
{ // indicate channels/sensors
uint32_tcompare_mask; // channels/sensors to compare
uint32_t inside_window_mask; // condition met when within range
// default=0 met when outside range
uint16_tlevel_lo; // Low-value of window
uint16_tlevel_hi; // High-value of window boolwindowa_enable; // comparison window A enable
} adc_cmpwin_t;
/* for ADC_CMD_CHECK_CONDITION_MET use uint32_t */
/***** ADC_READ() ARGUMENT DEFINITIONS *****/
typedef enum e_adc_reg
{
ADC_REG_CH0 = 0, // Channel 0ADC_REG_CH1,
ADC_REG_CH2,
ADC_REG_CH3,
ADC_REG_CH4,
ADC_REG_CH5,
ADC_REG_CH6,
ADC_REG_CH7, // Channel 7ADC_REG_CH16, // Channel 16ADC_REG_CH17,
ADC_REG_CH18,
ADC_REG_CH19,
ADC_REG_CH20,
ADC_REG_CH21,
ADC_REG_CH24,
ADC_REG_CH25,
ADC_REG_CH26,
ADC_REG_TEMP, // A/D Temperature sensor outputADC_REG_VOLT, // A/D Internal Voltage ReferenceADC_REG_DBLTRIG, // Data Duplication registerADC_REG_DBLTRIGA, // loaded when first multi-source trigger was AADC_REG_DBLTRIGB, // loaded when first multi-source trigger was BADC_REG_SELF_DIAG, // self-diagnosis registerADC_REG_MAX = ADC_REG_SELF_DIAG
} adc_reg_t;
R01AN1666EJ0220 Rev. 2.20 Page 21 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
2.10.6 RX210 Interface Types (r_s12ad_rx210_if.h)
/* ADC_OPEN() ARGUMENT DEFINITIONS */
typedefenume_adc_mode
{
ADC_MODE_SS_TEMPERATURE, // single scan temperature sensor
ADC_MODE_SS_INT_REF_VOLT, // single scan internal ref voltage sensor
ADC_MODE_SS_ONE_CH, // single scan one channel
ADC_MODE_SS_MULTI_CH, // 1 trigger source, scan multiple channels
ADC_MODE_CONT_ONE_CH, // continuous scan one channel
ADC_MODE_CONT_MULTI_CH, // continuous scan multiple channels
ADC_MODE_SS_ONE_CH_DBLTRIG, // on even trig save to ADDBLDR & interrupt
ADC_MODE_SS_MULTI_CH_GROUPED, // 2 trigger sources, scan multiple channels
ADC_MODE_SS_MULTI_CH_GROUPED_DBLTRIG_A,
ADC_MODE_MAX // This definition DO NOT USE for R_ADC_Open() argument
} adc_mode_t;
typedefenum e_adc_trig // trigger sources (set to TRSA bit or TRSB bit)
{
ADC_TRIG_ASYNC_ADTRG = 0, // ext asynchronous trigger; not for Group
// modes nor double trigger modes
ADC_TRIG_SYNC_TRG0AN = 1, // MTU0 TRGA
ADC_TRIG_SYNC_TRG0BN = 2, // MTU0 TRGB
ADC_TRIG_SYNC_TRGAN_OR_UDF4N = 3, // MTUx TRGA or MTU4 underflow
ADC_TRIG_SOFTWARE = 16 // software trigger; not for Group modes
// nor double trigger modes
// This is not set to TRSA or TRSB
} adc_trig_t;
typedefenume_adc_add
{
ADC_ADD_OFF = 0, // addition is turned off for chans/sensors
// add not allowed for temperature sensor
ADC_ADD_TWO_SAMPLES = 1,
ADC_ADD_THREE_SAMPLES = 2,
ADC_ADD_FOUR_SAMPLES = 3
R01AN1666EJ0220 Rev. 2.20 Page 22 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
typedefstructst_adc_cfg
{
adc_add_t add_cnt;
adc_align_t alignment; // ignored if addition used
adc_clear_t clearing;
adc_trig_t trigger; // default and Group A trigger source
adc_trig_t trigger_groupb; // valid only for group modes
uint8_t priority; // for S12ADIO int; 1=lo 15=hi 0=off/polled
uint8_t priority_groupb; // GBADI interrupt priority; 0-15
} adc_cfg_t;
/* ADC_CONTROL() ARGUMENT DEFINITIONS */
typedefenume_adc_cmd
{
// Commands for special hardware configurations
ADC_CMD_SET_DDA_STATE_CNT, // for Disconnect Detection Assist
ADC_CMD_SET_SAMPLE_STATE_CNT,
// Commands to enable channels or sensors
ADC_CMD_ENABLE_CHANS, // enables chans and A & B INT if pri != 0
ADC_CMD_ENABLE_TEMP_SENSOR, // enables sensor and INT if priority != 0
ADC_CMD_ENABLE_VOLT_SENSOR, // enables sensor and INT if priority != 0
// Commands to enable hardware triggers or cause software trigger
ADC_CMD_ENABLE_TRIG, // ADCSR.TRGE=1 for sync/async triggers
ADC_CMD_SCAN_NOW, // software trigger start scan
// Commands to poll for scan completion
ADC_CMD_CHECK_SCAN_DONE, // for Normal or GroupA scan
ADC_CMD_CHECK_SCAN_DONE_GROUPA,
ADC_CMD_CHECK_SCAN_DONE_GROUPB,
uint16_t chan[ADC_REG_ARRAY_MAX];
uint16_t temp;
uint16_t volt;
uint16_t dbltrig;
uint16_t self_diag;
} adc_data_t;
2.10.7 RX230 Interface Types (r_s12ad_rx230_if.h)
/***** ADC_OPEN() ARGUMENT DEFINITIONS *****/
typedefenume_adc_mode
{
ADC_MODE_SS_TEMPERATURE, // single scan temperature sensor
ADC_MODE_SS_INT_REF_VOLT, // single scan internal ref voltage sensor
ADC_MODE_SS_ONE_CH, // single scan one channel
ADC_MODE_SS_MULTI_CH, // 1 trigger source, scan multiple channels
ADC_MODE_CONT_ONE_CH, // continuous scan one channel
ADC_MODE_CONT_MULTI_CH, // continuous scan multiple channels
R01AN1666EJ0220 Rev. 2.20 Page 25 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
ADC_MODE_SS_ONE_CH_DBLTRIG, // on even triggers save to ADDBLDR &
// interrupt
ADC_MODE_SS_MULTI_CH_GROUPED, // 2 trigger sources, scan multiple channels
ADC_MODE_SS_MULTI_CH_GROUPED_DBLTRIG_A,
ADC_MODE_MAX // This definition DO NOT USE for R_ADC_Open() argument
} adc_mode_t;
ADC_TRIG_SOFTWARE = 15, // software trigger; not for Group modes
// nor double trigger modes
// This is not set to TRSA or TRSB
ADC_TRIG_NONE = 0x3F
} adc_trig_t;
adc_trig_t trigger; // ADSTRGR.TRSA, default and Group A
// trigger source
adc_trig_t trigger_groupb; // valid only for group modes
uint8_t priority; // for S12ADIO int; 1=lo 15=hi 0=off/polled
uint8_t priority_groupb; // S12GBADI interrupt priority; 0-15
} adc_cfg_t;
/***** ADC_CONTROL() ARGUMENT DEFINITIONS *****/
typedefenume_adc_cmd
{
// Commands for special hardware configurations
ADC_CMD_USE_VREFL0, // Low reference. Default is to use AVSS0.
ADC_CMD_USE_VREFH0, // High reference. Default is to use AVCC0.
ADC_CMD_SET_DDA_STATE_CNT, // For Disconnect Detection Assist
ADC_CMD_SET_SAMPLE_STATE_CNT, // Set the conversion time
// Command to configure channels, sensors, and comparator
ADC_CMD_ENABLE_CHANS, // Configure channels to scan
ADC_CMD_ENABLE_TEMP_SENSOR, // "configure" temperature sensor
ADC_CMD_ENABLE_VOLT_SENSOR, // "configure" internal ref voltage sensor
ADC_CMD_EN_COMPARATOR_LEVEL, // Enable comparator for threshold compare
ADC_CMD_EN_COMPARATOR_WINDOW, // Enable comparator for range compare
// Commands to enable hardware triggers or cause software trigger
ADC_CMD_ENABLE_TRIG, // ADCSR.TRGE=1 for sync/asynchronous
// triggers
ADC_CMD_SCAN_NOW, // Software trigger start scan
// Commands to poll for scan completion and comparator results
ADC_CMD_CHECK_SCAN_DONE, // For Normal or GroupA scan
ADC_CMD_CHECK_SCAN_DONE_GROUPA,
ADC_CMD_CHECK_SCAN_DONE_GROUPB,
ADC_CMD_CHECK_CONDITION_MET, // comparator condition
{
adc_sst_reg_t reg_id;
uint8_t num_states; // ch16-31 use the same value
} adc_sst_t;
/* for ADC_CMD_CONFIGURE_SCAN */
// Bitwise OR these masks together for desired channels and sensors
// Used for all commands containing a "mask" or "flags" field
{
ADC_ELC_SCAN_DONE = 0, // normal scan or Group A scan complete
ADC_ELC_GROUPB_SCAN_DONE,
ADC_ELC_ALL_SCANS_DONE
} adc_elc_t;
typedefstructst_adc_ch_cfg
{
uint32_t chan_mask; // channels/bits 0-7, 16-31
uint32_t chan_mask_groupb; // valid for group modes
adc_grpa_t priority_groupa; // valid for group modes
uint32_t add_mask; // valid if add enabled in Open()
adc_diag_t diag_method; // self-diagnosis virtual channel
adc_elc_t signal_elc; //
} adc_ch_cfg_t;
/* for ADC_CMD_EN_COMPARATOR_LEVEL and ADC_CMD_EN_COMPARATOR_WINDOW */
typedefstruct st_adc_cmpwin_cfg // bit-OR ADC_MASK_xxx to
{ // indicate channels/sensors
uint32_t compare_mask; // channels/sensors to compare
R01AN1666EJ0220 Rev. 2.20 Page 29 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
uint32_t inside_window_mask; // condition met when within range// default=0 met when outside range
uint16_t level_lo; // Low-value of window
uint16_t level_hi; // High-value of window
bool windowa_enable; // comparison window A enable
} adc_cmpwin_t;
/* for ADC_CMD_EN_COMPARATOR_WINDOW */
typedefstruct st_adc_cmpwin_cfg // bit-OR ADC_MASK_xxx to
{ // indicate channels/sensors
uint32_t compare_mask; // channels/sensors to compare
uint32_t inside_window_mask; // condition met when within range// default=0 met when outside range
uint16_t level_lo; // Low-value of window
uint16_t level_hi; // High-value of window
uint8_t int_priority; // S12CMPI priority level// 1=low 15=hi 0=polled
} adc_cmpwin_t;
/* for ADC_CMD_CHECK_CONDITION_MET use uint32_t */
/***** ADC_READ() ARGUMENT DEFINITIONS *****/
typedefenume_adc_reg
{
ADC_REG_CH0 = 0, // Channel 0
ADC_REG_CH1,
ADC_REG_CH2,
ADC_REG_CH3,
ADC_REG_CH4,
ADC_REG_CH5,
ADC_REG_CH6,
ADC_REG_CH7, // Channel 7
ADC_REG_CH16, // Channel 16
ADC_REG_CH17,
ADC_REG_CH18,
ADC_REG_CH19,
ADC_REG_CH20,
ADC_REG_CH21,
ADC_REG_CH22,
ADC_REG_CH23,
ADC_REG_CH24,
ADC_REG_CH25,
ADC_REG_CH26,
ADC_REG_CH27,
ADC_REG_CH28,
ADC_REG_CH29,
ADC_REG_CH30,
ADC_REG_CH31, // Channel 31
ADC_REG_TEMP, // A/D Temperature sensor output
ADC_REG_VOLT, // A/D Internal Voltage Reference
ADC_REG_DBLTRIG, // Data Duplication register
ADC_REG_DBLTRIGA, // loaded when first multi-source trigger was A
ADC_REG_DBLTRIGB, // loaded when first multi-source trigger was B
ADC_REG_SELF_DIAG, // self-diagnosis register
ADC_REG_MAX = ADC_REG_SELF_DIAG
} adc_reg_t;
R01AN1666EJ0220 Rev. 2.20 Page 30 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
{
ADC_MODE_SS_TEMPERATURE, // single scan temperature sensor
ADC_MODE_SS_INT_REF_VOLT, // single scan internal ref voltage sensor
ADC_MODE_SS_ONE_CH, // single scan one channel
ADC_MODE_SS_MULTI_CH, // 1 trigger source, scan multiple channels
ADC_MODE_CONT_ONE_CH, // continuous scan one channel
ADC_MODE_CONT_MULTI_CH, // continuous scan multiple channels
ADC_MODE_SS_ONE_CH_DBLTRIG, // on even triggers save to ADDBLDR & int
ADC_MODE_SS_MULTI_CH_GROUPED, // 2 trigger sources, scan multiple channels
ADC_MODE_SS_MULTI_CH_GROUPED_DBLTRIG_A,
ADC_MODE_MAX // This definition DO NOT USE for R_ADC_Open() argument
} adc_mode_t;
typedefenume_adc_align
{
ADC_ALIGN_RIGHT = 0x0000,
ADC_ALIGN_LEFT = 0x8000
} adc_align_t;
typedefenume_adc_add
{
ADC_ADD_OFF = 0, // addition is turned off for chans/sensors
ADC_ADD_TWO_SAMPLES = 1, // Two samples are added,Reg ADADC.ADC[1,0]
ADC_ADD_THREE_SAMPLES = 2, // Three samples are added
ADC_ADD_FOUR_SAMPLES = 3, // Four samples are added
ADC_ADD_SIXTEEN_SAMPLES = 5, // Sixteen samples are added
ADC_ADD_AVG_2_SAMPLES = 0x81, // average 2 samples
ADC_ADD_AVG_4_SAMPLES = 0x83, // average 4 samples
adc_speed_t conv_speed; // ADCSR.ADHSC, Two conversion speeds
adc_align_t alignment; // ADCER.ADRFMT, L or R align
adc_add_t add_cnt; // ADADC.ADC, Addition/average cnt select.
adc_clear_t clearing; // ADCER.ACE, Auto clearing enable/disable
adc_trig_t trigger; // ADSTRGR.TRSA, default & Grp A trig src
adc_trig_t trigger_groupb; // valid only for group modes
uint8_t priority; // for S12ADIO int; 1=lo 15=hi 0=off/polled
uint8_t priority_groupb; // S12GBADI interrupt priority; 0-15
} adc_cfg_t;
/* ADC_CONTROL() ARGUMENT DEFINITIONS */
typedefenume_adc_cmd
{
// Commands for special hardware configurations
ADC_CMD_USE_VREFL0, // Low reference. Default is to use AVSS0.
ADC_CMD_USE_VREFH0, // High reference. Default is to use AVCC0.
ADC_CMD_SET_DDA_STATE_CNT, // For Disconnect Detection Assist
ADC_CMD_SET_SAMPLE_STATE_CNT, // Set the conversion time
// Command to configure channels, sensors, and comparator
ADC_CMD_ENABLE_CHANS, // Configure channels to scan
ADC_CMD_ENABLE_TEMP_SENSOR, // "configure" temperature sensor
ADC_CMD_ENABLE_VOLT_SENSOR, // "configure" internal ref voltage sensor
ADC_CMD_EN_COMPARATOR_LEVEL, // Enable comparator for threshold compare
ADC_CMD_EN_COMPARATOR_WINDOW, // Enable comparator for range compare
// Commands to enable hardware triggers or cause software trigger
ADC_CMD_ENABLE_TRIG, // ADCSR.TRGE=1 for sync/async triggers
ADC_CMD_SCAN_NOW, // Software trigger start scan
// Commands to poll for scan completion and comparator results
ADC_CMD_CHECK_SCAN_DONE, // For Normal or GroupA scan
ADC_CMD_CHECK_SCAN_DONE_GROUPA,
ADC_CMD_CHECK_SCAN_DONE_GROUPB,
R01AN1666EJ0220 Rev. 2.20 Page 32 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
{
adc_sst_reg_t reg_id;
uint8_t num_states; // ch16-31 use the same value
} adc_sst_t;
/* for ADC_CMD_CONFIGURE_SCAN */
// Bitwise OR these masks together for desired channels and sensors
// Used for all commands containing a "mask" or "flags" field
{
ADC_ELC_SCAN_DONE = 0, // normal scan or Group A scan complete
ADC_ELC_GROUPB_SCAN_DONE,
ADC_ELC_ALL_SCANS_DONE,
} adc_elc_t;
typedef struct st_adc_ch_cfg
{
uint32_t chan_mask; // channels/bits 0-7, 16-31
uint32_t chan_mask_groupb; // valid for group modes
adc_grpa_t priority_groupa; // valid for group modes
uint32_t add_mask; // valid if add enabled in Open()
adc_diag_t diag_method; // self-diagnosis virtual channel
R01AN1666EJ0220 Rev. 2.20 Page 34 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
adc_elc_t signal_elc; //
} adc_ch_cfg_t;
/* for ADC_CMD_EN_COMPARATOR_LEVEL and ADC_CMD_EN_COMPARATOR_WINDOW */
typedef struct st_adc_cmpwin_cfg // bit-OR ADC_MASK_xxx to
{ // indicate channels/sensors
uint32_t compare_mask; // channels/sensors to compare
uint32_t inside_window_mask; // condition met when within range
// default=0 met when outside range
uint16_t level_lo; // Low-value of window
uint16_t level_hi; // High-value of window
bool windowa_enable; // comparison window A enable
} adc_cmpwin_t;
/* for ADC_CMD_CHECK_CONDITION_MET use uint32_t */
/***** ADC_READ() ARGUMENT DEFINITIONS *****/
typedef enum e_adc_reg
{
ADC_REG_CH0 = 0, // Channel 0
ADC_REG_CH1,
ADC_REG_CH2,
ADC_REG_CH3,
ADC_REG_CH4,
ADC_REG_CH5,
ADC_REG_CH6,
ADC_REG_CH7, // Channel 7
ADC_REG_CH16, // Channel 16
ADC_REG_CH17,
ADC_REG_CH18,
ADC_REG_CH19,
ADC_REG_CH20,
ADC_REG_CH21,
ADC_REG_CH22,
ADC_REG_CH23,
ADC_REG_CH24,
ADC_REG_CH25,
ADC_REG_CH26,
ADC_REG_CH27,
ADC_REG_CH28,
ADC_REG_CH29,
ADC_REG_CH30,
ADC_REG_CH31, // Channel 31
ADC_REG_TEMP, // A/D Temperature sensor output
ADC_REG_VOLT, // A/D Internal Voltage Reference
ADC_REG_DBLTRIG, // Data Duplication register
ADC_REG_DBLTRIGA, // loaded when first multi-source trigger was A
ADC_REG_DBLTRIGB, // loaded when first multi-source trigger was B
ADC_REG_SELF_DIAG, // self-diagnosis register
ADC_REG_MAX = ADC_REG_SELF_DIAG
} adc_reg_t;
R01AN1666EJ0220 Rev. 2.20 Page 35 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
} adc_data_t;
2.10.9 RX63x Interface Types (r_s12ad_rx63x_if.h)
/* ADC_OPEN() ARGUMENT DEFINITIONS */
typedefenume_adc_mode
{
ADC_MODE_SS_TEMPERATURE, // single scan temperature sensor
ADC_MODE_SS_INT_REF_VOLT, // single scan internal ref voltage sensor
ADC_MODE_SS_ONE_CH, // single scan one channel
ADC_MODE_SS_MULTI_CH, // 1 trigger source, scan multiple channels
ADC_MODE_CONT_ONE_CH, // continuous scan one channel
ADC_MODE_CONT_MULTI_CH, // continuous scan multiple channels
ADC_MODE_MAX // This definition DO NOT USE for R_ADC_Open() argument
} adc_mode_t;
typedefenum e_adc_trig // trigger sources (set to ADSTRS bit)
R01AN1666EJ0220 Rev. 2.20 Page 36 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
typedefstructst_adc_cfg
{
adc_add_t add_cnt;
adc_align_t alignment; // ignored if addition used
adc_clear_t clearing;
adc_speed_t conv_speed;
adc_trig_t trigger;
uint8_t priority; // for S12ADIO int; 1=lo 15=hi 0=off/polled
} adc_cfg_t;
/* ADC_CONTROL() ARGUMENT DEFINITIONS */
typedefenume_adc_cmd
{
// Commands for special hardware configurations
ADC_CMD_SET_SAMPLE_STATE_CNT,
// Commands to enable channels or sensors
ADC_CMD_ENABLE_CHANS, // enables chans and INT if priority != 0
ADC_CMD_ENABLE_TEMP_SENSOR, // enables sensor and INT if priority != 0
ADC_CMD_ENABLE_VOLT_SENSOR, // enables sensor and INT if priority != 0
// Commands to enable hardware triggers or cause software trigger
ADC_CMD_ENABLE_TRIG, // ADCSR.TRGE=1 for sync/async triggers
ADC_CMD_SCAN_NOW, // software trigger start scan
// Commands to poll for scan completion
ADC_CMD_CHECK_SCAN_DONE, // for Normal
// Advanced control commands
ADC_CMD_DISABLE_TRIG, // ADCSR.TRGE=0 for sync/async trigs
ADC_CMD_DISABLE_INT, // interrupt disable; ADCSR.ADIE=0
ADC_CMD_ENABLE_INT, // interrupt enable; ADCSR.ADIE=1
} adc_cmd_t;
/* for ADC_CMD_SET_SAMPLE_STATE_CNT */
typedefenum e_adc_sst_reg // sample state registers
ADC_MODE_SS_ONE_CH, // single scan one channel
ADC_MODE_SS_MULTI_CH, // 1 trigger source, scan multiple channels
ADC_MODE_CONT_ONE_CH, // continuous scan one channel
ADC_MODE_CONT_MULTI_CH, // continuous scan multiple channels
ADC_MODE_SS_ONE_CH_DBLTRIG, // on even triggers save to ADDBLDR & int
ADC_MODE_SS_MULTI_CH_GROUPED, // 2 trigger sources, scan multiple channels
ADC_MODE_SS_MULTI_CH_GROUPED_DBLTRIG_A,
ADC_MODE_MAX // This definition DO NOT USE for R_ADC_Open() argument
ADC_TRIG_SOFTWARE = 64, // software trigger; not for Group// modes nor double trigger modes // This is not set to TRSA or TRSB
ADC_TRIG_NONE = 0x3F
} adc_trig_t;
typedefstructst_adc_cfg
{
adc_res_t resolution; // 8, 10, or 12-bit
adc_align_t alignment; // ignored if addition used
adc_add_t add_cnt; // add or average samples
adc_clear_t clearing; // clear after read
adc_trig_t trigger; // default and Group A trigger source
adc_trig_t trigger_groupb; // valid only for group modes
uint8_t priority; // for S12ADIO int; 1=lo 15=hi 0=off/polled
uint8_t priority_groupb; // S12GBADI interrupt priority; 0-15
} adc_cfg_t;
/***** ADC_CONTROL() ARGUMENT DEFINITIONS *****/
typedefenume_adc_cmd
{
// Commands for special hardware configurations
ADC_CMD_SET_DDA_STATE_CNT, // for Disconnect Detection Assist
ADC_CMD_SET_SAMPLE_STATE_CNT,
// Command to configure channels, sensors, and comparator
ADC_CMD_ENABLE_CHANS, // configure channels and sensors to scan
R01AN1666EJ0220 Rev. 2.20 Page 40 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
ADC_CMD_EN_COMPARATOR_LEVEL, // enable comparator for threshold compare
ADC_CMD_EN_COMPARATOR_WINDOW, // enable comparator for range compare
// Commands to enable hardware triggers or cause software trigger
ADC_CMD_ENABLE_TRIG, // ADCSR.TRGE=1 for sync/async triggers
ADC_CMD_SCAN_NOW, // software trigger start scan
// Commands to poll for scan completion and comparator results
ADC_CMD_CHECK_SCAN_DONE, // for Normal or GroupA scan
ADC_CMD_CHECK_SCAN_DONE_GROUPA,
ADC_CMD_CHECK_SCAN_DONE_GROUPB,
ADC_CMD_CHECK_CONDITION_MET, // comparator condition
#define ADC_SST_SH_CNT_MIN (4) // minimum sample&hold states
#define ADC_SST_SH_CNT_MAX (255) // maximum sample&hold states
R01AN1666EJ0220 Rev. 2.20 Page 42 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
#define ADC_SST_SH_CNT_DEFAULT (24) // default sample&hold states
typedefstruct st_adc_ch_cfg // bit 0 is ch0; bit 15 is ch15
{
uint32_t scan_mask; // channels/bits 0-15
uint32_t scan_mask_groupb; // valid for group modes
adc_grpa_t priority_groupa; // valid for group modes
uint32_t add_mask; // valid if add enabled in Open()
adc_diag_t diag_method; // self-diagnosis virtual channelbool anex_enable; // unit1: use external amplifier
uint8_t sample_hold_mask; // channels/bits 0-2
uint8_t sample_hold_states; // minimum .4us
} adc_ch_cfg_t;
/* for ADC_CMD_EN_COMPARATOR_LEVEL and ADC_CMD_EN_COMPARATOR_WINDOW */
typedefstruct st_adc_cmpwin_cfg // bit-OR ADC_MASK_xxx to
{// indicate channels/sensors
uint32_t compare_mask; // channels/sensors to compare
uint32_t inside_window_mask; // condition met when within range// default=0 met when outside range
uint16_t level_lo;
uint16_t level_hi;
uint8_t int_priority; // S12CMPI priority level// 1=low 15=hi 0=polled
} adc_cmpwin_t;
/***** ADC_READ() ARGUMENT DEFINITIONS *****/
typedefenume_adc_reg
{
ADC_REG_CH0 = 0,
ADC_REG_CH1 = 1,
ADC_REG_CH2 = 2,
ADC_REG_CH3 = 3,
ADC_REG_CH4 = 4,
ADC_REG_CH5 = 5,
ADC_REG_CH6 = 6,
ADC_REG_CH7 = 7, // last channel unit0
ADC_REG_CH8 = 8,
ADC_REG_CH9 = 9,
ADC_REG_CH10 = 10,
ADC_REG_CH11 = 11,
ADC_REG_CH12 = 12,
ADC_REG_CH13 = 13,
ADC_REG_CH14 = 14,
ADC_REG_CH15 = 15,
ADC_REG_CH16 = 16,
ADC_REG_CH17 = 17,
ADC_REG_CH18 = 18,
ADC_REG_CH19 = 19,
ADC_REG_CH20 = 20,
ADC_REG_TEMP,
ADC_REG_VOLT,
// both units
ADC_REG_DBLTRIG,
ADC_REG_DBLTRIGA, // loaded when first multi-source trigger was A
ADC_REG_DBLTRIGB, // loaded when first multi-source trigger was B
ADC_REG_SELF_DIAG,
R01AN1666EJ0220 Rev. 2.20 Page 43 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
ADC_MODE_SS_ONE_CH, // single scan one channel
ADC_MODE_SS_MULTI_CH, // 1 trigger source, scan multiple channels
ADC_MODE_CONT_ONE_CH, // continuous scan one channel
ADC_MODE_CONT_MULTI_CH, // continuous scan multiple channels
ADC_MODE_SS_ONE_CH_DBLTRIG, // on even triggers save to ADDBLDR & int
ADC_MODE_SS_MULTI_CH_GROUPED, // 2 trigger sources, scan multiple channels
ADC_MODE_SS_MULTI_CH_GROUPED_GROUPC,// 3 trigger sources, scan multiple
// channels
ADC_MODE_SS_MULTI_CH_GROUPED_DBLTRIG_A,
ADC_MODE_SS_MULTI_CH_GROUPED_DBLTRIG_A_GROUPC,
ADC_MODE_MAX // This definition DO NOT USE for R_ADC_Open() argument
ADC_TRIG_HW_MAX,
ADC_TRIG_SOFTWARE = 64// software trigger; not for Group modes// nor double trigger modes
} adc_trig_t;
typedefstructst_adc_cfg
R01AN1666EJ0220 Rev. 2.20 Page 45 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
{
adc_res_t resolution; // 8, 10, or 12-bit
adc_align_t alignment; // ignored if addition used
adc_add_t add_cnt; // add or average samples
adc_clear_t clearing; // clear after read
adc_trig_t trigger; // default and Group A trigger source
adc_trig_t trigger_groupb; // valid only for group modes
adc_trig_t trigger_groupc; // valid only for group modes
uint8_t priority; // for S12ADIO int; 1=lo 15=hi 0=off/polled
uint8_t priority_groupb; // S12GBADI interrupt priority; 0-15
uint8_t priority_groupc; // S12GCADI interrupt priority; 0-15
} adc_cfg_t;
/***** ADC_CONTROL() ARGUMENT DEFINITIONS *****/
typedefenume_adc_cmd
{
// Commands for special hardware configurations
ADC_CMD_SET_DDA_STATE_CNT, // for Disconnect Detection Assist
ADC_CMD_SET_SAMPLE_STATE_CNT,
// Command to configure channels, sensors, and comparator
ADC_CMD_CONFIGURE_SCAN, // configure channels and sensors to scan
ADC_CMD_EN_COMPARATOR_LEVEL, // enable comparator for threshold compare
ADC_CMD_EN_COMPARATOR_WINDOW, // enable comparator for range compare
// Commands to enable hardware triggers or cause software trigger
ADC_CMD_ENABLE_TRIG, // ADCSR.TRGE=1 for sync/async triggers
ADC_CMD_SCAN_NOW, // software trigger start scan
// Commands to poll for scan completion and comparator results
ADC_CMD_CHECK_SCAN_DONE, // for Normal or GroupA scan
ADC_CMD_CHECK_SCAN_DONE_GROUPA,
ADC_CMD_CHECK_SCAN_DONE_GROUPB,
ADC_CMD_CHECK_SCAN_DONE_GROUPC,
ADC_CMD_CHECK_CONDITION_MET, // comparator condition
ADC_CMD_CHECK_CONDITION_METB, // comparator condition
/* for ADC_CMD_EN_COMPARATOR_LEVEL and ADC_CMD_EN_COMPARATOR_WINDOW */
typedefstruct st_adc_cmpwin_cfg // Window A bit-OR ADC_MASK_xxx to
{// indicate channels/sensors
// Window B ADC_COMP_WINB_xxx to
// indicate channels/sensors
uint32_t compare_mask; // channels/sensors to compare
uint32_t compare_maskb; // channels/sensors to compareb
uint32_t inside_window_mask; // condition met when within range// default=0 met when outside range
uint32_t inside_window_maskb;// condition met when within range// default=0 met when outside range
uint16_t level_lo;
uint16_t level_lob;
uint16_t level_hi;
uint16_t level_hib;
adc_comp_cond_t comp_cond; // window A/B complex conditions setting
uint8_t int_priority; // S12CMPAI and S12CMPBI priority level// 1=low 15=hi 0=polled
boolwindowa_enable; // comparison window A enable
boolwindowb_enable; // comparison window B enable
} adc_cmpwin_t;
/***** ADC_READ() ARGUMENT DEFINITIONS *****/
typedefenume_adc_reg
{
R01AN1666EJ0220 Rev. 2.20 Page 49 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
ADC_REG_CH0 = 0,
ADC_REG_CH1 = 1,
ADC_REG_CH2 = 2,
ADC_REG_CH3 = 3,
ADC_REG_CH4 = 4,
ADC_REG_CH5 = 5,
ADC_REG_CH6 = 6,
ADC_REG_CH7 = 7, // last channel unit0
ADC_REG_CH8 = 8,
ADC_REG_CH9 = 9,
ADC_REG_CH10 = 10,
ADC_REG_CH11 = 11,
ADC_REG_CH12 = 12,
ADC_REG_CH13 = 13,
ADC_REG_CH14 = 14,
ADC_REG_CH15 = 15,
ADC_REG_CH16 = 16,
ADC_REG_CH17 = 17,
ADC_REG_CH18 = 18,
ADC_REG_CH19 = 19,
ADC_REG_CH20 = 20,
ADC_REG_TEMP,
ADC_REG_VOLT,
// both units
ADC_REG_DBLTRIG,
ADC_REG_DBLTRIGA, // loaded when first multi-source trigger was A
ADC_REG_DBLTRIGB, // loaded when first multi-source trigger was B
ADC_REG_SELF_DIAG,
ADC_REG_MAX
R01AN1666EJ0220 Rev. 2.20 Page 50 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
2.11 Return Values
These are the different error codes API functions can return. The enum is found in r_s12ad_rx_if.h along with the API
function declarations.
typedefenum e_adc_err // ADC API error codes
{
ADC_SUCCESS = 0,
ADC_ERR_AD_LOCKED, // Open() call is in progress elsewhere
ADC_ERR_AD_NOT_CLOSED, // peripheral still running in another mode
ADC_ERR_MISSING_PTR, // missing required pointer argument
ADC_ERR_INVALID_ARG, // argument is not valid for parameter
ADC_ERR_ILLEGAL_ARG, // argument is illegal for mode
ADC_ERR_SCAN_NOT_DONE, // default, Group A, or Group B scan not done
ADC_ERR_TRIG_ENABLED, // scan running, cannot configure comparator
ADC_ERR_CONDITION_NOT_MET, // no chans/sensors passed comparator condition
ADC_ERR_UNKNOWN // unknown hardware error
} adc_err_t;
2.12 Adding a FIT Module to Your Project
This module must be added, in the e² studio, to each project in which it is used.
There are two methods for adding this module: using the FIT plugin, and adding it manually.
When the FIT plugin is used, FIT modules can be added to projects easily, and the include file path can be updated
automatically. Accordingly, we recommend using the FIT plugin when adding FIT modules to projects.
Methods for adding FIT modules to projects using the FIT plugin are described in section 3, Adding FIT Modules to e
studio Projects Manually, in the “Adding Firmware Integration Technology Modules to Projects (R01AN1723)”
application note. See that application note for details.
See section 4, Configuring the FIT Module for the methods for addition FIT modules to projects manually.
When using a FIT module the board support package FIT module (BSP module) must also be added to the project. See
the “Board Support Package Module Using Firmware Integration Technology (R01AN1685)” application note for
details on method for adding the BSP module.
2
R01AN1666EJ0220 Rev. 2.20 Page 51 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
Function
Description
R_ADC_Open()
Applies power to the A/D peripheral (and TEMPS peripheral on RX210 and RX63x),
sets the operational mode, trigger sources, interrupt priority, and configurations common
R_ADC_Control()
Provides commands for enabling channels and sensors, and for runtime operations.
R_ADC_Read()
Reads conversion results from a single channel, sensor, double trigger, or self-diagnosis
R_ADC_ReadAll()
Reads conversion results from all potential channel sources, enabled or not.
R_ADC_Close()
Ends any scan in progress, disables interrupts, and removes power to the A/D peripheral.
R_ADC_GetVersion()
Returns at runtime the driver version number.
3. API Functions
3.1 Summary
The following functions are included in this design:
to all channels and sensors. Optionally takes a callback function pointer for notifying the
user at interrupt level whenever a scan has completed.
These include enabling/disabling trigger sources and interrupts, initiating a software
trigger, and checking for scan completion.
register.
R01AN1666EJ0220 Rev. 2.20 Page 52 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
3.2 R_ADC_Open()
This function applies power to the A/D peripheral, sets the operational mode, trigger sources, interrupt priority, and
configurations common to all channels and sensors. If interrupt priority is non-zero, the function takes a callback
function pointer for notifying the user at interrupt level whenever a scan has completed or comparator condition met.
The function initializes the S12AD FIT module. This function must be called before calling any other API functions.
0 or 1. For MCUs with only one unit 0 should be passed (only the RX64M/RX71M/RX65x have 2 units).
mode
Operational mode. See type adc_mode_t in section 2.10 for the MCU being used.
The mode indicates the type of scan to be performed. For ADC_MODE_SS_MULTI_CH_
GROUPED_DBLTRIG_A, only one channel can be in Group A.
p_cfg
Pointer to configuration structure. See type adc_cfg_t in section 2.10 for the MCU being used.
The resolution field uses the adc_res_t enum. Lower resolution results in shorter conversion times (RX64M,
RX71M and RX65x).
The .alignment, .clearing, and .conversion fields use the adc_align_t, adc_clear_t, enums. If addition is
enabled, the .alignment field is ignored.
The .add_cnt field uses the adc_add_t enum. The number of samples added applies to all channels and sensors
(except for Temperature sensor on RX210). An individual channel may opt out of any addition using the Control()
function.
The .trigger and .trigger_groupb fields use the adc_trig_t enum for trigger sources.
The .priority and .groupb_priority fields use interrupt priority levels ranging from 1 (lowest) to 15 (highest). If the
priority is set to 0, the corresponding interrupt is disabled and the application must poll for the scan to complete
(use Control() function).
p_callback
Optional pointer to function called from interrupt when a scan completes
Return Values
ADC_SUCCESS: Successful
ADC_ERR_AD_LOCKED: Open() call is in progress elsewhere
ADC_ERR_AD_NOT_CLOSED: Peripheral is still running in another mode; Perform R_ADC_Close() first
ADC_ERR_INVALID_ARG: mode or element of p_cfg structure has invalid value
ADC_ERR_ILLEGAL_ARG: an argument is illegal based upon mode
ADC_ERR_MISSING_PTR: p_cfg pointer is FIT_NO_PTR/NULL
Properties
Prototyped in file “r_s12ad_rx_if.h”
Description
Applies power to the A/D peripheral, sets the operational mode, trigger sources, interrupt priority, and
configurations common to all channels and sensors. Setting the interrupt priority to 0 indicates that the
application will poll until scanning completes (see Control()). With a non-zero interrupt priority (interrupt
R01AN1666EJ0220 Rev. 2.20 Page 53 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
usage), a callback function is required. This function is called by the interrupts whenever a scan has
completed with an argument indicating which scan completed.
To set values of parameters used in this function, first clear all members of parameters to 0, and then set values.
Reentrant
No. For MCUs with a single unit this function should only be called once before a call to Close(). For the
RX64M/RX71M/RX65x this function may be called once for each unit.
Example (RX110, RX111, RX113)
adc_cfg_t config;
/* Clear all fields of the adc_cfg_t structure */
memset(&config, 0, sizeof(config));
/* INITIALIZE FOR SINGLE SCAN OF TEMPERATURE SENSOR
* - use software trigger to start scan; poll for completion
* - don't do any summing of conversion values
* - keep the data registers aligned right, and clear after reading is off
* - use normal speed conversion
*/
config.trigger = ADC_TRIG_SOFTWARE;
config.priority = 0; // denotes polling!
config.add_cnt = ADC_ADD_OFF;
config.alignment = ADC_ALIGN_RIGHT;
config.clearing = ADC_CLEAR_AFTER_READ_OFF;
config.conv_speed = ADC_CONVERT_SPEED_NORM;
MPC.P40PFS.BYTE = 0x80; // Pin Func Select P40 AN000
PORT4.PDR.BIT.B0 = 0; // set AN pin direction to input (dflt)
PORT4.PMR.BIT.B0 = 1; // set AN pin mode to peripheral
MPC.PB0PFS.BIT.PSEL = 0x09; // Pin Func Select PB0 ADTRIG0; SW3 on RSKRX111
PORTB.PDR.BIT.B0 = 0; // set ADTRIG0 pin direction to input (dflt)
PORTB.PMR.BIT.B0 = 1; // set ADTRIG0 pin mode to peripheral
R_BSP_RegisterProtectEnable(BSP_REG_PROTECT_MPC);
The application must set the A/D conversion clock (PCKD) prior to calling Open().Refer to User’s Hardware Manual
for PCLKB/ADCLK frequency ratios.
If a Continuous mode is selected, it is recommended not to use the S12ADI interrupt. That causes the majority of the
processing time to be spent at the interrupt level.
If interrupts are in use, a callback function is required which takes a single argument. This is a pointer to a structure
which is cast to a void pointer (provides consistency with other FIT module callback functions). See type
adc_mode_t in section 2.10 for the MCU being used.
Refer to the User’s
. The following is a sample
R01AN1666EJ0220 Rev. 2.20 Page 54 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
An example template for a callback function is provided here:
if (args->event == ADC_EVT_SCAN_COMPLETE)
{
// Read results here
nop();
}
else if (args->event == ADC_EVT_GROUPB_SCAN_COMPLETE)
{
// Read Group B results here
nop();
}
else if (args->event == ADC_EVT_CONDITION_MET)
{
// Process chans/sensors indicated in args->compare_flags
nop();
}
}
Special Notes (RX 63x):
Even if register automatic clearing is enabled for temperature sensor output or internal reference voltage, the
A/D conversion result is not cleared.
After the R_ADC_Open function is executed, wait at least 10 ms before executing A/D conversion.
Special Notes (RX110/RX111/RX113/RX210/RX130/RX230/RX231/RX65x/RX64M/RX71M):
After the R_ADC_Open function is executed, wait at least 1 µs before executing A/D conversion.
R01AN1666EJ0220 Rev. 2.20 Page 55 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
3.3 R_ADC_Control()
This function provides commands for enabling channels and sensors and for runtime operations. These include
enabling/disabling trigger sources and interrupts, initiating a software trigger, and checking for scan completion.
Format
adc_err_t R_ADC_Control(uint8_t unit,
adc_cmd_t const cmd,
void * const p_cfg);
Parameters
unit
0 or 1. For MCUs with only one unit 0 should be passed (only the RX64M/RX71M/RX65x have 2 units).
cmd
Command to run. See type adc_cmd_t in section 2.10 for the MCU being used.
Some commands require arguments. All other commands should use FIT_NO_PTR/NULL for the p_cfg argument.
p_cfg
Pointer to optional configuration structure. FIT_NO_PTR/NULL for most commands. See type adc_ch_cfg_t
in section 2.10 for the MCU being used.
Return Values
ADC_SUCCESS: Successful
ADC_ERR_MISSING_PTR: p_cfg pointer is FIT_NO_PTR/NULL when required as an argument
ADC_ERR_INVALID_ARG: cmd or element of p_cfg structure has invalid value.
ADC_ERR_ILLEGAL_ARG: cmd is illegal based upon mode
ADC_ERR_SCAN_NOT_DONE: The requested scan has not completed
ADC_ERR_TRIG_ENABLED: Cannot configure comparator because scan still running
ADC_ERR_CONDITION_NOT_MET: No channels/sensors met the comparison condition
Properties
Prototyped in file “r_s12ad_rx_if.h”
Description
Provides commands for enabling channels and sensors and for runtime operations. These include enabling/disabling
trigger sources and interrupts, initiating a software trigger, and checking for scan completion.
After an Open() call, the following sequence of Control() commands should be issued (MCU dependent):
1) Optionally issue commands for special hardware configuration (ADC_CMD_SET_DDA_STATE_CNT and/or
3) Issue a command to enable hardware triggers or cause a software trigger (ADC_CMD_TRIG_ENABLE or
ADC_CMD_SCAN_NOW).
4) If polling instead of using interrupts, check for completion of scan or comparator match
(ADC_CMD_CHECK_SCAN_DONE, ADC_CMD_CHECK_SCAN_DONE_GROUPA or
ADC_CMD_CHECK_SCAN_DONE_GROUPB, ADC_CMD_CHECK_CONDITION_MET).
5) When the scan completes, the converted data is accessed using the Read() function at the application or
interrupt level.
To set values of parameters used in this function, first clear all members of parameters to 0, and then set values.
R01AN1666EJ0220 Rev. 2.20 Page 56 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
Reentrant
Yes, but in general should not be used as such. A valid case for reentrancy would be in group mode with one task
performing the ADC_CMD_CHECK_SCAN_DONE_GROUPA and another performing the
ADC_CMD_CHECK_SCAN_DONE_GROUPB. Other commands such as enabling/disabling triggers or interrupts
would affect operations being performed by another task and reentrancy of this kind should be avoided.
Example 1: Single Channel Polling Unit 0 (RX64M, RX71M, RX65x only)
/* Clear all fields of the adc_cfg_t structure */
memset(&config, 0, sizeof(config));
/* Open ADC for software trigger, single scan temperature sensor, and polling */
config.resolution = ADC_RESOLUTION_10_BIT;
config.trigger = ADC_TRIG_SOFTWARE;
config.priority = 0; // denotes polling
config.add_cnt = ADC_ADD_OFF;
config.alignment = ADC_ALIGN_RIGHT;
config.clearing = ADC_CLEAR_AFTER_READ_OFF;
adc_err = R_ADC_Open(1, ADC_MODE_SS_ONE_CH, &config, NULL);
/* DO SPECIAL HARDWARE CONFIGURATION */
/* Clear all fields of the adc_sst_t structure */
memset(&sst, 0, sizeof(sst));
/* Clear all fields of the adc_ch_cfg_t structure */
memset(&ch_cfg, 0, sizeof(ch_cfg));
/* Set number of sampling states for 4us sample *
/* For PCLKD=60MHz, 1 state = 1/60MHz = 16.7ns, 4us/16.7ns = 240 states */
sst.reg_id = ADC_SST_TEMPERATURE;
sst.num_states = 240;
adc_err = R_ADC_Control(1, ADC_CMD_SET_SAMPLE_STATE_CNT, &sst);
/* CONFIGURE SCAN */
ch_cfg.chan_mask = ADC_MASK_TEMP;
ch_cfg.diag_method = ADC_DIAG_OFF;
ch_cfg.anex_enable = false;
ch_cfg.sample_hold_mask = 0; // not available on unit 1
adc_err = R_ADC_Control(1, ADC_CMD_ENABLE_CHANS, &ch_cfg);
/* After open, wait 1 us or longer before A/D conversion starts */
/* CAUSE SOFTWARE TRIGGER */
adc_err = R_ADC_Control(1, ADC_CMD_SCAN_NOW, NULL);
/* WAIT FOR SCAN TO COMPLETE */
while (R_ADC_Control(1, ADC_CMD_CHECK_SCAN_DONE, NULL) == ADC_ERR_SCAN_NOT_DONE)
{
}
/* READ RESULT */
adc_err = R_ADC_Read(1, ADC_REG_TEMP, &data);
R01AN1666EJ0220 Rev. 2.20 Page 58 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
Example 3: Grouped Channels with Interrupt Triggers, Double Trigger on Group A, and
Averaging (RX64M, RX71M, RX65x)
adc_cfg_t config;
adc_ch_cfg_t ch_cfg;
/* INITIALIZE MTU HERE (USED FOR TRIGGER SOURCES) */
/* OPEN ADC */
/* Clear all fields of each structure */
memset(&config, 0, sizeof(config));
memset(&ch_cfg, 0, sizeof(ch_cfg));
/* INITIALIZE ADC FOR GROUP SCANNING WITH DOUBLE TRIGGER
* - use synchronous trigger TRGA0N to start Group A scan; int priority 4
* - use synchronous trigger TRG0N to start Group B scan; int priority 5
* - allow each channel to be scanned four times and averaged before continuing
* - do not clear registers after reading
*/
config.resolution = ADC_RESOLUTION_8_BIT;
config.trigger = ADC_TRIG_SYNC_TRG0AN;
config.priority = 4;
config.trigger_groupb = ADC_TRIG_SYNC_TRG0EN;
config.priority_groupb= 5;
config.add_cnt = ADC_ADD_AVG_4_SAMPLES;
config.alignment = ADC_ALIGN_RIGHT;
config.clearing = ADC_CLEAR_AFTER_READ_OFF;
R_ADC_Open(1, ADC_MODE_SS_MULTI_CH_GROUPED_DBLTRIG_A, &config, MyCallback);
/* CONFIGURE SCAN */
/* Can only have 1 channel for double triggering, and is only channel in Group A
Have channel 8 as Group A, have 2, 3, and 9 as Group B
Perform addition/average on all channels except 9
*/
ch_cfg.chan_mask = ADC_MASK_CH8;
ch_cfg.chan_mask_groupb = ADC_MASK_CH2 | ADC_MASK_CH3 | ADC_MASK_CH9;
ch_cfg.priority_groupa = ADC_GRPA_PRIORITY_OFF;
ch_cfg.add_mask = ADC_MASK_CH8 | ADC_MASK_CH2 | ADC_MASK_CH3;
ch_cfg.diag_method = ADC_DIAG_OFF;
ch_cfg.anex_enable = false;
ch_cfg.sample_hold_mask = 0;
R_ADC_Control(1, ADC_CMD_ENABLE_CHANS, &ch_cfg);
/* After open, wait 1 us or longer before A/D conversion starts */
/* The callback is called twice from interrupt level- once after each
* group scan completes. The order depends upon the trigger order.
*/
void MyCallback(void *p_args)
{
adc_cb_args_t *args;
uint16_t dbltrg,data2,data3,data8,data9;
R01AN1666EJ0220 Rev. 2.20 Page 59 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
args = (adc_cb_args_t *)p_args;
/* READ RESULTS */
if (args->event == ADC_EVT_SCAN_COMPLETE)
{
/* From S12ADIO interrupt, Group A scan complete, read registers */
R_ADC_Read(1, ADC_REG_CH8, &data8); R_ADC_Read(1, ADC_REG_DBLTRIG, &dbltrg);
}
else if (args->event == ADC_EVT_SCAN_COMPLETE_GROUPB)
{
/* From GBADI interrupt, Group B scan complete, read registers */
R_ADC_Read(1, ADC_REG_CH2, &data2); R_ADC_Read(1, ADC_REG_CH3, &data3); R_ADC_Read(1, ADC_REG_CH9, &data9);
}
/* process data, or set flag for application level to do so */
}
Example 4: 3 Grouped Channels with Interrupt Triggers (RX65x)
adc_cfg_t config;
adc_ch_cfg_t ch_cfg;
/* INITIALIZE MTU HERE (USED FOR TRIGGER SOURCES) */
/* OPEN ADC */
/* Clear all fields of each structure */
memset(&config, 0, sizeof(config));
memset(&ch_cfg, 0, sizeof(ch_cfg));
/* INITIALIZE ADC FOR GROUP SCANNING WITH DOUBLE TRIGGER
* - use synchronous trigger TRGA0N to start Group A scan; int priority 4
* - use synchronous trigger TRGA1N to start Group B scan; int priority 5
* - use synchronous trigger TRGA2N to start Group C scan; int priority 6
* - allow each channel to be scanned four times and averaged before continuing
* - do not clear registers after reading
*/
config.resolution = ADC_RESOLUTION_8_BIT;
config.trigger = ADC_TRIG_SYNC_TRG0AN;
config.priority = 4;
config.trigger_groupb = ADC_TRIG_SYNC_TRG1AN;
config.priority_groupb= 5;
config.trigger_groupc = ADC_TRIG_SYNC_TRG2AN;
config.priority_groupc= 6;
config.add_cnt = ADC_ADD_OFF;
config.alignment = ADC_ALIGN_RIGHT;
config.clearing = ADC_CLEAR_AFTER_READ_OFF;
R_ADC_Open(0, ADC_MODE_SS_MULTI_CH_GROUPED_GROUPC, &config, MyCallback);
/* CONFIGURE SCAN */
/* Clear all fields of the adc_ch_cfg_t structure */
memset(&ch_cfg, 0, sizeof(ch_cfg));
R01AN1666EJ0220 Rev. 2.20 Page 60 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
/* Have channel 1 and 2 as Group A, have 3 and 4 as Group B,
have 5 and 6 as Group C
Perform addition/average on all channels except 9
*/
ch_cfg.scan_mask = ADC_MASK_CH1 | ADC_MASK_CH2;
ch_cfg.scan_mask_groupb = ADC_MASK_CH3 | ADC_MASK_CH4;
ch_cfg.scan_mask_groupc = ADC_MASK_CH5 | ADC_MASK_CH6;
ch_cfg.priority_groupa = ADC_GRPA_PRIORITY_OFF;
ch_cfg.add_mask = 0;
ch_cfg.diag_method = ADC_DIAG_OFF;
ch_cfg.anex_enable = false;
ch_cfg.sample_hold_mask = 0;
R_ADC_Control(0, ADC_CMD_CONFIGURE_SCAN, &ch_cfg);
/* After open, wait 1 us or longer before A/D conversion starts */
/* The callback is called twice from interrupt level- once after each
* group scan completes. The order depends upon the trigger order.
*/
void MyCallback(void *p_args)
{
adc_cb_args_t *args;
uint16_t data1,data2,data3,data4,data5,data6;
args = (adc_cb_args_t *)p_args;
/* READ RESULTS */
if (args->event == ADC_EVT_SCAN_COMPLETE)
{
/* From S12ADIO interrupt, Group A scan complete, read registers */
R_ADC_Read(0, ADC_REG_CH1, &data1);
R_ADC_Read(0, ADC_REG_CH2, &data2);
}
else if (args->event == ADC_EVT_SCAN_COMPLETE_GROUPB)
{
/* From GBADI interrupt, Group B scan complete, read registers */
R_ADC_Read(0, ADC_REG_CH3, &data3);
R_ADC_Read(0, ADC_REG_CH4, &data4);
}
else if (args->event == ADC_EVT_SCAN_COMPLETE_GROUPC)
{
/* From GCADI interrupt, Group C scan complete, read registers */
R_ADC_Read(0, ADC_REG_CH5, &data5);
R_ADC_Read(0, ADC_REG_CH6, &data6);
}
/* process data, or set flag for application level to do so */
}
R01AN1666EJ0220 Rev. 2.20 Page 61 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
Example 5: Multiple Channels with Interrupt Trigger and Comparator Checking (RX64M,
RX71M)
if (args->event == ADC_EVT_CONDITION_MET)
{
if (args->compare_flags & ADC_MASK_CH3)
{
// processing when channel 3 voltage is too low
}
else
{
// processing when channel 4 voltage is too low
}
}
}
Example 6: Multiple Channels with Interrupt Trigger and 2 Comparator Checking (RX65x)
if (args->event == ADC_EVT_CONDITION_MET)
{
if (args->compare_flags & ADC_MASK_CH3)
{
// processing when channel 3 voltage is too low
}
else
{
// processing when channel 4 voltage is too low
}
}
if (args->event == ADC_EVT_CONDITION_METB)
{
// processing when channel 5 voltage is too low
}
}
R01AN1666EJ0220 Rev. 2.20 Page 64 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
A/D Conversion Channel Settings
Commands for the R_ADC_Control Function
A/D conversion
start trigger
Waits completion of A/D
conversion
ADC_CMD_CHECK_SCAN_
DONE
Other than
software trigger
ADC_CMD_CHECK_SCAN_
DONE_GROUPA
ADC_CMD_CHECK_SCAN_
DONE_GROUPA
Other than
software trigger
ADC_CMD_CHECK_SCAN_
DONE_GROUPA
ADC_CMD_CHECK_SCAN_
DONE_GROUPC
Special Notes (RX Family Common):
When the A/D conversion start (ADST) bit is 1, settings such as mode must not be changed using this function.
However, the conversion status or the comparison result can be obtained.
When switching channels used for A/D conversion or settings, call the R_ADC_Close() function once and then call the
R_ADC_Open() function again to start.
When waiting completion of A/D conversion using the R_ADC_Control function, use the following commands.
Mode
Interrupt Starts A/D conversion
Software trigger ADC_CMD_SCAN_NOW
Single scan
Continuous
scan
Group scan
Disabled ADC_CMD_ENABLE_TRIG
Software trigger Disabled ADC_CMD_SCAN_NOW
Disabled ADC_CMD_ENABLE_TRIG
Other than
software trigger
Disabled ADC_CMD_ENABLE_TRIG
DONE_GROUPA
ADC_CMD_CHECK_SCAN_
DONE_GROUPB
(1)
(1)
(1)
(1)
(2)
ADC_CMD_CHECK_SCAN_
(3)
Note 1. In RX63x, ADC_CMD_CHECK_SCAN_DONE_GROUPA cannot be used. Please check the
interrupt request flag directly for completion of A/D conversion.
Note 2. Use ADC_CMD_CHECK_SCAN_DONE_GROUPB when waiting completion of A/D conversion for
Group B.
Note 3. ADC_CMD_CHECK_SCAN_DONE_GROUPC can be used only with RX65x.
When A/D conversion interrupts are enabled, the R_ADC_Control function cannot be used to wait completion of A/D
conversion except when using single scan mode with software trigger. Use the callback function for the A/D conversion
interrupt to wait completion of A/D conversion.
Special Notes (RX64M/RX71M/RX65x):
This function does not support operation under Group A Priority Control.
Channels and sensors can be combined in the same scan.
ELC is only for S12ADI, not S12GBADI or S12CMPI. (RX64M/RX71M)
ELC is only for S12ADI, not GBADI, GCADI, S12CMPAI or S12CMPBI. (RX65x)
Channel masks are checked against the pin package specified by the equate
BSP_CFG_MCU_PART_PACKAGE in r_bsp_config.h for available A/D channels.
The application should wait 30us after configuring the scan, before enabling the trigger for Temperature Sensor for best
results.
If Group A Priority is selected such that Group B operates in continuous scan mode, it is recommended not to use the
S12GBADI interrupt (RX64M/RX71M) and GBADI interrupt (RX65x). That causes the majority of the processing
time to be spent at the interrupt level.
Enabling the comparator should be done prior to enabling the triggers.
R01AN1666EJ0220 Rev. 2.20 Page 65 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
Dbl
Trig
Group
Scan
SelfDiag
Add/
Avg
ANEX
Sample
&Hold
Priority
GroupA
Sensors
Comparator
DDA
Double
Trigger
Group Scan
X
*S
Self-
Diagnosis
Add/Avg
X ANEX
X X X
X
Sample
&Hold
Priority
GroupA
Sensors
X X
X
Comparator
X X
Disconnect
Assist
Some features may not be used with others. The following table illustrates this.
X *B X X
X X X X X
*B *S *A
*A
Detection
X - Combination may not be used. For example, ANEX may not be used with group scan modes, Self-Diagnosis,
sensors or Disconnect Detection Assist.
*A - Sample and Hold channels must be in Group A.
*B - Sample and Hold channels must be in Group B or Group C.
*S - Sample and Hold channels cannot be split across groups.
X X X
Special Notes (RX130/RX230/RX231):
This function does not support following features.
• Compare function window B
• Compare function window A/B composite condition setting
Special Notes (RX130/RX230/RX231/RX64M/RX71M/RX65x):
When using the comparison, configure the comparison after the channel configuration.
This function does not support following feature.
•Group A priority control setting
Special Notes (RX63x):
Only AN008 to AN020 can be used for setting the number of sampling states. AN000 to AN007 are fixed to 20 states
regardless of the setting.
Special Notes (RX110/RX111/RX113):
For temperature sensor and internal reference voltage, the number of sampling states must be set to 5 µs or greater.
R01AN1666EJ0220 Rev. 2.20 Page 66 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
3.4 R_ADC_Read()
This function reads conversion results from a single channel, sensor, double trigger, or self-diagnosis register.
Format
adc_err_t R_ADC_Read(uint8_t unit,
adc_reg_t const reg_id,
uint16_t * const p_data);
Parameters
unit
0 or 1. For MCUs with only one unit 0 should be passed (only the RX64M/RX71M/RX65x have 2 units).
reg_id
Id for the register to read. See type adc_reg_t in section 2.10 for the MCU being used.
p_data
Pointer to variable to load value into.
Return Values
ADC_SUCCESS: Success
ADC_ERR_INVALID_ARG: unit or reg_id contains an invalid value.
ADC_ERR_MISSING _PTR: p_data is FIT_NO_PTR/NULL
Properties
Prototyped in file “r_s12ad_rx_if.h”
Description
Reads conversion results from a single channel, sensor, double trigger, or self-diagnosis register.
Reentrant
Yes.
Example
uint16_t data;
:
/* Read channel 0 on unit 0 */
R_ADC_Read(0, ADC_CH0_REG, &data); // conversion value placed in “data”
Special Notes (RX110/RX111/RX113):
For temperature sensor output and internal reference voltage, discard the first A/D conversion result after the open, and
use the second and the subsequent A/D conversion results.
R01AN1666EJ0220 Rev. 2.20 Page 67 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
3.5 R_ADC_ReadAll()
This function reads conversion results from all potential sources, enabled or not.
p_data
Pointer to structure to load register values into.
An example structure for the register values is as follows:
typedef struct st_adc_data
{
uint16_t chan[ADC_REG_ARRAY_MAX]; // chans/indexes used depends upon MCU
uint16_t temp;
uint16_t volt;
uint16_t dbltrig;
uint16_t self_diag;
} adc_data_t;
Return Values
ADC_SUCCESS: Success
ADC_ERR_MISSING_PTR: p_data is FIT_NO_PTR/NULL
Properties
Prototyped in file “r_s12ad_rx_if.h”
Description
Reads conversion results from all potential sources, enabled or not. This function is convenient for getting a
snapshot of all values at any point in time.
See type adc_data_t in section 2.10 for the MCU being used
Reentrant
Yes.
Example
adc_data_t data;
:
/* Read all channel registers available on hardware */
R_ADC_ReadAll(&data); // “data” loaded with all conversion reg values
Special Notes:
None.
R01AN1666EJ0220 Rev. 2.20 Page 68 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
3.6 R_ADC_Close()
This function ends any scan in progress, disables interrupts, and removes power to the A/D peripheral.
Format
adc_err_t R_ADC_Close(uint8_t unit);
Parameters
unit
0 or 1. For MCUs with only one unit 0 should be passed (only the RX64M/RX71M/RX65x have 2 units).
Return Values
ADC_ERR_INVALID_ARG: Unit not 0 or 1
Properties
Prototyped in file “r_s12ad_rx_if.h”
Description
Ends any scan in progress, disables interrupts, and removes power to the A/D peripheral. Allows call to Open() to be
performed again. This is necessary when changing scan configurations.
Reentrant
This may only be called once per unit after an Open() is performed.
This function will abort any scan that may be in progress.
R01AN1666EJ0220 Rev. 2.20 Page 69 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
3.7 R_ADC_GetVersion()
This function returns the driver version number at runtime.
Format
uint32_t R_ADC_GetVersion(void)
Parameters
None
Return Values
Version number.
Properties
Prototyped in file “r_s12ad_rx_if.h”
Description
Returns the version of this module. The version number is encoded such that the top 2 bytes are the major
version number and the bottom 2 bytes are the minor version number.
Reentrant
Yes
Example
uint32_t version;
:
version = R_ADC_GetVersion();
Special Notes:
This function is in-lined using the “#pragma inline” directive
R01AN1666EJ0220 Rev. 2.20 Page 70 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
4. Pin Setting
Regarding the pin setting used for this module, it is strictly recommended to perform the pin setting after calling the
function R_ADC_Open.
R01AN1666EJ0220 Rev. 2.20 Page 71 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
5. Demo Projects
Demo projects are complete stand-alone programs. They include function main() that utilizes the module and its
dependent modules (e.g. r_bsp). The standard naming convention for the demo project is <module>_demo_<board>
where <module> is the peripheral acronym (e.g. s12ad, cmt, sci) and the <board> is the standard RSK (e.g. rskrx113).
For example, s12ad FIT module demo project for RSKRX113 will be named as s12ad_demo_rskrx113. Similarly the
exported .zip file will be <module>_demo_<board>.zip. For the same example, the zipped export/import file will be
named as s12ad_demo_rskrx113.zip.
5.1 s12ad_int_demo_rskrx113
This demo uses periodic interrupts from MTU0 to trigger the ADC module to scan the potentiometer on the board. Each
time a scan completes, the program reads the converted value at interrupt level in a callback function and places it into a
global variable called “data”. This variable should be added to the Expressions window and made into a Real-time
Watch (double-click to make real-time). As the program runs, change the potentiometer position and observe the
corresponding changes in the variable.
5.2 s12ad_poll_demo_rskrx113
This demo scans the potentiometer on the board via a software trigger in an endless loop. Each time a scan completes,
the program reads the converted value at the application level and places it into a global variable called “data”. This
variable should be added to the Expressions window and made into a Real-time Watch (double-click to make real-time).
As the program runs, change the potentiometer position and observe the corresponding changes in the variable.
5.3 s12ad_poll_demo_rskrx130
This demo scans the potentiometer on the board via a software trigger in an endless loop. Each time a scan completes,
the program reads the converted value at the application level and places it into a global variable called “data”. This
variable should be added to the Expressions window and made into a Real-time Watch (double-click to make real-time).
As the program runs, change the potentiometer position and observe the corresponding changes in the variable.
5.4 s12ad_demo_rskrx64m
This is a simple demo of the RX64M A/D Converter (S12AD) for the RSKRX64M starter kit (FIT module
"r_s12ad_rx"). The demo uses the Multi-Function Timer Pulse Unit (MTU3a) to periodically trigger the ADC module
to perform conversion on channel 0 which is connected to the on-board potentiometer. Each time a scan completes, the
program reads the converted value at interrupt level in a callback function and places it into a global variable called
“g_data”. This variable should be added to the Expressions window and made into a Real-time Watch (double-click to
make real-time). As the program runs, change the potentiometer position and observe the corresponding changes in the
variable.
5.5 s12ad_demo_rskrx71m
This is a demo of the RX71M A/D Converter (S12AD) for the RSKRX71M starter kit (FIT module "r_s12ad_rx"). The
demo uses the Multi-Function Timer Pulse Unit 3 (MTU3a) to periodically trigger the ADC module to perform
conversion on channel 0 which is connected to the on-board potentiometer. Each time a scan completes, the program
reads the converted value at interrupt level in a callback function and places it into a global variable called “g_data”.
This variable should be added to the Expressions window and made into a Real-time Watch (double-click to make realtime). As the program runs, change the potentiometer position and observe the corresponding changes in the variable.
5.6 s12ad_demo_rskrx231
This is a demo of the RX231 A/D Converter (S12ADE) for the RSKRX231 starter kit (FIT module “r_s12ad_rx”). The
demo uses the Multi-Function Timer Pulse Unit 2 (MTU2a) to periodically trigger the ADC module to perform a
conversion on channel 0, which is connected to the on-board potentiometer. Each time a scan completes, the program
reads the converted value at interrupt level in a callback function and places it into a global variable called "g_data".
This variable should be added to the Expressions window and made into a Real-time Watch. To do that, add it to the
Expressions window then right-click it. From the drop-down menu click on "Real-time Refresh". Right click again and
select "Real-time Refresh Interval" and set the refresh value to 200 ms. As the program runs, change the potentiometer
position and observe the corresponding changes in the variable.
R01AN1666EJ0220 Rev. 2.20 Page 72 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
5.7 Adding a Demo to a Workspace
Demo projects are found in the FITDemos subdirectory of the e2 studio installation directory. To add a demo project to
a workspace, select File>Import>General>Existing Projects into Workspace, then click “Next”. From the Import
Projects dialog, choose the “Select archive file” radio button. “Browse” to the demo subdirectory, select the desired
demo zip file, then click “Finish”.
R01AN1666EJ0220 Rev. 2.20 Page 73 of 74
Dec 01, 2016
RX Family ADC Module Using Firmware Integration Technology
Related Technical Updates
This module reflects the content of the following technical updates.
• TN-RX*-A124A/E
• TN-RX*-A117A/E
Website and Support
Renesas Electronics Website
http://www.renesas.com/
Inquiries
http://www.renesas.com/inquiry
All trademarks and registered trademarks are the property of their respective owners.
R01AN1666EJ0220 Rev. 2.20 Page 74 of 74
Dec 01, 2016
Description
Page
Summary
1.00
Nov.15.2013
—
First edition issued
1.20
Apr.21.2014
1,3
Added mention of support for RX110/63x.
Disconnect Detection Assist (DDA)
1.30
Jun.05.2014
—
Fixed bug in code that eliminated channels 8-15.
1.40
Nov.07.2014
—
Added RX113 support.
2.00
Mar.30.2015
—
Added RX64M/RX71M support. Modified interface to include a
2.10
Jun.15.2015
—
Added RX231 support. Added an RX231 demo.
2.11
Mar.01.2016
—
Added RX130 and RX230 support.
2.20
Dec.01.2016
—
Added RX65N support.
5
2.9 Code Size:
53 to 64
3.2 R_ADC_Open(), 3.3 R_ADC_Control():
55
3.2 R_ADC_Open(): Added the Special Notes (RX 63x) and
56
3.3 R_ADC_Control(): Added the sentence to clear all
65
3.3 R_ADC_Control(): Added and modified the following items:
67
3.4 R_ADC_Read(): Added Special Notes (RX110/RX111/
71
4. Pin Setting: Added.
72
5.3 s12ad_poll_demo_rskrx130: Added.
Program
Fixed typo on comment lines.
Revised the initialization in the R_ADC_Open function.
Revision Record
Rev.
Date
11,12
Added interface for RX210 Sample&Hold, Self-Diagnosis, and
unit number.
- Changed code sizes for RX111.
- Added code sizes for RX65N.
Added the following code in each Example section.
- Code to clear all fields of each structure.
- Comment regarding a wait time before A/D conversion starts
after open.
Special Notes (RX110/RX111/RX113/RX210/RX130/RX230/
RX231/RX65x).
members of parameters in the Description.
- Special Notes (RX Family Common): Added four special
notes.
- Special Notes (RX64M/RX71M/RX65x): Added a special note
regarding operation under Group A Priority Control and
modified the table.
- Special Notes (RX63x) and Special Notes (RX110/RX111/
RX113): Added.
RX113).
Rev.
Date
Description
Page
Summary
2.20
Dec.01.2016
Program
Fixed the following issue:
Fixed the following issue:
Use Rev. 2.20 or later version of the S12AD FIT module.
Fixed the following issue:
Use Rev. 2.20 or later version of the S12AD FIT module.
Target Device:
RX64M/RX71M/RX230/RX231
Description:
There is an error in checking the range of the arguments.
Thus, when the trigger source de-selection state is set as the
trigger for group B, the R_ADC_Open function returns an
error.
Condition:
The following combination of arguments for the
R_ADC_Open function is set.
Second parameter (mode)
ADC_MODE_SS_MULTI_CH_GROUPED or
ADC_MODE_SS_MULTI_CH_GROUPED_DBLTRIG_A
Third parameter (p_cfg->trigger_groupb)
ADC_TRIG_NONE_GROUPB.
Measure:
Modified the code for checking the arguments of the
adc_check_open_cfg function.
Use Rev. 2.20 or later version of the S12AD FIT module.
Target Device:
RX230/RX231
Description:
The compare window A operation enable bit is not set to be
enabled. Thus comparison for levels and windows does not
work.
Condition:
Comparison does not work under any condition.
Measure:
Modified the code to enable the CMPAE bit using the
adc_control function when the compare function is selected.
Target Device:
RX64M/RX71M/RX230/RX231
Description:
After Disconnection Detection Assist (DDA) is set, the
register is not reset. Thus the Disconnection Detection Assist
(DDA) setting remains and this causes a combination error
when setting self-diagnosis. Then the R_ADC_Control
function returns an error.
Condition:
After Disconnection Detection Assist (DDA) is set, the FIT
module is closed and re-opened, and then self-diagnosis is
set.
Measure:
Added processing to reset all S12AD related registers in the
adc_open function and deleted the check during
Disconnection Detection Assist (DDA) operation from the
check with self-diagnosis set in the adc_check_scan_config
function.
Rev.
Date
Description
Page
Summary
2.20
Dec.01.2016
Program
Fixed the following issue:
Use Rev. 2.20 or later version of the S12AD FIT module.
Fixed the following issue:
Use Rev. 2.20 or later version of the S12AD FIT module.
Deleted unnecessary definitions.
Deleted unnecessary members.
Modified the following procedures according to the User’s
Fixed the following issue:
Use Rev. 2.20 or later version of the S12AD FIT module.
Modified the code to set the delay time properly when
converting the temperature sensor in RX64M and RX71M.
Modified processing for checking an invalid channel when
using the extended analog input in RX64M and RX71M.
Target Device:
RX230/RX231
Description:
The numbers of arguments (enum value) for an index of the
register table do not match and the indexed value becomes
out of range. Then the R_ADC_Read function cannot obtain
the result of self-diagnosis.
Condition:
Occurs under any conditions.
Measure:
Deleted unnecessary definitions from the enum (abc_reg_t)
for an index of the register table.
Target Device:
RX210
Description:
A parameter needed for compiling was deleted in rev. 2.10,
thus a build error occurs when compiling with RX210.
Condition:
A project with Rev.2.10 or Rev.2.11 of the S12AD FIT
module is built.
Measure:
Added ADC_CFG_PGA_GAIN to r_s12ad_rx_config.h.
Manual: Hardware:
- Procedure for when A/D conversion stops
- Procedure for when entering low power consumption modes
- Procedure to rewrite the ADHSC bit
Target Device:
RX64M/RX71M/RX230/RX231
Description:
Since the operator is incorrect in processing to avoid the
upper limit voltage becoming less than the lower limit voltage,
the upper and lower limit voltages cannot be set to the same
value in the comparison setting.
Condition:
The comparison (window comparison) is used.
Measure:
Rev.
Date
Description
Page
Summary
2.20
Dec.01.2016
Program
Unify the name of definitions that have same meanings but have
processing.
* See the warning on compiling to check the enum range.
Rev.
Date
Description
Page
Summary
2.20
Dec.01.2016
Program
Fixed the following issue:
Use Rev. 2.20 or later version of the S12AD FIT module.
Added the temperature sensor (temp) and internal reference
R_ADC_ReadAll function over all MCU groups.
Fixed the following issue:
Use Rev. 2.20 or later version of the S12AD FIT module.
Modified the code to reset the ADGSPCR register when setting a
RX64M, and RX71M.
Changed the structure for arguments of comparison in
comparison.
Target Device:
RX210
Description:
In the processing for checking arguments,
ADC_TRIG_SYNC_TEMPS is checked with “trigger” instead of
"trigger_groupb". Then the R_ADC_Open function returns an
error even if the ADC_TRIG_SYNC_TEMPS setting is valid.
Condition:
ADC_TRIG_SYNC_TEMPS is set as the trigger of A/D
conversion.
Measure:
Deleted the code for checking ADC_TRIG_SYNC_TEMPS in
the adc_open function.
* “trigger_groupb” is ignored in modes other than group scan
mode. In group scan mode, if ADC_TRIG_SYNC_TEMPS is
set to trigger_groupb, an error is returned. Thus the checking
process for ADC_TRIG_SYNC_TEMPS is unnecessary.
voltage (volt) to the adc_data_t structure in the RX63x, RX110,
RX111, RX113, and RX210 Groups to unify the behavior of the
Target Device:
RX64M/RX71M
Description:
In the processing for checking arguments, ADC_TRIG_NONE
is checked with "trigger". Then the R_ADC_Open function
returns an error even if the ADC_TRIG_NONE setting is valid.
Condition:
ADC_TRIG_NONE is set as the trigger of A/D conversion.
Measure:
Deleted the code for checking ADC_TRIG_NONE in the
adc_open function since ADC_TRIG_NONE can be set to the
TRSA register as well as the TRSB register.
mode other than group scan mode in the RX130, RX230, RX231,
RX130/RX230/RX231 to similar to the structure in RX65N. The
adc_cmplvl_t structure has been discarded, accordingly. Please
use the adc_cmpwin_t structure when using the level
Rev.
Date
Description
Page
Summary
2.20
Dec.01.2016
Program
Fixed the following issue:
Use Rev. 2.20 or later version of the S12AD FIT module.
Fixed the following issue:
Use Rev. 2.20 or later version of the S12AD FIT module.
Modified the code to use the interface provided in the BSP
is used in RX64M and RX71M.
Fixed the following issue:
Use Rev. 2.20 or later version of the S12AD FIT module.
Target Device:
RX130/RX230/RX231
Description:
No processing is provided to set the compare window operation
enable bit to "disabled". Thus once the compare function is
enabled, only the way to disable it is reopening. However,
please note that reopening does not work for RX230 and
RX231.
Condition:
Always occurs when the compare function is used.
Measure:
Added "windowa_enable" to the structure for arguments of the
compare function. Now the compare window operation enable
bit can be set to "enabled" or "disabled" according to true/false
setting of "windowa_enable", i.e. same processing as RX65N.
Target Device:
RX64M/RX71M
Description:
No processing is provided to set the WCMPE bit to “0” (level
comparison). Thus once window comparison is enabled, the
comparison cannot be set to level comparison.
Condition:
The comparison is reset to level comparison after setting to
window comparison.
Measure:
Modified the code to properly set the WCMPE bit according to
the selection of window or level comparison.
(R_BSP_InterruptControl function) for specifying the interrupt
enable bit and interrupt priority level when the compare interrupt
Target Device:
RX64M/RX71M
Description:
No processing is provided to set the compare interrupt enable
bit to “disabled”. Thus once the comparison is enabled, the
compare interrupt cannot be disabled.
Condition:
The interrupt priority level is set to "1" or greater while the
comparison is enabled.
Measure:
Modified the code to disable the compare interrupt when
executing the adc_close function and to disable group
interrupts if no FIT module uses group interrupts.
Rev.
Date
Description
Page
Summary
2.20
Dec.01.2016
Program
Fixed the following issue:
Use Rev. 2.20 or later version of the S12AD FIT module.
Deleted unnecessary processing to reset the register when
register is already reset to "0".
Replaced the RX113 provided wait function (adc_delay) with the
RX113 provided wait function (adc_delay) has been deleted.
Fixed the following issue:
Use Rev. 2.20 or later version of the S12AD FIT module.
Fixed the following issue:
Target Device:
RX130/RX230/RX231/RX64M/RX71M
Description:
An unspecified callback function (NULL) is executed and
improper interrupt occurs.
Condition:
After the R_ADC_Open function is executed with interrupts
disabled, the interrupt priority level of the compare interrupt is
set to “1” or greater.
Measure:
Modified the code to check the callback function before
executing it. If the callback function is NULL, the interrupt
handler is exited without performing any processing.
enabling an output of the temperature sensor in RX210 since the
BSP provided wait function (R_BSP_SoftwareDelay). * The
Target Device:
RX210
Description:
An unnecessary error determination is performed. Because of
this, when specifying a setting with the channel-dedicated
sample-and-hold function, the R_ADC_Control function returns
an error.
Condition:
In group scan mode, A/D conversion channels for group A and
group B are set with the channel-dedicated sample-and-hold
function.
Measure:
Deleted an unnecessary error determination as no limitation
regarding it is described in the User’s Manual: Hardware.
Target Device:
RX210
Description:
Since an error determination processing is not provided, if selfdiagnosis is enabled in a mode where self-diagnosis does not
work, the R_ADC_Control function cannot return an error.
Condition:
Self-diagnosis is enabled when double trigger mode is selected
in single scan mode or group scan mode.
Measure:
Added the error determination processing for when selfdiagnosis is enabled.
Use Rev. 2.20 or later version of the S12AD FIT module.
Rev.
Date
Description
Page
Summary
2.20
Dec.01.2016
Program
Fixed the following issue:
Use Rev. 2.20 or later version of the S12AD FIT module.
Fixed the following issue:
Use Rev. 2.20 or later version of the S12AD FIT module.
Fixed the following issue:
Use Rev. 2.20 or later version of the S12AD FIT module.
Fixed the following issue:
Use Rev. 2.20 or later version of the S12AD FIT module.
Target Device:
RX130/RX230/RX231
Description:
An unnecessary error determination is performed. Because of
this, when setting the disconnection detection assist function
after self-diagnosis is enabled, the R_ADC_Control function
returns an error.
Condition:
Discharge or precharge is selected for the disconnection
detection assist function after self-diagnosis is enabled.
Measure:
Deleted unnecessary determination processing described in the
Description above.
Target Device:
RX63x
Description:
The definition to determine a valid channel is incorrect and
channel 20 cannot be selected.
Condition:
A chip with 177, 176, 145, or 144 pins is selected.
Measure:
Modified the definition to determine a valid channel.
Target Device:
RX631
Description:
There is no definition to determine a valid channel and this
causes a compiling error.
Condition:
A chip with 64 pins or 48 pins is selected.
Measure:
Added the definition to determine a valid channel.
Target Device:
RX64M/RX71M/RX65x
Description:
When obtaining the compare match result, the compare
channel is cleared. Then, the subsequent compare match is not
performed.
Condition:
When any of the unit 1 channel from channel 16 to channel 20
is specified as the compare channel, the condition is met and
the compare match interrupt occurs, or the R_ADC_Control
function is executed by setting
ADC_CMD_CHECK_CONDITION_MET.
Measure:
Modified the register that was initialized when obtaining the
compare match result.
Rev.
Date
Description
Page
Summary
2.20
Dec.01.2016
Program
Fixed the following issue:
In RX63x and RX210, the TEMPS register is now modified only
when the temperature sensor module is enabled.
Added the definition "ADC_CONVERT_SPEED_DEFAULT" for
value as "ADC_CONVERT_SPEED_NORM".
Fixed the following issue:
Use Rev. 2.20 or later version of the S12AD FIT module.
In RX64M, RX71M, RX65x, RX130, RX230, and RX231, some
Target Device:
RX64M/RX71M/RX65x/RX130/RX230/RX231
Description:
When enabling self-diagnosis under a prohibited setting
condition, the operation ends normally.
Condition:
Self-diagnosis is enabled in double trigger mode with single
scan mode selected.
Measure:
Modified processing for checking the error condition when selfdiagnosis is enabled.
Use Rev. 2.20 or later version of the S12AD FIT module.
conversion speed of A/D conversion in RX110, RX111, and
RX113. "ADC_CONVERT_SPEED_DEFAULT" has the same
Target Device:
RX110
Description:
An error occurs when attempting to set the minimum value for
the number of sampling states.
Condition:
An error occurs whenever the number of sampling states can
be set.
Measure:
Modified the definition of the minimum value for the number of
sampling states.
function declarations differed from prototypes. These function
declarations now correspond to the prototypes.
1. Handling of Unused Pins
General Precautions in the Handling of Microprocessing Unit and Microcontroller Unit Products
The following usage notes are applicable to all Microprocessing unit and Microcontroller unit 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.
Handle unused pins in accordance with the directions given under Handling of Unused Pins in the
manual.
The input pins of CMOS products are generally in the high-impedance state. In operation with
an unused pin in the open-circuit state, extra electromagnetic noise is induced in the vicinity of
LSI, an associated shoot-through current flows internally, and malfunctions occur due to the
false recognition of the pin state as an input signal become possible. Unused pins should be
handled as described under Handling of Unused Pins in the manual.
2. Processing at Power-on
The state of the product is undefined at the moment when power is supplied.
The states of internal circuits in the LSI are indeterminate and the states of register settings and
3. Prohibition of Access to Reserved Addresses
4. Clock Signals
5. Differences between Products
pins are undefined at the moment when power is supplied.
In a finished product where the reset signal is applied to the external reset pin, the states of
pins are not guaranteed from the moment when power is supplied until the reset process is
completed.
In a similar way, the states of pins in a product that is reset by an on-chip power-on reset
function are not guaranteed from the moment when power is supplied until the power reaches
the level at which resetting has been specified.
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 accessed.
After applying a reset, only release the reset line after the operating clock signal has become
stable. When switching the clock signal during program execution, wait until the target clock signal
has stabilized.
When the clock signal is generated with an external resonator (or from an external oscillator)
during a reset, ensure that the reset line is only released after full stabilization of the clock
signal. Moreover, when switching to a clock signal produced with an external resonator (or by
an external oscillator) while program execution is in progress, wait until the target clock signal is
stable.
Before changing from one product to another, i.e. to a product with a different part number, confirm
that the change will not lead to problems.
The characteristics of Microprocessing unit or Microcontroller unit products in the same group
but having a different part number may differ in terms of the internal memory capacity, layout
pattern, and other factors, which can affect the ranges of electrical characteristics, such as
characteristic values, operating margins, immunity to noise, and amount of radiated noise.
When changing to a product with a different part number, implement a system-evaluation test
for the given product.
Notice
1. Descriptions of circuits, software and other relat ed information in this document are provided only to illus trate the operation of semiconductor products and application examples. You are fully responsible for
the incorporation of t hese circuits, software, and infor mation in the design of your equipm ent. Renesas Electr onics assumes no responsibilit y for any losses incurr ed by you or third parties ar ising from the use
of these circuits , software, or information.
2. Renesas Electronics has used reasonable care in pr eparing the information included in t his document, but Renesas Electronics does not warrant that such information is error free. Renesas Electronics
assumes no liability whats oever for any damages incurr ed by you resulting from er rors in or omissions fr om the information included her ein.
3. Renesas Electronics does not assume any liability for infringement of patents, copyrights, or ot her intellectual property rights of third part ies by or arising from the use of Renesas Elect ronics products or
technical information des cribed in this document. No license, express, implied or otherwise, is granted hereby under any patent s, copyrights or ot her intellectual property rights of Renesas E lectronics or
others.
4. You should not alter, modify, c opy, or otherwise misappr opriate any Renesas Electr onics product, whether in whole or in part. Renesas Electronics assumes no r esponsibility for any loss es incurred by you or
third parties arising f rom such alteration, modification, c opy or otherwise misappropriat ion of Renesas Electronics product.
5. Renesas Electronics products are c lassified according to t he following two quality grades: "Standard" and " High Quality". The recommended applications f or each Renesas Electronics product depends on
the product's qualit y grade, as indicated below.
"Standard": Computers; off ice equipment; communications equipment; t est and measurement equipment ; audio and visual equipment; home electronic appliances; m achine tools; personal elect ronic
equipment; and industrial r obots etc.
"High Quality": Transportation equipment (automobiles, t rains, ships, etc.); tr affic control sy stems; anti-dis aster systems ; anti-crime sys tems; and safet y equipment etc.
Renesas Electronics pr oducts are neither intended nor authorized for use in product s or systems that may pose a direct threat to human life or bodily injury (artificial lif e support devices or systems, surgic al
implantations etc. ), or may cause serious property damages (nuc lear reactor control s ystems, milit ary equipment etc.) . You must check t he quality grade of each Renesas Electronics product before using it
in a particular application. You may not use any Renesas Elec tronics product f or any application for which it is not intended. Renesas Elec tronics shall not be in any way liable f or any damages or losses
incurred by you or third par ties arising from t he use of any Renesas Electr onics product for which t he product is not intended by Renesas Electronics.
6. You should use the Renesas Electronics produc ts described in this docum ent within the range specif ied by Renesas Electronics, especially with respect to the maximum r ating, operating supply volt age
range, movement power v oltage range, heat radiation c haracteristics, installation and other product characterist ics. Renesas Electronics shall have no liability f or malfunctions or damages arising out of the
use of Renesas Electronic s products beyond such specified ranges.
7. Although Renesas Electronics endeavors t o improve the quality and reliability of its product s, semiconductor products have specif ic characteristic s such as the occurr ence of failure at a cert ain rate and
malfunctions under cer tain use conditions. F urther, Renesas Elect ronics products are not subject to radiat ion resistance design. Pleas e be sure to implement saf ety measures to guard t hem against the
possibility of physical injur y, and injury or damage caused by fire in the event of the failure of a Renesas Elec tronics product, such as safety design f or hardware and software including but not limited to
redundancy, fire cont rol and malfunction prevention, appropriate tr eatment for aging degradat ion or any other appropriate meas ures. Because the evaluat ion of microcomputer software alone is very difficult,
please evaluate the safet y of the final products or systems manufactured by you.
8. Please contact a Renesas Electronic s sales office for details as to environment al matters such as t he environmental compatibility of each Renesas Elect ronics product. Please use Renesas Electr onics
products in compliance wit h all applicable laws and regulations that r egulate the inclusion or use of c ontrolled substances, including without limitation, the EU RoHS Directive. Renesas Electronics assumes
no liability for damages or los ses occurring as a result of your noncompliance with applicable laws and regulations.
9. Renesas Electronics products and t echnology may not be used for or incorporated into any product s or systems whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or
regulations. You should not us e Renesas Electronics products or technology des cribed in this document f or any purpose relating to milit ary applications or use by the military, including but not limited to the
development of weapons of m ass destruction. When exporting the Renesas E lectronics products or technology described in this document, you should comply with the applicable export cont rol laws and
regulations and follow the proc edures required by such laws and regulat ions.
10. It is the responsibilit y of the buyer or distributor of Renesas Electronics product s, who distributes, disposes of, or otherwise places the product with a third party, to notify such t hird party in advance of t he
contents and conditions s et forth in this document, Renesas Elec tronics assumes no res ponsibility for any losses incurred by you or third part ies as a result of unauthorized use of Renesas Elect ronics
products.
11. This document may not be reproduced or duplicated in any form, in whole or in part, without prior writt en consent of Renesas Elect ronics.
12. Please contact a Renesas E lectronics sales office if you have any quest ions regarding the information contained in this document or Renesas Electronics products, or if you have any other inquiries.
(Note 1) "Renesas Elect ronics" as used in this document means Renesas Elec tronics Corporation and also inc ludes its majority-owned s ubsidiaries.
(Note 2) "Renesas Elect ronics product(s)" means any product dev eloped or manufactured by or f or Renesas Electronics.
http://www.renesas.com
Refer to "http://www.renesas.com/" for the latest and detailed information.
Renesas Electronics America Inc.
2801 Scott Boulevard Santa Clara, CA 95050-2549, U.S.A.
Tel: +1-408-588-6000, Fax: +1-408-588-6130
Renesas Electronics Canada Limited
9251 Yonge Street, Suite 8309 Richmond Hill, Ontario Canada L4C 9T3
Tel: +1-905-237-2004
Unit 301, Tower A, Central Towers, 555 Langao Road, Putuo District, Shanghai, P. R. China 200333
Tel: +86-21-2226-0888, Fax: +86-21-2226-0999
Renesas El ectronics Hong Kong Limited
Unit 1601-1611, 16/F., Tower 2, Grand Century Place, 193 Prince Edward Road West, Mongkok, Kowloon, Hong Kong
Tel: +852-2265-6688, Fax: +852 2886-9022
Renesas Electronics Taiwan Co., Ltd.
13F, No. 363, Fu Shing North Road, Taipei 10543, Taiwan
Tel: +886-2-8175-9600, Fax: +886 2-8175-9670
Renesas Electronics Singapore Pte. Ltd.
80 Bendemeer Road, Unit #06-02 Hyflux Innovation Centre, Singapore 339949
Tel: +65-6213-0200, Fax: +65-6213-0300
Renesas Electronics Malaysia Sdn.Bhd.
Unit 1207, Block B, Menara Amcorp, Amcorp Trade Centre, No. 18, Jln Persiaran Barat, 46050 Petaling Jaya, Selangor Darul Ehsan, Malaysia
Tel: +60-3-7955-9390, Fax: +60-3-7955-9510