<alp/counter.h> — Counters and Encoders
Generic up/down counter API plus quadrature-encoder mode.
Counter
#include <alp/counter.h>
alp_counter_t *cnt = alp_counter_open(&(alp_counter_config_t){
.channel_id = E1M_COUNTER0,
.clock_hz = 1000000,
});
alp_counter_start(cnt);
uint32_t value;
alp_counter_read(cnt, &value);
alp_counter_close(cnt);
Alarms
void on_alarm(alp_counter_t *c, void *user) { /* fired */ }
alp_counter_set_alarm(cnt, /* ticks_from_now */ 1000000, on_alarm, NULL);
Quadrature encoder
alp_qenc_t *qenc = alp_qenc_open(&(alp_qenc_config_t){
.channel_id = E1M_QENC0,
});
int32_t position;
alp_qenc_read(qenc, &position);
On the E1M-X V2N family the four quadrature encoders are owned by the GD32 supervisor; the host driver routes through <alp/chips/gd32g553.h>.
See also
Questions about this page? Discuss in Community Forum