Browse Source

drivers: sensor: mcux qdec add filter parameters

Add optional filter value properties. The filter is disabled by default
but can be enabled by setting the filter-sample-period > 0 in the dts
file. A latency is introduced if the filter is enabled. The latency can
be printed by setting sensor log level to debug.

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
pull/56513/head
Jeppe Odgaard 2 years ago committed by Fabio Baltieri
parent
commit
1ef0649825
  1. 10
      drivers/sensor/qdec_mcux/qdec_mcux.c
  2. 19
      dts/bindings/sensor/nxp,mcux-qdec.yaml

10
drivers/sensor/qdec_mcux/qdec_mcux.c

@ -166,11 +166,15 @@ static void init_inputs(const struct device *dev) @@ -166,11 +166,15 @@ static void init_inputs(const struct device *dev)
BUILD_ASSERT(IN_RANGE(DT_INST_PROP(n, p), min, max), \
STRINGIFY(p) " value is out of range")), ())
#define QDEC_SET_COND(n, v, p) \
COND_CODE_1(DT_INST_NODE_HAS_PROP(n, p), (v = DT_INST_PROP(n, p)), ())
#define QDEC_MCUX_INIT(n) \
\
BUILD_ASSERT((DT_PROP_LEN(XBAR_PHANDLE(n), xbar_maps) % 2) == 0, \
"xbar_maps length must be an even number"); \
QDEC_CHECK_COND(n, counts_per_revolution, 1, UINT16_MAX); \
QDEC_CHECK_COND(n, filter_sample_period, 0, UINT8_MAX); \
\
static struct qdec_mcux_data qdec_mcux_##n##_data = { \
.counts_per_revolution = DT_INST_PROP(n, counts_per_revolution) \
@ -198,6 +202,12 @@ static void init_inputs(const struct device *dev) @@ -198,6 +202,12 @@ static void init_inputs(const struct device *dev)
ENC_GetDefaultConfig(&data->qdec_config); \
data->qdec_config.decoderWorkMode = int_to_work_mode( \
DT_INST_PROP(n, single_phase_mode)); \
QDEC_SET_COND(n, data->qdec_config.filterCount, filter_count); \
QDEC_SET_COND(n, data->qdec_config.filterSamplePeriod, \
filter_sample_period); \
LOG_DBG("Latency is %u filter clock cycles + 2 IPBus clock " \
"periods", data->qdec_config.filterSamplePeriod * \
(data->qdec_config.filterCount + 3)); \
ENC_Init(config->base, &data->qdec_config); \
\
/* Update the position counter with initial value. */ \

19
dts/bindings/sensor/nxp,mcux-qdec.yaml

@ -28,6 +28,25 @@ properties: @@ -28,6 +28,25 @@ properties:
generates a count signal. The PHASEB input and the REV bit control the
counter direction.
filter-count:
type: int
enum: [0, 1, 2, 3, 4, 5, 6, 7]
description: |
The number of consecutive samples that must agree prior to the input
filter accepting an input transition. A value of 0 represents 3
samples. A value of 7 represents 10 samples.
filter-sample-period:
type: int
description: |
The sampling period (in IPBus clock cycles) of the decoder input signals.
Each input is sampled multiple times at the rate specified by the Filter
Sample Period. If FILT_PER is 0 (default), then the input filter is
bypassed. Bypassing the digital filter enables the position/position
difference counters to operate with count rates up to the IPBus
frequency. Turning on the input filter introduces a latency of:
((FILT_CNT + 3) * FILT_PER) FILT clock cycles + 2 IPBus clock periods.
xbar:
type: phandle
required: true

Loading…
Cancel
Save