![]() |
RX Flexible Software Package Documentation
Release v1.0.0
|
|
Functions | |
| fsp_err_t | R_PCIF_Open (pcif_ctrl_t *const p_ctrl, pcif_cfg_t const *const p_cfg) |
| fsp_err_t | R_PCIF_Stop (pcif_ctrl_t *const p_ctrl, pcif_stop_mode_t stop_mode) |
| fsp_err_t | R_PCIF_Start (pcif_ctrl_t *const p_ctrl) |
| fsp_err_t | R_PCIF_SetCounter (pcif_ctrl_t *const p_ctrl, pcif_phc_counter_info_t const *const p_counter_data, bool reset_counter) |
| fsp_err_t | R_PCIF_StatusGet (pcif_ctrl_t *const p_ctrl, pcif_status_t *const p_status) |
| fsp_err_t | R_PCIF_SoftwareEventGenerate (pcif_ctrl_t *const p_ctrl) |
| fsp_err_t | R_PCIF_Close (pcif_ctrl_t *const p_ctrl) |
Driver for the PCIF peripheral on RX MCUs. This module implements the PCIF Interface.
The Phase Counting Interface (PCIF) outputs A-phase, B-phase, and Z-phase signals for encoder-style motor control systems. The PCIF has two operating modes:
| Configuration | Options | Default | Description |
|---|---|---|---|
| Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
| Timer Support |
| Disabled | If select whether to use Timer module in the build. |
| Configuration | Options | Default | Description |
|---|---|---|---|
| General > Polarity > A-phase |
| Positive | Select the polarity for A phase. |
| General > Polarity > B-phase |
| Positive | Select the polarity for B phase. |
| General > Polarity > Z-phase |
| Positive | Select the polarity for Z phase. |
| General > Name | Name must be a valid C symbol | g_pcif0 | Module name. |
| General > Channel | Value must be an non-negative integer | 0 | Specify the PCIF channel. |
| General > Clock Source | MCU Specific Options | Select the clock source for the PCIF module. | |
| General > Mode |
| Phase Counting Mode | Select the clock source for the PCIF module. |
| General > Maximum Position | Manual Entry | 0x10000 | Specify The maximum value of the position counter. |
| Phase Counting Mode > ELC Support > Carrier Period Event Trigger Source | MCU Specific Options | Select external source that triggers the carrier period. | |
| Phase Counting Mode > Initialize Edge Data > Start Position | Value must be a non-negative integer and less than max position | 0 | Set specify start counter position. |
| Phase Counting Mode > Initialize Edge Data > Edge Count Data | Value must be a signed 16-bit integer | 0 | Set the initial edge counter. This value must also be within +/- the generated carrier period count. |
| Phase Counting Mode > Error Detect > Error Carrier Period Detection |
| Disable | Select carrier period error detection. |
| Phase Counting Mode > Error Detect > Error Edge Unprocessed Detection |
| Disable | Select edge unprocessed error detection. |
| Phase Counting Mode > Error Detect > Error Edge Counting Overflow Detection |
| Disable | Select edge counting overflow error detection. |
| Phase Counting Mode > Error Detect > Error Old Edge Detection |
| Disable | Select old edge error detection. |
| Phase Counting Mode > Carrier Period | Manual Entry | 500 | Specify the carrier period in microseconds selected. |
| Phase Counting Mode > Carrier Period Event Difference Threshold | Value must be a non-negative integer in the 16-bit range | 0x100 | Allowable difference range of carrier period events. This value must be less than the generated carrier period count. |
| Phase Counting Mode > Carrier Period Adjustment Mode |
| Register Based Mode | Carrier period adjustment mode selection. |
| Phase Counting Mode > Z Phase Width |
| Z-phase Width Disable | Select Z-phase width configuration. |
| Phase Counting Mode > Z Phase Sync |
| Z-phase Sync A Phase | Select Z-phase synchronize configuration. |
| Phase Counting Mode > Edge Counter Clear |
| Disable | Select automatic clear edge counter configuration. |
| Phase Counting Mode > Callback | Name must be a valid C symbol | NULL | A user callback function can be specified here. If this callback function is provided, it will be called from the interrupt service routine (ISR) each time the carrier period elapses |
| Incremental Mode > ELC Support > Crest Event Trigger Src | MCU Specific Options | Select external source that triggers the crest event. | |
| Incremental Mode > ELC Support > Trough Event Trigger Src | MCU Specific Options | Select external source that triggers the trough event. | |
| Incremental Mode > Downscale Resolution Ratio | Value must be from 1 to 64 | 1 | Specify the downscale resolution ratio. |
| Incremental Mode > AB-Phase Input Mode |
| Mode 0 (AB phase pulse) | Incremental AB phase input mode selection |
| Incremental Mode > AB-Phase Output Mode |
| Same as input | Incremental AB phase output mode selection |
| Incremental Mode > Z-Phase Output Mode |
| Immediate output | Incremental Z phase output mode selection |
| Incremental Mode > Z-Phase Output Minimum Cycle | Value must be from 1 to 256 | 1 | Specify the minimum output cycle. |
| Incremental Mode > Z Phase Generate Sources |
| Select Z phase generate sources. | |
| Incremental Mode > Clear Counter Sources |
| Select counter clear sources. |
PCIF uses CCLK as the core clock and CCLK_DIV as the output synchronization clock. CCLK can be selected from PCLKB or GPTCLK in the RX Configuration editor.
Configure the clocks so all HUM clock conditions are satisfied:
| Clock | HUM range or limit |
|---|---|
| PCLKB | Maximum 75 MHz |
| CCLK | Maximum 200 MHz |
| CCLK_DIV | 10 MHz to 20 MHz |
The following relationships must also be satisfied:
PCLKB >= 2 * CCLK_DIVPCLKB >= CCLK / 8For example, the HUM maximum-frequency setting is PCLKB = 75 MHz, CCLK = 200 MHz, and CCLK_DIV = 20 MHz.
This module can use PCOUTAn, PCOUTBn, and PCOUTZn pins as output pins.
This module can use PCINAn, PCINBn, and PCINZn pins as input pins for encoder signals.
SR.PCIFPS is 1.R_PCIF_StatusGet reports the PCIF operation state, rotation direction, and monitor values. In phase-counting mode, current_position_value is PHCPCMR.PHCPOSCNTM, position_write_value is PHCPCWDR.PHCPOSCNTWD, and input_counter_value is 0. In incremental mode, current_position_value is INCPCMR.INCOCNTM, input_counter_value is INCPCMR.INCICNTM, and position_write_value is 0.max_count_position field is the POSMAX register value. For an encoder with N edges per rotation, configure max_count_position = N - 1.PHCECR.PHCEDGCNT must be in the range -carrier_period_counts to +carrier_period_counts.There are two methods for controlling the carrier period:
PHCPERIODR.PHCPERIOD[15:0] value.Set PHCPERIODR.PHCPERIOD[15:0] to the mean interval of carrier period events. If the long-term mean event interval differs from the register setting, edges may not be completely processed and may be lost during long-term operation.
R_PCIF_SetCounter writes the new edge count and can also write the new position value.
position_write_value from R_PCIF_StatusGet can be used to inspect the latest position write value.Error detection is available only in phase-counting mode and must be enabled per error type in the configuration. If an error specified by PHCSR occurs, HUM operation is not guaranteed. Stop or reset the PCIF according to the phase-counting stop flow, clear the error state, and review the PCIF settings.
PCIF supports the following incremental input/output combinations:
| Input setting | Output setting | Input protocol mode | Output protocol mode |
|---|---|---|---|
| AB-phase pulse | Same as input | Mode 0 | Mode 0 |
| A-phase pulse, B-phase direction | Same as input | Mode 1 | Mode 1 |
| A-phase pulse, B-phase direction | AB-phase pulse | Mode 1 | Mode 0 |
| Pulse switching | Same as input | Mode 2 | Mode 2 |
| Pulse switching | AB-phase pulse | Mode 2 | Mode 0 |
Note:
The incremental resolution setting is encoded as INCRSL = ratio - 1. A setting of 0 outputs the same resolution as the input; a setting of 63 outputs 1/64 of the input resolution.
In incremental mode, the complete input position can be calculated from the monitor values returned by R_PCIF_StatusGet:
The following HUM restrictions are enforced by the driver:
z_output_min_cycles extends the Z-phase output assertion period. A configured value of 0 means 1 CCLK_DIV cycle, and 255 means 256 CCLK_DIV cycles. While the Z-phase output assertion period is being extended, other Z-phase output conditions are ignored until the extension completes.
The input ABZ signal must meet the HUM minimum toggle interval:
| Input protocol condition | Minimum required toggle interval |
|---|---|
| Mode 0 | 1 CCLK cycle + 1 CCLK_DIV cycle |
| Mode 1 | 1 CCLK cycle + 1 CCLK_DIV cycle |
| Mode 2 with constant rotation direction | 1 CCLK cycle + 1 CCLK_DIV cycle |
| Mode 2 when the rotation direction changes | 1 CCLK cycle + 2 CCLK_DIV cycles |
If the input signal does not satisfy these intervals, edges may be lost.
PHCECR.PHCEDGCNT[15:0] can represent values from -PHCPERIOD[15:0] to +PHCPERIOD[15:0]. The FSP API uses int16_t for edge count data, so values outside the signed 16-bit range cannot be passed through the API.This is a basic example of minimal use of the PCIF in an application.
This is an example of PCIF callback.
This is an example of PCIF phase counting mode.
This is an example of updating edge data in the PCIF main process.
This is an example of PCIF incremental mode.
Data Structures | |
| struct | pcif_extended_cfg_t |
| struct | pcif_instance_ctrl_t |
Macros | |
| #define | PCIF_INC_RESOLUTION_RATIO_SETTING_MAX |
| #define | PCIF_INC_Z_PHASE_GEN_COUNTER_INPUT_PROHIBITED_MASK |
| #define | PCIF_INC_COUNTER_CLEAR_Z_GEN_PROHIBITED_MASK |
Enumerations | |
| enum | pcif_phc_error_detection_enable_t |
| enum | pcif_phc_z_phase_width_t |
| enum | pcif_phc_z_phase_sync_t |
| enum | pcif_phc_carrier_period_mode_t |
| enum | pcif_phc_counter_clear_mode_t |
| enum | pcif_inc_ab_input_mode_t |
| enum | pcif_inc_ab_output_mode_t |
| enum | pcif_inc_z_output_mode_t |
| enum | pcif_inc_z_generate_source_t |
| enum | pcif_inc_position_counter_clear_t |
| struct pcif_extended_cfg_t |
Extended configuration structure for PCIF.
| Data Fields | ||
|---|---|---|
| pcif_phc_z_phase_width_t | z_width |
Set width Z phase. Setting for Phase Counting mode Setting Z phase |
| pcif_phc_z_phase_sync_t | z_sync | Set phase (A/B) to sync Z phase. |
| pcif_phc_carrier_period_mode_t | carrier_period_mode |
Set carrier period mode. Carrier Period Setting |
| uint16_t | carrier_period_diff_threshold | Carrier period difference threshold in CCLK_DIV cycles. |
| uint16_t | carrier_period_counts | Carrier period in CCLK_DIV cycles. |
| pcif_phc_counter_clear_mode_t | counter_clear_mode |
Set automatic clear counter mode. Edge Counter Setting |
| pcif_phc_counter_info_t * | p_init_counter_data | Set initial counter data. |
| pcif_phc_error_detection_enable_t | error_carrier_period_enable |
Set carrier period error detection enable. Error detection enable setting |
| pcif_phc_error_detection_enable_t | error_edge_count_enable | Set edge count error detection enable. |
| pcif_phc_error_detection_enable_t | error_edge_count_overflow_enable | Set edge count overflow error detection enable. |
| pcif_phc_error_detection_enable_t | error_old_edge_count_enable | Set old edge count error detection enable. |
| uint8_t | resolution_ratio_setting |
Output resolution: 0 = x1/1, N = x1/(N + 1), max 0x3F. Setting for Incremental mode |
| pcif_inc_ab_input_mode_t | ab_input_mode |
Set incremental input mode. Setting A/B phase |
| pcif_inc_ab_output_mode_t | ab_output_mode | Set incremental output mode. |
| uint8_t | z_output_min_cycles |
Minimum cycle Z output: 0 = 1 CCLK_DIV cycle, 0xFF = 256 cycles. Setting Z Phase |
| pcif_inc_z_generate_source_t | z_generate_source | Set Z phase generate source. |
| pcif_inc_z_output_mode_t | z_output_mode | Set incremental Z phase output mode. |
| pcif_inc_position_counter_clear_t | position_clear_source | Set incremental position counter clear mode. |
| struct pcif_instance_ctrl_t |
Control block used by driver. DO NOT INITIALIZE. Initialization occurs when pcif_api_t::open is called.
| #define PCIF_INC_RESOLUTION_RATIO_SETTING_MAX |
Maximum incremental mode resolution ratio setting (INCRSL[5:0]).
| #define PCIF_INC_Z_PHASE_GEN_COUNTER_INPUT_PROHIBITED_MASK |
Z phase generation sources that cannot be enabled together.
| #define PCIF_INC_COUNTER_CLEAR_Z_GEN_PROHIBITED_MASK |
Position clear source prohibited when counter-based Z phase generation is enabled.
Incremental mode Z phase generate source
Incremental position counter clear enable bit
| fsp_err_t R_PCIF_Open | ( | pcif_ctrl_t *const | p_ctrl, |
| pcif_cfg_t const *const | p_cfg | ||
| ) |
Initializes the pcif module and applies configurations. Implements pcif_api_t::open.
This function sets this clock divisor and the configurations specified in pcif_cfg_t.
Example:
| FSP_SUCCESS | Successful open. |
| FSP_ERR_ALREADY_OPEN | The control structure is already opened. |
| FSP_ERR_IP_CHANNEL_NOT_PRESENT | The channel requested in the p_cfg parameter is not available on this device. |
| FSP_ERR_ASSERTION | Parameter check failure due to one or more reasons below:
|
| FSP_ERR_INVALID_DATA | Parameter check failure due to one or more reasons below:
|
| fsp_err_t R_PCIF_Stop | ( | pcif_ctrl_t *const | p_ctrl, |
| pcif_stop_mode_t | stop_mode | ||
| ) |
Stop PCIF. Implements pcif_api_t::stop.
Example:
| FSP_SUCCESS | Module successfully stops. |
| FSP_ERR_ASSERTION | p_ctrl was NULL. |
| FSP_ERR_NOT_OPEN | The instance is not opened. |
| fsp_err_t R_PCIF_Start | ( | pcif_ctrl_t *const | p_ctrl | ) |
Starts PCIF. Implements pcif_api_t::start.
Example:
| FSP_SUCCESS | Timer successfully started. |
| FSP_ERR_ASSERTION | p_ctrl was NULL. |
| FSP_ERR_NOT_OPEN | The instance is not opened. |
| FSP_ERR_IN_USE | Channel is running. |
| fsp_err_t R_PCIF_SetCounter | ( | pcif_ctrl_t *const | p_ctrl, |
| pcif_phc_counter_info_t const *const | p_counter_data, | ||
| bool | reset_counter | ||
| ) |
Set counter data in phase counting mode. Implements pcif_api_t::setCounter. Only used in phase counting mode. This function returns the PCIF information.
Example:
| FSP_SUCCESS | Information successfully retrieved. |
| FSP_ERR_ASSERTION | p_ctrl was NULL. |
| FSP_ERR_NOT_OPEN | The instance is not opened. |
| FSP_ERR_INVALID_MODE | The mode is not phase counting. |
| FSP_ERR_INVALID_DATA | The new position or edge count is invalid. |
| fsp_err_t R_PCIF_StatusGet | ( | pcif_ctrl_t *const | p_ctrl, |
| pcif_status_t *const | p_status | ||
| ) |
Get PCIF status. Implements pcif_api_t::statusGet.
This function returns the PCIF status.
Example:
| FSP_SUCCESS | Status successfully retrieved. |
| FSP_ERR_ASSERTION | p_ctrl or p_status was NULL. |
| FSP_ERR_NOT_OPEN | The instance is not opened. |
| fsp_err_t R_PCIF_SoftwareEventGenerate | ( | pcif_ctrl_t *const | p_ctrl | ) |
Software reset PCIF. Implements pcif_api_t::softwareEventGenerate.
This function generates a software event to reset the PCIF.
Example:
| FSP_SUCCESS | Software event successfully generated. |
| FSP_ERR_ASSERTION | p_ctrl was NULL. |
| FSP_ERR_NOT_OPEN | The instance is not opened. |
| FSP_ERR_INVALID_MODE | The mode is not incremental. |
| fsp_err_t R_PCIF_Close | ( | pcif_ctrl_t *const | p_ctrl | ) |
Close PCIF. Implements pcif_api_t::close.
This function powers down the PCIF and closes the lower level timer drivers if they are used.
Example:
| FSP_SUCCESS | Timer successfully started. |
| FSP_ERR_ASSERTION | p_ctrl was NULL. |
| FSP_ERR_NOT_OPEN | The instance is not opened. |