qenc-readout
Open a quadrature encoder on E1M_QENC0 and poll the position counter. Demonstrates the encoder mode of <alp/counter.h>.
Source: examples/qenc-readout/.
board.yaml
schema_version: 2
som:
sku: E1M-AEN701
carrier:
name: E1M-EVK
cores:
m55_hp:
os: zephyr
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 *qenc = alp_qenc_open(&(alp_qenc_config_t){
.channel_id = E1M_QENC0,
});
if (qenc == 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_read(qenc, &position);
printk("[qenc] position=%d\n", position);
k_msleep(250);
}
alp_qenc_close(qenc);
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