Engee documentation

Artery Encoder

Reading the quadrature encoder through the microcontroller timer.

blockType: CFunction

Path in the library:

/Interfaces/Targets/Artery/Artery Encoder

Description

To work with the block, install/update the support package. equipment.

Block Artery Encoder It is used to read a quadrature encoder connected to timer channels in encoder mode. In the first step, the timer starts in encoder mode. The timer counter value is output to the block output.

Configuring the AT32 Workbench

AT32 Workbench does not generate code for encoder mode automatically. A _ manual insertion of the call is required tmr_encoder_mode_config() in the user section of the generated file wk_tmr.c.

  1. In AT32 Workbench, select the desired timer.

  2. Set up two timer channels as inputs:

    • for Channel1 mode, set Input direct mode;

    • for Channel2 mode, set Input direct mode;

    • for other channels, set Disable.

    artery encoder timer mode

  3. Configure the counter parameters in Counter Settings:

    • Period Value (ARR) — encoder resolution.

      artery encoder timer params

  4. Generate the project (Generate Code).

  5. Open the generated file project/src/wk_tmr.c, find the function wk_tmrX_init() (where X — your timer number) and add a call tmr_encoder_mode_config() in the user section before GPIO initialization:

    /* add user code begin tmrX_init 1 */
    
    tmr_encoder_mode_config(TMRX,
        TMR_ENCODER_MODE_C,
        TMR_INPUT_RISING_EDGE,
        TMR_INPUT_RISING_EDGE);
    
    /* add user code end tmrX_init 1 */

    Here TMR_ENCODER_MODE_C — quadrature encoder mode (counting on both channels). Available modes:

    Mode Description

    TMR_ENCODER_MODE_A

    The score on the fronts of TI1

    TMR_ENCODER_MODE_B

    The score on the fronts of TI2

    TMR_ENCODER_MODE_C

    Counting on both channels (TI1+TI2) — for quadrature encoder

Ports

Output

# Count — value of the encoder counter
scalar

Details
Data types

UInt32

Complex numbers support

No

Parameters

Main group

# Таймер: — microcontroller timer number
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20

Details
Values

1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20

Default value

1

Program usage name

m_tim_num

Tunable

No

Evaluatable

Yes