The section describes the programming interface of the ENC Peripheral driver.
Overview
The enhanced Quadrature Encoder/Decoder module provides interfacing capability to position/speed sensors used in industrial motor control applications. It has four input signals: PHASEA, PHASEB, INDEX, and HOME. This module is used to decode shaft position, revolution count, and speed.
Initialization
To initialize the ENC module, call the ENC_DRV_Init() function and pass the configuration data structure (enc_user_config_t), which can be filled by the ENC_DRV_StructInitUserConfigNormal() function with the default settings for the encoder. After it is initialized, the ENC module can function as an ENC decoder. The default settings are as follows.
enc_state_t encUserState;
Ensure that any default settings are changed after calling the ENC_DRV_StructInitUserConfigNormal() function. For example, changing INDEX input edge type and position compare register value:
After that, the initialization is completed by calling the initialization function:
To de-initialize the ENC peripheral, call the ENC_DRV_Deinit() function which shuts down the ENC clock to reduce the power consumption.
Testing ENC module
The ENC peripheral provides a test module to drive the ENC quadrature inputs which can provide a mechanism for customers to test the ENC module is functioning without being connected in the intended "incremental position sensor" for motor control.
To initialize the ENC Test module, call the ENC_DRV_TestInit() function and pass the configuration data structure (enc_test_config_t), which can be filled as the example shows.
Test module generates 100 quadrature advances into quadrature inputs with period 10 IPBus clock cycles.
Input monitor
ENC peripheral also provides monitoring of input signals. It can be used as follows.
ENC_DRV_ReadInputMonitorRegister(instance, true, &encInputMonitor);
The encInputMonitor structure contains the values of the raw (if true) or filtered (if false) PHASEA, PHASEB, INDEX and HOME input signals and the reset value of the raw and filtered values of PHASEA, PHASEB, INDEX, and HOME. If the input pins are connected to a pull-up, IMR 0-7 bits are set to one (1). If these input pins are connected to a pull-down device, the 0-7 bits are set to zeroes (0).
Interrupts
Interrupt may be enabled/disabled by calling the ENC_DRV_SetIntMode() function and passing the interrupt source enc_interrupt_source_t argument. The user callback function can be installed by calling the ENC_DRV_InstallCallback() function and passing the name as the type enc_callback_t argument. The parameter of user callback function may be passed too.
ENC peripheral provides these type of interrupts:
- Position compare interrupt
- HOME signal transition interrupt
- Watchdog time-out interrupt
- INDEX pulse transition interrupt
- Roll-under interrupt
- Roll-over interrupt
- Simultaneous PHASEA and PHASEB change interrupt
To get a status of any interrupt source use the ENC_DRV_GetIntMode() function. The flag status reading is provided by the ENC_DRV_GetStatusFlag() function and by clearing the flag with the ENC_DRV_ClearStatusFlag() function.
Reading Counters
To read the counters, call the ENC_DRV_ReadCounters() function and pass the argument of the enc_counter_t type. This function reads the position difference counter register that causes snapshots of the position, position difference counter and revolution counter registers are each placed into their respective hold registers. Then, the position counter value and revolution counter value are read from their hold registers. These three values are stored into a structure and passed as an argument of the function.
To reset counters (position, position difference, and revolution) use the ENC_DRV_ResetCounters() function.
Reading Hold Registers
To read an action, such as the trigger input signal, which causes getting snapshots of the position counter, position difference counter, and revolution counter register to their respective hold registers, use the ENC_DRV_ReadHoldRegisters() function.
|
enc_status_t | ENC_DRV_StructInitUserConfigNormal (enc_user_config_t *userConfigPtr) |
| Fills the initial user configuration for the ENC module without the interrupts enablement. More...
|
|
enc_status_t | ENC_DRV_Init (uint32_t instance, const enc_user_config_t *userConfigPtr) |
| Initializes an ENC instance for operation. More...
|
|
void | ENC_DRV_Deinit (uint32_t instance) |
| De-initializes the ENC peripheral. More...
|
|
enc_status_t | ENC_DRV_TestInit (uint32_t instance, const enc_test_config_t *userConfigPtr) |
| Initializes an ENC test module. More...
|
|
void | ENC_DRV_TestDeinit (uint32_t instance) |
| Shuts down the ENC test module, disables test counter, and clears the test period and test count values. More...
|
|
enc_status_t | ENC_DRV_SetIntMode (uint32_t instance, enc_int_source_t intSrc, bool enable) |
| Enables/disables the selected ENC interrupt. More...
|
|
bool | ENC_DRV_GetIntMode (uint32_t instance, enc_int_source_t intSrc) |
| Gets the configuration of the selected ENC interrupt. More...
|
|
bool | ENC_DRV_GetStatusFlag (uint32_t instance, enc_status_flag_t flag) |
| Gets the interrupt status flag of the selected interrupt source. More...
|
|
void | ENC_DRV_ClearStatusFlag (uint32_t instance, enc_status_flag_t flag) |
| Clears the status flag of the selected status source. More...
|
|
enc_status_t | ENC_DRV_ReadCounters (uint32_t instance, enc_counter_t *countRegPtr) |
| Reads the actual values of the ENC counter registers. More...
|
|
enc_status_t | ENC_DRV_ReadHoldReg (uint32_t instance, enc_counter_t *holdRegPtr) |
| Reads the ENC hold registers. More...
|
|
void | ENC_DRV_ResetCounters (uint32_t instance) |
| Resets the ENC counter registers. More...
|
|
enc_status_t | ENC_DRV_ReadInputMonitor (uint32_t instance, bool inputMonitorRaw, enc_input_monitor_t *inputMonitorPtr) |
| Reads the ENC input monitor register. More...
|
|
Use an instance of this structure with the ENC_DRV_Init()function. This enables configuration of the most common settings of the ENC peripheral with a single function call.
Data Fields |
uint32_t | posCntInitValue |
| Value to put in Initialization Register.
|
|
uint32_t | posCmpValue |
| Value to put in Position Compare Register.
|
|
uint32_t | moduloValue |
| Value to put in Modulus Register.
|
|
uint16_t | watchdogTimeout |
| Value to put in Watchdog Timeout Register.
|
|
uint8_t | filterCount |
| Value represents the number of consecutive samples that must agree prior to the input filter accepting an input transition.
|
|
uint8_t | filterPeriod |
| Value represents the sampling period (in IPBus clock cycles) of the decoder input signals.
|
|
enc_operation_mode_t | operationMode |
| Operation mode: Normal mode, modulo counting mode or bypass (signal phase count) mode.
|
|
bool | reverseCounting |
| Counting direction: Normal (false) or reverse (true) counting direction.
|
|
bool | indexInputNegativeEdge |
| Type of transition edge of INDEX input signal: positive (false) or negative (true).
|
|
bool | homeInputNegativeEdge |
| Type of transition edge of HOME input signal: positive (false) or negative (true).
|
|
bool | indexPulsePosInit |
| To use HOME (false) or INDEX (true) input to initialize position counter to value in Initialization Register.
|
|
bool | triggerUpdateHoldRegEnable |
| Enable/disable updating hold registers on TRIGGER input.
|
|
bool | triggerClearPosRegEnable |
| Enable/disable clear of position registers on TRIGGER input.
|
|
bool | moduloRevolutionCounting |
| Type of revolution counter - index pulse counting (on false) or modulo counting (on true).
|
|
bool | outputControlOnReading |
| Used to control the behaviour of the POSMATCH output signal. More...
|
|
bool enc_user_config_t::outputControlOnReading |
True - output control on reading position register, false - OC on match position register.
Use an instance of this structure with the ENC_DRV_TestInit()function. This enables configuration of the Test module of the ENC peripheral with a single function call.
uint8_t enc_test_config_t::testCount |
uint8_t enc_test_config_t::testPeriod |
bool enc_test_config_t::testNegativeSignalEnable |
Use an instance of this structure with the ENC_DRV_ReadHoldRegisters() or ENC_DRV_ReadCounters() functions. This reads counters and hold registers of Position, PositionDifference, Revolution Counter.
int32_t enc_counter_t::position |
int16_t enc_counter_t::posDiff |
int16_t enc_counter_t::revolution |
struct enc_input_monitor_t |
Use an instance of this structure with the ENC_DRV_ReadInputMonitorRegister(). This reads Input Monitor register that contains the values of the raw or filtered PHASEA, PHASEB, INDEX and HOME input signals.
bool enc_input_monitor_t::phaseA |
bool enc_input_monitor_t::phaseB |
bool enc_input_monitor_t::index |
bool enc_input_monitor_t::home |
This function fills the initial user configuration. Calling the initialization function with the filled parameter configures the ENC module to function as a simple Quadrature Encoder. The settings are:
- Parameters
-
userConfigPtr | Pointer to the user configuration structure. |
- Returns
- Execution status.
This function initializes the run-time state structure to un-gate the clock to the ENC module, initializes the module to user-defined settings and default settings, configures the IRQ state structure, and enables the module-level interrupt to the core. This example shows how to set up the enc_state_t and the enc_user_config_t parameters and how to call the ENC_DRV_Init function by passing in these parameters:
- Parameters
-
instance | ENC instance ID. |
userConfigPtr | The user configuration structure of type enc_user_config_t. The user is responsible to fill out the members of this structure and to pass the pointer of this structure into this function. |
- Returns
- Execution status.
void ENC_DRV_Deinit |
( |
uint32_t |
instance | ) |
|
This function shuts down the ENC clock to reduce power consumption.
- Parameters
-
This function initializes the run-time state structure to enable the test module and sets the test period and test count values. This example shows how to set up the enc_test_config_t parameters and how to call the ENC_DRV_TestInit function by passing in these parameters:
- Parameters
-
instance | ENC instance ID. |
userConfigPtr | The user configuration structure of type enc_test_config_t. |
- Returns
- Execution status.
void ENC_DRV_TestDeinit |
( |
uint32_t |
instance | ) |
|
The interrupt source is passing as argument of type enc_interrupt_source_t.
- Parameters
-
instance | ENC instance ID. |
intSrc | The type of interrupt to enable/disable. |
enable | Bool parameter to enable/disable. |
- Returns
- Execution status.
The interrupt type is passing as an argument of type enc_int_source_t.
- Parameters
-
instance | ENC instance ID. |
intSrc | The type of interrupt to get configuration. |
- Returns
- Configuration of selected interrupt source.
- Parameters
-
instance | ENC instance ID. |
flag | Selected type of status flag. |
- Returns
- State of selected flag.
- Parameters
-
instance | ENC instance ID. |
flag | Selected type of status flag. |
- Parameters
-
instance | ENC instance ID. |
countRegPtr | The structure of ENC counter registers. |
- Returns
- Execution status.
- Parameters
-
instance | ENC instance ID. |
holdRegPtr | The structure of ENC hold registers. |
- Returns
- Execution status.
void ENC_DRV_ResetCounters |
( |
uint32_t |
instance | ) |
|
- Parameters
-
instance | ENC instance ID. |
inputMonitorRaw | The type of input monitor - raw (true) / filtered (false). |
inputMonitorPtr | The structure of ENC Monitor register variables. |
- Returns
- Execution status.