Skip to main content

qenc-readout

Open a quadrature encoder on ALP_E1M_ENC0 and poll the accumulated position. Demonstrates the encoder mode of <alp/counter.h>. ALP_E1M_ENC0..ALP_E1M_ENC3 are reserved by the E1M spec for the four portable encoder slots.

Source: examples/qenc-readout/.

board.yaml

som:
sku: E1M-AEN701

preset: e1m-evk

cores:
m55_hp:
app: ./src
peripherals: [counter]

diagnostics:
log_level: info

Source (abbreviated)

#include <alp/counter.h>
#include <alp/e1m_pinout.h>

int main(void) {
alp_qenc_t *enc = alp_qenc_open(&(alp_qenc_config_t){
.encoder_id = ALP_E1M_ENC0, /* 0..ALP_E1M_ENC_COUNT-1 (= 4) */
.pulses_per_rev = 24, /* PEC12R-4222F-S0024 on the EVK */
});
if (enc == NULL) {
printk("[qenc] open failed: err=%d\n", (int)alp_last_error());
return -1;
}

for (int i = 0; i < 20; i++) {
int32_t position;
alp_qenc_get_position(enc, &position);
printk("[qenc] position=%d\n", position);
k_msleep(250);
}
alp_qenc_close(enc);
return 0;
}

V2N family

On E1M-X V2N the four quadrature encoders are owned by the on-module GD32G553 supervisor. The host driver routes alp_qenc_* through <alp/chips/gd32g553.h>; the example works unchanged because the wrapper hides the transport.

See also

Questions about this page? Discuss in Community Forum