HF-TMC51x0 Driver (TMC5130 & TMC5160) 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC51x0 (TMC5130 & TMC5160)
Loading...
Searching...
No Matches
abn_encoder_reader.cpp File Reference

ABN Encoder Position Reader - Continuously reads encoder position. More...

#include "../../../inc/tmc51x0.hpp"
#include "test_config/esp32_tmc51x0_bus.hpp"
#include "test_config/esp32_tmc51x0_test_config.hpp"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include <cinttypes>
Include dependency graph for abn_encoder_reader.cpp:

Functions

void app_main (void)
 

Variables

static const char * TAG = "ABN_Encoder"
 
static constexpr tmc51x0_test_config::TestRigType SELECTED_TEST_RIG
 
static constexpr uint16_t ENCODER_PPR = 4096
 
static constexpr bool ENCODER_INVERT_DIRECTION = false
 
static constexpr tmc51x0::ReferenceSwitchActiveLevel N_CHANNEL_ACTIVE
 
static constexpr tmc51x0::EncoderNSensitivity N_SENSITIVITY
 
static constexpr tmc51x0::EncoderClearMode N_CLEAR_MODE
 
static constexpr uint32_t READ_INTERVAL_MS = 100
 

Detailed Description

ABN Encoder Position Reader - Continuously reads encoder position.

This example demonstrates how to configure and continuously read position from an ABN (incremental) encoder connected to the TMC5160.

Configured for AS5047U Encoder:

  • 14-bit resolution: 16,384 positions per revolution
  • ABI (incremental) mode: 4,096 PPR (pulses per revolution)
  • Quadrature encoding: 4,096 PPR × 4 = 16,384 counts per revolution
  • Index pulse (I channel): One pulse per revolution (equivalent to N channel)
  • Output: A, B, and I (index) channels

ABN Encoder Configuration:

  • A/B channels: Quadrature encoder signals (required)
  • N/I channel: Index/zero pulse (one pulse per revolution)
  • AS5047U default: 4,096 PPR in ABI mode

Hardware Requirements:

  • ESP32 development board
  • TMC5160 stepper motor driver
  • AS5047U encoder connected to TMC5160 encoder pins:
    • A channel → TMC5160 ENC_A pin
    • B channel → TMC5160 ENC_B pin
    • I channel (index) → TMC5160 ENC_N pin
  • SPI connection between ESP32 and TMC5160
  • Motor connected (encoder reads motor position)

Pin Configuration (uses default dev board pins from esp32_tmc51x0_test_config.hpp):

  • SPI: MOSI=6, MISO=2, SCLK=5, CS=18
  • Control: EN=11, CLK=10, DIAG0=23, DIAG1=15
  • Encoder: A, B, I (index) channels connected to TMC5160 encoder interface
Author
Nebiyu Tadesse
Date
2025

Function Documentation

◆ app_main()

void app_main ( void )
Here is the call graph for this function:

Variable Documentation

◆ ENCODER_INVERT_DIRECTION

constexpr bool ENCODER_INVERT_DIRECTION = false
staticconstexpr

◆ ENCODER_PPR

constexpr uint16_t ENCODER_PPR = 4096
staticconstexpr

◆ N_CHANNEL_ACTIVE

◆ N_CLEAR_MODE

constexpr tmc51x0::EncoderClearMode N_CLEAR_MODE
staticconstexpr

◆ N_SENSITIVITY

◆ READ_INTERVAL_MS

constexpr uint32_t READ_INTERVAL_MS = 100
staticconstexpr

◆ SELECTED_TEST_RIG

constexpr tmc51x0_test_config::TestRigType SELECTED_TEST_RIG
staticconstexpr
Initial value:
=
@ TEST_RIG_FATIGUE
Fatigue test rig (Applied Motion 5034-369 motor, TMC51x0 EVAL board, reference switches,...

◆ TAG

const char* TAG = "ABN_Encoder"
static