![]() |
Synergy Software Package User's Manual
|
The Input Capture HAL module provides an API for measuring input pulse-width, period measurement and event count measurement. The Input Capture HAL module also configures the input capture parameters to use with the AGT peripheral on the Synergy MCU. A user-defined callback can be created to acquire the value each time a new measurement is complete.
The Input Capture HAL module configures the AGT for an input capture function.
The following hardware features are, or are not, supported by SSP for AGT Input Capture.
Legend:
| Symbol | Meaning |
|---|---|
| ✓ | Available (Tested) |
| ⌧ | Not Available (Not tested/not functional or both) |
| N/A | Not supported by MCU |
| MCU Group | Timer Mode | Pulse Output Mode | Event Counter Mode | Pulse width measurement mode |
|---|---|---|---|---|
| S124 | ⌧ | ⌧ | ✓ | ✓ |
| S128 | ⌧ | ⌧ | ✓ | ✓ |
| S1JA | ⌧ | ⌧ | ✓ | ✓ |
| S3A1 | ⌧ | ⌧ | ✓ | ✓ |
| S3A3 | ⌧ | ⌧ | ✓ | ✓ |
| S3A6 | ⌧ | ⌧ | ✓ | ✓ |
| S3A7 | ⌧ | ⌧ | ✓ | ✓ |
| S5D3 | ⌧ | ⌧ | ✓ | ✓ |
| S5D5 | ⌧ | ⌧ | ✓ | ✓ |
| S5D9 | ⌧ | ⌧ | ✓ | ✓ |
| S7G2 | ⌧ | ⌧ | ✓ | ✓ |
| MCU Group | Pulse period measurement mode | Event link function through ELC HAL driver | Compare/Match Function |
|---|---|---|---|
| S124 | ✓ | ⌧ | ⌧ |
| S128 | ✓ | ⌧ | ⌧ |
| S1JA | ✓ | ⌧ | ⌧ |
| S3A1 | ✓ | ⌧ | ⌧ |
| S3A3 | ✓ | ⌧ | ⌧ |
| S3A6 | ✓ | ⌧ | ⌧ |
| S3A7 | ✓ | ⌧ | ⌧ |
| S5D3 | ✓ | ⌧ | ⌧ |
| S5D5 | ✓ | ⌧ | ⌧ |
| S5D9 | ✓ | ⌧ | ⌧ |
| S7G2 | ✓ | ⌧ | ⌧ |
The Input Capture HAL module interface defines APIs for opening, closing, enabling, disabling, accessing status information, and accessing the last-capture value using the Asynchronous General-Purpose Timer (AGT) with Input Capture. 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 HAL Module API Summary.
Input Capture HAL Module API Summary
| Function Name | Example API Call and Description |
|---|---|
| open | g_input_capture.p_api->open(g_input_capture.p_ctrl, g_input_capture.p_cfg);Opens the Input Capture HAL and initializes configuration. |
| close | g_input_capture.p_api->close(g_input_capture.p_ctrl);Closes the input capture operation. Allow drive to be reconfigured, and may reduce power consumption. |
| enable | g_input_capture.p_api->enable(g_input_capture.p_ctrl);Enables input capture measurement. |
| disable | g_input_capture.p_api->disable(g_input_capture.p_ctrl);Disables input capture measurement. |
| infoGet | g_input_capture.p_api->infoGet(g_input_capture.p_ctrl, &input_capture_info);Gets the status (running or not) of the measurement counter. |
| lastCaptureGet | g_input_capture.p_api->lastCaptureGet(g_input_capture.p_ctrl, &input_capture_counter);Gets the last captured timer/overflows counter value. |
| versionGet | g_input_capture.p_api->versionGet(&input_capture_version);Retrieve the API version with the input_capture_version pointer. |
Status Return Values
| Name | Description |
|---|---|
| SSP_SUCCESS | API Call Successful. |
| SSP_ERR_ASSERTION | One of the parameters is NULL. Or the channel requested in the p_cfg parameter may not be available on the device selected in r_bsp_cfg.h. Or, p_cfg->mode is invalid. |
| SSP_ERR_IRQ_BSP_DISABLED | A required interrupt does not exist in the vector table. |
| SSP_ERR_IN_USE | Attempted to open an already open device instance. |
| SSP_ERR_NOT_OPEN | The channel is not opened. |
The Input Capture HAL module controls the AGT HAL module units on a Synergy microcontroller (as configured by the user). It directly accesses the AGT hardware without using any RTOS elements and provides convenient APIs to simplify development.
When a normal measurement is complete and a callback is available (with interrupts enabled,) the Input Capture HAL module invokes the callback with the argument input_capture_callback_args_t.
The argument input_capture_callback_args_t indicates the channel, the event input_capture_event_t, the value of the timer captured when the interrupt occurred, and the number of counter overflows that occurred during this measurement.
If the interrupts are not enabled, the values read by the APIs would be the last captured timer/overflows counter value.
AGT Input Capture Measurement and overflow
The input capture interface provides support for pulse-width, period measurement, and event count measurement. The input capture interface also provides support for one-shot measurement and periodic measurement. The AGT hardware does not natively support one-shot functionality. Code is automatically included in the interrupt service routine (ISR) to stop and clear the timer.
The AGT hardware doesn't have a hardware interrupt vector for event count measurement. Therefore, the compare match vector triggers a callback when the counter reaches the count value supplied by user.
AGT Input Capture Signal
The input capture measurement starts when the input capture signal edge (rising or falling) is detected on the input capture signal pin (AGTIO). The input could be captured in any one of the AGT input capture pin (such as AGTIO0_A, AGTIO0_B, or AGTIO0_C) as configured by user. The pin corresponding to this selection must also be configured in AGT peripheral in the configurator.xml (that is, under configuration.xml > pins > peripherals > Timer:AGT). The details on pins to be configured are in the user manual under the AGT block diagram and in the I/O ports section. Note that in the S3 and S5 series MCUs, AGTIO0_B is P402, AGTIO0_C is P403, and all other AGTIO pins are AGTIO0_A. The S1 MCU Series have only AGTIO0_A pins.
The noise filter samples the external signal at intervals of the PCLK divided by one of the values. When three consecutive samples are at the same level (high or low), then that level is passed on as the observed state of the signal.
For event count measurement, the module can be configured to count a single or both edges. That is, if it is configured as single edge, the signal edge as input by the user is counted, and if it is configured as both edges, pulses are counted on the starting edge of the pulse (either rising or falling edge). And the module will generate a callback when the pulse count reaches the event count value set by the user.
Event count measurement uses the capture compare interrupt to compare the counter value with the user expected value (and trigger a callback when they are the same), and uses the measurement and overflow interrupt to keep track of the overflow. Hence the priority of the measurement and overflow interrupt must be set higher than the latter, as the capturing of overflow takes precedence to compare match callback.
For pulse width measurement, if the input capture module is opened in the middle of an active level input by user, the module will start capturing the width from where it opened, and hence the captured width will not be the right width of the pulse.
Converting Measurement Counts to Time
When a measurement completes, the raw-count data and the number of overflows is returned to the user in the callback function.
If desired, the raw measurement data can be converted to logical time units in the callback or user application. To convert the raw data, the current clock frequency and its pre-scaler value, number of overflows, maximum counter value, and measurement counts should be considered. The measurement counts and the number of overflows are provided in the callback arguments input_capture_callback_args_t.
The recommended method to obtain the current clock frequency is to use the cgc_api_t::systemClockFreqGet API. The input clock frequency is the clock frequency divided by the pre-scaler value and is represented as clk_freq_hz in the following Input Capture Time Calculation table. Note that pre-scaler are only available for AGTLCLK and AGTSCLK clocks
The maximum counter value for all boards is 0xFFFF. This maximum counter value plus one (since counter starts from zero) is represented as max_counts in the following table:
Input Capture Time Calculation
| Desired Time Units | Formula |
|---|---|
| Nanoseconds (ns) | time_s = ((overflows * max_counts) + counter) * 1000000000 / clk_freq_hz |
| Microseconds (us) | time_s = ((overflows * max_counts) + counter) * 1000000 / clk_freq_hz |
| Milliseconds (ms) | time_s = ((overflows * max_counts) + counter) * 1000 / clk_freq_hz |
| Seconds (s) | time_s = ((overflows * max_counts) + counter) / clk_freq_hz |
This section describes how to include the Input Capture HAL Module in an application using the SSP configurator.
To add the Input Capture 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 Input Capture Driver is g_input_capture0. This name can be changed in the associated Properties window.)
Input Capture HAL Module Selection Sequence
| Resource | ISDE Tab | Stacks Selection Sequence |
|---|---|---|
| g_input_captureInput Capture Driver on r_agt_input_capture | Threads->HAL/Common Stacks | New Stack> Driver> Timers> Input Capture Driver on r_agt_input_capture |
When the Input Capture Driver on r_agt_input_capture 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.
The Input Capture 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. They 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.
Configuration Settings for the Input Capture HAL Module on r_agt_input_capture
| ISDE Property | Value | Description |
|---|---|---|
| Parameter Checking | BSP, Enabled, Disabled Default: BSP | Enable or disable the parameter error checking. |
| Name | g_input_capture | Module name. |
| Channel | 0 | Physical hardware channel. |
| Mode | Pulse Width, Period, Event count Default: Pulse Width | Measures the input signal. |
| Signal Edge | Rising, Falling Default: Rising | Start measurement on rising or falling edge. Measurement stops on the opposite edge. |
| AGTIO Pin Select | AGTIO_A, AGTIO_B, AGTIO_C Default: AGTIO_A | Captures the input signal through one of these pins. |
| Event Edge Polarity | Single Edge, Both Edge Default: Both Edge | Counts the pulses on single edges (that is, on either rising or falling) or on both edges (that is, on either rising or falling) is received, in the event counter mode. |
| Repetition | Periodic, One Shot Default: Periodic | Capture a single measurement, then disable captures (one shot) until enable is called, or capture measurements continuously (periodic). |
| Auto Start | True, False Default: True | Set to true to enable measurements after configuring or false to leave the measurements disabled until enable is called. |
| Input Signal Filter | None, PCLK/1, PCLK/8, PCLK/32. Default: None | The noise filter samples the external signal at intervals of the PCLKB divided by one of the values. When 3 consecutive samples are at the same level (high or low), that level is passed on as the observed state of the signal. |
| Clock source | PCLKB, PCLKB/8, PCLKB/2, AGTLCLK, AGTSCLK Default: PCLKB | Input capture clock source. |
| Clock Divider | PCLK/1, PCLK/2, PCLK/4, PCLK/8, PCKL/16, PCLK/32, PCLK/64, PCLK/128 Default: PCLK/1 | Clock divider used to scale the measurement counter. |
| Callback | NULL | A user callback function must be registered in open. The callback will be called from the interrupt service routine (ISR) each time the measurement or overflow occurs. Warning: Since the callback is called from an ISR, care should be taken not to use blocking calls or lengthy processing. Spending excessive time in an ISR can affect the responsiveness of the system. |
| Measurement and Overflow Interrupt Priority | Priority 0 (highest), Priority 1:14, Priority 15 (lowest - not valid if using ThreadX) Default: Priority 12 | Select the measurement and overflow interrupt priority. |
| Capture Interrupt Priority | Priority 0 (highest), Priority 1:14, Priority 15 (lowest - not valid if using ThreadX) Default: Priority 12 | Select the capture interrupt priority, captured interrupt is used only for event count mode. |
The AGT HAL module uses the PCLKB, AGTLCLK and AGTSCLK as its clock source. The clock frequency is set using the SSP configurator Clocks tab prior to a build, or using the CGC Interface at run-time.
The AGT peripheral module uses pins on the MCU to communicate to external devices. I/O pins must be selected and configured as required by the external device. The following table illustrates the method for selecting the pins within the SSP configuration window and the subsequent table illustrates an example selection for the associated pins.
Pin Selection for the AGT HAL Module on r_agt
| Resource | ISDE Tab | Pin selection Sequence |
|---|---|---|
| AGT | Pins | Select Peripherals > Timer: AGT> AGT0 |
Pin Configuration Settings for the Input capture HAL Module on r_agt_input_capture
| Property | Value | Description |
|---|---|---|
| Operation Mode | Disabled, Custom, Timer Output, Compare Match, Count Measurement, Gated Count Default: Disabled | Select timer operation mode. |
| AGTIO | None, P100, P402, P403 Default: None | AGTIO pin. |
| AGTO | None Default: None | AGTO pin. |
| AGTOA | None Default: None | AGTOA pin. |
| AGTOB | None Default: None | AGTOB pin |
| AGTEE | None Default: None | AGTEE pin. |
The typical steps in using the Input Capture HAL module in an application are:
These common steps are illustrated in a typical operational flow diagram in the following figure: