This is the quick start guide for the XMEGA Quadrature Decoder (QDEC) , with step-by-step instructions on how to configure and use the driver in a selection of use cases.
The use cases are described with "setup" and "usage" sections, which each have "example code" and "workflow" subsections. This documentation first presents code fragments and function definitions along with instructions on where they can be placed, e.g., into the application C-file or the main() function, then follows up with explanations for all the lines of code.
Basic use case
In this basic use case, QDEC is configured for:
- a common quadrature encoder with two lines (phase 0 / phase 90)
- no index line on this
Setup steps
Example code
Add to application C-file:
static void qdec_init(void)
{
}
Add to main()
:
Workflow
- Initialize the clock system:
-
- Note
- The QDEC driver requires the system clock driver to be initialized in order to compute the correct QDEC filters.
- Create a function
qdec_init()
to intialize the QDEC:
static void qdec_init(void)
{
}
- Allocate configuration structs for the QDEC:
- Initialize the configuration structure with the identified as commonly hardware ressources and parameters:
- Define the PORT and pins used by QDec. These must be contiguous on PORT and only the first pin phase is request. A filter timing must be given to filter the rebounces:
- Define the QDec revolution. It is the number of position for one revolution:
- Load and enable the QDec configuration:
Usage steps
Example code
Add to, e.g., main-loop in application C-file:
Workflow
- Read the current QDec position:
- Read the current QDec direction: