Synergy Software Package User's Manual
Comparator Driver on r_acmplp

ACMPLP HAL Module Introduction

The ACMPLP HAL module implements the comparator API for signal processing applications and supports the ACMPLP peripheral available on the Synergy microcontroller hardware. A callback is available to signal the user application on transition events.

ACMPLP HAL Module Features

  • Normal mode or window mode
  • Callback on rising edge, falling edge or both
  • Configurable debounce filter
  • Option to include comparator output on VCOUT pin
ACMPLP_BD.png
ACMPLP HAL Module Block Diagram

ACMPLP Hardware support details

The following hardware features are, or are not, supported by the SSP for the ACMPLP:

Legend:

Symbol Meaning
Available (Tested)
Not Available (Not tested/not functional or both)
N/A Not supported by MCU 
MCU
Group
Normal or window
mode
Callback on rising edge, falling
edge, or both
Configurable
debounce filter
Option to include comparator output on VCOUT
S124
S128
S1JA
S3A1
S3A3
S3A6
S3A7
S5D3 N/A N/A N/A N/A
S5D5 N/A N/A N/A N/A
S5D9 N/A N/A N/A N/A
S7G2 N/A N/A N/A N/A

ACMPLP HAL Module APIs Overview

The ACMPLP HAL module defines API functions to open, enable, get status and close the module. A complete list of the available APIs, an example API call and a short description of each can be found in the following table. A table of status return values follows the API summary table.

ACMPLP HAL Module API Summary

Function Name Example API Call and Description
open g_comparator0.p_api->open(g_comparator0.p_ctrl, g_comparator0.p_cfg);
Configures the comparator and starts operation. Callbacks and pin output are not active until comparator_api_t::outputEnable is called. comparator_api_t::outputEnable should be called after the output has stabilized.
outputEnable g_comparator0.p_api->outputEnable(g_comparator0.p_ctrl);
Enables the comparator output, which can be polled using statusGet(). Also enables pin output and interrupts as configured during open().
infoGet g_comparator0.p_api->infoGet(g_comparator0.p_ctrl, p_info);
Provides the minimum stabilization wait time in microseconds.
statusGet g_comparator0.p_api->statusGet(g_comparator0.p_ctrl, p_status);
Provides the operating status of the comparator.
close g_comparator0.p_api->close(g_comparator0.p_ctrl);
Close the module.
versionGet g_comparator0.p_api->read(&version);
Retrieves the version using the version pointer.
Note
For more complete descriptions of operation and definitions for the function data structures, typedefs, defines, API data, API structures, and function variables, review the SSP User's Manual API References for the associated module.

Status Return Values

Name Description
SSP_SUCCESS API Call Successful.
SSP_ERR_INVALID_ARGUMENT Parameter has invalid value.
SSP_ERR_NOT_OPEN Unit is not open.
SSP_ERR_ASSERTION An input pointer is NULL.
SSP_ERR_IN_USE Peripheral is in use or hardware lock is taken.
SSP_ERR_TIMEOUT The debounce filter is off and 2 consecutive matching values were not read within 1024 attempts.
Note
Lower-level drivers may return common error codes. Refer to the SSP User's Manual API References for the associated module for a definition of all relevant status return values.

ACMPLP HAL Module Operational Overview

The Comparator Driver (r_acmplp) HAL module controls the Low-Power Analog Comparator (ACMPLP) peripheral on a Synergy microcontroller. It directly controls the ACMPLP hardware without using any RTOS elements and provides convenient APIs to simplify development.

ACMPLP HAL Module Important Operational Notes and Limitations

ACMPLP HAL Module Operational Notes

Comparator Output on VCOUT Pin

The signal on the VCOUT pin is a logical 'OR' of the outputs of all comparators (ACMPHS and ACMPLP) with their output pin enabled.

Interrupts and Callbacks

When a comparator event occurs, the R_ACMPLP HAL module calls the callback (comparator_cfg_t::p_callback) with the callback argument (comparator_callback_args_t).

ACMPLP HAL Module Limitations

  • This module does not support  the Filter 16 option for PCLK divisor in the hardware digital debounce filter.
  • This module only works for selected Synergy MCUs. Consult the release notes for your current SSP release to see which MCUs are supported by this module. The MCU Hardware Manual shows which peripherals are available for each MCU.
  • Refer to the latest SSP Release Notes for any additional operational limitations for this module.

Including the ACMPLP HAL Module in an Application

This section describes how to include the ACMPLP HAL Module in an application using the SSP configurator.

Note
This section assumes you are familiar with creating a project, adding threads, adding a stack to a thread and configuring a block within the stack. If you are unfamiliar with any of these items, refer to the first few chapters of the SSP User's Manual to learn how to manage each of these important steps in creating SSP-based applications.

To add the Comparator Driver to an application, simply add it to a thread using the stacks selection sequence given in the following table. (The default name for the Comparator Driver is g_acmplp0. This name can be changed in the associated Properties window.)

ACMPLP HAL Module Selection Sequence

Resource ISDE Tab Stacks Selection Sequence
g_comparator0 Comparator Driver on r_acmplp Threads New Stack> Driver> Analog> Comparator Driver on r_acmplp

When the Comparator Driver on r_acmplp is added to the thread stack as shown in the following figure, the configurator automatically adds any needed lower‑level modules. Any modules needing additional configuration information have the box text highlighted in Red. Modules with a Gray band are individual modules that stand alone. Modules with a Blue band are shared or common; they need only be added once and can be used by multiple stacks. Modules with a Pink band can require the selection of lower-level modules; these are either optional or recommended. (This is indicated in the block with the inclusion of this text.) If the addition of lower-level modules is required, the module description include Add in the text. Clicking on any Pink banded modules brings up the New icon and displays possible choices.

ACMPLP_MS.png
ACMPLP Module Stack

Configuring the ACMPLP HAL Module

The ACMPLP HAL Module must be configured by the user for the desired operation. The available configuration settings and defaults for all the user-accessible properties are given in the properties tab within the SSP configurator and are shown in the following tables for easy reference. Only properties that can be changed without causing conflicts are available for modification. Other properties are locked and not available for changes and are identified with a lock icon for the locked property in the Properties window in the ISDE. This approach simplifies the configuration process and makes it much less error-prone than previous manual approaches to configuration. The available configuration settings and defaults for all the user-accessible properties are given in the Properties tab within the SSP Configurator and are shown in the following tables for easy reference.

Note
You may want to open your ISDE, create the module and explore the property settings in parallel with looking over the following configuration table settings. This will help orient you and can be a useful 'hands-on' approach to learning the ins and outs of developing with SSP.

Configuration Settings for the ACMPLP HAL Module on r_acmplp

ISDE Property Value Description
Parameter Checking BSP, Enabled, Disabled
Default: BSP
Controls whether to include code for API parameter checking.
Name g_comparator Module name.
Channel 0 Select the hardware channel.
Mode Mode Normal, Mode Window
Default: Mode Normal
In normal 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.
Trigger Trigger Rising, Trigger Falling, Trigger Both Edge
Default: Trigger Both Edge
The trigger specifies when a comparator callback event should occur. Unused if the interrupt priority is disabled or the callback is NULL.
Filter Filter Off, Filter 1, Filter 8, Filter 32
Default: Filter Off
Select the PCLK divisor for the hardware digital debounce filter. Larger divisors provide a longer debounce and take longer for the output to update.
Invert Off, On
Default: Off
Turns this on to invest comparator output. This affects the output read from StatusGet(), the pin output level, and the edge trigger.
Pin Output Off, On
Default: Off
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.
Callback NULL Define this function in the application. It is called when the Trigger event occurs.
Comparator Interrupt Priority Priority 0 (highest), Priority 1:14, Priority 15 (lowest - not valid if using ThreadX), Disabled
Default: Disabled
Select the interrupt priority for the comparator interrupt.
Note
The example settings and defaults are for a project using the Synergy S7G2 MCU Group. Other MCUs may have different default values and available configuration settings.

Configuration Settings for the ACMPLP HAL Module Lower Level Modules

Typically, only a small number of settings must be modified from the default for lower level drivers as indicated via the Red text in the Thread Stack block. Notice that some of the configuration properties must be set to a certain value for proper framework operation and will be locked to prevent user modification. The following table identifies all the settings within the properties section for the module:

Configuration Settings for the Analog Connection HAL Module on r_analog_connect

ISDE Property Value Description
Parameter Checking BSP, Enabled, Disabled
 
Default: BSP
Enable or disable the parameter error checking.
Name g_analog_connect0 Module name.
Connection Table Name g_analog_connect0_table This connection table name is passed to the connectMultiple API function to make all configured connections.
ACMPHS0 IVCMP No Connection, PORT5 P500, PORT0 P013, PORT1 P100
 
Default: No Connection
Select the connection for ACMPHS0 IVCMP
Note
Not required for ACMPLP Module.
ACMHS0 IVREF No Connection, PORT5 P501, PORT0 P014, PORT1 P101, DAC80 DA, DAC120 DA, Analog0 VREF
 
Default: No Connection
Select the connection for ACMPHS0 IVREF
Note
Not required for ACMPLP Module.
ACMPL0 IVREF0 No Connection, PORT1 P109, DAC80 DA
 
Default: No Connection
Select the connection for ACMPL0 IVREF0.
ACMPLP1 IVREF1 No Connection, PORT1 P110, DAC81 DA
 
Default: No Connection
Select the connection for ACMPLP1 IVREF1.
ACMPLP0 IVCMP No Connection, PORT4 P400, OPAMP0 AMPO
 
Default: No Connection
Select the connection for ACMPLP0 IVCMP.
ACMPLP0 IVREF No Connection, ANALOG0 VREF, ACMPLP0 IVREF0
 
Default: No Connection
Select the connection for ACMPLP0 IVREF.
ACMPLP1 IVCMP No Connection, PORT4 P408, OPAMP1 AMPO
 
Default: No Connection
Select the connection for ACMPLP1 IVCMP.
ACMPLP1 IVREF No Connection, ANALOG0 VREF, ACMPLP0 IVREF0, ACMPLP1 IVREF1
 
Default: No Connection
Select the connection for ACMPLP1 VREF.
OPAMP0 AMPO No Connection, PORT0P014, PORT0 P013, PORT0P003, PORT0 P002
 
Default: No Connection
Select the connection for OAMP0 AMPO.
Note
Not required for ACMPLP Module.
OPAMP0 AMPM No Connection, PORT5 P501, PORT5 500, PORT0 P014, PORT0 P113, PORT0 P003, OPAMP0 AMPO
 
Default: No Connection
Select the connection for OPAMP0 AMPM.
Note
Not required for ACMPLP Module.
OPAMP0 AMPP No Connection, PORT5 P500, PORT0 P014, PORT0P013, PORT0 P002, DAC120 DA
 
Default: No Connection
Select the connection for OPAMP0 AMPP.
Note
Not required for ACMPLP Module.
OPAMP1 AMPM No Connection, PORT0 P014, OPAMP1 AMPO
 
Default: No Connection
Select the connection for OPAMP1 AMPM.
Note
Not required for ACMPLP Module.
OPAMP1 AMPP No Connection, PORT0 P014, PORT0 P013, PORT0 P003, PORT0 P002, DAC80 DA
 
Default: No Connection
Select the connection for OPAMP1 AMPP.
Note
Not required for ACMPLP Module.
OPAMP2 AMPM No Connection, PORT0 P003, OPAMP2 AMPO
 
Default: No Connection
Select the connection for OPAMP2 AMPM.
Note
Not required for ACMPLP Module.
OPAMP2 AMPP No Connection, PORT0 P003, PORT0 P002, DAC81DA
 
Default: No Connection
Select the connection for OPAMP2 AMPP.
Note
Not required for ACMPLP Module.
Note
The example settings and defaults are for a project using the Synergy S1JA MCU Group. Other MCUs may have different default values and available configuration settings.

ACMPLP HAL Module Clock Configuration

The ACMPLP HAL module uses the PCLKB as its clock source.

To change the clock frequency at run-time, use the CGC Interface.

ACMPLP HAL Module Pin Configuration

To use the ACMPLP HAL module, the port pins for the channels receiving the analog input must be set as input pins in the pin configurator in the ISDE. The following table illustrates the method for selecting the pins within the ISDE configuration window:

Pin Selection for the ACMPLP HAL Module on r_acmplp

Resource ISDE Tab Pin selection Sequence
ACMPLP Pins Select Peripherals> Analog:ACMP

Configuration Settings for the ACMPLP HAL Module Lower Level Modules

Typically, only a small number of settings must be modified from the default for lower level drivers as indicated via the Red text in the Thread Stack block. Notice that some of the configuration properties must be set to a certain value for proper framework operation and will be locked to prevent user modification. The following table identifies all the settings within the properties section for the module: 

Configuration Settings for the Analog Connection HAL Module on r_analog_connect

ISDE Property Value Description
Parameter Checking BSP, Enabled, Disabled 

Default: BSP
Enable or disable the parameter error checking.
Name g_analog_connect0 Module name.
Connection Table Name g_analog_connect0_table This connection table name is passed to the connectMultiple API function to make all configured connections.
ACMPHS0 IVCMP No Connection, PORT5 P500, PORT0 P013, PORT1 P100

Default: No Connection
Select the connection for ACMPHS0 IVCMP.
Note
 Not required for ACMPLP Module.
ACMHS0 IVREF No Connection, PORT5 P501, PORT0 P014, PORT1 P101, DAC80 DA, DAC120 DA, Analog0 VREF

Default: No Connection
Select the connection for ACMPHS0 IVREF.
 
Note
 Not required for ACMPLP Module.
ACMPL0 IVREF0 No Connection, PORT1 P109, DAC80 DA

Default: No Connection
Select the connection for ACMPL0 IVREF0.
ACMPLP1 IVREF1 No Connection, PORT1 P110, DAC81 DA

Default: No Connection
Select the connection for ACMPLP1 IVREF1.
ACMPLP0 IVCMP No Connection, PORT4 P400, OPAMP0 AMPO

Default: No Connection
Select the connection for ACMPLP0 IVCMP.
ACMPLP0 IVREF No Connection, ANALOG0 VREF, ACMPLP0 IVREF0

Default: No Connection
Select the connection for ACMPLP0 IVREF.
ACMPLP1 IVCMP No Connection, PORT4 P408, OPAMP1 AMPO

Default: No Connection
Select the connection for ACMPLP1 IVCMP.
ACMPLP1 IVREF No Connection, ANALOG0 VREF, ACMPLP0 IVREF0, ACMPLP1 IVREF1

Default: No Connection
Select the connection for ACMPLP1 VREF.
OPAMP0 AMPO No Connection, PORT0P014, PORT0 P013, PORT0P003, PORT0 P002

Default: No Connection
Select the connection for OAMP0 AMPO.
 
Note
 Not required for ACMPLP Module.
OPAMP0 AMPM No Connection, PORT5 P501, PORT5 500, PORT0 P014, PORT0 P113, PORT0 P003, OPAMP0 AMPO

Default: No Connection
Select the connection for OPAMP0 AMPM.
 
Note
 Not required for ACMPLP Module.
OPAMP0 AMPP No Connection, PORT5 P500, PORT0 P014, PORT0P013, PORT0 P002, DAC120 DA

Default: No Connection
Select the connection for OPAMP0 AMPP.
 
Note
 Not required for ACMPLP Module.
OPAMP1 AMPM No Connection, PORT0 P014, OPAMP1 AMPO

Default: No Connection
Select the connection for OPAMP1 AMPM.
 
Note
 Not required for ACMPLP Module.
OPAMP1 AMPP No Connection, PORT0 P014, PORT0 P013, PORT0 P003, PORT0 P002, DAC80 DA

Default: No Connection
Select the connection for OPAMP1 AMPP.
 
Note
 Not required for ACMPLP Module.
OPAMP2 AMPM No Connection, PORT0 P003, OPAMP2 AMPO

Default: No Connection
Select the connection for OPAMP2 AMPM.
 
Note
 Not required for ACMPLP Module.
OPAMP2 AMPP No Connection, PORT0 P003, PORT0 P002, DAC81DA

Default: No Connection
Select the connection for OPAMP2 AMPP.
 
Note
 Not required for ACMPLP Module.
Note
The example settings and defaults are for a project using the Synergy S1JA MCU Group. Other MCUs may have different default values and available configuration settings.

Using the ACMPLP HAL Module in an Application

The typical steps in using the ACMPLP HAL module in an application are:

  1. Initialize the ACMPLP using the comparator_api_t::open API.
  2. Before VCOUT is enabled, the low level corresponding hardware register must be configured as mentioned below:     
    1. Either directly configuring HW registers (COMPMDR/COMPSELn) in application.
    2. Or using Analog Connect module APIs which in turn configure low level registers.  
  3. After configuring the modules and internal connections, wait for the minimum stabilization wait time before enabling output.  The minimum stabilization wait time can be queried using the comparator_api_t::infoGet API.
  4. Enable the comparator output using the comparator_api_t::outputEnable API.  This enables pin output, interrupts and the comparator_api_t::statusGet API as configured during the open API call.
  5. [Optional] Use the comparator_api_t::statusGet API to poll comparator status.
  6. [Optional] Use the comparator_api_t::close API to disable the comparator and power down the peripheral.

These common steps are illustrated in a typical operational flow diagram in the following figure:

ACMPLP_TA.png
Flow Diagram of a Typical ACMPLP HAL Module Application