31.1 PDEC Asynchronous Driver
In the Position Decoder (PDEC) asynchronous driver, a callback function can be registered in the driver by the application, and the callback function will be triggered when axis position changed.
The driver pdec_async_read_position function will attempt to read the required position results of the axis.
Summary of the API's Functional Features
Initialize and deinitialize the driver and associated hardware
Hookup callback handlers on position changed done and IRQ events
Enable or disable PDEC module
Read back axis position result
Summary of Configuration Options
Select whether phase A, B, or index invert is to be used
Select whether phase A or B should be swapped
Which clock source and prescaler the PDEC uses
Which configuration the PDEC uses
Which events the PDEC interrupt uses
Run in Standby or Debug mode
Driver Implementation Description
After PDEC hardware initialization, thee application can register the callback function for axis position changed and IRQ events by pdec_async_register_callback.
Example of Usage
The following shows a simple example of using the PDEC. The PDEC must have been initialized by pdec_async_init. This initialization will configure the operation of the PDEC, such as input pins, prescaler value, PDEC configuration, and interrupt configuration, etc.
The example registers a callback function for comparison ready and enables the PDEC, and read back the result of the axis position changed.
static void position_cb_POSITION_DECODER_0(struct pdec_async_descriptor *const descr, uint8_t ch)
{
uint16_t count;
count = pdec_async_read_position(descr, ch);
}
static void irq_handler_cb_POSITION_DECODER_0(struct pdec_async_descriptor *const descr,
enum pdec_async_callback_type type, uint8_t ch)
{
}
/**
* Example of using POSITION_DECODER_0.
*/
void POSITION_DECODER_0_example(void)
{
pdec_async_register_callback(
&POSITION_DECODER_0, PDEC_ASYNC_POS_CHANGED_CB, (FUNC_PTR)position_cb_POSITION_DECODER_0);
pdec_async_register_callback(&POSITION_DECODER_0, PDEC_ASYNC_IRQ_CB, (FUNC_PTR)irq_handler_cb_POSITION_DECODER_0);
pdec_async_enable(&POSITION_DECODER_0);
}
Dependencies
-
The PDEC peripheral and its related I/O lines and clocks
-
The NVIC must be configured so that PDEC interrupt requests are periodically serviced