RA Flexible Software Package Documentation  Release v5.2.0

Comparator, Low-Power (r_acmplp)


fsp_err_t R_ACMPLP_Open (comparator_ctrl_t *const p_ctrl, comparator_cfg_t const *const p_cfg)
fsp_err_t R_ACMPLP_InfoGet (comparator_ctrl_t *const p_ctrl, comparator_info_t *const p_info)
fsp_err_t R_ACMPLP_OutputEnable (comparator_ctrl_t *const p_ctrl)
fsp_err_t R_ACMPLP_StatusGet (comparator_ctrl_t *const p_ctrl, comparator_status_t *const p_status)
fsp_err_t R_ACMPLP_Close (comparator_ctrl_t *p_ctrl)

Detailed Description

Driver for the ACMPLP peripheral on RA MCUs. This module implements the Comparator Interface.



The ACMPLP HAL module supports the following features:


Build Time Configurations for r_acmplp

The following build time configurations are defined in fsp_cfg/r_acmplp_cfg.h:

Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.
Reference Voltage Selection for ACMPLP1 (Standard mode only)
  • IVREF0
  • IVREF1
IVREF1 ACMPLP1 may optionally be configured to use IVREF0 as a reference input instead of IVREF1. Note that if IVREF0 is selected, ACMPLP0 and ACMPLP1 must use the same setting for IVREF.

Configurations for Analog > Comparator, Low-Power (r_acmplp)

This module can be added to the Stacks tab via New Stack > Analog > Comparator, Low-Power (r_acmplp).

NameName must be a valid C symbolg_comparator0 Module name.
ChannelValue must be a non-negative integer0 Select the hardware channel.
  • Standard
  • Window
Standard In standard mode, comparator output is high if VCMP > VREF. In window mode, comparator output is high if VCMP is outside the range of VREF0 to VREF1.
  • Rising
  • Falling
  • Both Edge
Both Edge The trigger specifies when a comparator callback event should occur. Unused if the interrupt priority is disabled or the callback is NULL.
  • No sampling (bypass)
  • Sampling at PCLKB
  • Sampling at PCLKB/8
  • Sampling at PCLKB/32
No sampling (bypass) Select the PCLK divisor for the hardware digital debounce filter. Larger divisors provide a longer debounce and take longer for the output to update.
Output Polarity
  • Not Inverted
  • Inverted
Not Inverted When enabled comparator output is inverted. This affects the output read from R_ACMPLP_StatusGet(), the pin output level, and the edge trigger.
Pin Output (VCOUT)
  • Disabled
  • Enabled
Disabled Turn this on to include the output from this comparator on VCOUT. The comparator output on VCOUT is OR'd with output from all other ACMPHS and ACMPLP comparators.
Vref (Standard mode only)
  • Enabled
  • Disabled
Disabled If reference voltage selection is enabled then internal reference voltage is used as comparator input
CallbackName must be a valid C symbolNULL Define this function in the application. It is called when the Trigger event occurs.
Comparator Interrupt PriorityMCU Specific OptionsSelect the interrupt priority for the comparator interrupt.
Analog Input Voltage Source (IVCMP)MCU Specific OptionsSelect the comparator input source. Only options for the configured channel are valid.
Reference Voltage Input Source (IVREF)MCU Specific OptionsSelect the comparator reference voltage source.

If channel 1 is seleected and the 'Reference Voltage Selection (ACMPLP1)' config option is set to IVREF0, select one of the Channel 0 options. In all other cases, only options for the configured channel are valid.

Clock Configuration

The ACMPLP peripheral is clocked from PCLKB. You can set the PCLKB frequency using the Clocks tab of the RA Configuration editor or by using the CGC Interface at run-time.

Pin Configuration

Comparator output can be enabled or disabled on each channel individually. The VCOUT pin is a logical OR of all comparator outputs.

The CMPINn pins are used as comparator inputs. The CMPREFn pins are used as comparator reference values.

Usage Notes

ACMPLP Standard Mode Operation

Noise Filter

When the noise filter is enabled, the ACMPLP0/ACMPLP1 signal is sampled three times based on the sampling clock selected. The filter clock frequency is determined by PCLKB and the comparator_filter_t setting.

Output Polarity

If output polarity is configured as "Inverted" then the VCOUT signal will be inverted and the R_ACMPLP_StatusGet() will return an inverted status.

Window Mode

In window mode, the comparator indicates if the analog input voltage falls within the window (low and high reference voltage) or is outside the window.

ACMPLP Window Mode Operation



Basic Example

The following is a basic example of minimal use of the ACMPLP. The comparator is configured to trigger a callback when the input rises above the internal reference voltage (VREF). A GPIO output acts as the comparator input and is externally connected to the CMPIN input of the ACMPLP.

/* Connect this control pin to the VCMP input of the comparator. This can be any GPIO pin
* that is not input only. */
volatile uint32_t g_comparator_events = 0U;
/* This callback is called when a comparator event occurs. */
void acmplp_example_callback (comparator_callback_args_t * p_args)
void acmplp_example ()
fsp_err_t err = FSP_SUCCESS;
/* Disable pin register write protection, if enabled */
/* Start with the VCMP pin low. This example assumes the comparator is configured to trigger
* when VCMP rises above VREF. */
/* Initialize the ACMPLP module */
err = R_ACMPLP_Open(&g_comparator_ctrl, &g_comparator_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
/* Wait for the minimum stabilization wait time before enabling output. */
R_ACMPLP_InfoGet(&g_comparator_ctrl, &info);
/* Enable the comparator output */
(void) R_ACMPLP_OutputEnable(&g_comparator_ctrl);
/* Set VCMP low. */
while (0 == g_comparator_events)
/* Wait for interrupt. */
/* Check status of comparator, Status will be COMPARATOR_STATE_OUTPUT_HIGH */
(void) R_ACMPLP_StatusGet(&g_comparator_ctrl, &status);


enum  acmplp_input_t
enum  acmplp_reference_t

Enumeration Type Documentation

◆ acmplp_input_t


Not available on all MCUs.


Not available on all MCUs.

◆ acmplp_reference_t


Not available on all MCUs.

Function Documentation

◆ R_ACMPLP_Open()

fsp_err_t R_ACMPLP_Open ( comparator_ctrl_t *const  p_ctrl,
comparator_cfg_t const *const  p_cfg 

Configures the comparator and starts operation. Callbacks and pin output are not active until outputEnable() is called. comparator_api_t::outputEnable() should be called after the output has stabilized. Implements comparator_api_t::open().

Comparator inputs must be configured in the application code prior to calling this function.

Return values
FSP_SUCCESSOpen successful.
FSP_ERR_ASSERTIONAn input pointer is NULL
FSP_ERR_INVALID_ARGUMENTAn argument is invalid. Window mode (COMPARATOR_MODE_WINDOW) and filter of 1 (COMPARATOR_FILTER_1) are not supported in this implementation. p_cfg->p_callback is not NULL, but ISR is not enabled. ISR must be enabled to use callback function.
FSP_ERR_ALREADY_OPENThe control block is already open or the hardware lock is taken.
FSP_ERR_IN_USEThe channel is already in use.

◆ R_ACMPLP_InfoGet()

fsp_err_t R_ACMPLP_InfoGet ( comparator_ctrl_t *const  p_ctrl,
comparator_info_t *const  p_info 

Provides the minimum stabilization wait time in microseconds. Implements comparator_api_t::infoGet().

Return values
FSP_SUCCESSInformation stored in p_info.
FSP_ERR_ASSERTIONAn input pointer was NULL.
FSP_ERR_NOT_OPENInstance control block is not open.

◆ R_ACMPLP_OutputEnable()

fsp_err_t R_ACMPLP_OutputEnable ( comparator_ctrl_t *const  p_ctrl)

Enables the comparator output, which can be polled using comparator_api_t::statusGet(). Also enables pin output and interrupts as configured during comparator_api_t::open(). Implements comparator_api_t::outputEnable().

Return values
FSP_SUCCESSComparator output is enabled.
FSP_ERR_ASSERTIONAn input pointer was NULL.
FSP_ERR_NOT_OPENInstance control block is not open.

◆ R_ACMPLP_StatusGet()

fsp_err_t R_ACMPLP_StatusGet ( comparator_ctrl_t *const  p_ctrl,
comparator_status_t *const  p_status 

Provides the operating status of the comparator. Implements comparator_api_t::statusGet().

Return values
FSP_SUCCESSOperating status of the comparator is provided in p_status.
FSP_ERR_ASSERTIONAn input pointer was NULL.
FSP_ERR_NOT_OPENInstance control block is not open.

◆ R_ACMPLP_Close()

fsp_err_t R_ACMPLP_Close ( comparator_ctrl_t p_ctrl)

Stops the comparator. Implements comparator_api_t::close().

Return values
FSP_SUCCESSInstance control block closed successfully.
FSP_ERR_ASSERTIONAn input pointer was NULL.
FSP_ERR_NOT_OPENInstance control block is not open.