45.6.2.2 Enabling, Disabling, and Resetting
The PDEC must be configured before it is enabled by the following steps:
- Enable the PDEC bus clock (CLK_PDEC_APB).
- Select the mode of operation by writing the Mode bits in the Control A register (CTRLA.MODE).
- Select the PDEC mode configuration by writing the Configuration bits in the Control A register (CTRLA.CONF).
- Select the PDEC event or pin input signal source by writing the Event Enable Input bit in the Event Control register (EVCTRL.EVEI) or the Pin Enable bit in Control A register (CTRLA.PINEN).
- Select the angular counter length value by writing the Angular bits in the Control A register (CTRLA.ANGULAR).
Optionally, the following configurations can be set before enabling PDEC:
- The GCLK_PDEC clock can be prescaled by writing to the Prescaler register (PRESC).
- A filter can be applied to the input signal by writing a corresponding value to the Filter register (FILTER).
- If the resolution of the rotary sensor is not a power of 2, an Angular period can be set (CTRLA.PEREN and CC0 register).
The PDEC is enabled by writing a '1' to the Enable bit in the Control A register (CTRLA.ENABLE). The PDEC is disabled by writing a '0' to CTRLA.ENABLE.
In QDEC or HALL operation modes, PDEC decoding is enabled writing a START command in the Control B Set register (CTRLBSET.CMD=START). The PDEC decoding is disabled writing a STOP command in the Control B Set register (CTRLBSET.CMD=STOP).
The PDEC is reset by writing a '1' to the Software Reset bit in the Control A register (CTRLA.SWRST). All registers in the PDEC, except DBGCTRL, will be reset to their initial state, and the PDEC will be disabled.
The PDEC should be disabled before the PDEC is reset to avoid undefined behavior.