mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 11:26:12 +08:00
doc: Improved QE Documentation and add mt6816 board profile doc
This commit explain that the QE encoder driver can be used to internal QE from microcontroller or external magnetic encoder. Also explains how to use the mt6816 board profile to STM32F4Discovery Signed-off-by: Alan C. Assis <acassis@gmail.com>
This commit is contained in:
committed by
Alan C. Assis
parent
928d7682ce
commit
51cd4a548f
@@ -2,6 +2,16 @@
|
||||
Quadrature Encoder Drivers
|
||||
==========================
|
||||
|
||||
A Quadrature Encoder (QE) is a kind of sensor normally used to read
|
||||
angular rotation of a motor or other turning device.
|
||||
|
||||
NuttX supports internal QE peripheral that exists in some microcontrollers
|
||||
like ESP32, iMXRT, STM32, nRF5x, TIVA, and others, and also supports
|
||||
Magnetic Rotary Encoders like AS5048, MT6816, etc.
|
||||
|
||||
Internal Peripheral Quadrature Encoder
|
||||
======================================
|
||||
|
||||
NuttX supports a low-level, two-part Quadrature Encoder driver.
|
||||
|
||||
#. An "upper half", generic driver that provides the common
|
||||
@@ -28,6 +38,46 @@ following locations:
|
||||
for the specific processor ``<architecture>`` and for the
|
||||
specific ``<chip>`` Quadrature Encoder peripheral devices.
|
||||
|
||||
Magnetic Rotary Encoder
|
||||
=======================
|
||||
|
||||
Although technically a Magnetic Rotary Encoder is not a Quadrature Encoder,
|
||||
usually uses the QE Lower Half driver to export a device compatible with
|
||||
quadrature encoder. This way an application using an ordinary QE encoder
|
||||
could use a Magnetic Rotary Encoder with any modification, just need to
|
||||
enable and initialize the Magnetic Rotary Encoder on their board.
|
||||
|
||||
This is how a board powered by STM32 will initialize a MT6816 Magnetic
|
||||
Rotary Encoder:
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
/* Initialize the SPI bus connected to MT6816 */
|
||||
|
||||
spi = stm32_spibus_initialize(spi_busno);
|
||||
if (spi == NULL)
|
||||
{
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Initialize MT6816 using `spi` and a `device number` starting from 0 */
|
||||
|
||||
dev = mt6816_initialize(spi, (uint16_t) devno);
|
||||
if (dev == NULL)
|
||||
{
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Use the returned qe lower half to register /dev/qe# (# => devno) */
|
||||
|
||||
ret = qe_register(qe_path, dev);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: Failed to register MT6816 qe%d driver: %d\n",
|
||||
devno, ret);
|
||||
ret = -ENODEV;
|
||||
}
|
||||
|
||||
Application Programming Interface
|
||||
=================================
|
||||
|
||||
|
||||
@@ -1523,6 +1523,61 @@ After compiling and flashing the firmware in our board, run kbd command.
|
||||
code : 49
|
||||
type : 1
|
||||
|
||||
mt6816
|
||||
------
|
||||
|
||||
This board config enables the MagTek MT6816 Magnetic Rotary Encoder connected
|
||||
to STM32F4Discovery board SPI1 this way:
|
||||
|
||||
================ ======
|
||||
STM32F4Discovery MT6816
|
||||
================ ======
|
||||
3V [1] VCC
|
||||
GND GND
|
||||
PE3 CSN
|
||||
SPI1 MOSI (PA7) MOSI
|
||||
SPI1 MISO (PA6) MISO
|
||||
SPI1 SCK (PA5) SCK
|
||||
================ ======
|
||||
|
||||
1: You need to remove the diode D3 and short-circuit the PADs in the
|
||||
board to get 3.3V. Be aware: although my board works fine, it could
|
||||
damage something that expects 3V in our board (double check).
|
||||
|
||||
IMPORTANT: You need to connect the HVPP (pin 2) to VCC in order to get
|
||||
MT6816 working in SPI mode. Just short-circuit R3 pads will work:
|
||||
|
||||
.. figure:: mt6816.png
|
||||
:align: center
|
||||
|
||||
After compiling and flashing the firmware in our board, run qe command:
|
||||
|
||||
.. code:: console
|
||||
|
||||
NuttShell (NSH) NuttX-12.13.0
|
||||
nsh> ls /dev
|
||||
/dev:
|
||||
console
|
||||
null
|
||||
qe0
|
||||
ttyS0
|
||||
zero
|
||||
nsh> qe
|
||||
qe_main: Hardware initialized. Opening the encoder device: /dev/qe0
|
||||
qe_main: Number of samples: 0
|
||||
qe_main: 1. 6546
|
||||
qe_main: 2. 6620
|
||||
qe_main: 3. 7384
|
||||
qe_main: 4. 7808
|
||||
qe_main: 5. 7900
|
||||
qe_main: 6. 7984
|
||||
qe_main: 7. 7989
|
||||
qe_main: 8. 7993
|
||||
qe_main: 9. 7998
|
||||
qe_main: 10. 8008
|
||||
qe_main: 11. 8052
|
||||
qe_main: 12. 8064
|
||||
|
||||
netnsh
|
||||
------
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 179 KiB |
Reference in New Issue
Block a user