|
| fsp_err_t | R_ADC_W_Open (adc_ctrl_t *p_ctrl, adc_cfg_t const *const p_cfg) |
| |
| fsp_err_t | R_ADC_W_ScanCfg (adc_ctrl_t *p_ctrl, void const *const p_scan_cfg) |
| |
| fsp_err_t | R_ADC_W_CallbackSet (adc_ctrl_t *const p_api_ctrl, void(*p_callback)(adc_callback_args_t *), void *const p_context, adc_callback_args_t *const p_callback_memory) |
| |
| fsp_err_t | R_ADC_W_ScanStart (adc_ctrl_t *p_ctrl) |
| |
| fsp_err_t | R_ADC_W_ScanGroupStart (adc_ctrl_t *p_ctrl, adc_group_mask_t group_id) |
| |
| fsp_err_t | R_ADC_W_ScanStop (adc_ctrl_t *p_ctrl) |
| |
| fsp_err_t | R_ADC_W_StatusGet (adc_ctrl_t *p_ctrl, adc_status_t *p_status) |
| |
| fsp_err_t | R_ADC_W_Read (adc_ctrl_t *p_ctrl, adc_channel_t const reg_id, uint16_t *const p_data) |
| |
| fsp_err_t | R_ADC_W_Read32 (adc_ctrl_t *p_ctrl, adc_channel_t const reg_id, uint32_t *const p_data) |
| |
| fsp_err_t | R_ADC_W_InfoGet (adc_ctrl_t *p_ctrl, adc_info_t *p_adc_info) |
| |
| fsp_err_t | R_ADC_W_Close (adc_ctrl_t *p_ctrl) |
| |
| fsp_err_t | R_ADC_W_Calibrate (adc_ctrl_t *const p_ctrl, void const *p_extend) |
| |
| fsp_err_t | R_ADC_W_OffsetSet (adc_ctrl_t *const p_ctrl, adc_channel_t const reg_id, int32_t offset) |
| |
| fsp_err_t | R_ADC_W_SensorWakeupcfg (adc_ctrl_t *const p_ctrl) |
| |
| fsp_err_t | R_ADC_W_FifoRead (adc_ctrl_t *p_ctrl, adc_channel_t const reg_id, uint16_t *const p_data) |
| |
Driver for ADC_W version of the ADC peripheral on RAFW MCUs. This module implements the ADC Interface.
Overview
Features
The ADC module supports the following features:
- 4, 7, 10 or 12-bit resolution
- Four analog channels
- Software scan triggers with no-wait mode
- Continuous scan mode
- Optional callback when certain conditions are met
- Generated an interrupt request when the ADC result is over or under the threshold
- Generated an interrupt request when number of ADC results in FIFO exceed the threshold
- Built-in FIFO for each channel
- External sensor wake-up function that uses the analog input signal through an ADC
Configuration
Build Time Configurations for r_adc_w
The following build time configurations are defined in fsp_cfg/r_adc_w_cfg.h:
| Configuration | Options | Default | Description |
| Parameter Checking |
-
Default (BSP)
-
Enabled
-
Disabled
| Default (BSP) | If selected code for parameter checking is included in the build. |
| Interrupt Support |
| Enabled | Enable Scan End Interrupt support for the ADC module. |
Configurations for Analog > ADC (r_adc_w)
This module can be added to the Stacks tab via New Stack > Analog > ADC (r_adc_w).
| Configuration | Options | Default | Description |
| General |
| Resolution |
-
12-Bit
-
10-Bit
-
7-Bit
-
4-Bit
| 12-Bit | Specifies the conversion resolution for this unit. |
| ADC Input Clock Divider | Must be a valid integer | 3 | Specifies divider for ADC input clock. |
| Interrupts |
| Upper threshold of conversion result | Must be a valid integer | 65535 | Specify the threshold of the conversion value that corresponds to the condition to generate an interrupt request. |
| Lower threshold of conversion result | Must be a valid integer | 0 | Specify the threshold of the conversion value that corresponds to the condition to generate an interrupt request. |
| Callback | Name must be a valid C symbol | NULL | A user callback function. If this callback function is provided, it is called from the interrupt service routine (ISR) whenever the AD conversion result meets the interrupt generation condition. |
| Scan End Interrupt Priority | MCU Specific Options | | Select scan end interrupt priority. |
| Sensor Wakeup |
| Timer count clock source |
-
7.81 msec
-
31.25 msec
-
62.5 msec
-
250 msec
-
1000 msec
-
4000 msec
-
16000 msec
-
64000 msec
| 7.81 msec | Timer count clock source used for the sensor wakeup function. (base = 32.768KHz). |
| Timer value | Must be a valid integer | 1 | The AD conversion period is 'Timer count clock source' multiplied by (Timer value + 1). The range of Timer value is from 1 to 0xF. ex. when 'Timer count clock source' 7.81 msec period, the cycle is 15.62 to 124.8 msec. when 'Timer count clock source' 64,000 msec period, the cycle is 128,000 ~ 1,024,000 msec (max. 17.1 min). |
| Sample number for average |
| 4 | This is the number of ADC sample data to be averaged.The average value is obtained and compared with the value set in Wake-up-threshold to check whether the condition is satisfied. |
| Name | Name must be a valid C symbol | g_adc0 | Module name. |
Configurations for Analog > ADC_W Channel Configuration (r_adc_w)
| Configuration | Options | Default | Description |
| DMA support |
| DMA support |
| Disabled | Enable DMA support for this channel. |
| Interrupts |
| Interrupt Mode of FIFO |
| Disabled | Specify the interrupt mode of FIFO. If HALF is selected, an interrupt occurs when the analog to digital conversion is completed and the FIFO is filled with 4 data. |
| Interrupt Mode of Threshold |
| Disabled | If Over is selected, an interrupt occurs when the conversion result exceeds the specified threshold. If Under is selected, an interrupt occurs when the conversion result falls below the specified threshold. |
| Sensor Wake-up |
| Sensor wakeup support |
| Disabled | Enable Sensor Wake-up support for this channel. |
| Wake-up threshold | Must be a valid integer | 0 | The threshold used to wake up from Sleep mode. From 0 to 0xFFF. |
| Threshold mode selection |
| Over | If Over threshold is selected, sleep mode ends when the input value exceeds the threshold.(If Under threshold is selected, sleep mode ends when it falls below the threshold.) |
Clock Configuration
The ADC input clock source is configured to use AUX_CLK with a selectable division ratio.
Pin Configuration
The ADCx pins are analog input channels that can be used with the ADC_W.
Conversion frequency
Conversion frequency depends on input clock, resolution(clock cycle per sample), and number of channels used.
- Clock cycle per sample is determined by the resolution
- 12-bit resolution : Clock cycle per Sample = 15
- 10-bit resolution : Clock cycle per Sample = 12
- 7-bit resolution : Clock cycle per Sample = 9
- 4-bit resolution : Clock cycle per Sample = 6
- The conversion frequency of AD conversion slows down when multiple channels are used simultaneously.
- Use two channels: conversion frequency becomes 1/8 (=4 x 2 channels)
- Use three channels: conversion frequency becomes 1/12 (=4 x 3 channels)
- Use four channels: conversion frequency becomes 1/16 (=4 x 4 channels)
For example, when the input clock is 15 MHz, the resolution is 10 bits, and two channels are used, the conversion frequency is as follows.
- 15(inpuut clock) / 12(Clock cycle per Sample) / 8(two channels) = 0.15625 MHz
Usage Notes
ADC_W Operational Conversion
The driver supports an operation conversion mode: Continuous scan mode. For each time conversion, ADC peripheral only converts for each a pin.
Continuous scan mode
In Continuous scan mode, the specified channels are scanned continuously. This scan continues until R_ADC_W_ScanStop() is called.
When Interrupt Is Not Enabled
If interrupts are not enabled, R_ADC_W_StatusGet() can be used to check if AD conversion has started. The read API function is used to access the converted ADC result.
When Interrupt Is Enabled
An interrupt is generated depend on setting condition of converted ADC result is over or under the threshold value, or number of ADC results in FIFO exceed the threshold.
- Note
- If interrupts occur frequently, the interrupt handler may be called more frequently, causing the application to stop processing
Selecting ADC Input Clock Divider
The ADC input clock is configured to use the AUX_CLK with the specified division ratio.
FIFO
The FIFOs consist of 4 stages and can hold up to 4 A/D conversion data. One FIFO is implemented for each channel.
Data in the FIFO can be read by R_ADC_W_FifoRead().
Sensor Wake-up
Even in Sleep mode, when a change of an external analog signal is detected, a wakeup event occurs and normal operation is resumed.
This function can be used in up to four channels. Also, when multiple external sensors are used, analog signals are detected while the channel are automatically changed. For example, if all four channels are set as input sources which have their threshold register respectively, the channels are measured sequentially from 0 to 3.
If one of the four ADC channels exceed the allowed range of values set by the threshold register, the device awakes from the Sleep mode.
Examples
Basic Example
This is a basic example of minimal use of the ADC_W in an application.
void adc_w_basic_example (void)
{
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
uint16_t channel0_conversion_result;
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
}
ADC-DMAC Transfer Example
This example demonstrates reading multiple data from an ADC channel and storing the data in memory through DMAC.
#define TEST_DMAC_TRANS_LEN (32)
#define BSP_VECTOR_DMA_IRQN ((IRQn_Type) 0)
static uint8_t dma_done_1 = 0;
static uint16_t adc_dmac_dst[TEST_DMAC_TRANS_LEN];
dmac_instance_ctrl_t g_transfer0_ctrl;
{
.p_dest = &adc_dmac_dst,
.p_src = (uint16_t
const *) (ADC_CH0_DMAC_SRC_ADDR +
ADC_CHANNEL_0),
.length = TEST_DMAC_TRANS_LEN,
};
{
.irq = BSP_VECTOR_DMA_IRQN,
.ipl = (15),
.channel_prio = (7),
.periph_trigger = BSP_DMAC_TRIG_AUXADC0,
.irq_num_of_trans = TEST_DMAC_TRANS_LEN,
.p_callback = DMAC_Callback,
.p_context = NULL,
};
{
.p_extend = (void *) &g_transfer0_extend,
};
{
.p_cfg = &g_transfer0_cfg,
.p_api = &g_transfer_on_dmac_w
};
{
dma_done_1 = 1;
}
void adc_w_dmac_example (void)
{
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
uint32_t timeout = UINT16_MAX;
while ((!dma_done_1) && (timeout > 0U))
{
timeout--;
}
assert(FSP_SUCCESS == err);
}
ADC-Sensor Wake-up Example
This is an example of using the ADC sensor wake-up function.
void adc_w_sensor_wakeup_example (void)
{
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
#if 0 // TIN-TODO
#endif
}
◆ adc_w_scan_cfg_t
ADC_W active channel configuration
| Data Fields |
|
uint32_t |
scan_mask |
Channels/bits: bit 0 is ch0; bit 3 is ch3. |
◆ adc_w_channel_cfg_t
| struct adc_w_channel_cfg_t |
ADC chennel config structure
◆ adc_w_extended_cfg_t
| struct adc_w_extended_cfg_t |
ADC extended configuration data
| Data Fields |
|
uint16_t |
conversion_clockdiv |
Divider for conversion clock (fAD) setting. |
|
uint16_t |
upper_bound_limit |
Setting upper limit conversion value. |
|
uint16_t |
lower_bound_limit |
Setting lower limit conversion value. |
|
adc_w_channel_cfg_t const * |
p_channel_cfgs[BSP_FEATURE_ADC_W_MAX_NUM_CHANNELS] |
Configuration for each channel, set to NULL if unused. |
|
adc_w_timer_count_clock_source_t |
timer_count_clock_source |
Setting lower limit conversion value. |
|
uint16_t |
timer_value |
Timer count clock source for sensor wakeup mode (base = 32.768KHz) |
|
adc_w_sample_average_t |
sample_average |
Sample number for average in sensor wakeup mode. |
◆ adc_w_instance_ctrl_t
| struct adc_w_instance_ctrl_t |
ADC instance control block. DO NOT INITIALIZE. Initialized in adc_api_t::open().
Data Fields |
|
adc_cfg_t const * | p_cfg |
| | Boolean to verify that the Unit has been initialized.
|
| |
|
void(* | p_callback )(adc_callback_args_t *) |
| | Pointer to callback that is called when an adc_w_event_t occurs.
|
| |
|
void * | p_context |
| | User defined context passed into callback function.
|
| |
|
uint32_t | initialized |
| | Initialized status of ADC_W.
|
| |
|
uint32_t | opened |
| | Open status of ADC_W.
|
| |
|
uint32_t | scan_mask |
| | Scan mask of enabled channels.
|
| |
|
uint32_t | scan_cfg_mask |
| | Scan mask of configured channels.
|
| |
◆ adc_w_dma_enable_t
DMA enable
| Enumerator |
|---|
| ADC_W_DMA_DISABLED | DMA disabled
|
| ADC_W_DMA_ENABLED | DMA enabled
|
◆ adc_w_thd_interrupt_mode_t
ADC Interrupt Mode Threshold
| Enumerator |
|---|
| ADC_W_INTERRUPT_THD_NONE | Threshold interrupt is disabled
|
| ADC_W_INTERRUPT_THD_OVER | An interrupt occurs when the conversion result exceeds the threshold.
|
| ADC_W_INTERRUPT_THD_UNDER | An interrupt occurs when the conversion result is below the threshold.
|
◆ adc_w_fifo_interrupt_mode_t
ADC Interrupt Mode FIFO
| Enumerator |
|---|
| ADC_W_INTERRUPT_FIFO_NONE | FIFO interrupt is disabled
|
| ADC_W_INTERRUPT_FIFO_HALF | An interrupt occurs when the FIFO is filled with four data.
|
◆ adc_w_sensorwakeup_enable_t
ADC Sensor Wakeup Mode enable
| Enumerator |
|---|
| ADC_W_SENSOR_WAKEUP_DISABLED | sensor wakeup disabled
|
| ADC_W_SENSOR_WAKEUP_ENABLED | sensor wakeup enabled
|
◆ adc_w_sensorwakeup_thd_mode_t
Threshold mode selection for sensor wakeup mode
| Enumerator |
|---|
| ADC_W_SENSOR_WAKEUP_THD_OVER | Over threshold
|
| ADC_W_SENSOR_WAKEUP_THD_UNDER | Under threshold
|
◆ adc_w_timer_count_clock_source_t
Timer count clock source for sensor wakeup mode (base = 32.768KHz)
| Enumerator |
|---|
| ADC_W_TIMER_COUNT_SOURCE_8 | 7.81-msec period
|
| ADC_W_TIMER_COUNT_SOURCE_31 | 31.25-msec period
|
| ADC_W_TIMER_COUNT_SOURCE_62 | 62.5-msec period
|
| ADC_W_TIMER_COUNT_SOURCE_250 | 250-msec period
|
| ADC_W_TIMER_COUNT_SOURCE_1000 | 1000-msec period
|
| ADC_W_TIMER_COUNT_SOURCE_4000 | 4000-msec period
|
| ADC_W_TIMER_COUNT_SOURCE_16000 | 16000-msec period
|
| ADC_W_TIMER_COUNT_SOURCE_64000 | 64,000-msec period
|
◆ adc_w_sample_average_t
Sample number for average in sensor wakeup mode
| Enumerator |
|---|
| ADC_W_SAMPLE_AVERAGE_4 | 4-sample processing
|
| ADC_W_SAMPLE_AVERAGE_8 | 8-sample processing
|
| ADC_W_SAMPLE_AVERAGE_16 | 16-sample processing
|
| ADC_W_SAMPLE_AVERAGE_32 | 32-sample processing
|
| ADC_W_SAMPLE_AVERAGE_64 | 64-sample processing
|
| ADC_W_SAMPLE_AVERAGE_128 | 128-sample processing
|
| ADC_W_SAMPLE_AVERAGE_256 | 256-sample processing
|
| ADC_W_SAMPLE_AVERAGE_512 | 512-sample processing
|
◆ R_ADC_W_Open()
Initialize the ADC_W peripheral. If interrupt is enabled, the function registers a callback function for notifying the user when ADC interrupt event occurrs. Implements adc_api_t::open.
- Return values
-
| FSP_SUCCESS | Module is ready for use. |
| FSP_ERR_ASSERTION | An input argument is invalid. |
| FSP_ERR_ALREADY_OPEN | The instance control structure has already been opened. |
| FSP_ERR_IRQ_BSP_DISABLED | A callback is provided, but the interrupt is not enabled. |
◆ R_ADC_W_ScanCfg()
Configures the enabled channels of the ADC. Channel specific settings are set in this function. Pass a pointer to adc_w_scan_cfg_t to p_extend. Implements adc_api_t::scanCfg.
- Return values
-
| FSP_SUCCESS | Channel specific settings applied. |
| FSP_ERR_ASSERTION | An input argument is invalid. |
| FSP_ERR_NOT_OPEN | Unit is not open. |
◆ R_ADC_W_CallbackSet()
Updates the user callback. Implements adc_api_t::callbackSet
- Return values
-
| FSP_SUCCESS | Callback updated successfully. |
| FSP_ERR_NOT_OPEN | Unit is not open. |
| FSP_ERR_ASSERTION | A required pointer is NULL. |
◆ R_ADC_W_ScanStart()
This function starts the software triggered scan.
- Precondition
- Call R_ADC_W_ScanCfg after R_ADC_W_Open before starting a scan.
- Return values
-
| FSP_SUCCESS | Scan started. |
| FSP_ERR_ASSERTION | An input argument is invalid. |
| FSP_ERR_NOT_OPEN | ADC_W is not open. |
| FSP_ERR_NOT_INITIALIZED | ADC_W is not initialized. |
◆ R_ADC_W_ScanGroupStart()
adc_api_t::scanGroupStart is not supported on the ADC_W. Use scanStart instead.
- Return values
-
| FSP_ERR_UNSUPPORTED | Function not supported in this implementation. |
◆ R_ADC_W_ScanStop()
Immediately stops converters. This function will abort conversions.
- Return values
-
| FSP_SUCCESS | Scan stopped. |
| FSP_ERR_ASSERTION | An input argument is invalid. |
| FSP_ERR_NOT_OPEN | Unit is not open. |
| FSP_ERR_NOT_INITIALIZED | Unit is not initialized. |
◆ R_ADC_W_StatusGet()
Provides the status of any scan process that was started.
- Return values
-
| FSP_SUCCESS | Module status stored in the provided pointer p_status. |
| FSP_ERR_ASSERTION | An input argument is invalid. |
| FSP_ERR_NOT_OPEN | ADC_W is not open. |
◆ R_ADC_W_Read()
Reads conversion results from a channel register.
- Return values
-
| FSP_SUCCESS | Data read into provided p_data. |
| FSP_ERR_ASSERTION | An input argument is invalid. |
| FSP_ERR_NOT_OPEN | Unit is not open. |
| FSP_ERR_NOT_INITIALIZED | Unit is not initialized. |
◆ R_ADC_W_Read32()
Reads conversion results from a channel register into a 32-bit result.
- Return values
-
| FSP_SUCCESS | Data read into provided p_data. |
| FSP_ERR_ASSERTION | An input argument is invalid. |
| FSP_ERR_NOT_OPEN | ADC_W is not open. |
| FSP_ERR_NOT_INITIALIZED | ADC_W is not initialized. |
◆ R_ADC_W_InfoGet()
Returns the address of the lowest number configured channel, determine the size of data that must be read.
- Return values
-
| FSP_SUCCESS | Information stored in p_adc_info. |
| FSP_ERR_ASSERTION | An input argument is invalid. |
| FSP_ERR_NOT_OPEN | ADC_W is not open. |
| FSP_ERR_NOT_INITIALIZED | ADC_W is not initialized. |
◆ R_ADC_W_Close()
This function ends any scan or select mode in progress, disables interrupts, and removes power to the A/D peripheral.
- Return values
-
| FSP_SUCCESS | Module closed. |
| FSP_ERR_ASSERTION | An input argument is invalid. |
| FSP_ERR_NOT_OPEN | ADC_W is not open. |
◆ R_ADC_W_Calibrate()
adc_api_t::calibrate is not supported on the ADC_W.
- Return values
-
| FSP_ERR_UNSUPPORTED | Function not supported in this implementation. |
◆ R_ADC_W_OffsetSet()
adc_api_t::offsetSet is not supported on the ADC_W.
- Return values
-
| FSP_ERR_UNSUPPORTED | Function not supported in this implementation. |
◆ R_ADC_W_SensorWakeupcfg()
Prepare ADC_W to enter sensor wakeup mode. This function must be called before entering sleep mode.
- Parameters
-
| [in] | p_ctrl | Pointer to the ADC control block |
- Return values
-
| FSP_SUCCESS | ADC is configured to request sensor wakeup mode. |
| FSP_ERR_ASSERTION | An input argument is invalid. |
| FSP_ERR_NOT_OPEN | ADC_W is not open. |
◆ R_ADC_W_FifoRead()
Reads conversion results from FIFO for the given channel. When reading multiple data from the FIFO, call this function repeatedly.
- Return values
-
| FSP_SUCCESS | Data read into provided p_data. |
| FSP_ERR_ASSERTION | An input argument is invalid. |
| FSP_ERR_NOT_OPEN | Unit is not open. |
| FSP_ERR_NOT_INITIALIZED | Unit not initialized. |