Compare commits
11
Commits
v1.1-RELEASE
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
efe4c320b4 | ||
|
|
4068ba6e01 | ||
|
|
49697cc2b2 | ||
|
|
9ded7e0483 | ||
|
|
1e9fb3ed9f | ||
|
|
cb64a5057a | ||
|
|
01eb754e01 | ||
|
|
b71fd008df | ||
|
|
7b3685a930 | ||
|
|
d4b2a7a69e | ||
|
|
24c01a0d7c |
No files matched your search
@@ -16,6 +16,8 @@ jobs:
|
||||
steps:
|
||||
- name: Check out the repo
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # fetch all commits and tags
|
||||
|
||||
- name: Doxygen build
|
||||
uses: mattnotmitt/doxygen-action@v1.9.5
|
||||
|
||||
@@ -1,44 +1,52 @@
|
||||
RP2040-Decoder
|
||||
===============
|
||||
# RP2040-Decoder
|
||||
|
||||
This Project is a DIY DCC Decoder for model railroad locomotives which aims to be cost effective.
|
||||
Designed to be a low-cost, open-source alternative to commercial DCC decoders, it utilizes the Raspberry Pi RP2040 dual-core microcontroller. The decoder features DCC protocol decoding and command interpretation alongside motor control in a compact 25x20 mm form factor.
|
||||
|
||||
Features
|
||||
--------
|
||||
## Key Features
|
||||
* **DCC Signal Decoding**: Interrupt-based edge detection with full packet/protocol decoding.
|
||||
* **Motor Control**: 128 speed steps with configurable acceleration/deceleration ramping and v_min/v_mid/v_max; closed-loop control for consistent motor speed under varying load conditions.
|
||||
* **Flexible I/O**: 4x transistor-switched outputs and 6x additional GPIOs; all of them PWM capable.
|
||||
* **CV Configuration**: Function mapping and programming track support.
|
||||
* **Standards Compliance**: Implements the most important NMRA (S-9.1, S-9.2.x) and RCN (210, 212, 216) DCC standards.
|
||||
* **Compact Form Factor**: 25x20 mm board size.
|
||||
* **Integrated Documentation**: Comprehensive [GitHub Pages documentation](https://gab-k.github.io/RP2040-Decoder/) covering hardware theory and software implementation.
|
||||
|
||||
- DCC digital signal decoding
|
||||
- Motor load/speed control
|
||||
- 4 Outputs switched by transistors with configurable optional PWM
|
||||
- 6 additional GPIO for lighter loads or custom applications
|
||||
- Programmable on programming track
|
||||
- CV Function Mapping
|
||||
- Board size of 25x20 mm
|
||||
- Pre-compiled software available and flashable via USB using your regular file explorer
|
||||
- Debugging via Serial Wire Debug or optional logging via stdio and UART/USB serial port
|
||||
## Architecture Overview
|
||||
The system uses each of the two ARM Cortex-M0+ cores for separate tasks:
|
||||
|
||||
Getting Started & Documentation
|
||||
------------
|
||||
* **Core 0: Signal Processing & Management**
|
||||
* DCC edge detection and packet decoding.
|
||||
* Configuration Variable (CV) management using persistent flash storage.
|
||||
* Service Mode (Programming Track) logic and acknowledgment pulse generation.
|
||||
* **Core 1: Motion Control**
|
||||
* **PID Controller**: A discrete-time PID motor controller implementation utilizing based on a bilinear transform formula.
|
||||
* **Back-EMF Feedback**: ADC sampling during PWM-off cycles.
|
||||
* **Adaptive Control**: Gain scheduling for $K_P$ and a startup controller (feed-forward) to overcome static friction.
|
||||
|
||||
The [documentation](https://gab-k.github.io/RP2040-Decoder/) provides an overview of the steps required to use the decoder. It also tries to give an insight into how the hardware and software works.
|
||||
## Hardware Revisions
|
||||
|
||||
|
||||
License
|
||||
-------
|
||||
- Software - MIT license
|
||||
- Hardware - CERN Open Hardware Licence Version 2 - Permissive
|
||||
- [LICENSE](https://github.com/gab-k/RP2040-Decoder/blob/main/LICENSE)
|
||||
|
||||
|
||||
------------
|
||||
USB hardware version
|
||||
<div style="display: flex; justify-content: space-between; align-items: center;">
|
||||
<img src="https://raw.githubusercontent.com/gab-k/RP2040-Decoder/refs/heads/gh-pages/img_USB/top.png" alt="Image 1" style="width: 45%;"/>
|
||||
<img src="https://raw.githubusercontent.com/gab-k/RP2040-Decoder/refs/heads/gh-pages/img_USB/bottom.png" alt="Image 2" style="width: 45%;"/>
|
||||
### USB Version
|
||||
Optimized for ease of use; supports UF2 drag-and-drop flashing and serial logging.
|
||||
<div style="display: flex; gap: 10px;">
|
||||
<img src="https://raw.githubusercontent.com/gab-k/RP2040-Decoder/refs/heads/gh-pages/img_USB/top.png" width="45%" />
|
||||
<img src="https://raw.githubusercontent.com/gab-k/RP2040-Decoder/refs/heads/gh-pages/img_USB/bottom.png" width="45%" />
|
||||
</div>
|
||||
|
||||
Legacy hardware version
|
||||
<div style="display: flex; justify-content: space-between; align-items: center;">
|
||||
<img src="https://raw.githubusercontent.com/gab-k/RP2040-Decoder/refs/heads/gh-pages/img_Legacy/top.png" alt="Image 1" style="width: 45%;"/>
|
||||
<img src="https://raw.githubusercontent.com/gab-k/RP2040-Decoder/refs/heads/gh-pages/img_Legacy/bottom.png" alt="Image 2" style="width: 45%;"/>
|
||||
### Legacy Version
|
||||
Revision without USB, one sided assembly, flashed via SWD.
|
||||
<div style="display: flex; gap: 10px;">
|
||||
<img src="https://raw.githubusercontent.com/gab-k/RP2040-Decoder/refs/heads/gh-pages/img_Legacy/top.png" width="45%" />
|
||||
<img src="https://raw.githubusercontent.com/gab-k/RP2040-Decoder/refs/heads/gh-pages/img_Legacy/bottom.png" width="45%" />
|
||||
</div>
|
||||
|
||||
## Getting Started
|
||||
|
||||
To get started, you will first need the hardware. The different options for acquiring a board are outlined [here](https://gab-k.github.io/RP2040-Decoder/sphinx/html/gs/getting_started.html#where-to-get-the-board).
|
||||
|
||||
For the software, you have a few options: you can either [build it from source](https://gab-k.github.io/RP2040-Decoder/sphinx/html/gs/getting_started.html#building-the-software) or use the ready-to-flash [binaries built by the CI pipeline](https://github.com/gab-k/RP2040-Decoder/releases) on each release. [Flashing the firmware](https://gab-k.github.io/RP2040-Decoder/sphinx/html/gs/getting_started.html#flashing-the-software) can be done via SWD or, if you are using the USB hardware version, simply by dragging and dropping the file using your regular file explorer.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
* **Software**: MIT License
|
||||
* **Hardware**: CERN Open Hardware Licence Version 2 - Permissive
|
||||
+5
-5
@@ -127,11 +127,11 @@ uint8_t CV_ARRAY_DEFAULT [CV_ARRAY_SIZE] = {
|
||||
0b00000000, //CV_102 -
|
||||
0b00000000, //CV_103 -
|
||||
0b00000000, //CV_104 -
|
||||
0b00000000, //CV_105 -
|
||||
0b00000000, //CV_106 -
|
||||
0b00000000, //CV_107 -
|
||||
0b00000000, //CV_108 -
|
||||
0b00000000, //CV_109 -
|
||||
0b00000000, //CV_105 - user data
|
||||
0b00000000, //CV_106 - user data
|
||||
0b00000001, //CV_107 - MSB Manufacturer ID for DIY https://www.decoderdb.com/database/decoderdb-list
|
||||
0b00001011, //CV_108 - LSB Manufacturer ID
|
||||
DECODER_ID, //CV_109 - Decoder ID defined by board .h file (e.g. RP2040-Decoder-board-USB.h)
|
||||
0b00000000, //CV_110 -
|
||||
0b00000000, //CV_111 -
|
||||
///// PWM - Configuration //////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
// For board detection
|
||||
#define RP2040_DECODER
|
||||
|
||||
// Decoder ID (CV_109)
|
||||
#define DECODER_ID 1
|
||||
|
||||
// In case the xosc takes longer to stabilize than usual
|
||||
#ifndef PICO_XOSC_STARTUP_DELAY_MULTIPLIER
|
||||
#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
// For board detection
|
||||
#define RP2040_DECODER
|
||||
|
||||
// Decoder ID (CV_109)
|
||||
#define DECODER_ID 2
|
||||
|
||||
// In case the xosc takes longer to stabilize than usual
|
||||
#ifndef PICO_XOSC_STARTUP_DELAY_MULTIPLIER
|
||||
#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64
|
||||
|
||||
@@ -3,6 +3,28 @@
|
||||
# This can be dropped into an external project to help locate this SDK
|
||||
# It should be include()ed prior to project()
|
||||
|
||||
# Copyright 2020 (c) 2020 Raspberry Pi (Trading) Ltd.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
||||
# following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
|
||||
# disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
|
||||
# disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
|
||||
# derived from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
|
||||
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
|
||||
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
|
||||
@@ -40,25 +62,40 @@ if (NOT PICO_SDK_PATH)
|
||||
if (PICO_SDK_FETCH_FROM_GIT_PATH)
|
||||
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
|
||||
endif ()
|
||||
# GIT_SUBMODULES_RECURSE was added in 3.17
|
||||
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
|
||||
FetchContent_Declare(
|
||||
pico_sdk
|
||||
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
||||
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
|
||||
GIT_SUBMODULES_RECURSE FALSE
|
||||
)
|
||||
else ()
|
||||
FetchContent_Declare(
|
||||
pico_sdk
|
||||
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
||||
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
|
||||
)
|
||||
endif ()
|
||||
FetchContent_Declare(
|
||||
pico_sdk
|
||||
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
||||
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
|
||||
)
|
||||
|
||||
if (NOT pico_sdk)
|
||||
message("Downloading Raspberry Pi Pico SDK")
|
||||
FetchContent_Populate(pico_sdk)
|
||||
# GIT_SUBMODULES_RECURSE was added in 3.17
|
||||
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
|
||||
FetchContent_Populate(
|
||||
pico_sdk
|
||||
QUIET
|
||||
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
||||
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
|
||||
GIT_SUBMODULES_RECURSE FALSE
|
||||
|
||||
SOURCE_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-src
|
||||
BINARY_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-build
|
||||
SUBBUILD_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-subbuild
|
||||
)
|
||||
else ()
|
||||
FetchContent_Populate(
|
||||
pico_sdk
|
||||
QUIET
|
||||
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
||||
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
|
||||
|
||||
SOURCE_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-src
|
||||
BINARY_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-build
|
||||
SUBBUILD_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-subbuild
|
||||
)
|
||||
endif ()
|
||||
|
||||
set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
|
||||
endif ()
|
||||
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
|
||||
|
||||
@@ -6,10 +6,41 @@
|
||||
# -- Project information -----------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
|
||||
|
||||
import subprocess
|
||||
import re
|
||||
|
||||
def get_latest_release_tag():
|
||||
try:
|
||||
# Get all tags matching the pattern
|
||||
tags = subprocess.check_output(
|
||||
['git', 'tag', '--list', 'v*-RELEASE'],
|
||||
universal_newlines=True
|
||||
).splitlines()
|
||||
|
||||
if not tags:
|
||||
return "unknown"
|
||||
|
||||
# Sort tags in reverse version order
|
||||
tags.sort(reverse=True)
|
||||
|
||||
latest_tag = tags[0]
|
||||
|
||||
# Extract version numbers (optional: you can customize this regex)
|
||||
match = re.match(r'v(\d+\.\d+)-RELEASE', latest_tag)
|
||||
if match:
|
||||
return match.group(1)
|
||||
else:
|
||||
return "unknown"
|
||||
|
||||
except Exception:
|
||||
return "unknown"
|
||||
|
||||
|
||||
|
||||
project = 'RP2040-Decoder'
|
||||
copyright = '2024, Gabriel Koppenstein'
|
||||
author = 'Gabriel Koppenstein'
|
||||
release = '0.3, 1.0'
|
||||
release = get_latest_release_tag()
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
||||
@@ -31,4 +62,5 @@ html_static_path = ['_static']
|
||||
breathe_projects = {
|
||||
"RP2040-Decoder": "../../doxygen/build/xml"
|
||||
}
|
||||
breathe_default_project = "RP2040-Decoder"
|
||||
breathe_default_project = "RP2040-Decoder"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
Hardware
|
||||
======================
|
||||
|
||||
Revision 1.0
|
||||
USB
|
||||
------------
|
||||
|
||||
.. toctree::
|
||||
@@ -9,7 +9,7 @@ Revision 1.0
|
||||
|
||||
USB/hw_description
|
||||
|
||||
Revision 0.3
|
||||
Legacy
|
||||
------------
|
||||
|
||||
.. toctree::
|
||||
|
||||
@@ -72,7 +72,7 @@ The *Speed Helper* block effectively sets the setpoint of the controller accordi
|
||||
For feedback the back EMF voltage *V_EMF* is measured via voltage divider and ADC. *V_EMF* is proportional to the motor speed.
|
||||
|
||||
|
||||
While the central component is the PID controller, there is an additional block called `Feed-forward <https://en.wikipedia.org/wiki/Feed_forward_(control)>`_ that has an impact on the control output variable. The Feed-forward block adds an additional offset to the output depending on the setpoint; this is done to achieve better control. A more detailed explanation regarding Feed-forward can be found below. The speed helper block corresponds to the ``speed_helper()`` function, which delays changing the setpoint according to the configured deceleration/acceleration rates.
|
||||
While the central component is the PID controller, there is an additional block called `Feed-forward <https://en.wikipedia.org/wiki/Feed_forward_(control)>`_ that has an impact on the control output variable. The Feed-forward block adds an additional offset to the output depending on the setpoint; this is done to achieve better control. A more detailed explanation regarding Feed-forward can be found below. The speed helper block corresponds to the :c:func:`speed_helper()` function, which delays changing the setpoint according to the configured deceleration/acceleration rates.
|
||||
|
||||
.. figure:: ../../../svg/sw/Block_Diagram_Digital_Controller.svg
|
||||
:alt: Block Diagram - Digital Controller
|
||||
@@ -90,16 +90,35 @@ This means the actual output of the PID controller is the sum of the PID output
|
||||
The benefit of doing this is that the PID controller does not have to work in the non linear friction region of the motor, improving control performance.
|
||||
|
||||
|
||||
Speed Table Initialization
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The speed table is a crucial component of the motor control system, as it translates the 128 speed steps received from the DCC controller into specific setpoints for the PID controller. This table is initialized once at startup in the :c:func:`init_controller` function. The shape of the speed curve can be configured using three CV values: `V_min` (CV2), `V_mid` (CV6), and `V_max` (CV5).
|
||||
|
||||
- **V_min (CV2):** Defines the starting voltage (setpoint) for the first speed step.
|
||||
- **V_mid (CV6):** Sets the voltage at the midpoint of the speed range (speed step 64).
|
||||
- **V_max (CV5):** Determines the maximum voltage at the highest speed step (126).
|
||||
|
||||
The speed table is calculated with two linear interpolations: one from `V_min` to `V_mid` and another from `V_mid` to `V_max`. This creates a two-segment linear speed curve, which allows for a non-linear relationship between the speed step and the motor voltage. For example, you can have a gentle acceleration at low speeds and a more aggressive one at higher speeds.
|
||||
|
||||
The :c:func:`speed_helper` function then uses this table to gradually adjust the setpoint based on the configured acceleration and deceleration rates.
|
||||
|
||||
|
||||
Startup Controller
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Used on startup, meaning when the motor is not moving. First the startup controller retrieves the last `BASE_PWM_ARR_LEN` base PWM levels.
|
||||
The base pwm levels are not retained on a power cycle. That means when there is no previous base PWM level saved, the startup controller will start ramping up from 0.
|
||||
When there is less than `BASE_PWM_ARR_LEN` base PWM levels saved, the startup controller will ramp up from the average of the saved base PWM levels.
|
||||
The startup controller is used when the motor is stationary to find the minimum PWM level required to overcome static friction. This process is not retained on a power cycle.
|
||||
|
||||
After the startup controller retrieved the average of the last base pwm levels :math:`\bar{b}` it sets a PWM duty cycle level of :math:`\frac{2}{3} \cdot \bar{b}` and then ramps up the duty cycle/PWM level until the motor starts moving.
|
||||
When no previous startup PWM levels are saved the startup controller begins ramping up from 0.
|
||||
The actual value at which the motor started moving is multiplied by `K_FF` and used as a reference for the :ref:`feed forward <feed_forward>` block.
|
||||
The initial PWM level for the startup sequence is determined as follows:
|
||||
|
||||
- If previous successful startup levels are saved in memory, the controller calculates their average, :math:`\bar{b}`, and sets the initial PWM level to :math:`\frac{2}{3} \cdot \bar{b}`.
|
||||
- If no previous levels are saved, the ramp-up starts from a PWM level of 0.
|
||||
|
||||
From this starting point, the controller progressively ramps up the duty cycle until motor movement is detected. The ramp-up is not smooth but occurs in steps, with the step size determined by the maximum PWM level (which is a function of the PWM frequency).
|
||||
|
||||
If the PWM level reaches its maximum without motor movement, the controller reduces the starting level by half and retries, preventing excessive power to a stalled motor.
|
||||
|
||||
Once movement is detected (via back-EMF voltage), the current PWM `level` is saved as a new base value for future startups. This value is also multiplied by `K_FF` (from CV47) and used as the feed-forward term for the PID controller.
|
||||
|
||||
|
||||
|
||||
@@ -156,6 +175,10 @@ Gain Scheduling
|
||||
|
||||
Another aspect to consider is the implementation of `gain scheduling <https://en.wikipedia.org/wiki/Gain_scheduling>`_. K\ :sub:`P` is a function of the current setpoint. Often it is favorable to have a higher proportional gain K\ :sub:`P` for slow speeds, achieving better control results. The illustration above shows the default setting for K\ :sub:`P`. CV_54 & CV_55 are used to set K\ :sub:`P` @ x\ :sub:`0`, CV_56 & CV_57 for K\ :sub:`P` @ x\ :sub:`1`, and CV_58 & CV_59 for K\ :sub:`P` @ x\ :sub:`2`. Additionally, CV_60 is used to shift x\ :sub:`1` from the leftmost point (0% = 0/255) to the rightmost point (100% = 255/255).
|
||||
|
||||
The :c:func:`get_kp()` function implements this gain scheduling. It calculates the proportional gain `K_p` based on the current setpoint `sp`. The function uses two different linear equations to determine `K_p`, depending on whether the setpoint is above or below the `k_p_x_1` threshold. This creates a piecewise linear function for `K_p`, allowing for different gain characteristics at different speed ranges.
|
||||
|
||||
The parameters for these linear equations (`k_p_m_1`, `k_p_m_2`, `k_p_y_0`, `k_p_y_1`) are pre-calculated in the :c:func:`init_controller` function based on the corresponding CV values.
|
||||
|
||||
|
||||
.. _feed_forward:
|
||||
|
||||
@@ -167,10 +190,20 @@ In essence this means that the output of the PID controller is not only the sum
|
||||
The base PWM level is set by the startup controller and is the PWM level at which the motor starts moving.
|
||||
|
||||
|
||||
Speed Helper
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
|
||||
The :c:func:`speed_helper` function is responsible for implementing smooth acceleration and deceleration. It is called by a repeating timer, with the interval configured by CV175. This function acts as a temporal filter for the speed setpoint.
|
||||
|
||||
Instead of instantly changing the motor's setpoint to the new target speed step, the :c:func:`speed_helper` function gradually increments or decrements the current setpoint based on the acceleration (CV3) and deceleration (CV4) rates. These CVs determine how many calls to :c:func:`speed_helper` are needed for a single speed step change. For example, if the acceleration rate is set to 5, the :c:func:`speed_helper` must be called 5 times before the setpoint is incremented to the next speed step. This creates a time-based acceleration/deceleration curve.
|
||||
|
||||
The function also handles direction changes. If a direction change is detected, it will immediately jump to the new target speed without any delay, ensuring a responsive change in direction.
|
||||
|
||||
|
||||
Back-EMF voltage measurement
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
To provide a feedback signal proportional to the motor speed, the ADC is used to measure the `Back-EMF voltage <https://en.wikipedia.org/wiki/Counter-electromotive_force>`_. The measurement works by setting the PWM duty cycle to 0%, waiting for a certain delay time (CV_62), and then measuring x times (x = CV_63). While measuring, the array with measurement values is sorted using insertion sort. Afterwards, y elements (y = CV_63) from the left (lowest values) and z elements (z = CV_64) from the right (highest values) will be dismissed to mitigate the impact of potential outliers in measurement. The average value of the remaining values will be computed and fed back into the control algorithm. Considering default settings (100us delay, 100 samples, ~2µs sampling time), the complete measurement run, including averaging, takes about 0.3ms to 0.35ms, which effectively reduces the maximum possible duty cycle to about 93% to 94%.
|
||||
To provide a feedback signal proportional to the motor speed, the ADC is used to measure the `Back-EMF voltage <https://en.wikipedia.org/wiki/Counter-electromotive_force>`_. The measurement works by setting the PWM duty cycle to 0%, waiting for a certain delay time (CV_62), and then measuring x times (x = CV_61). The ADC input channel is selected based on the motor's direction (forward or reverse). While measuring, the array with measurement values is sorted using insertion sort. Afterwards, y elements (y = CV_63) from the left (lowest values) and z elements (z = CV_64) from the right (highest values) will be dismissed to mitigate the impact of potential outliers in measurement. The average value of the remaining values will be computed and fed back into the control algorithm. Considering default settings (100us delay, 100 samples, ~2µs sampling time), the complete measurement run, including averaging, takes about 0.3ms to 0.35ms, which effectively reduces the maximum possible duty cycle to about 93% to 94%.
|
||||
|
||||
DCC signal decoding
|
||||
------------------------------
|
||||
|
||||
Reference in new issue
Block a user