Compare commits
16 Commits
stone-disp
...
rpi-fan-co
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1786fa0b41 | ||
|
|
f3490212bf | ||
|
|
84e351d154 | ||
|
|
986927d740 | ||
|
|
6be2dd0b7d | ||
|
|
b2ffcb5d72 | ||
|
|
1ad6c75788 | ||
|
|
e97472c2a3 | ||
|
|
bba35c9622 | ||
|
|
9640a5b747 | ||
|
|
49d52ca0ed | ||
|
|
08598ca7a3 | ||
|
|
36f6f1863b | ||
|
|
0c1b8f4e86 | ||
|
|
29af5335f5 | ||
|
|
8b97a1853d |
BIN
.gitmodules
(Stored with Git LFS)
vendored
BIN
.gitmodules
(Stored with Git LFS)
vendored
Binary file not shown.
BIN
motor-control/firmware/.gitignore
(Stored with Git LFS)
vendored
Normal file
BIN
motor-control/firmware/.gitignore
(Stored with Git LFS)
vendored
Normal file
Binary file not shown.
18
motor-control/firmware/.vscode/c_cpp_properties.json
vendored
Normal file
18
motor-control/firmware/.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Linux",
|
||||||
|
"includePath": [
|
||||||
|
"${workspaceFolder}/include/**",
|
||||||
|
"${workspaceFolder}/lib/pico-sdk/lib/tinyusb/src"
|
||||||
|
],
|
||||||
|
"defines": [],
|
||||||
|
"compilerPath": "/usr/bin/gcc",
|
||||||
|
"cStandard": "c17",
|
||||||
|
"cppStandard": "c++14",
|
||||||
|
"intelliSenseMode": "linux-gcc-arm",
|
||||||
|
"configurationProvider": "ms-vscode.cmake-tools"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": 4
|
||||||
|
}
|
||||||
31
motor-control/firmware/.vscode/launch.json
vendored
Executable file
31
motor-control/firmware/.vscode/launch.json
vendored
Executable file
@@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Pico: Debug External OpenOCD",
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"executable": "${command:cmake.launchTargetPath}",
|
||||||
|
"request": "launch",
|
||||||
|
"preLaunchTask": "Pico: flash main",
|
||||||
|
"type": "cortex-debug",
|
||||||
|
"servertype": "external",
|
||||||
|
"gdbPath" : "gdb-multiarch",
|
||||||
|
"gdbTarget": "localhost:3333",
|
||||||
|
"device": "RP2040",
|
||||||
|
"configFiles": [
|
||||||
|
"interface/cmsis-dap.cfg",
|
||||||
|
"target/rp2040.cfg"
|
||||||
|
],
|
||||||
|
|
||||||
|
"svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd",
|
||||||
|
"runToEntryPoint": "main",
|
||||||
|
|
||||||
|
"postRestartCommands": [
|
||||||
|
"continue"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
79
motor-control/firmware/.vscode/settings.json
vendored
Normal file
79
motor-control/firmware/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
{
|
||||||
|
"cSpell.words": [
|
||||||
|
"apcsw",
|
||||||
|
"apreg",
|
||||||
|
"apsel",
|
||||||
|
"arrayname",
|
||||||
|
"baseaddr",
|
||||||
|
"Bhaskra",
|
||||||
|
"bitwidth",
|
||||||
|
"BOOTSEL",
|
||||||
|
"cget",
|
||||||
|
"channellist",
|
||||||
|
"charmsg",
|
||||||
|
"clkdiv",
|
||||||
|
"cpnum",
|
||||||
|
"deassert",
|
||||||
|
"deasserted",
|
||||||
|
"deasserting",
|
||||||
|
"doxygen",
|
||||||
|
"dpreg",
|
||||||
|
"drawio",
|
||||||
|
"dreq",
|
||||||
|
"eabi",
|
||||||
|
"eventlist",
|
||||||
|
"gpio",
|
||||||
|
"helptext",
|
||||||
|
"jtag",
|
||||||
|
"lindex",
|
||||||
|
"memaccess",
|
||||||
|
"microcontroller",
|
||||||
|
"multiarch",
|
||||||
|
"multicore",
|
||||||
|
"Pico",
|
||||||
|
"picoprobe",
|
||||||
|
"pindirs",
|
||||||
|
"pinout",
|
||||||
|
"pregen",
|
||||||
|
"resexit",
|
||||||
|
"semihosting",
|
||||||
|
"srst",
|
||||||
|
"struct",
|
||||||
|
"targetname",
|
||||||
|
"TPIU",
|
||||||
|
"trst",
|
||||||
|
"UART",
|
||||||
|
"virt",
|
||||||
|
"waitstate",
|
||||||
|
"watchpoint",
|
||||||
|
"watchpoints",
|
||||||
|
"wready"
|
||||||
|
],
|
||||||
|
"cmake.sourceDirectory": "/home/alexander/Projects/gobot/motor-control/firmware",
|
||||||
|
"cmake.buildDirectory": "${workspaceFolder}/build",
|
||||||
|
"cmake.configureOnOpen": true,
|
||||||
|
"files.associations": {
|
||||||
|
"timer.h": "c",
|
||||||
|
"stdlib.h": "c",
|
||||||
|
"stdio.h": "c",
|
||||||
|
"string.h": "c",
|
||||||
|
"assert.h": "c",
|
||||||
|
"gen.h": "c",
|
||||||
|
"multicore.h": "c",
|
||||||
|
"pio.h": "c",
|
||||||
|
"freertos.h": "c",
|
||||||
|
"random": "c",
|
||||||
|
"queue.h": "c",
|
||||||
|
"string_view": "c",
|
||||||
|
"instructionformat.h": "c",
|
||||||
|
"includeglobals.h": "c",
|
||||||
|
"dacconfig.h": "c",
|
||||||
|
"freertosconfig.h": "c",
|
||||||
|
"*.tcc": "cpp"
|
||||||
|
},
|
||||||
|
"cortex-debug.variableUseNaturalFormat": false,
|
||||||
|
"todo-tree.filtering.ignoreGitSubmodules": true,
|
||||||
|
"todo-tree.tree.showBadges": true,
|
||||||
|
"terminal.integrated.scrollback": 10000,
|
||||||
|
"C_Cpp.refactoring.includeHeader": "always",
|
||||||
|
}
|
||||||
107
motor-control/firmware/.vscode/tasks.json
vendored
Normal file
107
motor-control/firmware/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"type": "cmake",
|
||||||
|
"label": "CMake: build main",
|
||||||
|
"command": "build",
|
||||||
|
"targets": [
|
||||||
|
"main"
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"cwd": "${workspaceRoot}"
|
||||||
|
},
|
||||||
|
"group": "build",
|
||||||
|
"presentation": {
|
||||||
|
"echo": true,
|
||||||
|
"reveal": "always",
|
||||||
|
"focus": true,
|
||||||
|
"panel": "dedicated",
|
||||||
|
"showReuseMessage": true,
|
||||||
|
"clear": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "shell",
|
||||||
|
"label": "Pico: flash main",
|
||||||
|
"command": [
|
||||||
|
"scripts/flash.exp",
|
||||||
|
"${workspaceRoot}/build/bin/main.elf"
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"cwd": "${workspaceRoot}"
|
||||||
|
},
|
||||||
|
"group": "test",
|
||||||
|
"dependsOn": [
|
||||||
|
"CMake: build main"
|
||||||
|
],
|
||||||
|
"presentation": {
|
||||||
|
"echo": true,
|
||||||
|
"reveal": "always",
|
||||||
|
"focus": true,
|
||||||
|
"panel": "dedicated",
|
||||||
|
"showReuseMessage": true,
|
||||||
|
"clear": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "shell",
|
||||||
|
"label": "Pico: launch openocd",
|
||||||
|
"command": [
|
||||||
|
"scripts/launch_openocd.sh"
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"cwd": "${workspaceRoot}"
|
||||||
|
},
|
||||||
|
"isBackground": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "shell",
|
||||||
|
"label": "Pico: Reset Device",
|
||||||
|
"command": [
|
||||||
|
"scripts/reset.exp"
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"cwd": "${workspaceRoot}"
|
||||||
|
},
|
||||||
|
"isBackground": true,
|
||||||
|
"problemMatcher": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "cmake",
|
||||||
|
"label": "CMake: Clean",
|
||||||
|
"command": "clean"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "cmake",
|
||||||
|
"label": "CMake: Clean Rebuild",
|
||||||
|
"command": "cleanRebuild"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "cmake",
|
||||||
|
"label": "CMake: Configure",
|
||||||
|
"command": "configure"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "shell",
|
||||||
|
"label": "Doxygen: Generate Docs",
|
||||||
|
"command": [
|
||||||
|
"doxygen ./docs/Doxyfile"
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"cwd": "${workspaceRoot}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "shell",
|
||||||
|
"label": "Nuke Build Directory",
|
||||||
|
"command": [
|
||||||
|
"rm -rf build"
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"cwd": "${workspaceRoot}"
|
||||||
|
},
|
||||||
|
"problemMatcher": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
70
motor-control/firmware/CMakeLists.txt
Executable file
70
motor-control/firmware/CMakeLists.txt
Executable file
@@ -0,0 +1,70 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.12)
|
||||||
|
|
||||||
|
# Including the SDK (must be before project)
|
||||||
|
|
||||||
|
if (NOT "$ENV{PICO_SDK_PATH_OVERRIDE}" STREQUAL "")
|
||||||
|
SET(PICO_SDK_PATH "$ENV{PICO_SDK_PATH_OVERRIDE}")
|
||||||
|
else()
|
||||||
|
SET(PICO_SDK_PATH "${CMAKE_SOURCE_DIR}/lib/pico-sdk")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
#SET(PICO_TOOLCHAIN_PATH "${PICO_SDK_PATH}/cmake/preload/toolchains/")
|
||||||
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
||||||
|
|
||||||
|
include(${PICO_SDK_PATH}/pico_sdk_init.cmake)
|
||||||
|
|
||||||
|
#include(pico_extras_import_optional.cmake)
|
||||||
|
|
||||||
|
project(pico_examples C CXX ASM)
|
||||||
|
set(CMAKE_C_STANDARD 23)
|
||||||
|
set(CMAKE_CXX_STANDARD 23)
|
||||||
|
|
||||||
|
if (PICO_SDK_VERSION_STRING VERSION_LESS "1.3.0")
|
||||||
|
message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.3.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(PICO_EXAMPLES_PATH ${PROJECT_SOURCE_DIR})
|
||||||
|
|
||||||
|
# Initialize the SDK
|
||||||
|
pico_sdk_init()
|
||||||
|
|
||||||
|
include(example_auto_set_url.cmake)
|
||||||
|
|
||||||
|
add_compile_options(-Wall
|
||||||
|
-Wno-format # int != int32_t as far as the compiler is concerned because gcc has int32_t as long int
|
||||||
|
-Wno-unused-function # we have some for the docs that aren't called
|
||||||
|
)
|
||||||
|
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
||||||
|
add_compile_options(-Wno-maybe-uninitialized)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# adding sources files & includes
|
||||||
|
add_executable(main
|
||||||
|
src/main.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(main PUBLIC
|
||||||
|
include/
|
||||||
|
build/
|
||||||
|
)
|
||||||
|
|
||||||
|
include(${PROJECT_SOURCE_DIR}/cmake/tmc2209.cmake)
|
||||||
|
|
||||||
|
# Adding PIO
|
||||||
|
pico_generate_pio_header(main ${CMAKE_CURRENT_LIST_DIR}/src/tmc2209/pulser.pio)
|
||||||
|
|
||||||
|
# pull in common dependencies
|
||||||
|
target_link_libraries(main
|
||||||
|
pico_stdlib
|
||||||
|
pico_multicore
|
||||||
|
hardware_pio
|
||||||
|
|
||||||
|
tmc2209_driver
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# create map/bin/hex file etc.
|
||||||
|
pico_add_extra_outputs(main)
|
||||||
|
|
||||||
|
# add url via pico_set_program_url
|
||||||
|
example_auto_set_url(main)
|
||||||
106
motor-control/firmware/Jenkinsfile
vendored
Normal file
106
motor-control/firmware/Jenkinsfile
vendored
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
pipeline {
|
||||||
|
agent none
|
||||||
|
|
||||||
|
stages {
|
||||||
|
stage('git checkout') {
|
||||||
|
agent {
|
||||||
|
label 'docker'
|
||||||
|
}
|
||||||
|
|
||||||
|
steps {
|
||||||
|
git branch: 'firmware-dev',
|
||||||
|
credentialsId: 'osci-rendering_github',
|
||||||
|
url: 'git@github.com:AlexanderHD27/oscilloscope-drawing.git'
|
||||||
|
|
||||||
|
sh 'git submodule update --init --recursive'
|
||||||
|
sh "ls -laF"
|
||||||
|
stash includes: "firmware/lib/doxygen-awesome-css/**", name: 'libs-doxygen'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('build build-container') {
|
||||||
|
agent {
|
||||||
|
label 'docker'
|
||||||
|
}
|
||||||
|
|
||||||
|
steps {
|
||||||
|
sh 'docker build -t rpi_pico_build_container firmware/docker/'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('build') {
|
||||||
|
parallel {
|
||||||
|
stage('build firmware') {
|
||||||
|
agent {
|
||||||
|
docker {
|
||||||
|
image 'rpi_pico_build_container'
|
||||||
|
label 'docker'
|
||||||
|
reuseNode true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
env.PICO_SDK_PATH_OVERRIDE = sh(script: 'echo $PWD/firmware/lib/pico-sdk', returnStdout: true).trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
dir('firmware/build') {
|
||||||
|
sh 'echo building in $PWD'
|
||||||
|
sh 'rm -rf *'
|
||||||
|
sh 'echo PicoSDK path: $PICO_SDK_PATH_OVERRIDE'
|
||||||
|
sh 'cmake ..'
|
||||||
|
sh 'cmake --build . --config Debug'
|
||||||
|
sh 'make -j4 all'
|
||||||
|
}
|
||||||
|
|
||||||
|
stash includes: "firmware/build/bin/*", name: 'binary'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('build docs') {
|
||||||
|
agent {
|
||||||
|
docker {
|
||||||
|
image 'rpi_pico_build_container'
|
||||||
|
label 'docker'
|
||||||
|
reuseNode true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
steps {
|
||||||
|
unstash 'libs-doxygen'
|
||||||
|
sh "doxygen firmware/docs/Doxyfile"
|
||||||
|
stash includes: "firmware/docs/html/*", name: 'html-docs'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('publish') {
|
||||||
|
parallel {
|
||||||
|
stage('publish docs') {
|
||||||
|
agent {
|
||||||
|
label 'cdc-deploy'
|
||||||
|
}
|
||||||
|
|
||||||
|
steps {
|
||||||
|
sh 'rm -rf /www/projects/osci-rendering/docs/*'
|
||||||
|
unstash 'html-docs'
|
||||||
|
sh 'cp -r firmware/docs/html/* /www/projects/osci-rendering/docs'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('publish binary') {
|
||||||
|
agent {
|
||||||
|
label 'cdc-deploy'
|
||||||
|
}
|
||||||
|
|
||||||
|
steps {
|
||||||
|
sh 'rm -rf /www/projects/osci-rendering/bin/*'
|
||||||
|
unstash 'binary'
|
||||||
|
sh 'cp -r bin/* /www/projects/osci-rendering/bin'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
motor-control/firmware/README.md
(Stored with Git LFS)
Normal file
BIN
motor-control/firmware/README.md
(Stored with Git LFS)
Normal file
Binary file not shown.
0
motor-control/firmware/TODOs.md
Normal file
0
motor-control/firmware/TODOs.md
Normal file
16
motor-control/firmware/cmake/tmc2209.cmake
Normal file
16
motor-control/firmware/cmake/tmc2209.cmake
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
add_library(tmc2209_driver STATIC
|
||||||
|
src/tmc2209/uart_interface.cpp
|
||||||
|
src/tmc2209/uart_registers.cpp
|
||||||
|
src/tmc2209/step.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(tmc2209_driver PRIVATE
|
||||||
|
include/tmc2209/
|
||||||
|
build/
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(tmc2209_driver
|
||||||
|
pico_stdlib
|
||||||
|
hardware_uart
|
||||||
|
hardware_pio
|
||||||
|
)
|
||||||
8
motor-control/firmware/docker/Dockerfile
Normal file
8
motor-control/firmware/docker/Dockerfile
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
FROM ubuntu:22.04
|
||||||
|
|
||||||
|
RUN apt -y update
|
||||||
|
RUN apt -y install build-essential gcc-arm-none-eabi doxygen cmake python3
|
||||||
|
RUN mkdir /data
|
||||||
|
|
||||||
|
WORKDIR /data
|
||||||
|
|
||||||
3
motor-control/firmware/docker/build_docs.sh
Executable file
3
motor-control/firmware/docker/build_docs.sh
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
doxygen ./firmware/docs/Doxyfile
|
||||||
11
motor-control/firmware/docker/build_firmware.sh
Executable file
11
motor-control/firmware/docker/build_firmware.sh
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
cd ./firmware/build
|
||||||
|
rm -rf *
|
||||||
|
|
||||||
|
export PICO_SDK_PATH_OVERRIDE="/data/firmware/lib/pico-sdk"
|
||||||
|
echo $PICO_SDK_PATH_OVERRIDE
|
||||||
|
|
||||||
|
cmake ..
|
||||||
|
cmake --build . --config Debug
|
||||||
|
make -j4 all
|
||||||
2658
motor-control/firmware/docs/Doxyfile
Normal file
2658
motor-control/firmware/docs/Doxyfile
Normal file
File diff suppressed because it is too large
Load Diff
BIN
motor-control/firmware/docs/tmc2209_datasheet_rev1.09.pdf
(Stored with Git LFS)
Normal file
BIN
motor-control/firmware/docs/tmc2209_datasheet_rev1.09.pdf
(Stored with Git LFS)
Normal file
Binary file not shown.
5
motor-control/firmware/example_auto_set_url.cmake
Executable file
5
motor-control/firmware/example_auto_set_url.cmake
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
set(PICO_EXAMPLE_URL_BASE "https://github.com/raspberrypi/pico-examples/tree/HEAD")
|
||||||
|
macro(example_auto_set_url TARGET)
|
||||||
|
file(RELATIVE_PATH URL_REL_PATH "${PICO_EXAMPLES_PATH}" "${CMAKE_CURRENT_LIST_DIR}")
|
||||||
|
pico_set_program_url(${TARGET} "${PICO_EXAMPLE_URL_BASE}/${URL_REL_PATH}")
|
||||||
|
endmacro()
|
||||||
517
motor-control/firmware/include/tmc2209/registers_map.hpp
Normal file
517
motor-control/firmware/include/tmc2209/registers_map.hpp
Normal file
@@ -0,0 +1,517 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// =================================================================================================
|
||||||
|
// General Registers (p.23)
|
||||||
|
// =================================================================================================
|
||||||
|
#define REG_ADDR_GENERAL_GCONF 0x00
|
||||||
|
#define REG_ADDR_GENERAL_GSTAT 0x01
|
||||||
|
#define REG_ADDR_GENERAL_IFCNT 0x02
|
||||||
|
#define REG_ADDR_GENERAL_NODECONF 0x03
|
||||||
|
#define REG_ADDR_GENERAL_OTP_PROG 0x04
|
||||||
|
#define REG_ADDR_GENERAL_OTP_READ 0x05
|
||||||
|
#define REG_ADDR_GENERAL_IOIN 0x06
|
||||||
|
#define REG_ADDR_GENERAL_FACTORY_CONF 0x07
|
||||||
|
|
||||||
|
/// @brief Global configuration flags
|
||||||
|
struct REG_GCONF {
|
||||||
|
/**
|
||||||
|
* (Reset default=1)
|
||||||
|
* 0: Use internal reference derived from 5VOUT
|
||||||
|
* 1: Use voltage supplied to VREF as current reference
|
||||||
|
*/
|
||||||
|
unsigned int I_scale_analog: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (Reset default: OTP)
|
||||||
|
* 0: Operation with external sense resistors
|
||||||
|
* 1: Internal sense resistors. Use current supplied into VREF as reference for internal sense resistor. VREF pin internally is driven to GND in this mode.
|
||||||
|
*/
|
||||||
|
unsigned int internal_Rsense: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (Reset default: OTP)
|
||||||
|
* 0: StealthChop PWM mode enabled (depending on velocity thresholds). Initially switch from off to on state while in stand still, only.
|
||||||
|
* 1: SpreadCycle mode enabled A high level on the pin SPREAD inverts this flag to switch between both chopper modes.
|
||||||
|
*/
|
||||||
|
unsigned int en_SpreadCycle: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1: Inverse motor direction
|
||||||
|
*/
|
||||||
|
unsigned int shaft: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0: INDEX shows the first microstep position of sequencer
|
||||||
|
* 1: INDEX pin outputs overtemperature prewarning flag (otpw) instead
|
||||||
|
*/
|
||||||
|
unsigned int index_otpw: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0: INDEX output as selected by index_otpw
|
||||||
|
* 1: INDEX output shows step pulses from internal pulse generator (toggle upon each step)
|
||||||
|
*/
|
||||||
|
unsigned int index_step: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0: PDN_UART controls standstill current reduction
|
||||||
|
* 1: PDN_UART input function disabled. Set this bit, when using the UART interface!
|
||||||
|
*/
|
||||||
|
unsigned int pdn_disable: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0: Microstep resolution selected by pins MS1, MS2
|
||||||
|
* 1: Microstep resolution selected by MRES register
|
||||||
|
*/
|
||||||
|
unsigned int mstep_reg_select: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0: No filtering of STEP pulses
|
||||||
|
* 1: Software pulse generator optimization enabled when fullstep frequency > 750Hz (roughly). TSTEP shows filtered step time values when active
|
||||||
|
*/
|
||||||
|
unsigned int multistep_filt: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0: Normal operation
|
||||||
|
* 1: Enable analog test output on pin ENN (pull down resistor off), ENN treated as enabled. IHOLD[1..0] selects the function of DCO: 0…2: T120, DAC, VDDH
|
||||||
|
*/
|
||||||
|
unsigned int test_mode: 1;
|
||||||
|
|
||||||
|
unsigned int :22;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief Global status flags
|
||||||
|
struct REG_GSTAT {
|
||||||
|
/**
|
||||||
|
* 1: Indicates that the IC has been reset since the last read access to GSTAT. All registers have been cleared to reset values.
|
||||||
|
*/
|
||||||
|
unsigned int reset: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1: Indicates, that the driver has been shut down due to overtemperature or short circuit detection since the last read access. Read DRV_STATUS for details. The flag can only be cleared when all error conditions are cleared
|
||||||
|
*/
|
||||||
|
unsigned int drv_err: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates an undervoltage on the charge pump. The driver is disabled in this case. This flag is not latched and thus does not need to be cleared
|
||||||
|
*/
|
||||||
|
unsigned int uv_cp: 1;
|
||||||
|
|
||||||
|
unsigned int :29;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief Interface transmission counter
|
||||||
|
struct REG_IFCNT {
|
||||||
|
/**
|
||||||
|
* Interface transmission counter. This register becomes incremented with each successful UART interface write access. Read out to check the serial transmission for lost data. Read accesses do not change the content. The counter wraps around from 255 to 0.
|
||||||
|
*/
|
||||||
|
unsigned int mstep: 8;
|
||||||
|
|
||||||
|
unsigned int :24;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief Node configuration
|
||||||
|
struct REG_NODECONF {
|
||||||
|
unsigned int :8;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SENDDELAY for read access (time until reply is sent):
|
||||||
|
* 0, 1: 8 bit times (Attention: Don’t use in multi-node)
|
||||||
|
* 2, 3: 3*8 bit times
|
||||||
|
* 4, 5: 5*8 bit times
|
||||||
|
* 6, 7: 7*8 bit times
|
||||||
|
* 8, 9: 9*8 bit times
|
||||||
|
* 10, 11: 11*8 bit times
|
||||||
|
* 12, 13: 13*8 bit times
|
||||||
|
* 14, 15: 15*8 bit times
|
||||||
|
*/
|
||||||
|
unsigned int senddelay: 4;
|
||||||
|
|
||||||
|
unsigned int :16;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief OTP programming
|
||||||
|
struct REG_OPT_PROG {
|
||||||
|
/**
|
||||||
|
* Selection of OTP bit to be programmed to the selected byte location (n=0..7: programs bit n to a logic 1)
|
||||||
|
*/
|
||||||
|
unsigned int otpbit: 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Selection of OTP programming location (0, 1 or 2)
|
||||||
|
*/
|
||||||
|
unsigned int optbyte: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to 0xbd to enable programming. A programming time of minimum 10ms per bit is recommended (check by reading OTP_READ).
|
||||||
|
*/
|
||||||
|
unsigned int optmagic: 8;
|
||||||
|
|
||||||
|
unsigned int :16;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief OTP read (Access to OTP memory result and update)
|
||||||
|
struct OTP_READ {
|
||||||
|
/// @brief OTP0 byte 0 read data
|
||||||
|
unsigned int opt0: 8;
|
||||||
|
|
||||||
|
/// @brief OTP1 byte 1 read data
|
||||||
|
unsigned int opt1: 8;
|
||||||
|
|
||||||
|
/// @brief OTP2 byte 2 read data
|
||||||
|
unsigned int opt2: 8;
|
||||||
|
|
||||||
|
unsigned int :8;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/// @brief Inputs (Reads the state of all input pins available)
|
||||||
|
struct REG_IOIN {
|
||||||
|
unsigned int enn: 1;
|
||||||
|
unsigned int :1;
|
||||||
|
unsigned int ms1: 1;
|
||||||
|
unsigned int ms2: 1;
|
||||||
|
unsigned int diag: 1;
|
||||||
|
unsigned int :1;
|
||||||
|
unsigned int pdn_uart: 1;
|
||||||
|
unsigned int step: 1;
|
||||||
|
unsigned int spread_en: 1;
|
||||||
|
unsigned int dir: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief VERSION: 0x21=first version of the IC Identical numbers mean full digital compatibility.
|
||||||
|
*/
|
||||||
|
unsigned int version: 8;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct REG_FACTORY_CONF {
|
||||||
|
/**
|
||||||
|
* Lowest to highest clock frequency. Check at charge pump output. The frequency span is not guaranteed, but it is tested, that tuning to 12MHz internal clock is possible. The devices come preset to 12MHz clock frequency by OTP programming.
|
||||||
|
*/
|
||||||
|
unsigned int fclktrim: 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* %00: OT=143°C, OTPW=120°C
|
||||||
|
* %01: OT=150°C, OTPW=120°C
|
||||||
|
* %10: OT=150°C, OTPW=143°C
|
||||||
|
* %11: OT=157°C, OTPW=143°C
|
||||||
|
*/
|
||||||
|
unsigned int ottrim: 2;
|
||||||
|
|
||||||
|
unsigned int :25;
|
||||||
|
};
|
||||||
|
|
||||||
|
// =================================================================================================
|
||||||
|
// Velocity Dependent Control (p.28)
|
||||||
|
// =================================================================================================
|
||||||
|
#define REG_ADDR_VELOCITY_IHOLD_IRUN 0x10
|
||||||
|
#define REG_ADDR_VELOCITY_TPOWERDOWN 0x11
|
||||||
|
#define REG_ADDR_VELOCITY_TSTEP 0x12
|
||||||
|
#define REG_ADDR_VELOCITY_TPWMTHRS 0x13
|
||||||
|
#define REG_ADDR_VELOCITY_VACTUAL 0x22
|
||||||
|
|
||||||
|
/// @brief Driver current control
|
||||||
|
struct REG_IHOLD_IRUN {
|
||||||
|
/**
|
||||||
|
* (Reset default: OTP)
|
||||||
|
* IHOLD (Reset default: OTP)
|
||||||
|
* Standstill current (0=1/32 … 31=32/32)
|
||||||
|
* In combination with StealthChop mode, setting
|
||||||
|
* IHOLD=0 allows to choose freewheeling or coil short circuit (passive braking) for motor stand still.
|
||||||
|
*/
|
||||||
|
unsigned int ihold: 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (Reset default=31)
|
||||||
|
* Motor run current (0=1/32 … 31=32/32)
|
||||||
|
*
|
||||||
|
* Tint: Choose sense resistors in a way, that normal IRUN is 16 to 31 for best microstep performance.
|
||||||
|
*/
|
||||||
|
unsigned int irun: 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (Reset default: OTP)
|
||||||
|
* Controls the number of clock cycles for motor power down after standstill is detected (stst=1) and TPOWERDOWN has expired. The smooth transition avoids a motor jerk upon power down.
|
||||||
|
* 0: instant power down
|
||||||
|
* 1..15: Delay per current reduction step in multiple of 2^18 clocks
|
||||||
|
*/
|
||||||
|
unsigned int iholddelay: 4;
|
||||||
|
unsigned int :18;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct REG_TPOWERDOWN {
|
||||||
|
/**
|
||||||
|
* (Reset default=20)
|
||||||
|
* Sets the delay time from stand still (stst) detection to motor current power down. Time range is about 0 to 5.6 seconds.
|
||||||
|
* 0…((2^8)-1) * 2^18 tCLK
|
||||||
|
* Attention: A minimum setting of 2 is required to allow automatic tuning of StealthChop PWM_OFFS_AUTO.
|
||||||
|
*/
|
||||||
|
unsigned int tpow: 8;
|
||||||
|
|
||||||
|
unsigned int :24;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief Time between two 1/256 microsteps
|
||||||
|
struct REG_TSTEP {
|
||||||
|
/**
|
||||||
|
* Actual measured time between two 1/256 microsteps derived from the step input frequency in units of 1/fCLK. Measured value is (2^20)-1 in case of overflow or stand still. TSTEP always relates to 1/256 step, independent of the actual MRES. The TSTEP related threshold uses a hysteresis of 1/16 of the compare value to compensate for jitter in the clock or the step frequency: (Txxx*15/16)-1 is the lower compare value for each TSTEP based comparison.
|
||||||
|
* This means, that the lower switching velocity equals the calculated setting, but the upper switching velocity is higher as defined by the hysteresis setting.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
unsigned int tstep: 20;
|
||||||
|
|
||||||
|
unsigned int :12;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief Upper velocity for StealthChop voltage PWM mode
|
||||||
|
struct REG_TPWMTHRS {
|
||||||
|
/**
|
||||||
|
* Sets the upper velocity for StealthChop voltage PWM mode.
|
||||||
|
* TSTEP ≥ TPWMTHRS
|
||||||
|
* - StealthChop PWM mode is enabled, if configured
|
||||||
|
* When the velocity exceeds the limit set by TPWMTHRS, the driver switches to SpreadCycle.
|
||||||
|
* 0: Disabled
|
||||||
|
*/
|
||||||
|
unsigned int tpwmthrs: 20;
|
||||||
|
|
||||||
|
unsigned int :12;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct REG_VACTUAL {
|
||||||
|
/**
|
||||||
|
* ACTUAL allows moving the motor by UART control.
|
||||||
|
* It gives the motor velocity in +-(2^23)-1 [μsteps / t]
|
||||||
|
* 0: Normal operation. Driver reacts to STEP input.
|
||||||
|
* !=0: Motor moves with the velocity given by VACTUAL. Step pulses can be monitored via INDEX output. The motor direction is controlled by the sign of VACTUAL.
|
||||||
|
*/
|
||||||
|
int vactual: 24;
|
||||||
|
|
||||||
|
unsigned int :8;
|
||||||
|
};
|
||||||
|
|
||||||
|
// =================================================================================================
|
||||||
|
// StallGuard (p.29)
|
||||||
|
// =================================================================================================
|
||||||
|
|
||||||
|
#define REG_ADDR_STALLGUARD_TCOOLTHRS 0x14
|
||||||
|
#define REG_ADDR_STALLGUARD_SGTHRS 0x40
|
||||||
|
#define REG_ADDR_STALLGUARD_SG_RESULT 0x41
|
||||||
|
#define REG_ADDR_STALLGUARD_COOLCONF 0x42
|
||||||
|
|
||||||
|
struct REG_TCOOLTHRS {
|
||||||
|
/**
|
||||||
|
* This is the lower threshold velocity for switching on smart energy CoolStep and StallGuard to DIAG output. (unsigned) Set this parameter to disable CoolStep at low speeds, where it cannot work reliably. The stall output signal become enabled when exceeding this velocity. It becomes disabled again once the velocity falls below this threshold.
|
||||||
|
* TCOOLTHRS ≥ TSTEP > TPWMTHRS
|
||||||
|
* - CoolStep is enabled, if configured (only with StealthChop)
|
||||||
|
* - Stall output signal on pin DIAG is enabled
|
||||||
|
*/
|
||||||
|
unsigned int tcoolthrs: 20;
|
||||||
|
|
||||||
|
unsigned int :12;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct REG_SGTHRS {
|
||||||
|
/**
|
||||||
|
* Detection threshold for stall. The StallGuard value SG_RESULT becomes compared to the double of this threshold. A stall is signaled with
|
||||||
|
* SG_RESULT ≤ SGTHRS*2
|
||||||
|
*/
|
||||||
|
unsigned int sgthrs: 8;
|
||||||
|
|
||||||
|
unsigned int :24;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct REG_SG_RESULT {
|
||||||
|
/**
|
||||||
|
* StallGuard result. SG_RESULT becomes updated with each fullstep, independent of TCOOLTHRS and SGTHRS. A higher value signals a lower motor load and more torque headroom. Intended for StealthChop mode, only. Bits 9 and 0 will always show 0. Scaling to 10 bit is for compatibility to StallGuard2
|
||||||
|
*/
|
||||||
|
unsigned int sg_result: 10;
|
||||||
|
|
||||||
|
unsigned int :22;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct REG_COOLCONF {
|
||||||
|
/**
|
||||||
|
* @brief CoolStep configuration
|
||||||
|
*/
|
||||||
|
unsigned int coolconf: 16;
|
||||||
|
|
||||||
|
unsigned int :16;
|
||||||
|
};
|
||||||
|
|
||||||
|
// =================================================================================================
|
||||||
|
// Sequencer Registers (p.30)
|
||||||
|
// =================================================================================================q
|
||||||
|
|
||||||
|
#define REG_ADDR_SEQUENCER_MSCNT 0x6A
|
||||||
|
#define REG_ADDR_SEQUENCER_MSCURACT 0x6B
|
||||||
|
|
||||||
|
/// @brief Microstep counter
|
||||||
|
struct REG_MSCNT {
|
||||||
|
/**
|
||||||
|
* Microstep counter. Indicates actual position in the microstep table for CUR_A. CUR_B uses an offset of 256 into the table. Reading out MSCNT allows determination of the motor position within the electrical wave.
|
||||||
|
*/
|
||||||
|
unsigned int mscnt: 10;
|
||||||
|
|
||||||
|
unsigned int :22;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief Microstep current (actual)
|
||||||
|
struct REG_MSCURACT {
|
||||||
|
/**
|
||||||
|
* Actual microstep current for motor phase B (sine wave) as read from the internal sine wave table (not scaled by current setting)
|
||||||
|
*/
|
||||||
|
int cur_a: 9;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Actual microstep current for motor phase A (co-sine wave) as read from the internal sine wave table (not scaled by current setting)
|
||||||
|
*/
|
||||||
|
int cur_b: 9;
|
||||||
|
|
||||||
|
unsigned int :14;
|
||||||
|
};
|
||||||
|
|
||||||
|
// =================================================================================================
|
||||||
|
// Chopper Registers (p.32)
|
||||||
|
// =================================================================================================
|
||||||
|
|
||||||
|
#define REG_ADDR_CHOPPER_CHOPCONF 0x6C
|
||||||
|
#define REG_ADDR_CHOPPER_DRV_STATUS 0x6F
|
||||||
|
#define REG_ADDR_CHOPPER_PWMCONF 0x70
|
||||||
|
#define REG_ADDR_CHOPPER_PWM_SCALE 0x71
|
||||||
|
#define REG_ADDR_CHOPPER_PWM_AUTO 0x72
|
||||||
|
|
||||||
|
struct REG_CHOPCONF {
|
||||||
|
/**
|
||||||
|
* @brief off time and driver enable
|
||||||
|
* Off time setting controls duration of slow decay phase
|
||||||
|
* NCLK= 24 + 32*TOFF
|
||||||
|
* %0000: Driver disable, all bridges off
|
||||||
|
* %0001: 1 – use only with TBL ≥ 2
|
||||||
|
* %0010 ... %1111: 2 ... 15
|
||||||
|
* (Default: OTP, resp. 3 in StealthChop mode)
|
||||||
|
*/
|
||||||
|
unsigned int toff: 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief hysteresis start value added to HEND
|
||||||
|
* %000 ... %111:
|
||||||
|
* Add 1, 2, ..., 8 to hysteresis low value HEND
|
||||||
|
* (1/512 of this setting adds to current setting)
|
||||||
|
* Attention: Effective HEND+HSTRT ≤ 16.
|
||||||
|
* Hint: Hysteresis decrement is done each 16 clocks
|
||||||
|
*/
|
||||||
|
unsigned int hstrt: 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief HEND hysteresis low value OFFSET sine wave offset
|
||||||
|
* %0000 ... %1111:
|
||||||
|
* Hysteresis is -3, -2, -1, 0, 1, ..., 12
|
||||||
|
* (1/512 of this setting adds to current setting)
|
||||||
|
* This is the hysteresis value which becomes used for the hysteresis chopper.
|
||||||
|
* (Default: OTP, resp. 0 in StealthChop mode)
|
||||||
|
*/
|
||||||
|
unsigned int hend: 4;
|
||||||
|
|
||||||
|
unsigned int :1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TBL blank time select
|
||||||
|
* %00 ... %11:
|
||||||
|
* Set comparator blank time to 16, 24, 32 or 40 clocks
|
||||||
|
* Hint: %00 or %01 is recommended for most applications
|
||||||
|
* (Default: OTP)
|
||||||
|
*/
|
||||||
|
unsigned int tbl: 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief sense resistor voltage based current scaling
|
||||||
|
* 0: Low sensitivity, high sense resistor voltage
|
||||||
|
* 1: High sensitivity, low sense resistor voltage
|
||||||
|
*/
|
||||||
|
unsigned int vsense: 1;
|
||||||
|
|
||||||
|
unsigned int :6;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief micro step resolution
|
||||||
|
* %0000: Native 256 microstep setting.
|
||||||
|
* %0001 ... %1000:
|
||||||
|
* 128, 64, 32, 16, 8, 4, 2, FULLSTEP
|
||||||
|
* Reduced microstep resolution.
|
||||||
|
* The resolution gives the number of microstep entries per sine quarter wave.
|
||||||
|
* When choosing a lower microstep resolution, the driver automatically uses microstep positions which result in a symmetrical wave.
|
||||||
|
* Number of microsteps per step pulse = 2^MRES (Selection by pins unless disabled by GCONF. mstep_reg_select)
|
||||||
|
*/
|
||||||
|
unsigned int mres: 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief interpolation to 256 microsteps
|
||||||
|
* 1: The actual microstep resolution (MRES) becomes extrapolated to 256 microsteps for smoothest motor operation. (Default: 1)
|
||||||
|
*/
|
||||||
|
unsigned int intpol: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief enable double edge step pulses
|
||||||
|
* 1: Enable step impulse at each step edge to reduce step frequency requirement. This mode is not compatible with the step filtering function (multistep_filt)
|
||||||
|
*/
|
||||||
|
unsigned int dedge: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief short to GND protection disable
|
||||||
|
* 0: Short to GND protection is on
|
||||||
|
* 1: Short to GND protection is disabled
|
||||||
|
*/
|
||||||
|
unsigned int diss2g: 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Low side short protection disable
|
||||||
|
* 0: Short protection low side is on
|
||||||
|
* 1: Short protection low side is disabled
|
||||||
|
*/
|
||||||
|
unsigned int diss2vs: 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DRV_STATUS {
|
||||||
|
unsigned int drv_status: 32;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PWMCONF {
|
||||||
|
unsigned int pwmconf: 22;
|
||||||
|
unsigned int :10;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Results of StealthChop amplitude regulator. These values can be used to monitor automatic PWM amplitude scaling (255=max. voltage).
|
||||||
|
*/
|
||||||
|
struct PWM_SCALE {
|
||||||
|
/**
|
||||||
|
* Actual PWM duty cycle. This value is used for scaling the values CUR_A and CUR_B read from the sine wave table.
|
||||||
|
*/
|
||||||
|
unsigned int pwm_scale_sum: 8;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 9 Bit signed offset added to the calculated PWM duty cycle. This is the result of the automatic amplitude regulation based on current measurement.
|
||||||
|
*/
|
||||||
|
unsigned int pwm_scale_auto: 9;
|
||||||
|
|
||||||
|
unsigned int :15;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* These automatically generated values can be read out in order to determine a default / power up setting for PWM_GRAD and PWM_OFS.
|
||||||
|
*/
|
||||||
|
struct PWM_AUTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Automatically determined offset value
|
||||||
|
*/
|
||||||
|
unsigned int pwm_ofs_auto: 8;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Automatically determined gradient value
|
||||||
|
*/
|
||||||
|
unsigned int pwm_grad_auto: 8;
|
||||||
|
|
||||||
|
unsigned int :16;
|
||||||
|
};
|
||||||
78
motor-control/firmware/include/tmc2209/step.hpp
Normal file
78
motor-control/firmware/include/tmc2209/step.hpp
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "hardware/pio.h"
|
||||||
|
#include "pulser.pio.h"
|
||||||
|
|
||||||
|
class TMC2209_step_dual {
|
||||||
|
private:
|
||||||
|
uint step0_pin;
|
||||||
|
uint step1_pin;
|
||||||
|
uint dir0_pin;
|
||||||
|
uint dir1_pin;
|
||||||
|
uint enable0_pin;
|
||||||
|
uint enable1_pin;
|
||||||
|
|
||||||
|
const int sm_num_divider0 = 0;
|
||||||
|
const int sm_num_divider1 = 1;
|
||||||
|
const int sm_num_counter0 = 2;
|
||||||
|
const int sm_num_counter1 = 3;
|
||||||
|
|
||||||
|
PIO pio_core;
|
||||||
|
|
||||||
|
pio_sm_config sm_config_divider0;
|
||||||
|
pio_sm_config sm_config_counter0;
|
||||||
|
pio_sm_config sm_config_divider1;
|
||||||
|
pio_sm_config sm_config_counter1;
|
||||||
|
|
||||||
|
uint pulser_program_offset;
|
||||||
|
const uint subprogram_offset_divider = 0;
|
||||||
|
const uint subprogram_offset_counter = 6;
|
||||||
|
|
||||||
|
const float base_clock_freq_khz = 500.0;
|
||||||
|
|
||||||
|
const uint32_t sleep_time_us = 500;
|
||||||
|
bool done_flag0;
|
||||||
|
bool done_flag1;
|
||||||
|
bool done_flag0_arm;
|
||||||
|
bool done_flag1_arm;
|
||||||
|
|
||||||
|
uint remaining_step_count0;
|
||||||
|
uint remaining_step_count1;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void init_pio();
|
||||||
|
void init_gpio();
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
void irq_handler0();
|
||||||
|
void irq_handler1();
|
||||||
|
|
||||||
|
TMC2209_step_dual(
|
||||||
|
uint step0_pin,
|
||||||
|
uint step1_pin,
|
||||||
|
uint dir0_pin,
|
||||||
|
uint dir1_pin,
|
||||||
|
uint enable0_pin,
|
||||||
|
uint enable1_pin,
|
||||||
|
PIO pio_core
|
||||||
|
);
|
||||||
|
|
||||||
|
void set_conf0(uint frequency, bool dir);
|
||||||
|
void set_conf1(uint frequency, bool dir);
|
||||||
|
|
||||||
|
void pulse0(uint n);
|
||||||
|
void pulse1(uint n);
|
||||||
|
|
||||||
|
void pulse0_int(int n);
|
||||||
|
void pulse1_int(int n);
|
||||||
|
|
||||||
|
bool wait0(int timeout_ms);
|
||||||
|
bool wait1(int timeout_ms);
|
||||||
|
|
||||||
|
uint get_remaining_steps0();
|
||||||
|
uint get_remaining_steps1();
|
||||||
|
};
|
||||||
|
|
||||||
|
extern TMC2209_step_dual * g_step_driver_instance;
|
||||||
|
void step_irq0_handler();
|
||||||
|
void step_irq1_handler();
|
||||||
125
motor-control/firmware/include/tmc2209/tmc2209.hpp
Normal file
125
motor-control/firmware/include/tmc2209/tmc2209.hpp
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "pico/stdlib.h"
|
||||||
|
#include "hardware/uart.h"
|
||||||
|
|
||||||
|
#include "registers_map.hpp"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Interface to communicate with TMC2209 driver via UART
|
||||||
|
* This implements basic read and write operations to the TMC2209 driver
|
||||||
|
* It does not implement any register specific operations
|
||||||
|
*/
|
||||||
|
class TMC2209_UART {
|
||||||
|
private:
|
||||||
|
uint8_t node_address;
|
||||||
|
uart_inst_t *uart_inst;
|
||||||
|
uint baudrate;
|
||||||
|
uint tx_pin;
|
||||||
|
uint rx_pin;
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a new tmc2209 uart object
|
||||||
|
* This does not initialize the UART peripheral, it just sets the parameters
|
||||||
|
*
|
||||||
|
* @param uart_id which UART to use (uart0 or uart1)
|
||||||
|
* @param node_address this is the address of the TMC2209 driver set by ms1, ms2 pins (0-3)
|
||||||
|
* @param baudrate UART baudrate to use (250k > baudrate > 2000, good value 115200, the tmc2209 has automatic baudrate detection)
|
||||||
|
* @param tx_pin TX pin of RP2040. Depending on the UART peripheral, diffrent pins are valid
|
||||||
|
* @param rx_pin RX pin of RP2040. Depending on the UART peripheral, diffrent pins are valid
|
||||||
|
*/
|
||||||
|
TMC2209_UART(uart_inst_t *uart_inst, uint8_t node_address, uint baudrate, uint tx_pin, uint rx_pin);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialize UART peripheral and pins
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void init();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Calculate CRC8-ATM checksum for the given data
|
||||||
|
* the specific implementation is taken from TMC2209 datasheet
|
||||||
|
*
|
||||||
|
* @param data Data to calculate CRC for
|
||||||
|
* @param size Size of the data (without CRC byte)
|
||||||
|
* @return uint8_t Calculated CRC8 checksum
|
||||||
|
*/
|
||||||
|
uint8_t calc_crc8_atm(uint8_t *data, uint8_t size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Perform a read operation to the TMC2209 driver
|
||||||
|
* This does not check if register is write only.
|
||||||
|
* It will wait for the response from the driver
|
||||||
|
*
|
||||||
|
* @param address
|
||||||
|
* @return uint32_t Data read from the register
|
||||||
|
*/
|
||||||
|
uint32_t read(uint8_t address);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Perform a write operation to the TMC2209 driver
|
||||||
|
* This does not check if register is read only.
|
||||||
|
* It will wait for the response from the driver
|
||||||
|
*
|
||||||
|
* @param address Where to write the data (register Address)
|
||||||
|
* @param value Data to write to the register
|
||||||
|
*/
|
||||||
|
void write(uint8_t address, uint32_t value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This if any CRC error occured during the last read/write operation. Should be checked after each operation
|
||||||
|
*/
|
||||||
|
bool crc_error_flag = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Higher level interface to TMC2209 driver
|
||||||
|
* This class simplifies dealing with the registers of the TMC2209 driver
|
||||||
|
* so you can just set the values
|
||||||
|
*/
|
||||||
|
class TMC2209_Registers {
|
||||||
|
|
||||||
|
private:
|
||||||
|
TMC2209_UART uart_driver;
|
||||||
|
|
||||||
|
REG_CHOPCONF chopconfBuffer;
|
||||||
|
|
||||||
|
public:
|
||||||
|
TMC2209_Registers(TMC2209_UART uart_driver);
|
||||||
|
|
||||||
|
void set_reg_gconf(
|
||||||
|
bool i_scale_analog,
|
||||||
|
bool internal_rsense,
|
||||||
|
bool en_SpreadCycle,
|
||||||
|
bool shaft,
|
||||||
|
bool index_otpw,
|
||||||
|
bool index_step,
|
||||||
|
bool pdn_disable,
|
||||||
|
bool mstep_reg_select,
|
||||||
|
bool multistep_filt
|
||||||
|
);
|
||||||
|
|
||||||
|
void set_holdCurrent(
|
||||||
|
uint8_t currentHold,
|
||||||
|
uint8_t currentRun,
|
||||||
|
uint8_t holdDelay
|
||||||
|
);
|
||||||
|
|
||||||
|
void set_thresholdPowerdown(uint8_t threshold);
|
||||||
|
void set_thresholdStealthChop(uint32_t threshold);
|
||||||
|
void set_thresholdCoolStep(uint32_t threshold);
|
||||||
|
void set_thresholdStall(uint8_t threshold);
|
||||||
|
|
||||||
|
void set_chopConfig(
|
||||||
|
bool lowsideShortProtection,
|
||||||
|
bool GNDShortProtection,
|
||||||
|
bool doubleEdge,
|
||||||
|
bool interpolation,
|
||||||
|
uint8_t microstepResolution,
|
||||||
|
bool voltageSensatifity,
|
||||||
|
uint8_t hysteresisOffset,
|
||||||
|
uint8_t hysteresisStart
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
1
motor-control/firmware/lib/FreeRTOS-Kernel
Submodule
1
motor-control/firmware/lib/FreeRTOS-Kernel
Submodule
Submodule motor-control/firmware/lib/FreeRTOS-Kernel added at 310ace5dd0
1
motor-control/firmware/lib/doxygen-awesome-css
Submodule
1
motor-control/firmware/lib/doxygen-awesome-css
Submodule
Submodule motor-control/firmware/lib/doxygen-awesome-css added at cc1bee0804
1
motor-control/firmware/lib/pico-sdk
Submodule
1
motor-control/firmware/lib/pico-sdk
Submodule
Submodule motor-control/firmware/lib/pico-sdk added at beb6f990a6
1
motor-control/firmware/lib/tinyusb
Submodule
1
motor-control/firmware/lib/tinyusb
Submodule
Submodule motor-control/firmware/lib/tinyusb added at 3eea46056e
1
motor-control/firmware/rpiPico.code-profile
Normal file
1
motor-control/firmware/rpiPico.code-profile
Normal file
File diff suppressed because one or more lines are too long
2
motor-control/firmware/scripts/build.sh
Executable file
2
motor-control/firmware/scripts/build.sh
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
cd build
|
||||||
|
make -j10
|
||||||
8
motor-control/firmware/scripts/build_and_flash.sh
Executable file
8
motor-control/firmware/scripts/build_and_flash.sh
Executable file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
if ! scripts/build.sh; then
|
||||||
|
exit
|
||||||
|
else
|
||||||
|
scripts/flash.exp main.elf
|
||||||
|
fi
|
||||||
|
|
||||||
21
motor-control/firmware/scripts/flash.exp
Executable file
21
motor-control/firmware/scripts/flash.exp
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/expect
|
||||||
|
|
||||||
|
set timeout 30
|
||||||
|
|
||||||
|
set input_file [lindex $argv 0]
|
||||||
|
|
||||||
|
spawn telnet localhost 4444
|
||||||
|
expect "> "
|
||||||
|
send "program $input_file verify\n"
|
||||||
|
expect "** Programming Finished **"
|
||||||
|
|
||||||
|
send "reset halt\n"
|
||||||
|
expect "> "
|
||||||
|
|
||||||
|
send "rp2040.core1 arp_reset assert 0\n"
|
||||||
|
expect "> "
|
||||||
|
send "rp2040.core0 arp_reset assert 0\n"
|
||||||
|
expect "> "
|
||||||
|
|
||||||
|
send "exit\n"
|
||||||
|
exit
|
||||||
3
motor-control/firmware/scripts/flash_direct.sh
Executable file
3
motor-control/firmware/scripts/flash_direct.sh
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
openocd -f interface/cmsis-dap.cfg -c "adapter speed 5000" -f target/rp2040.cfg -c "program $1 verify reset exit"
|
||||||
4
motor-control/firmware/scripts/launch_openocd.sh
Executable file
4
motor-control/firmware/scripts/launch_openocd.sh
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
sudo openocd -f interface/cmsis-dap.cfg -c "adapter speed 5000" -f target/rp2040.cfg
|
||||||
|
|
||||||
2
motor-control/firmware/scripts/launch_serial_monitor.sh
Executable file
2
motor-control/firmware/scripts/launch_serial_monitor.sh
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
minicom -D $1
|
||||||
22
motor-control/firmware/scripts/remote/flash.exp
Executable file
22
motor-control/firmware/scripts/remote/flash.exp
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/expect
|
||||||
|
|
||||||
|
set timeout 30
|
||||||
|
|
||||||
|
set input_file [lindex $argv 0]
|
||||||
|
set host [lindex $argv 1]
|
||||||
|
|
||||||
|
spawn telnet $host 4444
|
||||||
|
expect "> "
|
||||||
|
send "program $input_file verify\n"
|
||||||
|
expect "** Programming Finished **"
|
||||||
|
|
||||||
|
send "reset halt\n"
|
||||||
|
expect "> "
|
||||||
|
|
||||||
|
send "rp2040.core1 arp_reset assert 0\n"
|
||||||
|
expect "> "
|
||||||
|
send "rp2040.core0 arp_reset assert 0\n"
|
||||||
|
expect "> "
|
||||||
|
|
||||||
|
send "exit\n"
|
||||||
|
exit
|
||||||
12
motor-control/firmware/scripts/remote/flash.sh
Executable file
12
motor-control/firmware/scripts/remote/flash.sh
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
|
||||||
|
in_file=$(basename "$1")
|
||||||
|
|
||||||
|
echo "Input file: $1"
|
||||||
|
echo "Input file (base): $in_file"
|
||||||
|
echo "Host: $2"
|
||||||
|
|
||||||
|
scp $1 $2:/tmp
|
||||||
|
|
||||||
|
./scripts/remote/flash.exp "/tmp/$in_file" "$2"
|
||||||
13
motor-control/firmware/scripts/remote/reset.exp
Executable file
13
motor-control/firmware/scripts/remote/reset.exp
Executable file
@@ -0,0 +1,13 @@
|
|||||||
|
#!/usr/bin/expect
|
||||||
|
|
||||||
|
set timeout 30
|
||||||
|
|
||||||
|
set host [lindex $argv 0]
|
||||||
|
|
||||||
|
spawn telnet $host 4444
|
||||||
|
|
||||||
|
expect "> "
|
||||||
|
send "reset\n"
|
||||||
|
expect "> "
|
||||||
|
send "exit\n"
|
||||||
|
exit
|
||||||
20
motor-control/firmware/scripts/remote/run_openocd.exp
Normal file
20
motor-control/firmware/scripts/remote/run_openocd.exp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/expect
|
||||||
|
|
||||||
|
set timeout 30
|
||||||
|
|
||||||
|
spawn ssh [lindex $argv 0]
|
||||||
|
|
||||||
|
expect "# "
|
||||||
|
send "cd ~/gobot/"
|
||||||
|
expect "# "
|
||||||
|
|
||||||
|
send "git fetch"
|
||||||
|
expect "# "
|
||||||
|
|
||||||
|
send "git checkout motor-ctrl-firmware"
|
||||||
|
expect "# "
|
||||||
|
|
||||||
|
send "cd motor-control/firmware/scripts/remote"
|
||||||
|
expect "# "
|
||||||
|
|
||||||
|
send "./run_openocd.sh"
|
||||||
3
motor-control/firmware/scripts/remote/run_openocd.sh
Normal file
3
motor-control/firmware/scripts/remote/run_openocd.sh
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
src/openocd -f interface/cmsis-dap.cfg -c "bindto 0.0.0.0" -c "adapter speed 5000" -f target/rp2040.cfg -s tcl
|
||||||
13
motor-control/firmware/scripts/reset.exp
Executable file
13
motor-control/firmware/scripts/reset.exp
Executable file
@@ -0,0 +1,13 @@
|
|||||||
|
#!/usr/bin/expect
|
||||||
|
|
||||||
|
set timeout 30
|
||||||
|
|
||||||
|
set input_file [lindex $argv 0]
|
||||||
|
|
||||||
|
spawn telnet localhost 4444
|
||||||
|
|
||||||
|
expect "> "
|
||||||
|
send "reset\n"
|
||||||
|
expect "> "
|
||||||
|
send "exit\n"
|
||||||
|
exit
|
||||||
112
motor-control/firmware/src/main.cpp
Executable file
112
motor-control/firmware/src/main.cpp
Executable file
@@ -0,0 +1,112 @@
|
|||||||
|
/**
|
||||||
|
* @file main.c
|
||||||
|
* @author AlexanderHD27
|
||||||
|
* @brief Main file of the RPi Pico Firmware for the Oscilloscope-Renderer
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2024-02-15
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2024
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "tmc2209/tmc2209.hpp"
|
||||||
|
#include "pico/stdio.h"
|
||||||
|
#include "hardware/uart.h"
|
||||||
|
|
||||||
|
#include "pulser.pio.h"
|
||||||
|
#include "tmc2209/step.hpp"
|
||||||
|
|
||||||
|
#define LED_PIN 25
|
||||||
|
|
||||||
|
#define ENABLE0_PIN 2
|
||||||
|
#define ENABLE1_PIN 3
|
||||||
|
|
||||||
|
#define LIMIT0_PIN 10
|
||||||
|
#define LIMIT1_PIN 11
|
||||||
|
|
||||||
|
#define STEP0_PIN 6
|
||||||
|
#define STEP1_PIN 7
|
||||||
|
#define DIR0_PIN 8
|
||||||
|
#define DIR1_PIN 9
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
gpio_init(DIR0_PIN);
|
||||||
|
gpio_set_dir(DIR0_PIN, GPIO_OUT);
|
||||||
|
gpio_put(DIR0_PIN, 0);
|
||||||
|
|
||||||
|
gpio_init(DIR1_PIN);
|
||||||
|
gpio_set_dir(DIR1_PIN, GPIO_OUT);
|
||||||
|
gpio_put(DIR1_PIN, 0);
|
||||||
|
|
||||||
|
for(int i=0; i<100; i++) {
|
||||||
|
gpio_put(DIR0_PIN, 1);
|
||||||
|
gpio_put(DIR1_PIN, 1);
|
||||||
|
sleep_ms(2);
|
||||||
|
gpio_put(DIR0_PIN, 0);
|
||||||
|
gpio_put(DIR1_PIN, 0);
|
||||||
|
sleep_ms(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TMC2209_step_dual step_driver = TMC2209_step_dual(
|
||||||
|
STEP0_PIN, STEP1_PIN,
|
||||||
|
DIR0_PIN, DIR1_PIN,
|
||||||
|
ENABLE0_PIN, ENABLE1_PIN,
|
||||||
|
pio0
|
||||||
|
);
|
||||||
|
TMC2209_UART uart_driver0 = TMC2209_UART(uart0, 0, 19200, 0, 1);
|
||||||
|
TMC2209_UART uart_driver1 = TMC2209_UART(uart1, 0, 19200, 4, 5);
|
||||||
|
uart_driver0.init();
|
||||||
|
uart_driver1.init();
|
||||||
|
|
||||||
|
sleep_ms(5);
|
||||||
|
|
||||||
|
|
||||||
|
step_driver.set_conf1(10000, 0);
|
||||||
|
|
||||||
|
|
||||||
|
gpio_init(LIMIT0_PIN);
|
||||||
|
gpio_set_dir(LIMIT0_PIN, GPIO_IN);
|
||||||
|
gpio_pull_up(LIMIT0_PIN);
|
||||||
|
|
||||||
|
gpio_init(LIMIT1_PIN);
|
||||||
|
gpio_set_dir(LIMIT1_PIN, GPIO_IN);
|
||||||
|
gpio_pull_up(LIMIT1_PIN);
|
||||||
|
|
||||||
|
step_driver.set_conf0(10000, 1);
|
||||||
|
step_driver.pulse0(10000);
|
||||||
|
step_driver.wait0(0);
|
||||||
|
|
||||||
|
step_driver.set_conf0(10000, 0);
|
||||||
|
step_driver.pulse0(100000);
|
||||||
|
while(!gpio_get(LIMIT1_PIN)) {
|
||||||
|
sleep_ms(1);
|
||||||
|
}
|
||||||
|
step_driver.pulse0(0);
|
||||||
|
sleep_ms(500);
|
||||||
|
|
||||||
|
step_driver.set_conf0(10000, 1);
|
||||||
|
step_driver.pulse0(200);
|
||||||
|
step_driver.wait0(0);
|
||||||
|
|
||||||
|
step_driver.set_conf0(500, 0);
|
||||||
|
step_driver.pulse0(5000);
|
||||||
|
while(!gpio_get(LIMIT1_PIN)) {
|
||||||
|
sleep_ms(1);
|
||||||
|
}
|
||||||
|
step_driver.pulse0(0);
|
||||||
|
sleep_ms(1);
|
||||||
|
|
||||||
|
gpio_init(LED_PIN);
|
||||||
|
gpio_set_dir(LED_PIN, GPIO_OUT);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
sleep_ms(50);
|
||||||
|
gpio_put(LED_PIN, 0);
|
||||||
|
sleep_ms(50);
|
||||||
|
gpio_put(LED_PIN, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
43
motor-control/firmware/src/tmc2209/pulser.pio
Normal file
43
motor-control/firmware/src/tmc2209/pulser.pio
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
|
||||||
|
.program pulser
|
||||||
|
clock_div:
|
||||||
|
PULL NOBLOCK
|
||||||
|
MOV X, OSR
|
||||||
|
MOV Y, X
|
||||||
|
l0:
|
||||||
|
JMP Y-- l0
|
||||||
|
|
||||||
|
IRQ CLEAR 0 REL
|
||||||
|
; SM 0 + 0 -> IRQ 0
|
||||||
|
; SM 1 + 0 -> IRQ 1
|
||||||
|
|
||||||
|
JMP clock_div
|
||||||
|
|
||||||
|
counter:
|
||||||
|
; SM 2 + 2 -> IRQ 0
|
||||||
|
; SM 3 + 2 -> IRQ 1
|
||||||
|
PULL
|
||||||
|
MOV X, OSR
|
||||||
|
JMP !X l1_end
|
||||||
|
JMP X-- l1
|
||||||
|
l1:
|
||||||
|
PULL NOBLOCK
|
||||||
|
MOV Y, OSR
|
||||||
|
MOV X, OSR
|
||||||
|
JMP !Y l1_end
|
||||||
|
|
||||||
|
IRQ WAIT 2 REL
|
||||||
|
SET PINS, 1
|
||||||
|
IRQ WAIT 2 REL
|
||||||
|
SET PINS, 0
|
||||||
|
|
||||||
|
JMP X-- l1
|
||||||
|
|
||||||
|
l1_end:
|
||||||
|
MOV ISR, X
|
||||||
|
PUSH NOBLOCK
|
||||||
|
IRQ SET 0 REL
|
||||||
|
; SM 2 + 0 -> IRQ 2
|
||||||
|
; SM 3 + 0 -> IRQ 3
|
||||||
|
JMP counter
|
||||||
|
|
||||||
290
motor-control/firmware/src/tmc2209/step.cpp
Normal file
290
motor-control/firmware/src/tmc2209/step.cpp
Normal file
@@ -0,0 +1,290 @@
|
|||||||
|
#include "step.hpp"
|
||||||
|
#include "pico/stdio.h"
|
||||||
|
#include "hardware/pio.h"
|
||||||
|
#include "hardware/irq.h"
|
||||||
|
#include <pico/time.h>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
TMC2209_step_dual * g_step_driver_instance;
|
||||||
|
|
||||||
|
void step_irq0_handler() {
|
||||||
|
g_step_driver_instance->irq_handler0();
|
||||||
|
};
|
||||||
|
|
||||||
|
void step_irq1_handler() {
|
||||||
|
g_step_driver_instance->irq_handler1();
|
||||||
|
};
|
||||||
|
|
||||||
|
TMC2209_step_dual::TMC2209_step_dual(
|
||||||
|
uint step0_pin,
|
||||||
|
uint step1_pin,
|
||||||
|
uint dir0_pin,
|
||||||
|
uint dir1_pin,
|
||||||
|
uint enable0_pin,
|
||||||
|
uint enable1_pin,
|
||||||
|
PIO pio_core
|
||||||
|
) {
|
||||||
|
this->step0_pin = step0_pin;
|
||||||
|
this->step1_pin = step1_pin;
|
||||||
|
this->dir0_pin = dir0_pin;
|
||||||
|
this->dir1_pin = dir1_pin;
|
||||||
|
this->enable0_pin = enable0_pin;
|
||||||
|
this->enable1_pin = enable1_pin;
|
||||||
|
this->pio_core = pio_core;
|
||||||
|
|
||||||
|
g_step_driver_instance = this;
|
||||||
|
|
||||||
|
this->done_flag0 = false;
|
||||||
|
this->done_flag1 = false;
|
||||||
|
this->done_flag0_arm = false;
|
||||||
|
this->done_flag1_arm = false;
|
||||||
|
|
||||||
|
init_gpio();
|
||||||
|
init_pio();
|
||||||
|
};
|
||||||
|
|
||||||
|
void TMC2209_step_dual::init_gpio() {
|
||||||
|
gpio_init(this->enable0_pin);
|
||||||
|
gpio_init(this->enable1_pin);
|
||||||
|
gpio_set_dir(this->enable0_pin, GPIO_OUT);
|
||||||
|
gpio_set_dir(this->enable1_pin, GPIO_OUT);
|
||||||
|
gpio_put(this->enable0_pin, 0);
|
||||||
|
gpio_put(this->enable1_pin, 0);
|
||||||
|
sleep_ms(1);
|
||||||
|
|
||||||
|
gpio_init(this->dir0_pin);
|
||||||
|
gpio_init(this->dir1_pin);
|
||||||
|
gpio_set_dir(this->dir0_pin, GPIO_OUT);
|
||||||
|
gpio_set_dir(this->dir1_pin, GPIO_OUT);
|
||||||
|
gpio_put(this->dir0_pin, 1);
|
||||||
|
gpio_put(this->dir1_pin, 1);
|
||||||
|
sleep_ms(1);
|
||||||
|
};
|
||||||
|
|
||||||
|
void TMC2209_step_dual::init_pio() {
|
||||||
|
pio_sm_set_enabled(this->pio_core, this->sm_num_divider0, false);
|
||||||
|
pio_sm_set_enabled(this->pio_core, this->sm_num_divider1, false);
|
||||||
|
pio_sm_set_enabled(this->pio_core, this->sm_num_counter0, false);
|
||||||
|
pio_sm_set_enabled(this->pio_core, this->sm_num_counter1, false);
|
||||||
|
|
||||||
|
this->pulser_program_offset = pio_add_program(this->pio_core, &pulser_program);
|
||||||
|
|
||||||
|
this->sm_config_divider0 = pulser_program_get_default_config(this->pulser_program_offset);
|
||||||
|
this->sm_config_divider1 = pulser_program_get_default_config(this->pulser_program_offset);
|
||||||
|
this->sm_config_counter0 = pulser_program_get_default_config(this->pulser_program_offset);
|
||||||
|
this->sm_config_counter1 = pulser_program_get_default_config(this->pulser_program_offset);
|
||||||
|
|
||||||
|
pio_gpio_init(this->pio_core, this->step0_pin);
|
||||||
|
pio_gpio_init(this->pio_core, this->step1_pin);
|
||||||
|
|
||||||
|
pio_sm_set_consecutive_pindirs(this->pio_core, this->sm_num_counter0, this->step0_pin, 1, true);
|
||||||
|
pio_sm_set_consecutive_pindirs(this->pio_core, this->sm_num_counter1, this->step1_pin, 1, true);
|
||||||
|
|
||||||
|
sm_config_set_set_pins(&this->sm_config_counter0, this->step0_pin, 1);
|
||||||
|
sm_config_set_set_pins(&this->sm_config_counter1, this->step1_pin, 1);
|
||||||
|
|
||||||
|
pio_sm_init(
|
||||||
|
this->pio_core,
|
||||||
|
this->sm_num_divider0,
|
||||||
|
this->pulser_program_offset + this->subprogram_offset_divider,
|
||||||
|
&this->sm_config_divider0
|
||||||
|
);
|
||||||
|
pio_sm_init(
|
||||||
|
this->pio_core,
|
||||||
|
this->sm_num_divider1,
|
||||||
|
this->pulser_program_offset + this->subprogram_offset_divider,
|
||||||
|
&this->sm_config_divider1
|
||||||
|
);
|
||||||
|
pio_sm_init(
|
||||||
|
this->pio_core,
|
||||||
|
this->sm_num_counter0,
|
||||||
|
this->pulser_program_offset + this->subprogram_offset_counter,
|
||||||
|
&this->sm_config_counter0
|
||||||
|
);
|
||||||
|
pio_sm_init(
|
||||||
|
this->pio_core,
|
||||||
|
this->sm_num_counter1,
|
||||||
|
this->pulser_program_offset + this->subprogram_offset_counter,
|
||||||
|
&this->sm_config_counter1
|
||||||
|
);
|
||||||
|
|
||||||
|
float clock_div = ((float)(SYS_CLK_KHZ))/(base_clock_freq_khz);
|
||||||
|
|
||||||
|
pio_sm_set_clkdiv(this->pio_core, this->sm_num_divider0, clock_div);
|
||||||
|
pio_sm_set_clkdiv(this->pio_core, this->sm_num_divider1, clock_div);
|
||||||
|
pio_sm_set_clkdiv(this->pio_core, this->sm_num_counter0, 1.0);
|
||||||
|
pio_sm_set_clkdiv(this->pio_core, this->sm_num_counter1, 1.0);
|
||||||
|
|
||||||
|
pio_sm_set_enabled(this->pio_core, this->sm_num_divider0, true);
|
||||||
|
pio_sm_set_enabled(this->pio_core, this->sm_num_divider1, true);
|
||||||
|
pio_sm_set_enabled(this->pio_core, this->sm_num_counter0, true);
|
||||||
|
pio_sm_set_enabled(this->pio_core, this->sm_num_counter1, true);
|
||||||
|
|
||||||
|
pio_set_irq0_source_enabled(this->pio_core, pis_interrupt2, true);
|
||||||
|
pio_set_irq1_source_enabled(this->pio_core, pis_interrupt3, true);
|
||||||
|
|
||||||
|
if(this->pio_core == pio0) {
|
||||||
|
irq_set_exclusive_handler(PIO0_IRQ_0, step_irq0_handler);
|
||||||
|
irq_set_exclusive_handler(PIO0_IRQ_1, step_irq1_handler);
|
||||||
|
|
||||||
|
irq_set_enabled(PIO0_IRQ_0, true);
|
||||||
|
irq_set_enabled(PIO0_IRQ_1, true);
|
||||||
|
} else if(this->pio_core == pio1) {
|
||||||
|
irq_set_exclusive_handler(PIO1_IRQ_0, step_irq0_handler);
|
||||||
|
irq_set_exclusive_handler(PIO1_IRQ_1, step_irq1_handler);
|
||||||
|
|
||||||
|
irq_set_enabled(PIO1_IRQ_0, true);
|
||||||
|
irq_set_enabled(PIO1_IRQ_1, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
set_conf0(1000, 0);
|
||||||
|
set_conf1(1000, 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
void TMC2209_step_dual::set_conf0(uint frequency, bool dir) {
|
||||||
|
uint32_t cycles = (uint32_t)(base_clock_freq_khz / (((float)(frequency))/1000.0)) - 6;
|
||||||
|
|
||||||
|
gpio_put(this->dir0_pin, dir);
|
||||||
|
pio_sm_put_blocking(
|
||||||
|
this->pio_core,
|
||||||
|
this->sm_num_divider0,
|
||||||
|
cycles
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
void TMC2209_step_dual::set_conf1(uint frequency, bool dir) {
|
||||||
|
uint32_t cycles = (uint32_t)(base_clock_freq_khz / (((float)(frequency))/1000.0)) - 6;
|
||||||
|
|
||||||
|
gpio_put(this->dir1_pin, dir);
|
||||||
|
pio_sm_put_blocking(
|
||||||
|
this->pio_core,
|
||||||
|
this->sm_num_divider1,
|
||||||
|
cycles
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
void TMC2209_step_dual::pulse0(uint n) {
|
||||||
|
this->remaining_step_count0 = n;
|
||||||
|
this->done_flag0_arm = true;
|
||||||
|
this->done_flag0 = false;
|
||||||
|
|
||||||
|
pio_sm_put_blocking(
|
||||||
|
this->pio_core, this->sm_num_counter0, n
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
void TMC2209_step_dual::pulse1(uint n) {
|
||||||
|
this->remaining_step_count1 = n;
|
||||||
|
this->done_flag1_arm = true;
|
||||||
|
this->done_flag1 = false;
|
||||||
|
|
||||||
|
pio_sm_put_blocking(
|
||||||
|
this->pio_core, this->sm_num_counter1, n
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
void TMC2209_step_dual::pulse0_int(int n) {
|
||||||
|
this->remaining_step_count0 = n;
|
||||||
|
this->done_flag0_arm = true;
|
||||||
|
if(n < 0) {
|
||||||
|
n = abs(n);
|
||||||
|
gpio_put(this->dir1_pin, gpio_get(this->dir1_pin) ^ 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
pio_sm_put_blocking(
|
||||||
|
this->pio_core, this->sm_num_counter0, n
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
void TMC2209_step_dual::pulse1_int(int n) {
|
||||||
|
this->remaining_step_count1 = n;
|
||||||
|
this->done_flag1_arm = true;
|
||||||
|
if(n < 0) {
|
||||||
|
n = abs(n);
|
||||||
|
gpio_put(this->dir1_pin, gpio_get(this->dir1_pin) ^ 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
pio_sm_put_blocking(
|
||||||
|
this->pio_core, this->sm_num_counter1, n
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
void TMC2209_step_dual::irq_handler0() {
|
||||||
|
this->remaining_step_count0 = pio_sm_get(this->pio_core, this->sm_num_counter0);
|
||||||
|
|
||||||
|
if(this->done_flag0_arm) {
|
||||||
|
done_flag0 = true;
|
||||||
|
} else {
|
||||||
|
done_flag0 = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
pio_interrupt_clear(this->pio_core, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TMC2209_step_dual::irq_handler1() {
|
||||||
|
this->remaining_step_count1 = pio_sm_get(this->pio_core, this->sm_num_counter1);
|
||||||
|
|
||||||
|
if(this->done_flag1_arm) {
|
||||||
|
done_flag1 = true;
|
||||||
|
} else {
|
||||||
|
done_flag1 = false;
|
||||||
|
}
|
||||||
|
pio_interrupt_clear(this->pio_core, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TMC2209_step_dual::wait0(int timeout_ms) {
|
||||||
|
int t = timeout_ms*1000;
|
||||||
|
bool continues = timeout_ms <= 0;
|
||||||
|
|
||||||
|
if(!this->done_flag0_arm)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
while(t > 0 || continues) {
|
||||||
|
|
||||||
|
if(done_flag0) {
|
||||||
|
this->done_flag0_arm = false;
|
||||||
|
done_flag0 = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!continues)
|
||||||
|
t -= sleep_time_us;
|
||||||
|
|
||||||
|
sleep_us(sleep_time_us);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool TMC2209_step_dual::wait1(int timeout_ms) {
|
||||||
|
int t = timeout_ms*1000;
|
||||||
|
bool continues = timeout_ms <= 0;
|
||||||
|
|
||||||
|
if(!this->done_flag1_arm)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
while(t > 0 || continues) {
|
||||||
|
|
||||||
|
if(done_flag1) {
|
||||||
|
this->done_flag1_arm = false;
|
||||||
|
done_flag1 = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!continues)
|
||||||
|
t -= sleep_time_us;
|
||||||
|
|
||||||
|
sleep_us(sleep_time_us);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
uint TMC2209_step_dual::get_remaining_steps0() {
|
||||||
|
return this->remaining_step_count0;
|
||||||
|
};
|
||||||
|
|
||||||
|
uint TMC2209_step_dual::get_remaining_steps1() {
|
||||||
|
return this->remaining_step_count1;
|
||||||
|
};
|
||||||
80
motor-control/firmware/src/tmc2209/uart_interface.cpp
Normal file
80
motor-control/firmware/src/tmc2209/uart_interface.cpp
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
#include "pico/stdlib.h"
|
||||||
|
#include "pico.h"
|
||||||
|
#include "hardware/uart.h"
|
||||||
|
|
||||||
|
#include "tmc2209.hpp"
|
||||||
|
|
||||||
|
TMC2209_UART::TMC2209_UART(
|
||||||
|
uart_inst_t *uart_inst,
|
||||||
|
uint8_t node_address,
|
||||||
|
uint baudrate,
|
||||||
|
uint tx_pin,
|
||||||
|
uint rx_pin
|
||||||
|
) {
|
||||||
|
this->uart_inst = uart_inst;
|
||||||
|
this->node_address = node_address & 0b11;
|
||||||
|
this->baudrate = baudrate;
|
||||||
|
this->tx_pin = tx_pin;
|
||||||
|
this->rx_pin = rx_pin;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TMC2209_UART::init() {
|
||||||
|
gpio_set_function(this->tx_pin, UART_FUNCSEL_NUM(this->uart_inst, this->tx_pin));
|
||||||
|
gpio_set_function(this->rx_pin, UART_FUNCSEL_NUM(this->uart_inst, this->rx_pin));
|
||||||
|
|
||||||
|
// UART format: 8 data bits, 1 stop bit, no parity
|
||||||
|
// -> https://www.analog.com/media/en/technical-documentation/data-sheets/TMC2209_datasheet_rev1.09.pdf
|
||||||
|
uart_set_format(this->uart_inst, 8, 1, UART_PARITY_NONE);
|
||||||
|
|
||||||
|
// Clear to Send (CTS) and Request to Send (RTS) are not used
|
||||||
|
// (This is for automaticlly telling the other side that it is ready to receive/send data)
|
||||||
|
uart_set_hw_flow(this->uart_inst, false, false);
|
||||||
|
|
||||||
|
uart_set_fifo_enabled(this->uart_inst, true);
|
||||||
|
|
||||||
|
uart_init(this->uart_inst, this->baudrate);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TMC2209_UART::calc_crc8_atm(uint8_t *data, uint8_t size) {
|
||||||
|
int i,j;
|
||||||
|
uint8_t crc = 0; // CRC located in last byte of message
|
||||||
|
uint8_t currentByte;
|
||||||
|
|
||||||
|
for (i=0; i<size; i++) { // Execute for all bytes of a message
|
||||||
|
currentByte = data[i]; // Retrieve a byte to be sent from Array
|
||||||
|
|
||||||
|
for (j=0; j<8; j++) {
|
||||||
|
if ((crc >> 7) ^ (currentByte & 0x01)) { // update CRC based result of XOR operation
|
||||||
|
crc = (crc << 1) ^ 0x07;
|
||||||
|
} else {
|
||||||
|
crc = (crc << 1);
|
||||||
|
}
|
||||||
|
currentByte = currentByte >> 1;
|
||||||
|
} // for CRC bit
|
||||||
|
} // for message byte
|
||||||
|
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t TMC2209_UART::read(uint8_t address) {
|
||||||
|
uint8_t data[4] = {
|
||||||
|
0b01010101, // Sync byte
|
||||||
|
this->node_address, // Node address
|
||||||
|
(address & (uint8_t)(0x7F)), // Register address, last bit is 0 for read
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
data[3] = this->calc_crc8_atm(data, 3);
|
||||||
|
|
||||||
|
uart_write_blocking(this->uart_inst, data, 4);
|
||||||
|
|
||||||
|
uint8_t response[12];
|
||||||
|
uart_read_blocking(this->uart_inst, response, 12);
|
||||||
|
|
||||||
|
if(response[11] != calc_crc8_atm(&response[4], 7)) {
|
||||||
|
this->crc_error_flag = true;
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return *((uint32_t*) &response[7]);
|
||||||
|
}
|
||||||
|
}
|
||||||
1
motor-control/firmware/src/tmc2209/uart_registers.cpp
Normal file
1
motor-control/firmware/src/tmc2209/uart_registers.cpp
Normal file
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
BIN
motor-control/motor-driver-breakout-v2/Pasted image.png
(Stored with Git LFS)
Normal file
BIN
motor-control/motor-driver-breakout-v2/Pasted image.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
motor-control/motor-driver-breakout-v2/motor-driver-breakout-v2-backups/motor-driver-breakout-v2-2024-09-12_232323.zip
(Stored with Git LFS)
Normal file
BIN
motor-control/motor-driver-breakout-v2/motor-driver-breakout-v2-backups/motor-driver-breakout-v2-2024-09-12_232323.zip
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
motor-control/motor-driver-breakout-v2/motor-driver-breakout-v2-backups/motor-driver-breakout-v2-2024-09-12_235008.zip
(Stored with Git LFS)
Normal file
BIN
motor-control/motor-driver-breakout-v2/motor-driver-breakout-v2-backups/motor-driver-breakout-v2-2024-09-12_235008.zip
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
motor-control/motor-driver-breakout-v2/motor-driver-breakout-v2-backups/motor-driver-breakout-v2-2024-09-26_185927.zip
(Stored with Git LFS)
Normal file
BIN
motor-control/motor-driver-breakout-v2/motor-driver-breakout-v2-backups/motor-driver-breakout-v2-2024-09-26_185927.zip
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
motor-control/motor-driver-breakout-v2/motor-driver-breakout-v2-backups/motor-driver-breakout-v2-2024-09-26_195637.zip
(Stored with Git LFS)
Normal file
BIN
motor-control/motor-driver-breakout-v2/motor-driver-breakout-v2-backups/motor-driver-breakout-v2-2024-09-26_195637.zip
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
motor-control/motor-driver-breakout-v2/motor-driver-breakout-v2.kicad_sch
(Stored with Git LFS)
BIN
motor-control/motor-driver-breakout-v2/motor-driver-breakout-v2.kicad_sch
(Stored with Git LFS)
Binary file not shown.
BIN
motor-control/motor-driver-breakout-v2/motor-driver-breakout-v2.pdf
(Stored with Git LFS)
BIN
motor-control/motor-driver-breakout-v2/motor-driver-breakout-v2.pdf
(Stored with Git LFS)
Binary file not shown.
Reference in New Issue
Block a user