diff --git a/sphinx/doctrees/environment.pickle b/sphinx/doctrees/environment.pickle index fd50a82..a2efad6 100644 Binary files a/sphinx/doctrees/environment.pickle and b/sphinx/doctrees/environment.pickle differ diff --git a/sphinx/doctrees/hardware/rev_0_3/hw_description.doctree b/sphinx/doctrees/hardware/rev_0_3/hw_description.doctree index cf74325..4cd9e9f 100644 Binary files a/sphinx/doctrees/hardware/rev_0_3/hw_description.doctree and b/sphinx/doctrees/hardware/rev_0_3/hw_description.doctree differ diff --git a/sphinx/doctrees/hardware/rev_1_0/hw_description.doctree b/sphinx/doctrees/hardware/rev_1_0/hw_description.doctree index 50ccf01..17a6e50 100644 Binary files a/sphinx/doctrees/hardware/rev_1_0/hw_description.doctree and b/sphinx/doctrees/hardware/rev_1_0/hw_description.doctree differ diff --git a/sphinx/doctrees/other/getting_started.doctree b/sphinx/doctrees/other/getting_started.doctree index e65180c..a2cd683 100644 Binary files a/sphinx/doctrees/other/getting_started.doctree and b/sphinx/doctrees/other/getting_started.doctree differ diff --git a/sphinx/doctrees/software/header_files.doctree b/sphinx/doctrees/software/header_files.doctree index acda21a..0ee0c37 100644 Binary files a/sphinx/doctrees/software/header_files.doctree and b/sphinx/doctrees/software/header_files.doctree differ diff --git a/sphinx/doctrees/software/sw_description.doctree b/sphinx/doctrees/software/sw_description.doctree index 02edb3e..98a9c9c 100644 Binary files a/sphinx/doctrees/software/sw_description.doctree and b/sphinx/doctrees/software/sw_description.doctree differ diff --git a/sphinx/html/_images/Block_Diagram_Control.svg b/sphinx/html/_images/Block_Diagram_Control.svg new file mode 100644 index 0000000..11a030f --- /dev/null +++ b/sphinx/html/_images/Block_Diagram_Control.svg @@ -0,0 +1,4 @@ + + + +
Speed Helper
Motor Controller

PID MODE

or

STARTUP MODE
Motor Driver
ADC
Motor
Setpoint
Accel/Decel - Rate
Target Speedstep
Measurement
+

-
Error
Output
BEMF-Voltage
RPM
Voltage Divider
\ No newline at end of file diff --git a/sphinx/html/_images/Block_Diagram_PID.svg b/sphinx/html/_images/Block_Diagram_PID.svg new file mode 100644 index 0000000..c9364d6 --- /dev/null +++ b/sphinx/html/_images/Block_Diagram_PID.svg @@ -0,0 +1,4 @@ + + + +
KI
KI
I
I
KP
KP
Output
Output
P
P
        +
+
       +
+...
KD
KD
s
s
D
D
Error
Error
1/s
1/s
1/(sτ+1)
1/(sτ+1)
Text is not SVG - cannot display
\ No newline at end of file diff --git a/sphinx/html/_images/adaptive_kp.svg b/sphinx/html/_images/adaptive_kp.svg new file mode 100644 index 0000000..c3356ca --- /dev/null +++ b/sphinx/html/_images/adaptive_kp.svg @@ -0,0 +1,131 @@ + + + gl2ps_renderer figure + +Creator: GL2PS 1.4.2, (C) 1999-2020 C. Geuzaine +For: Octave +CreationDate: Thu Aug 4 01:55:04 2022 + + + + + + + + + + + + + + + + + + + + + + 0 + + + 500 + + + 1000 + + + 1500 + + + 2000 + + + + + + + + + + + + + 0 + + + 5 + + + 10 + + + 15 + + + 20 + + + + + + + sp + + + k + p + (sp) + + + + + + + + + + + + + + + + + + + + + + + + + + + k + p + + + + + + + x0 | y0 + + + + + + + x1 | y1 + + + + + + + x2 | y2 + + + + diff --git a/sphinx/html/_images/feed_forward.svg b/sphinx/html/_images/feed_forward.svg new file mode 100644 index 0000000..0b53f41 --- /dev/null +++ b/sphinx/html/_images/feed_forward.svg @@ -0,0 +1,159 @@ + + + gl2ps_renderer figure + +Creator: GL2PS 1.4.2, (C) 1999-2020 C. Geuzaine +For: Octave +CreationDate: Mon Aug 1 18:41:06 2022 + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 500 + + + 1000 + + + 1500 + + + 2000 + + + 2500 + + + + + + + + + + + + + + + 0 + + + 1000 + + + 2000 + + + 3000 + + + 4000 + + + 5000 + + + + + + + sp + + + PWM-Level (sp) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + forward + + + + reverse + + + + + + + x1 | y1 (fwd) + + + + + + + x2 | y2 (fwd) + + + + + + + x1 | y1 (rev) + + + + + + + x2 | y2 (rev) + + + + adjustment threshold y2 + + + + diff --git a/sphinx/html/_sources/hardware/rev_0_3/hw_description.rst.txt b/sphinx/html/_sources/hardware/rev_0_3/hw_description.rst.txt index 24585a5..c76e382 100644 --- a/sphinx/html/_sources/hardware/rev_0_3/hw_description.rst.txt +++ b/sphinx/html/_sources/hardware/rev_0_3/hw_description.rst.txt @@ -1,8 +1,9 @@ Overview -==================== +============================== .. figure:: ../../../../svg/hw/rev_0_3/Block_Diagram_Hardware.svg :alt: Block Diagram + :align: center Harware block diagram @@ -22,7 +23,7 @@ The above block diagram gives a general overview regarding the operation of comp - Crystal oscillator Electrical Characteristics -==================== +============================== .. table:: Electrical Characteristics & Absolute Maximum Ratings :widths: auto @@ -46,10 +47,11 @@ Electrical Characteristics (2): According to: `T2N7002BK Datasheet `_ Input Stage -==================== +============================== .. figure:: ../../../../svg/hw/rev_0_3/Input_Stage.svg :alt: Input Stage + :align: center Input stage @@ -58,20 +60,22 @@ D1 Rectifies the DCC square-wave into +V, the amplitude is not critical as long The MOSFET on the right effectively translates the rather high DCC voltage to a suitable level for the microcontroller to process. When Q1 is turned off GPIO21 is pulled high by the RP2040 internal pull-up resistor, as soon as Q1 gets turned on (V\ :sub:`GS`\ > V\ :sub:`GS,th`\), GPIO21 gets pulled to GND potential. R1 and R2 ensure that V\ :sub:`GS`\ doesn't exceed ±20V. Motor Driver -==================== +============================== .. figure:: ../../../../svg/hw/rev_0_3/Motor_Driver.svg :alt: Motor Driver + :align: center Motor driver The Motor Driver is a special H-Bridge IC that is made for DC motors. To control the motor, it is necessary to measure the back-EMF voltage, which is directly related to the motor's speed. This is done by the ADC, which measures at Points ADC_EMF_A and ADC_EMF_B. The two resistors work together as a voltage divider. Auxiliary Outputs -==================== +============================== .. figure:: ../../../../svg/hw/rev_0_3/Aux_Outputs.svg :alt: Auxiliary Outputs + :align: center Auxiliary Outputs @@ -79,31 +83,33 @@ Switching of loads can be done using four N-Channel MOSFETs (Q2 to Q5). The amou GPIO -==================== +============================== To switch lighter loads, six GPIO soldering pads are connected to GPIO0 to GPIO5 pins. Although not yet set up in the software, they could be used as inputs as well (e.g. reed switch). GPIO0 and GPIO1 can also be used to facilitate stdio logging via UART, which can easily be set up in CMakeLists.txt. Microcontroller -==================== +============================== .. figure:: ../../../../svg/hw/rev_0_3/Microcontroller.svg :alt: Microcontroller + :align: center Microcontroller, flash memory, crystal oscillator, ... The Microcontroller needs a crystal oscillator for its clock. External flash memory holds the configuration variables and the program itself. R3 & C14 are used to filter ADC_AVDD (ADC Reference Voltage). Complete Schematic -==================== +============================== .. figure:: ../../../../svg/hw/rev_0_3/RP2040-Decoder.svg :alt: Complete Schematic + :align: center Complete Schematic BOM & Alternative Parts -==================== +============================== .. table:: BOM :widths: auto @@ -142,14 +148,16 @@ Alternative for HT7533S: .. _wiring_rev_0_3: + Wiring the Decoder -==================== +============================== .. figure:: ../../../../svg/hw/rev_0_3/Wiring_diagram.svg - :width: 700 - :alt: Wiring Diagram + :align: center + :width: 700 + :alt: Wiring Diagram - Wiring Diagram + Wiring Diagram The illustration above provides an example of a wiring configuration. It supports the connection of up to 4 transistor-switched outputs and 6 GPIOs for lighter loads or custom applications. diff --git a/sphinx/html/_sources/hardware/rev_1_0/hw_description.rst.txt b/sphinx/html/_sources/hardware/rev_1_0/hw_description.rst.txt index dc039ef..2bf67a9 100644 --- a/sphinx/html/_sources/hardware/rev_1_0/hw_description.rst.txt +++ b/sphinx/html/_sources/hardware/rev_1_0/hw_description.rst.txt @@ -1,7 +1,8 @@ Overview -==================== +============================== .. figure:: ../../../../svg/hw/rev_1_0/Block_Diagram_Hardware.svg + :align: center :alt: Block Diagram Harware block diagram @@ -23,7 +24,7 @@ The above block diagram gives a general overview regarding the operation of comp - USB Connector Electrical Characteristics -==================== +============================== .. table:: Electrical Characteristics & Absolute Maximum Ratings :widths: auto @@ -49,9 +50,10 @@ Electrical Characteristics (3): T\ :sub:`Case`\ = 25°C, keep power dissipation, thermal resistance the corresponding temperature rise ΔT and switching losses in PWM mode in mind! Input Stage -==================== +============================== .. figure:: ../../../../svg/hw/rev_1_0/Input_Stage.svg + :align: center :alt: Input Stage Input stage @@ -60,9 +62,10 @@ D2 Rectifies the DCC square-wave into VDC, the amplitude is not critical as long The MOSFET on the right effectively translates the rather high DCC voltage to a suitable level for the microcontroller to process. When Q1 is turned off GPIO21 is pulled high by the RP2040 internal pull-up resistor, as soon as Q1 gets turned on (V\ :sub:`GS`\ > V\ :sub:`GS,th`\), GPIO21 gets pulled to GND potential. R1 and R2 ensure that V\ :sub:`GS`\ doesn't exceed ±12V. Motor Driver -==================== +============================== .. figure:: ../../../../svg/hw/rev_1_0/Motor_Driver.svg + :align: center :alt: Motor Driver Motor driver @@ -70,9 +73,10 @@ Motor Driver The Motor Driver is a special H-Bridge IC that is made for DC motors. To control the motor, it is necessary to measure the back-EMF voltage, which is directly related to the motor's speed. This is done by the ADC, which measures at Points ADC_EMF_A and ADC_EMF_B. The two resistors work together as a voltage divider. Auxiliary Outputs -==================== +============================== .. figure:: ../../../../svg/hw/rev_1_0/Aux_Outputs.svg + :align: center :alt: Auxiliary Outputs Auxiliary Outputs @@ -80,14 +84,15 @@ Auxiliary Outputs Switching of loads can be done using four N-Channel MOSFETs (Q2 to Q5). The amount of current is somewhat dependend on either static R\ :sub:`DS(on)`\ losses and/or switching losses using PWM. They are switching on the low-side, which means the load effectively gets connected to GND potential as the transistor starts to conduct. GPIO24 - GPIO27 are used. GPIO -==================== +============================== To switch lighter loads, six GPIO soldering pads are connected to GPIO0 to GPIO5 pins. Although not yet set up in the software, they could be used as inputs as well (e.g. reed switch). GPIO0 and GPIO1 can also be used to facilitate stdio logging via UART, which can easily be set up in CMakeLists.txt. Microcontroller -==================== +============================== .. figure:: ../../../../svg/hw/rev_1_0/Microcontroller.svg + :align: center :alt: Microcontroller Microcontroller, flash memory, crystal oscillator, USB connector, ... @@ -95,15 +100,16 @@ Microcontroller The Microcontroller needs a crystal oscillator for its clock. External flash memory holds the configuration variables and the program itself. The USB connector can be used to flash the software onto the decoder and also for logging via stdio (can be enabled via CMakeLists.txt). D3 is used as a status LED. R11 & C13 are used to filter ADC_AVDD (ADC Reference Voltage). Complete Schematic -==================== +============================== .. figure:: ../../../../svg/hw/rev_1_0/RP2040-Decoder.svg + :align: center :alt: Complete Schematic Complete Schematic BOM & Alternative Parts -==================== +============================== .. table:: BOM :widths: auto @@ -142,12 +148,14 @@ Alternative for HT7533S: .. _wiring_rev_1_0: + Wiring the Decoder -==================== +============================== .. figure:: ../../../../svg/hw/rev_1_0/Wiring_diagram.svg :width: 700 :alt: Wiring Diagram + :align: center Wiring Diagram diff --git a/sphinx/html/_sources/index.rst.txt b/sphinx/html/_sources/index.rst.txt index 1c9a751..3447a3d 100644 --- a/sphinx/html/_sources/index.rst.txt +++ b/sphinx/html/_sources/index.rst.txt @@ -15,4 +15,3 @@ RP2040-Decoder Documentation software/index other/index other/troubleshooting - other/debugging \ No newline at end of file diff --git a/sphinx/html/_sources/other/getting_started.rst.txt b/sphinx/html/_sources/other/getting_started.rst.txt index 7175ebb..abcd068 100644 --- a/sphinx/html/_sources/other/getting_started.rst.txt +++ b/sphinx/html/_sources/other/getting_started.rst.txt @@ -1,20 +1,21 @@ Getting started -=============== +================================== 1. Where to get the board? --------------------------- +---------------------------------- You can choose any PCB manufacturer you like.The PCB is designed to fit with JLCPCB.com's capabilities and constraints.You can assemble the board yourself, but it's best not to do so if you're not familiar with soldering small components. Alternatively, you can order the board fully or partly assembled.Soldering the back of the PCB by hand is not too difficult. All parts are normally available at LCSC.com, who supply parts to JLCPCB.com. 2. Production files? ---------------------- +---------------------------------- In order to export the production files (Gerber/BOM/Pick and Place), you need `KiCad `_ which is open source. In case you are ordering from JLCPCB it is recommended to use the `Fabrication-Toolkit KiCad plugin by bennymeg `_ .. _building_the_software: + 3. Building the software ------------------------- +---------------------------------- If you got a RP2040-Decoder with USB the easiest way to get the RP2040-Decoder up and running is to just use the precompiled .uf2 file and ignore the rest of this section. @@ -22,8 +23,10 @@ However sometimes you might want to build by yourself, be it for debugging or to The easiest way to do this is to just use `Visual Studio Code `_ and the Raspberry Pi Pico extension. The `official documentation `_ of the Pi Pico does a great job of explaining this in detail. +Note: If you are building for Hardware Rev 0.3 or below change the board defintion in your CMakeLists.txt file to: "RP2040-Decoder-board-legacy.h" + 4. Flashing the software ------------------------- +---------------------------------- For RP2040-Decoders with USB there is two ways of flashing the software: @@ -37,21 +40,21 @@ For RP2040-Decoders with USB there is two ways of flashing the software: For RP2040-Decoders without USB the only way of flashing the software is via SWD 4.1. Flashing the software via .uf2 file -^^^^^^^^^^^^^^^^^^^^^^^^ +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ When first plugged in the RP2040 boots into Mass Storage Device mode. To flash the software, you need to drag the '.uf2' file onto the disk using any file explorer. This will write the file to the Flash and restart the RP2040. In case you want to repeat the flasing process, temporarily connect the solder bridge called JP1 on the back side of the board and power cycle the device. This procedure is also described in the `Raspberry Pi Pico Datasheet Chapter 4.1 `_ 4.2. Flashing the software via SWD -^^^^^^^^^^^^^^^^^^^^^^^^ +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Flashing via SWD is a little more complicated but also comes with great advantages in terms of debugging. The book on `Getting started with Raspberry Pi Pico-series `_ does a great job of explaining how debugging works. As already suggested in :ref:`3. ` it is recommended to use the `Visual Studio Code Extension `_. Most relevant in the book are `Chapter 4.3. Debug `_ and `Appendix A: Debugprobe `_ 5. Wiring ---------- +---------------------------------- | Please refer to the hardware section for your board: | :ref:`Wiring Rev 1.0 ` diff --git a/sphinx/html/_sources/software/header_files.rst.txt b/sphinx/html/_sources/software/header_files.rst.txt index a8cf886..64b3b57 100644 --- a/sphinx/html/_sources/software/header_files.rst.txt +++ b/sphinx/html/_sources/software/header_files.rst.txt @@ -2,27 +2,27 @@ Header files ================= core0.h -------- +-------------- .. doxygenfile:: core0.h :project: RP2040-Decoder core1.h -------- +-------------- .. doxygenfile:: core1.h :project: RP2040-Decoder shared.h -------- +-------------- .. doxygenfile:: shared.h :project: RP2040-Decoder CV.h -------- +-------------- .. doxygenfile:: CV.h :project: RP2040-Decoder diff --git a/sphinx/html/_sources/software/sw_description.md.txt b/sphinx/html/_sources/software/sw_description.md.txt deleted file mode 100644 index 6e243ea..0000000 --- a/sphinx/html/_sources/software/sw_description.md.txt +++ /dev/null @@ -1,82 +0,0 @@ -# Software Description - -## Overview - -The Software is structured as follows: -* Core0.c - - DCC package detection & decoding - - Programming mode (Modify and read CVs on programming track) - - ADC-Offset measurement - - Feed-forward base PWM measurement - -* Core1.c - - PID motor controller -* CV.h - - Default configuration variables - -Conveniently The Raspberry Pi Foundation provides a well documented [SDK](https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-c-sdk.pdf) for the RP2040. The SDK provides abstraction to a higher level and therefore there is no need to access any registers directly. Everything is written using the SDK so hopefully the code is easier to understand. In the following, the motor control and the decoding of the DCC signals will be explained. - -## Motor control overview - -![Block Diagram](https://github.com/1nct/RP2040-Decoder/blob/main/docs/svg/Block_Diagram_Control.svg) -*** -**Block diagram - Motor control** - -The above block diagram in essence describes the functionality of the control loop. 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 is corresponding to the speed_helper() function which delays changing the setpoint according to the configured deceleration/acceleration rates. - - -## PID Controller - -![PID Controller](https://github.com/gab-k/RP2040-Decoder/blob/main/docs/svg/Block_Diagram_PID.svg) - -The block diagram above shows the PID controller in the s-domain. The derivative part contains an additional digital low pass filter used to filter out high-frequency noise. - -Output = E * (KP + KI/s + (KD*s)/(sτ+1)) = P + I + D - -* P = E * KP -* I = E * KI/s -* D = E * (KD*s)/(sτ+1) - -The continuous-time system representation can now be transformed into a discrete-time representation using [bilinear transform](https://en.wikipedia.org/wiki/Bilinear_transform) [ s = 2*(z-1) / Ts*(z+1) ]. - -This results in the following difference equations which are then implemented in software: - -* pn = KP * en -* in = 0.5KI * (en + en-1) + in-1 -* dn = [ 2KD * (en - en-1) + (2τ - Ts) * dn-1 ] / [ 2τ + Ts] - -=> outputn = pn + in + dn - -Also note that instead of using derivative of error, derivative on measurement is used. This is done to prevent a high derivative part in the event of a large change in setpoint. - -### Gain scheduling - -![K_P](https://github.com/gab-k/RP2040-Decoder/blob/main/docs/svg/adaptive_kp.svg) - -Another aspect to consider is the implementation of [gain scheduling](https://en.wikipedia.org/wiki/Gain_scheduling). KP is a function of the current setpoint. Often it is favorable to have a higher proportional gain KP for slow speeds, achieving better control results. The illustration above shows the default setting for KP. CV_54 & CV_55 are used to set KP @ x0, CV_56 & CV_57 for KP @ x1 and CV_58 & CV_59 for KP @ x2. Additionally CV_60 is used to shift x1 from the leftmost point (0% = 0/255) to the rightmost point (100% = 255/255). - -### Feed-forward - -![Feed-forward](https://github.com/gab-k/RP2040-Decoder/blob/main/docs/svg/feed_forward.svg) -To achieve better control [Feed-forward](https://en.wikipedia.org/wiki/Feed_forward_(control)) is used. On startup the decoder will check for a configuration regarding Feed-forward control - when no configuration is found the decoder automatically runs a calibration to establish a base pwm level (y1) for both directions. The base pwm level (y1) will vary depending on load, motor and voltage on the tracks and can be configured with CV_176 - CV_179. If the setpoint is greater than the threshold, y2 is corrected automatically when in reaches 0.5imin or 0.5imax. CV_47 can be used to set how sensitive this correction is. - -### Back-EMF voltage measurement - -To provide a feedback signal which is 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 are being 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 - -The detection of the DCC signal works by looking at every rising and falling edge and calculating the time between them. When the time between rising and falling edge is greater than 87μs then this is equivalent to "0", else "1" - This value then gets shifted into a 64-Bit variable. - -Decoding is done after every falling edge. It starts with an error detection which when not passed will dismiss the received command. Then the address will be decoded and compared to the address stored in the configuration. If the address matches the command/instruction will be decoded. - -Only a few instructions are currently implemented, only 128 speed step instructions are supported. - -**Implemented instructions:** -* 0011-1111 - (128 Speed Step Control) - 2 Byte length -* 10XX-XXXX - (Function Group Instruction) (F0 - F12) -* 110X-XXXX - Expansion Instruction (F13 - F31) - -All DCC instructions can be found in Section 9.2, 9.2.1 and 9.2.1.1 of the [NMRA Communications Standard ](https://www.nmra.org/index-nmra-standards-and-recommended-practices) - - diff --git a/sphinx/html/_sources/software/sw_description.rst.txt b/sphinx/html/_sources/software/sw_description.rst.txt new file mode 100644 index 0000000..ea8e113 --- /dev/null +++ b/sphinx/html/_sources/software/sw_description.rst.txt @@ -0,0 +1,151 @@ +Software Description +============================== + +Overview +------------------------------ + +Software files high level overview: + +- **core0.c / core0.h** + + - DCC package detection & decoding + - Programming mode (Modify and read CVs on programming track) + - ADC-Offset measurement + +- **core1.c / core0.h** + + - PID motor controller + - Back-EMF voltage measurement + +- **shared.c / shared.h** (used by both cores) + +- Error handling +- Helper functions for retrieving CV's + +- **CV.h** + +- Default configuration variables + +- **CMakeLists.txt** + + - CMake version, SDK version, C standard version + - Board definitions + - Compile/Build options + - Sources files, header files + - Debug logging configuration (via stdio using UART/USB) + - Linked libraries + +- **RP2040-Decoder-board.h or RP2040-Decoder-board-legacy.h** + + - Flash Size + - Pin specification + + - LED pin when available + - UART_TX/UART_RX when used + - DCC input pin + - Motor Control PWM pins + - ADC pins + + + + +Conveniently, The Raspberry Pi Foundation provides a well-documented `SDK `_ for the RP2040. The SDK provides abstraction to a higher level, and therefore there is no need to access any registers directly. Everything is written using the SDK, so hopefully, the code is easier to understand. + +Motor control +------------------------------ + +.. figure:: ../../../svg/sw/Block_Diagram_Control.svg + :alt: Block Diagram + :align: center + + Motor control - Block diagram + +The above block diagram in essence describes the functionality of the control loop. While the central component is the PID controller, there is an additional block called `Feed-forward `_ 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. + +PID Controller +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. figure:: ../../../svg/sw/Block_Diagram_PID.svg + :alt: PID Controller figure + :align: center + + PID Controller + +The block diagram above shows the PID controller in the s-domain. The derivative part contains an additional digital low-pass filter used to filter out high-frequency noise. + +.. math:: + + \begin{align} + \text{Output} &= E \cdot \left(K_P + \frac{K_I}{s} + \frac{K_D \cdot s}{s \tau + 1}\right) = P + I + D \\ + P &= E \cdot K_P \\ + I &= E \cdot \frac{K_I}{s} \\ + D &= E \cdot \frac{K_D \cdot s}{s \tau + 1} + \end{align} + +With :math:`T_s` being the sampling time / controller update rate / time step of the discrete system. +And :math:`\tau` being the filter time constant of the digital filter + +The continuous-time system representation can now be transformed into a discrete-time representation using `bilinear transform `_ :math:`s = \frac{2 \cdot (z - 1)}{T_s \cdot (z + 1)}`. + +This results in the following difference equations which are then implemented in software: + +.. math:: + + \begin{align} + p_n &= K_P \cdot e_n \\ + i_n &= 0.5 \cdot K_I \cdot \left(e_n + e_{n-1}\right) + i_{n-1} \\ + d_n &= \frac{2 K_D \cdot \left(e_n - e_{n-1}\right) + \left(2 \tau - T_s\right) \cdot d_{n-1}}{2 \tau + T_s} \\ + \text{output}_n &= p_n + i_n + d_n + \end{align} + + +Also note that instead of using the derivative of error, the derivative on measurement is used. This is done to prevent a high derivative part in the event of a large change in setpoint. + + +Gain Scheduling +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. figure:: ../../../svg/sw/adaptive_kp.svg + :alt: Gain Scheduling figure + :align: center + + Gain Scheduling + +Another aspect to consider is the implementation of `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). + +Feed-forward +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +.. figure:: ../../../svg/sw/feed_forward.svg + :alt: Feed forward figure + :align: center + + Feed-forward + + +TODO: Update this part: + +To achieve better control, `Feed-forward `_ is used. On startup, the decoder will check for a configuration regarding Feed-forward control. When no configuration is found, the decoder automatically runs a calibration to establish a base PWM level (y\ :sub:`1`) for both directions. The base PWM level (y\ :sub:`1`) will vary depending on load, motor, and voltage on the tracks and can be configured with CV_176 - CV_179. If the setpoint is greater than the threshold, y\ :sub:`2` is corrected automatically when i\ :sub:`n` reaches 0.5i\ :sub:`min` or 0.5i\ :sub:`max`. CV_47 can be used to set how sensitive this correction is. + +Back-EMF voltage measurement +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +To provide a feedback signal proportional to the motor speed, the ADC is used to measure the `Back-EMF voltage `_. 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%. + +DCC signal decoding +------------------------------ + +The detection of the DCC signal works by looking at every rising and falling edge and calculating the time between them. When the time between rising and falling edge is greater than 87μs, then this is equivalent to "0"; otherwise, "1". This value then gets shifted into a 64-Bit variable. + +Decoding is done after every falling edge. It starts with an error detection, which, when not passed, dismisses the received command. Then the address will be decoded and compared to the address stored in the configuration. If the address matches, the command/instruction will be decoded. + +Only a few instructions are currently implemented; only 128 speed step instructions are supported. + +**Implemented instructions:** + +- ``0011-1111`` - (128 Speed Step Control) - 2 Byte length +- ``10XX-XXXX`` - (Function Group Instruction) (F0 - F12) +- ``110X-XXXX`` - Expansion Instruction (F13 - F31) + +All DCC instructions can be found in Section 9.2, 9.2.1, and 9.2.1.1 of the `NMRA Communications Standard `_. diff --git a/sphinx/html/hardware/rev_0_3/hw_description.html b/sphinx/html/hardware/rev_0_3/hw_description.html index b5c6bda..2c73350 100644 --- a/sphinx/html/hardware/rev_0_3/hw_description.html +++ b/sphinx/html/hardware/rev_0_3/hw_description.html @@ -102,7 +102,7 @@

Overview

-
+
Block Diagram

Harware block diagram

@@ -207,7 +207,7 @@

Input Stage

-
+
Input Stage

Input stage

@@ -218,7 +218,7 @@

Motor Driver

-
+
Motor Driver

Motor driver

@@ -228,7 +228,7 @@

Auxiliary Outputs

-
+
Auxiliary Outputs

Auxiliary Outputs

@@ -242,7 +242,7 @@

Microcontroller

-
+
Microcontroller

Microcontroller, flash memory, crystal oscillator, …

@@ -252,7 +252,7 @@

Complete Schematic

-
+
Complete Schematic

Complete Schematic

@@ -383,7 +383,7 @@

Wiring the Decoder

-
+
Wiring Diagram
diff --git a/sphinx/html/hardware/rev_1_0/hw_description.html b/sphinx/html/hardware/rev_1_0/hw_description.html index 27f634f..c0e1043 100644 --- a/sphinx/html/hardware/rev_1_0/hw_description.html +++ b/sphinx/html/hardware/rev_1_0/hw_description.html @@ -101,7 +101,7 @@

Overview

-
+
Block Diagram

Harware block diagram

@@ -208,7 +208,7 @@

Input Stage

-
+
Input Stage

Input stage

@@ -217,8 +217,8 @@

D2 Rectifies the DCC square-wave into VDC, the amplitude is not critical as long as it’s within the 25V limit. The rectified voltage VDC is then provided to the 3.3V voltage regulator and to the motor driver. The shottky diode D1 and the bridge rectifier D2 ensure a logical “or” linkage of the VBUS supply voltages and the DCC input voltage

The MOSFET on the right effectively translates the rather high DCC voltage to a suitable level for the microcontroller to process. When Q1 is turned off GPIO21 is pulled high by the RP2040 internal pull-up resistor, as soon as Q1 gets turned on (VGS> VGS,th), GPIO21 gets pulled to GND potential. R1 and R2 ensure that VGSdoesn’t exceed ±12V. Motor Driver -====================

-
+==============================

+
Motor Driver

Motor driver

@@ -228,7 +228,7 @@ Motor Driver

Auxiliary Outputs

-
+
Auxiliary Outputs

Auxiliary Outputs

@@ -242,7 +242,7 @@ Motor Driver

Microcontroller

-
+
Microcontroller

Microcontroller, flash memory, crystal oscillator, USB connector, …

@@ -252,7 +252,7 @@ Motor Driver

Complete Schematic

-
+
Complete Schematic

Complete Schematic

@@ -383,7 +383,7 @@ Motor Driver

Wiring the Decoder

-
+
Wiring Diagram
diff --git a/sphinx/html/index.html b/sphinx/html/index.html index 7b14592..bc7362e 100644 --- a/sphinx/html/index.html +++ b/sphinx/html/index.html @@ -18,6 +18,7 @@ + diff --git a/sphinx/html/other/getting_started.html b/sphinx/html/other/getting_started.html index ca3783a..f0785bf 100644 --- a/sphinx/html/other/getting_started.html +++ b/sphinx/html/other/getting_started.html @@ -108,6 +108,7 @@ In case you are ordering from JLCPCB it is recommended to use the Visual Studio Code and the Raspberry Pi Pico extension. The official documentation of the Pi Pico does a great job of explaining this in detail.

+

Note: If you are building for Hardware Rev 0.3 or below change the board defintion in your CMakeLists.txt file to: “RP2040-Decoder-board-legacy.h”

4. Flashing the software

diff --git a/sphinx/html/searchindex.js b/sphinx/html/searchindex.js index f4684ad..a9d758f 100644 --- a/sphinx/html/searchindex.js +++ b/sphinx/html/searchindex.js @@ -1 +1 @@ -Search.setIndex({"alltitles": {"1. Where to get the board?": [[5, "where-to-get-the-board"]], "2. Production files?": [[5, "production-files"]], "3. Building the software": [[5, "building-the-software"]], "4. Flashing the software": [[5, "flashing-the-software"]], "4.1. Flashing the software via .uf2 file": [[5, "flashing-the-software-via-uf2-file"]], "4.2. Flashing the software via SWD": [[5, "flashing-the-software-via-swd"]], "5. Wiring": [[5, "wiring"]], "6. Resolving issues": [[5, "resolving-issues"]], "Alternative for HT7533S:": [[1, "alternative-for-ht7533s"], [2, "alternative-for-ht7533s"]], "Alternatives for BDR6133:": [[1, "alternatives-for-bdr6133"], [2, "alternatives-for-bdr6133"]], "Auxiliary Outputs": [[1, "auxiliary-outputs"], [2, "auxiliary-outputs"]], "BOM": [[1, "id8"], [2, "id8"]], "BOM & Alternative Parts": [[1, "bom-alternative-parts"], [2, "bom-alternative-parts"]], "Back-EMF voltage measurement": [[10, "back-emf-voltage-measurement"]], "CV List": [[4, "cv-list"]], "CV.h": [[8, "cv-h"]], "CV_1 - Basic address": [[4, "cv-1-basic-address"]], "CV_11 - Packet timeout": [[4, "cv-11-packet-timeout"]], "CV_112, CV_113, CV_114, CV_115 - GPIO PWM Configuration": [[4, "cv-112-cv-113-cv-114-cv-115-gpio-pwm-configuration"]], "CV_116 to CV_171 - PWM Slice configuration": [[4, "cv-116-to-cv-171-pwm-slice-configuration"]], "CV_12 - Permitted operating modes": [[4, "cv-12-permitted-operating-modes"]], "CV_17 & CV_18 - 14-Bit extended/long address": [[4, "cv-17-cv-18-14-bit-extended-long-address"]], "CV_172 - ADC Offset": [[4, "cv-172-adc-offset"]], "CV_173 - ADC offset measurement cycles": [[4, "cv-173-adc-offset-measurement-cycles"]], "CV_174 - Additional motor-PWM clock divider.": [[4, "cv-174-additional-motor-pwm-clock-divider"]], "CV_175 - speed_helper timer delay": [[4, "cv-175-speed-helper-timer-delay"]], "CV_176, CV_177, CV_178, CV_179 - Base PWM Level used in feed-forward control": [[4, "cv-176-cv-177-cv-178-cv-179-base-pwm-level-used-in-feed-forward-control"]], "CV_2 - V_min": [[4, "cv-2-v-min"]], "CV_257 to CV_512 - Function Mapping CVs": [[4, "cv-257-to-cv-512-function-mapping-cvs"]], "CV_29 - Decoder Configuration": [[4, "cv-29-decoder-configuration"]], "CV_3 - Acceleration rate": [[4, "cv-3-acceleration-rate"]], "CV_31 & CV_32 - Extended CV pointer (Read-Only)": [[4, "cv-31-cv-32-extended-cv-pointer-read-only"]], "CV_4 - Deceleration rate": [[4, "cv-4-deceleration-rate"]], "CV_47 - Feed-forward gain k_ff": [[4, "cv-47-feed-forward-gain-k-ff"]], "CV_48 - Filter time constant (tau) in ms": [[4, "cv-48-filter-time-constant-tau-in-ms"]], "CV_49 - PID Control sampling time t in ms": [[4, "cv-49-pid-control-sampling-time-t-in-ms"]], "CV_5 - V_max": [[4, "cv-5-v-max"]], "CV_50 - PID Control I Factor": [[4, "cv-50-pid-control-i-factor"]], "CV_51 - PID Control D Factor": [[4, "cv-51-pid-control-d-factor"]], "CV_52 & CV_53 - PID Integral Limits": [[4, "cv-52-cv-53-pid-integral-limits"]], "CV_54 & CV_55 - Gain scheduling config k_p @ x0": [[4, "cv-54-cv-55-gain-scheduling-config-k-p-x0"]], "CV_56 & CV_57 - Gain scheduling config k_p @ x1": [[4, "cv-56-cv-57-gain-scheduling-config-k-p-x1"]], "CV_58 & CV_59 - Gain scheduling config k_p @ x2": [[4, "cv-58-cv-59-gain-scheduling-config-k-p-x2"]], "CV_6 - V_mid": [[4, "cv-6-v-mid"]], "CV_60 - Gain scheduling config x1 shift percentage": [[4, "cv-60-gain-scheduling-config-x1-shift-percentage"]], "CV_61 - Measurement Iterations": [[4, "cv-61-measurement-iterations"]], "CV_62 - Measurement Delay": [[4, "cv-62-measurement-delay"]], "CV_63 & CV_64 - Measurement array cutoffs": [[4, "cv-63-cv-64-measurement-array-cutoffs"]], "CV_65 - New flash variable": [[4, "cv-65-new-flash-variable"]], "CV_7 - Version No. (Read-Only)": [[4, "cv-7-version-no-read-only"]], "CV_8 - Manufacturer (Read-Only)": [[4, "cv-8-manufacturer-read-only"]], "CV_9 - Motor PWM Frequency": [[4, "cv-9-motor-pwm-frequency"]], "Complete Schematic": [[1, "complete-schematic"], [2, "complete-schematic"]], "Configuration Variables (CV)": [[4, null]], "Contents:": [[3, null], [6, null], [9, null]], "DCC signal decoding": [[10, "dcc-signal-decoding"]], "Electrical Characteristics": [[1, "electrical-characteristics"], [2, "electrical-characteristics"]], "Electrical Characteristics & Absolute Maximum Ratings": [[1, "id2"], [2, "id2"]], "Feed-forward": [[10, "feed-forward"]], "GPIO": [[1, "gpio"], [2, "gpio"]], "Gain scheduling": [[10, "gain-scheduling"]], "Getting started": [[5, null]], "Hardware": [[0, null]], "Header files": [[8, null]], "Input Stage": [[1, "input-stage"], [2, "input-stage"]], "Microcontroller": [[1, "microcontroller"], [2, "microcontroller"]], "Motor Driver": [[1, "motor-driver"]], "Motor control overview": [[10, "motor-control-overview"]], "Note": [[4, "note"]], "Other": [[6, null]], "Overview": [[1, null], [2, null], [10, "overview"]], "PID Controller": [[10, "pid-controller"]], "RP2040-Decoder Documentation": [[3, null]], "Revision 0.3": [[0, "revision-0-3"]], "Revision 1.0": [[0, "revision-1-0"]], "Software": [[9, null]], "Software Description": [[10, null]], "Speed step configuration": [[4, "speed-step-configuration"]], "Troubleshooting": [[7, null]], "Wiring the Decoder": [[1, "wiring-the-decoder"], [2, "wiring-the-decoder"]], "core0.h": [[8, "core0-h"]], "core1.h": [[8, "core1-h"]], "shared.h": [[8, "shared-h"]]}, "docnames": ["hardware/index", "hardware/rev_0_3/hw_description", "hardware/rev_1_0/hw_description", "index", "other/CV_list", "other/getting_started", "other/index", "other/troubleshooting", "software/header_files", "software/index", "software/sw_description"], "envversion": {"sphinx": 64, "sphinx.domains.c": 3, "sphinx.domains.changeset": 1, "sphinx.domains.citation": 1, "sphinx.domains.cpp": 9, "sphinx.domains.index": 1, "sphinx.domains.javascript": 3, "sphinx.domains.math": 2, "sphinx.domains.python": 4, "sphinx.domains.rst": 2, "sphinx.domains.std": 2}, "filenames": ["hardware/index.rst", "hardware/rev_0_3/hw_description.rst", "hardware/rev_1_0/hw_description.rst", "index.rst", "other/CV_list.md", "other/getting_started.rst", "other/index.rst", "other/troubleshooting.md", "software/header_files.rst", "software/index.rst", "software/sw_description.md"], "indexentries": {}, "objects": {}, "objnames": {}, "objtypes": {}, "terms": {"": [1, 2, 5, 10], "0": [1, 2, 3, 4, 5, 7, 10], "0011": 10, "0603_1608metric": [1, 2], "0xff": 4, "1": [1, 2, 3, 4, 10], "10": [1, 2, 4], "100": [4, 10], "10000": 4, "1001": 4, "100111000100": 4, "100n": [1, 2], "100u": 10, "10khz": 4, "10u": [1, 2], "10v": 7, "10xx": 10, "110000": 4, "11000011010011": 4, "11000100": 4, "11010011": 4, "110x": 10, "1111": 10, "1249": 4, "12499": 4, "125": 4, "12500": 4, "126": 4, "128": 10, "12mhz": [1, 2], "12v": 2, "13": 4, "145": [1, 2], "155": [1, 2], "16": 4, "16bit": 4, "16v": 7, "192": 4, "1ep_7x7mm_p0": [1, 2], "1k": [1, 2], "2": [1, 2, 3, 4, 10], "20": 4, "200": [1, 2], "20v": [1, 7], "23": [1, 2], "231": 4, "24": [1, 2], "25": 2, "250": 4, "2500": 4, "255": [4, 10], "25v": [1, 2], "269aa": [1, 2], "2a": [1, 2], "2k": 10, "2x2": [1, 2], "2\u00b5": 10, "2\u03c4": 10, "3": [1, 2, 3, 4, 7], "32": 4, "33p": [1, 2], "33tr3": [1, 2], "35m": 10, "3m": 10, "3v": [1, 2, 7], "3v3": 7, "4": [1, 2, 3, 4], "400": 1, "40v": [1, 2], "4a": [1, 2], "4mm": [1, 2], "4pin_3": [1, 2], "5": [1, 2, 3, 4], "50": [1, 2], "56": [1, 2], "5i": 10, "5k": 10, "5mm": [1, 2], "6": [1, 2, 3, 4], "60v": [1, 2], "64": [4, 10], "64mb": [1, 2], "6k8": [1, 2], "7": 4, "8": [1, 2, 4, 7], "87\u03bc": 10, "8a": [1, 2], "9": 10, "93": 10, "94": 10, "A": [1, 2, 4, 5, 10], "As": 5, "For": [1, 2, 4, 5], "If": [4, 5, 7, 10], "In": [5, 10], "It": [1, 2, 4, 10], "Not": 4, "On": 10, "TO": [1, 2], "That": 4, "The": [1, 2, 4, 5, 10], "Then": 10, "These": 4, "To": [1, 2, 4, 5, 7, 10], "about": 10, "abov": [1, 2, 4, 10], "abstract": 10, "acceler": 10, "access": 10, "accord": [1, 2, 10], "achiev": [4, 10], "adc": [1, 2, 10], "adc_avdd": [1, 2], "adc_emf_a": [1, 2], "adc_emf_b": [1, 2], "add": 10, "addit": 10, "addition": 10, "address": 10, "adjust": 4, "advantag": 5, "advis": 4, "after": 10, "afterward": 10, "algorithm": 10, "all": [4, 5, 10], "alreadi": 5, "also": [1, 2, 4, 5, 10], "altern": [0, 4, 5], "although": [1, 2], "alwai": [1, 2, 4], "am": 4, "amount": [1, 2, 4], "amplitud": [1, 2], "an": [1, 2, 4, 10], "analog": 7, "ani": [4, 5, 10], "anoth": [4, 5, 10], "appendix": 5, "applic": [1, 2], "ar": [1, 2, 4, 5, 10], "around": 7, "arrai": 10, "aspect": 10, "assembl": 5, "assum": [1, 2], "automat": [4, 10], "aux": [1, 2], "aux1": 4, "aux2": 4, "auxiliari": 0, "avail": [4, 5], "averag": 10, "b": 4, "back": [1, 2, 5], "base": [5, 10], "becaus": 7, "been": [1, 2], "begin": 4, "behavior": 4, "being": 10, "below": [1, 2, 10], "bemf": 4, "bennymeg": 5, "best": 5, "better": [1, 2, 10], "between": [4, 10], "bewar": 7, "bilinear": 10, "bin": 4, "bit": 10, "bit0": 4, "bit14": 4, "bit15": 4, "bit5": 4, "bit6": 4, "bit7": 4, "block": [1, 2, 10], "blue": 4, "board": [3, 4], "bom": [0, 5], "book": 5, "boot": 5, "both": [4, 10], "bridg": [1, 2, 5], "build": 3, "byte": [4, 10], "c": [2, 4, 10], "c1": [1, 2], "c10": [1, 2], "c11": [1, 2], "c12": [1, 2], "c13": [1, 2], "c14": [1, 2], "c15": [1, 2], "c16": [1, 2], "c17": [1, 2], "c2": [1, 2], "c3": [1, 2], "c4": [1, 2], "c5": [1, 2], "c6": [1, 2], "c7": [1, 2], "c8": [1, 2], "c9": [1, 2], "calcul": [4, 10], "calibr": [4, 10], "call": [4, 5, 10], "can": [1, 2, 4, 5, 7, 10], "cannot": 8, "capabl": 5, "capacitor": [1, 2], "case": [2, 5], "central": 10, "ceram": [1, 2], "certain": 10, "chang": [4, 10], "channel": [1, 2, 4], "chapter": [4, 5], "character": 4, "characterist": 0, "check": [4, 7, 10], "chip": 4, "choos": 5, "circuit": [1, 2], "clk_div": 4, "clock": [1, 2], "cmakelist": [1, 2], "code": [5, 10], "com": 5, "come": 5, "command": 10, "commun": 10, "compar": 10, "complet": [0, 7, 10], "complic": 5, "compon": [1, 2, 4, 5, 10], "comput": [4, 10], "condit": 4, "conduct": [1, 2], "configur": [1, 2, 3, 6, 10], "connect": [1, 2, 4, 5], "connector": 2, "consid": 10, "constraint": 5, "contain": [4, 10], "continu": 10, "control": [1, 2, 9], "conveni": 10, "copi": 5, "core0": [4, 9, 10], "core1": [9, 10], "correct": [4, 7, 10], "correspond": [2, 4, 10], "could": [1, 2, 5], "creat": 5, "critic": [1, 2], "crystal": [1, 2], "crystal_smd_3225": [1, 2], "current": [1, 2, 4, 10], "custom": [1, 2], "cv": [3, 6, 7, 9, 10], "cv8": [4, 7], "cv_144": 4, "cv_145": 4, "cv_146": 4, "cv_149": 4, "cv_150": 4, "cv_176": 10, "cv_179": 10, "cv_47": 10, "cv_54": 10, "cv_55": 10, "cv_56": 10, "cv_57": 10, "cv_58": 10, "cv_59": 10, "cv_60": 10, "cv_62": 10, "cv_63": 10, "cv_64": 10, "cv_setup_check": 4, "cycl": [5, 10], "d": [1, 2, 10], "d1": [1, 2], "d2": 2, "d3": 2, "datasheet": [1, 2, 4, 5], "dc": [1, 2], "dcc": [1, 2, 4, 9], "dd": [1, 2], "debug": 5, "debugprob": 5, "dec": 4, "deceler": 10, "decod": [0, 5, 7, 9], "default": [4, 10], "defin": 4, "delai": 10, "depend": [4, 10], "dependend": [1, 2], "deriv": [4, 10], "describ": [5, 10], "descript": [3, 9], "design": 5, "desold": 7, "detail": [4, 5, 10], "detect": 10, "determin": 4, "devic": 5, "diagram": [1, 2, 10], "differ": [1, 2, 10], "difficult": 5, "digit": [4, 10], "diod": [1, 2], "direct": [4, 10], "directli": [1, 2, 10], "disabl": 4, "discard": 4, "discret": [4, 10], "discuss": 5, "disk": 5, "dismiss": 10, "dissip": 2, "divid": [1, 2], "do": [4, 5, 7], "document": [5, 10], "doe": 5, "doesn": [1, 2, 7], "domain": [4, 10], "done": [1, 2, 4, 10], "dont": 7, "down": 7, "downstream": 4, "doxygenfil": 8, "drag": 5, "driver": [0, 2], "dropout": [1, 2], "duti": [4, 10], "e": [1, 2, 4, 10], "each": 4, "easier": 10, "easiest": 5, "easili": [1, 2], "edg": 10, "effect": [1, 2, 4, 10], "either": [1, 2, 4], "electr": 0, "element": [4, 10], "els": 10, "emerg": 4, "emf": [1, 2], "enabl": [2, 4], "ensur": [1, 2], "equat": 10, "equival": [4, 10], "error": 10, "essenc": 10, "establish": 10, "event": 10, "everi": [4, 10], "everyth": 10, "exampl": [1, 2, 4], "exce": [1, 2], "expans": 10, "expect": [5, 7], "explain": [1, 2, 5, 10], "explan": [4, 10], "explor": 5, "export": 5, "extens": 5, "extern": [1, 2], "f": [1, 2, 4], "f0": 10, "f12": 10, "f13": 10, "f31": 10, "fabric": 5, "facilit": [1, 2], "factori": 4, "fall": 10, "familiar": 5, "faster": 4, "favor": 10, "fed": 10, "feedback": 10, "few": 10, "file": [3, 9], "filter": [1, 2, 10], "find": 8, "first": 5, "fit": 5, "flase": 5, "flash": [1, 2, 3], "follow": [4, 5, 7, 10], "footprint": [1, 2], "forth": 4, "found": [4, 10], "foundat": 10, "four": [1, 2, 4], "free": [1, 2], "frequenc": 10, "from": [4, 5, 10], "fulli": 5, "function": [1, 2, 10], "furthermor": [1, 2], "g": [1, 2], "gener": [1, 2], "gerber": 5, "get": [1, 2, 3, 4, 10], "give": [1, 2], "gnd": [1, 2, 7], "got": 5, "gpio": 0, "gpio0": [1, 2], "gpio1": [1, 2], "gpio21": [1, 2], "gpio24": [1, 2], "gpio25": 4, "gpio27": [1, 2], "gpio5": [1, 2], "great": 5, "greater": 10, "green": 4, "group": 10, "gs7533": [1, 2], "h": [1, 2, 4, 9, 10], "ha": [1, 2, 4, 10], "hand": 5, "happen": 4, "hardwar": [3, 5], "harwar": [1, 2], "have": [4, 5, 10], "header": [3, 9], "headlight": 4, "helper": 10, "here": 4, "high": [1, 2, 4, 10], "higher": 10, "highest": [4, 10], "hold": [1, 2], "hopefulli": 10, "how": [4, 5, 10], "howev": 5, "hz": 4, "i": [1, 2, 5, 7, 10], "ic": [1, 2], "ignor": 5, "ih": [1, 2], "il": [1, 2], "illustr": [1, 2, 4, 10], "impact": 10, "implement": 10, "includ": [1, 2, 10], "inclus": 4, "independ": 4, "index": 4, "indic": 4, "induct": [1, 2], "init": 4, "input": 0, "insert": 10, "instead": 10, "instruct": [4, 5, 10], "interfac": 5, "intern": [1, 2], "iovdd": [1, 2], "irrelev": 4, "issu": [3, 7], "its": [1, 2], "itself": [1, 2, 5], "jlcpcb": 5, "job": 5, "jp1": 5, "just": 5, "k": 10, "keep": [1, 2], "kicad": 5, "kmb24f": [1, 2], "larg": 10, "lcsc": 5, "lead": 4, "led": 2, "left": [4, 10], "leftmost": 10, "length": 10, "level": [1, 2, 10], "lighter": [1, 2], "like": [5, 7], "limit": [1, 2], "linkag": 2, "list": 6, "littl": 5, "load": [1, 2, 10], "log": [1, 2], "logic": 2, "long": [1, 2], "look": 10, "loop": 10, "loss": [1, 2], "low": [1, 2, 4, 10], "lowest": 10, "ma": [1, 2], "made": [1, 2], "make": 5, "mani": 4, "manufactur": 5, "mass": 5, "match": 10, "max": [1, 2, 4, 10], "maximum": [4, 10], "mb": [1, 2], "mean": [1, 2, 4], "measur": [1, 2, 7], "memori": [1, 2, 7], "mention": 4, "mhz": 4, "microcontrol": 0, "mid": 4, "might": 5, "min": [4, 10], "mind": [1, 2], "minimum": [1, 2, 4], "mitig": 10, "mode": [2, 5, 10], "modif": 5, "modifi": 10, "more": [4, 5, 10], "mosfet": [1, 2], "most": 5, "motor": [0, 2, 7, 9], "n": [1, 2, 10], "name": [1, 2], "narrow": 7, "necessari": [1, 2], "need": [1, 2, 5, 10], "new": 5, "nmra": 10, "nois": 10, "normal": [4, 5], "note": [1, 2, 6, 10], "now": 10, "off": [1, 2], "offici": 5, "offset": 10, "often": 10, "one": 4, "onli": [5, 10], "onto": [2, 5], "open": 5, "oper": [1, 2], "option": 4, "order": 5, "oscil": [1, 2, 4], "other": [3, 4, 5], "otherwis": 4, "out": [1, 2, 10], "outlier": 10, "output": [0, 4, 10], "overview": [0, 9], "own": 5, "p": 10, "packag": [4, 10], "pad": [1, 2], "paramet": [1, 2, 4], "part": [0, 4, 5, 10], "partli": 5, "pass": [4, 10], "pcb": 5, "percent": 4, "period": 4, "pi": [5, 10], "pick": 5, "pico": 5, "pid": 9, "pid_control": 4, "pin": [1, 2, 7], "place": 5, "pleas": 5, "plug": 5, "plugin": 5, "point": [1, 2, 10], "posit": 4, "possibl": 10, "potenti": [1, 2, 10], "power": [2, 5, 7], "precompil": 5, "prefer": 5, "prevent": 10, "procedur": [4, 5], "process": [1, 2, 5], "product": 3, "program": [1, 2, 10], "proport": 10, "protect": [1, 2], "provid": [1, 2, 10], "pt2476": [1, 2], "pt5126a": [1, 2], "public": 4, "pull": [1, 2], "purpos": [1, 2], "pwm": [1, 2, 10], "q1": [1, 2], "q2": [1, 2], "q3": [1, 2], "q4": [1, 2], "q5": [1, 2], "qfn": [1, 2], "quantiti": [1, 2], "question": 5, "r": [1, 2], "r1": [1, 2], "r11": 2, "r2": [1, 2], "r3": [1, 2], "r5": [1, 2], "r6": [1, 2], "r7": [1, 2], "r8": [1, 2], "r9": [1, 2], "rang": [4, 7], "raspberri": [5, 10], "rate": 10, "rather": [1, 2], "re": 5, "reach": 10, "read": 10, "receiv": [4, 10], "recommend": 5, "rectifi": [1, 2], "red": 4, "reduc": 10, "reed": [1, 2], "ref": [1, 2], "refer": [1, 2, 4, 5], "regard": [1, 2, 4, 10], "regist": 10, "regul": [1, 2], "relat": [1, 2], "relev": 5, "remain": 10, "repeat": 5, "repres": 4, "represent": 10, "reset": [4, 7], "resist": 2, "resistor": [1, 2], "resolv": 3, "respect": 4, "rest": 5, "restart": 5, "result": 10, "rev": [4, 5], "revers": 4, "revis": 3, "right": [1, 2, 4, 10], "rightmost": 10, "rise": [2, 10], "rm": [1, 2], "rp2040": [1, 2, 4, 5, 10], "rp2350": 5, "run": [5, 10], "same": 4, "sampl": 10, "schemat": 0, "sdk": 10, "second": 4, "section": [5, 10], "see": 4, "sensit": 10, "seri": 5, "serial": 5, "set": [1, 2, 4, 10], "setpoint": 10, "sever": 4, "share": 9, "shift": [1, 2, 10], "short": 4, "shottki": 2, "should": [4, 7], "show": [4, 10], "si1308edl": 2, "side": [1, 2, 4, 5], "signal": [1, 2, 4, 9], "six": [1, 2], "slow": 10, "small": 5, "so": [4, 5, 10], "softwar": [1, 2, 3], "soic": [1, 2], "solder": [1, 2, 5], "sometim": 5, "somewhat": [1, 2], "somewher": 7, "soon": [1, 2], "sort": 10, "sot": [1, 2], "sourc": 5, "special": [1, 2], "speed": [1, 2, 6, 10], "speed_help": 10, "squar": [1, 2], "stage": 0, "standard": 10, "start": [1, 2, 3, 10], "startup": [4, 10], "state": 4, "static": [1, 2], "statu": [2, 4], "stdio": [1, 2], "step": [6, 10], "still": [4, 5], "stop": 4, "storag": 5, "store": 10, "structur": 10, "studio": 5, "subdivid": [1, 2], "suggest": 5, "suitabl": [1, 2], "suppli": [2, 5, 7], "support": [1, 2, 4, 5, 10], "switch": [1, 2, 4], "symbol": [1, 2], "system": 10, "s\u03c4": 10, "t": [1, 2, 7, 10], "t2n7002bk": [1, 2], "take": 10, "temperatur": 2, "temporarili": 5, "term": 5, "th": [1, 2], "than": 10, "thei": [1, 2], "them": [4, 10], "therefor": [4, 10], "thermal": 2, "thi": [1, 2, 4, 5, 7, 10], "threshold": 10, "time": 10, "togeth": [1, 2], "too": [4, 5], "toolkit": 5, "total": [1, 2, 4], "tp": [1, 2], "track": [7, 10], "transform": 10, "transistor": [1, 2], "translat": [1, 2], "travel": 4, "trigger": 4, "troubl": 5, "troubleshoot": [3, 5, 6], "try": 7, "turn": [1, 2], "two": [1, 2, 4, 5], "txt": [1, 2], "type": [1, 2], "u1": [1, 2], "u2": [1, 2], "u3": [1, 2], "u4": [1, 2], "uart": [1, 2], "understand": 10, "unit": [1, 2], "up": [1, 2, 5], "us": [1, 2, 5, 10], "usb": [2, 5], "usual": 4, "v": [1, 2, 7], "valid": 4, "valu": [1, 2, 4, 7, 10], "vari": 10, "variabl": [1, 2, 3, 6, 10], "vbu": 2, "vdc": 2, "via": [1, 2], "visual": 5, "voltag": [1, 2, 4, 7], "w25q64jvssiq": [1, 2], "wai": 5, "wait": 10, "want": 5, "wave": [1, 2], "well": [1, 2, 10], "wheel": [1, 2], "when": [1, 2, 4, 5, 7, 10], "where": 3, "which": [1, 2, 4, 5, 10], "while": [4, 10], "who": 5, "wire": [0, 3, 7], "within": [1, 2], "without": 5, "work": [1, 2, 4, 5, 7, 10], "would": 4, "wrap": 4, "write": [4, 5, 7], "written": [4, 10], "x": [4, 10], "x322512msb4si": [1, 2], "xxxx": 10, "y": 10, "y1": [1, 2, 4], "y2": 4, "yet": [1, 2], "you": [4, 5, 7], "your": [4, 5, 7], "yourself": [4, 5], "z": 10, "\u03b4t": 2}, "titles": ["Hardware", "Overview", "Overview", "RP2040-Decoder Documentation", "Configuration Variables (CV)", "Getting started", "Other", "Troubleshooting", "Header files", "Software", "Software Description"], "titleterms": {"0": 0, "1": [0, 5], "14": 4, "2": 5, "3": [0, 5], "4": 5, "5": 5, "6": 5, "No": 4, "absolut": [1, 2], "acceler": 4, "adc": 4, "addit": 4, "address": 4, "altern": [1, 2], "arrai": 4, "auxiliari": [1, 2], "back": 10, "base": 4, "basic": 4, "bdr6133": [1, 2], "bit": 4, "board": 5, "bom": [1, 2], "build": 5, "characterist": [1, 2], "clock": 4, "complet": [1, 2], "config": 4, "configur": 4, "constant": 4, "content": [3, 6, 9], "control": [4, 10], "core0": 8, "core1": 8, "cutoff": 4, "cv": [4, 8], "cv_1": 4, "cv_11": 4, "cv_112": 4, "cv_113": 4, "cv_114": 4, "cv_115": 4, "cv_116": 4, "cv_12": 4, "cv_17": 4, "cv_171": 4, "cv_172": 4, "cv_173": 4, "cv_174": 4, "cv_175": 4, "cv_176": 4, "cv_177": 4, "cv_178": 4, "cv_179": 4, "cv_18": 4, "cv_2": 4, "cv_257": 4, "cv_29": 4, "cv_3": 4, "cv_31": 4, "cv_32": 4, "cv_4": 4, "cv_47": 4, "cv_48": 4, "cv_49": 4, "cv_5": 4, "cv_50": 4, "cv_51": 4, "cv_512": 4, "cv_52": 4, "cv_53": 4, "cv_54": 4, "cv_55": 4, "cv_56": 4, "cv_57": 4, "cv_58": 4, "cv_59": 4, "cv_6": 4, "cv_60": 4, "cv_61": 4, "cv_62": 4, "cv_63": 4, "cv_64": 4, "cv_65": 4, "cv_7": 4, "cv_8": 4, "cv_9": 4, "cycl": 4, "d": 4, "dcc": 10, "deceler": 4, "decod": [1, 2, 3, 4, 10], "delai": 4, "descript": 10, "divid": 4, "document": 3, "driver": 1, "electr": [1, 2], "emf": 10, "extend": 4, "factor": 4, "feed": [4, 10], "file": [5, 8], "filter": 4, "flash": [4, 5], "forward": [4, 10], "frequenc": 4, "function": 4, "gain": [4, 10], "get": 5, "gpio": [1, 2, 4], "h": 8, "hardwar": 0, "header": 8, "ht7533": [1, 2], "i": 4, "input": [1, 2], "integr": 4, "issu": 5, "iter": 4, "k_ff": 4, "k_p": 4, "level": 4, "limit": 4, "list": 4, "long": 4, "m": 4, "manufactur": 4, "map": 4, "maximum": [1, 2], "measur": [4, 10], "microcontrol": [1, 2], "mode": 4, "motor": [1, 4, 10], "new": 4, "note": 4, "offset": 4, "onli": 4, "oper": 4, "other": 6, "output": [1, 2], "overview": [1, 2, 10], "packet": 4, "part": [1, 2], "percentag": 4, "permit": 4, "pid": [4, 10], "pointer": 4, "product": 5, "pwm": 4, "rate": [1, 2, 4], "read": 4, "resolv": 5, "revis": 0, "rp2040": 3, "sampl": 4, "schedul": [4, 10], "schemat": [1, 2], "share": 8, "shift": 4, "signal": 10, "slice": 4, "softwar": [5, 9, 10], "speed": 4, "speed_help": 4, "stage": [1, 2], "start": 5, "step": 4, "swd": 5, "t": 4, "tau": 4, "time": 4, "timeout": 4, "timer": 4, "troubleshoot": 7, "uf2": 5, "us": 4, "v_max": 4, "v_mid": 4, "v_min": 4, "variabl": 4, "version": 4, "via": 5, "voltag": 10, "where": 5, "wire": [1, 2, 5], "x0": 4, "x1": 4, "x2": 4}}) \ No newline at end of file +Search.setIndex({"alltitles": {"1. Where to get the board?": [[5, "where-to-get-the-board"]], "2. Production files?": [[5, "production-files"]], "3. Building the software": [[5, "building-the-software"]], "4. Flashing the software": [[5, "flashing-the-software"]], "4.1. Flashing the software via .uf2 file": [[5, "flashing-the-software-via-uf2-file"]], "4.2. Flashing the software via SWD": [[5, "flashing-the-software-via-swd"]], "5. Wiring": [[5, "wiring"]], "6. Resolving issues": [[5, "resolving-issues"]], "Alternative for HT7533S:": [[1, "alternative-for-ht7533s"], [2, "alternative-for-ht7533s"]], "Alternatives for BDR6133:": [[1, "alternatives-for-bdr6133"], [2, "alternatives-for-bdr6133"]], "Auxiliary Outputs": [[1, "auxiliary-outputs"], [2, "auxiliary-outputs"]], "BOM": [[1, "id8"], [2, "id8"]], "BOM & Alternative Parts": [[1, "bom-alternative-parts"], [2, "bom-alternative-parts"]], "Back-EMF voltage measurement": [[10, "back-emf-voltage-measurement"]], "CV List": [[4, "cv-list"]], "CV.h": [[8, "cv-h"]], "CV_1 - Basic address": [[4, "cv-1-basic-address"]], "CV_11 - Packet timeout": [[4, "cv-11-packet-timeout"]], "CV_112, CV_113, CV_114, CV_115 - GPIO PWM Configuration": [[4, "cv-112-cv-113-cv-114-cv-115-gpio-pwm-configuration"]], "CV_116 to CV_171 - PWM Slice configuration": [[4, "cv-116-to-cv-171-pwm-slice-configuration"]], "CV_12 - Permitted operating modes": [[4, "cv-12-permitted-operating-modes"]], "CV_17 & CV_18 - 14-Bit extended/long address": [[4, "cv-17-cv-18-14-bit-extended-long-address"]], "CV_172 - ADC Offset": [[4, "cv-172-adc-offset"]], "CV_173 - ADC offset measurement cycles": [[4, "cv-173-adc-offset-measurement-cycles"]], "CV_174 - Additional motor-PWM clock divider.": [[4, "cv-174-additional-motor-pwm-clock-divider"]], "CV_175 - speed_helper timer delay": [[4, "cv-175-speed-helper-timer-delay"]], "CV_176, CV_177, CV_178, CV_179 - Base PWM Level used in feed-forward control": [[4, "cv-176-cv-177-cv-178-cv-179-base-pwm-level-used-in-feed-forward-control"]], "CV_2 - V_min": [[4, "cv-2-v-min"]], "CV_257 to CV_512 - Function Mapping CVs": [[4, "cv-257-to-cv-512-function-mapping-cvs"]], "CV_29 - Decoder Configuration": [[4, "cv-29-decoder-configuration"]], "CV_3 - Acceleration rate": [[4, "cv-3-acceleration-rate"]], "CV_31 & CV_32 - Extended CV pointer (Read-Only)": [[4, "cv-31-cv-32-extended-cv-pointer-read-only"]], "CV_4 - Deceleration rate": [[4, "cv-4-deceleration-rate"]], "CV_47 - Feed-forward gain k_ff": [[4, "cv-47-feed-forward-gain-k-ff"]], "CV_48 - Filter time constant (tau) in ms": [[4, "cv-48-filter-time-constant-tau-in-ms"]], "CV_49 - PID Control sampling time t in ms": [[4, "cv-49-pid-control-sampling-time-t-in-ms"]], "CV_5 - V_max": [[4, "cv-5-v-max"]], "CV_50 - PID Control I Factor": [[4, "cv-50-pid-control-i-factor"]], "CV_51 - PID Control D Factor": [[4, "cv-51-pid-control-d-factor"]], "CV_52 & CV_53 - PID Integral Limits": [[4, "cv-52-cv-53-pid-integral-limits"]], "CV_54 & CV_55 - Gain scheduling config k_p @ x0": [[4, "cv-54-cv-55-gain-scheduling-config-k-p-x0"]], "CV_56 & CV_57 - Gain scheduling config k_p @ x1": [[4, "cv-56-cv-57-gain-scheduling-config-k-p-x1"]], "CV_58 & CV_59 - Gain scheduling config k_p @ x2": [[4, "cv-58-cv-59-gain-scheduling-config-k-p-x2"]], "CV_6 - V_mid": [[4, "cv-6-v-mid"]], "CV_60 - Gain scheduling config x1 shift percentage": [[4, "cv-60-gain-scheduling-config-x1-shift-percentage"]], "CV_61 - Measurement Iterations": [[4, "cv-61-measurement-iterations"]], "CV_62 - Measurement Delay": [[4, "cv-62-measurement-delay"]], "CV_63 & CV_64 - Measurement array cutoffs": [[4, "cv-63-cv-64-measurement-array-cutoffs"]], "CV_65 - New flash variable": [[4, "cv-65-new-flash-variable"]], "CV_7 - Version No. (Read-Only)": [[4, "cv-7-version-no-read-only"]], "CV_8 - Manufacturer (Read-Only)": [[4, "cv-8-manufacturer-read-only"]], "CV_9 - Motor PWM Frequency": [[4, "cv-9-motor-pwm-frequency"]], "Complete Schematic": [[1, "complete-schematic"], [2, "complete-schematic"]], "Configuration Variables (CV)": [[4, null]], "Contents:": [[3, null], [6, null], [9, null]], "DCC signal decoding": [[10, "dcc-signal-decoding"]], "Electrical Characteristics": [[1, "electrical-characteristics"], [2, "electrical-characteristics"]], "Electrical Characteristics & Absolute Maximum Ratings": [[1, "id2"], [2, "id2"]], "Feed-forward": [[10, "id2"]], "GPIO": [[1, "gpio"], [2, "gpio"]], "Gain Scheduling": [[10, "gain-scheduling"]], "Getting started": [[5, null]], "Hardware": [[0, null]], "Header files": [[8, null]], "Input Stage": [[1, "input-stage"], [2, "input-stage"]], "Microcontroller": [[1, "microcontroller"], [2, "microcontroller"]], "Motor Driver": [[1, "motor-driver"]], "Motor control": [[10, "motor-control"]], "Note": [[4, "note"]], "Other": [[6, null]], "Overview": [[1, null], [2, null], [10, "overview"]], "PID Controller": [[10, "pid-controller"]], "RP2040-Decoder Documentation": [[3, null]], "Revision 0.3": [[0, "revision-0-3"]], "Revision 1.0": [[0, "revision-1-0"]], "Software": [[9, null]], "Software Description": [[10, null]], "Speed step configuration": [[4, "speed-step-configuration"]], "Troubleshooting": [[7, null]], "Wiring the Decoder": [[1, "wiring-the-decoder"], [2, "wiring-the-decoder"]], "core0.h": [[8, "core0-h"]], "core1.h": [[8, "core1-h"]], "shared.h": [[8, "shared-h"]]}, "docnames": ["hardware/index", "hardware/rev_0_3/hw_description", "hardware/rev_1_0/hw_description", "index", "other/CV_list", "other/getting_started", "other/index", "other/troubleshooting", "software/header_files", "software/index", "software/sw_description"], "envversion": {"sphinx": 64, "sphinx.domains.c": 3, "sphinx.domains.changeset": 1, "sphinx.domains.citation": 1, "sphinx.domains.cpp": 9, "sphinx.domains.index": 1, "sphinx.domains.javascript": 3, "sphinx.domains.math": 2, "sphinx.domains.python": 4, "sphinx.domains.rst": 2, "sphinx.domains.std": 2}, "filenames": ["hardware/index.rst", "hardware/rev_0_3/hw_description.rst", "hardware/rev_1_0/hw_description.rst", "index.rst", "other/CV_list.md", "other/getting_started.rst", "other/index.rst", "other/troubleshooting.md", "software/header_files.rst", "software/index.rst", "software/sw_description.rst"], "indexentries": {}, "objects": {}, "objnames": {}, "objtypes": {}, "terms": {"": [1, 2, 5, 10], "0": [1, 2, 3, 4, 5, 7, 10], "0011": 10, "0603_1608metric": [1, 2], "0xff": 4, "1": [1, 2, 3, 4, 10], "10": [1, 2, 4], "100": [4, 10], "10000": 4, "1001": 4, "100111000100": 4, "100n": [1, 2], "100u": 10, "10khz": 4, "10u": [1, 2], "10v": 7, "10xx": 10, "110000": 4, "11000011010011": 4, "11000100": 4, "11010011": 4, "110x": 10, "1111": 10, "1249": 4, "12499": 4, "125": 4, "12500": 4, "126": 4, "128": 10, "12mhz": [1, 2], "12v": 2, "13": 4, "145": [1, 2], "155": [1, 2], "16": 4, "16bit": 4, "16v": 7, "192": 4, "1ep_7x7mm_p0": [1, 2], "1k": [1, 2], "2": [1, 2, 3, 4, 10], "20": 4, "200": [1, 2], "20v": [1, 7], "23": [1, 2], "231": 4, "24": [1, 2], "25": 2, "250": 4, "2500": 4, "255": [4, 10], "25v": [1, 2], "269aa": [1, 2], "2a": [1, 2], "2x2": [1, 2], "2\u00b5": 10, "3": [1, 2, 3, 4, 7], "32": 4, "33p": [1, 2], "33tr3": [1, 2], "35m": 10, "3m": 10, "3v": [1, 2, 7], "3v3": 7, "4": [1, 2, 3, 4], "400": 1, "40v": [1, 2], "4a": [1, 2], "4mm": [1, 2], "4pin_3": [1, 2], "5": [1, 2, 3, 4, 10], "50": [1, 2], "56": [1, 2], "5i": 10, "5mm": [1, 2], "6": [1, 2, 3, 4], "60v": [1, 2], "64": [4, 10], "64mb": [1, 2], "6k8": [1, 2], "7": 4, "8": [1, 2, 4, 7], "87\u03bc": 10, "8a": [1, 2], "9": 10, "93": 10, "94": 10, "A": [1, 2, 4, 5, 10], "And": 10, "As": 5, "For": [1, 2, 4, 5], "If": [4, 5, 7, 10], "In": 5, "It": [1, 2, 4, 10], "Not": 4, "On": 10, "TO": [1, 2], "That": 4, "The": [1, 2, 4, 5, 10], "Then": 10, "These": 4, "To": [1, 2, 4, 5, 7, 10], "With": 10, "_n": 10, "about": 10, "abov": [1, 2, 4, 10], "abstract": 10, "acceler": 10, "access": 10, "accord": [1, 2, 10], "achiev": [4, 10], "adc": [1, 2, 10], "adc_avdd": [1, 2], "adc_emf_a": [1, 2], "adc_emf_b": [1, 2], "add": 10, "addit": 10, "addition": 10, "address": 10, "adjust": 4, "advantag": 5, "advis": 4, "after": 10, "afterward": 10, "algorithm": 10, "align": 10, "all": [4, 5, 10], "alreadi": 5, "also": [1, 2, 4, 5, 10], "altern": [0, 4, 5], "although": [1, 2], "alwai": [1, 2, 4], "am": 4, "amount": [1, 2, 4], "amplitud": [1, 2], "an": [1, 2, 4, 10], "analog": 7, "ani": [4, 5, 10], "anoth": [4, 5, 10], "appendix": 5, "applic": [1, 2], "ar": [1, 2, 4, 5, 10], "around": 7, "arrai": 10, "aspect": 10, "assembl": 5, "assum": [1, 2], "automat": [4, 10], "aux": [1, 2], "aux1": 4, "aux2": 4, "auxiliari": 0, "avail": [4, 5, 10], "averag": 10, "b": 4, "back": [1, 2, 5], "base": [5, 10], "becaus": 7, "been": [1, 2], "begin": [4, 10], "behavior": 4, "being": 10, "below": [1, 2, 5, 10], "bemf": 4, "bennymeg": 5, "best": 5, "better": [1, 2, 10], "between": [4, 10], "bewar": 7, "bilinear": 10, "bin": 4, "bit": 10, "bit0": 4, "bit14": 4, "bit15": 4, "bit5": 4, "bit6": 4, "bit7": 4, "block": [1, 2, 10], "blue": 4, "board": [3, 4, 10], "bom": [0, 5], "book": 5, "boot": 5, "both": [4, 10], "bridg": [1, 2, 5], "build": [3, 10], "byte": [4, 10], "c": [2, 4, 10], "c1": [1, 2], "c10": [1, 2], "c11": [1, 2], "c12": [1, 2], "c13": [1, 2], "c14": [1, 2], "c15": [1, 2], "c16": [1, 2], "c17": [1, 2], "c2": [1, 2], "c3": [1, 2], "c4": [1, 2], "c5": [1, 2], "c6": [1, 2], "c7": [1, 2], "c8": [1, 2], "c9": [1, 2], "calcul": [4, 10], "calibr": [4, 10], "call": [4, 5, 10], "can": [1, 2, 4, 5, 7, 10], "cannot": 8, "capabl": 5, "capacitor": [1, 2], "case": [2, 5], "cdot": 10, "central": 10, "ceram": [1, 2], "certain": 10, "chang": [4, 5, 10], "channel": [1, 2, 4], "chapter": [4, 5], "character": 4, "characterist": 0, "check": [4, 7, 10], "chip": 4, "choos": 5, "circuit": [1, 2], "clk_div": 4, "clock": [1, 2], "cmake": 10, "cmakelist": [1, 2, 5, 10], "code": [5, 10], "com": 5, "come": 5, "command": 10, "commun": 10, "compar": 10, "compil": 10, "complet": [0, 7, 10], "complic": 5, "compon": [1, 2, 4, 5, 10], "comput": [4, 10], "condit": 4, "conduct": [1, 2], "configur": [1, 2, 3, 6, 10], "connect": [1, 2, 4, 5], "connector": 2, "consid": 10, "constant": 10, "constraint": 5, "contain": [4, 10], "continu": 10, "control": [1, 2, 9], "conveni": 10, "copi": 5, "core": 10, "core0": [4, 9, 10], "core1": [9, 10], "correct": [4, 7, 10], "correspond": [2, 4, 10], "could": [1, 2, 5], "creat": 5, "critic": [1, 2], "crystal": [1, 2], "crystal_smd_3225": [1, 2], "current": [1, 2, 4, 10], "custom": [1, 2], "cv": [3, 6, 7, 9, 10], "cv8": [4, 7], "cv_144": 4, "cv_145": 4, "cv_146": 4, "cv_149": 4, "cv_150": 4, "cv_176": 10, "cv_179": 10, "cv_47": 10, "cv_54": 10, "cv_55": 10, "cv_56": 10, "cv_57": 10, "cv_58": 10, "cv_59": 10, "cv_60": 10, "cv_62": 10, "cv_63": 10, "cv_64": 10, "cv_setup_check": 4, "cycl": [5, 10], "d": [1, 2, 10], "d1": [1, 2], "d2": 2, "d3": 2, "d_": 10, "d_n": 10, "datasheet": [1, 2, 4, 5], "dc": [1, 2], "dcc": [1, 2, 4, 9], "dd": [1, 2], "debug": [5, 10], "debugprob": 5, "dec": 4, "deceler": 10, "decod": [0, 5, 7, 9], "default": [4, 10], "defin": 4, "definit": 10, "defint": 5, "delai": 10, "depend": [4, 10], "dependend": [1, 2], "deriv": [4, 10], "describ": [5, 10], "descript": [3, 9], "design": 5, "desold": 7, "detail": [4, 5, 10], "detect": 10, "determin": 4, "devic": 5, "diagram": [1, 2, 10], "differ": [1, 2, 10], "difficult": 5, "digit": [4, 10], "diod": [1, 2], "direct": [4, 10], "directli": [1, 2, 10], "disabl": 4, "discard": 4, "discret": [4, 10], "discuss": 5, "disk": 5, "dismiss": 10, "dissip": 2, "divid": [1, 2], "do": [4, 5, 7], "document": [5, 10], "doe": 5, "doesn": [1, 2, 7], "domain": [4, 10], "done": [1, 2, 4, 10], "dont": 7, "down": 7, "downstream": 4, "doxygenfil": 8, "drag": 5, "driver": [0, 2], "dropout": [1, 2], "duti": [4, 10], "e": [1, 2, 4, 10], "e_": 10, "e_n": 10, "each": 4, "easier": 10, "easiest": 5, "easili": [1, 2], "edg": 10, "effect": [1, 2, 4, 10], "either": [1, 2, 4], "electr": 0, "element": [4, 10], "emerg": 4, "emf": [1, 2], "enabl": [2, 4], "end": 10, "ensur": [1, 2], "equat": 10, "equival": [4, 10], "error": 10, "essenc": 10, "establish": 10, "event": 10, "everi": [4, 10], "everyth": 10, "exampl": [1, 2, 4], "exce": [1, 2], "expans": 10, "expect": [5, 7], "explain": [1, 2, 5], "explan": [4, 10], "explor": 5, "export": 5, "extens": 5, "extern": [1, 2], "f": [1, 2, 4], "f0": 10, "f12": 10, "f13": 10, "f31": 10, "fabric": 5, "facilit": [1, 2], "factori": 4, "fall": 10, "familiar": 5, "faster": 4, "favor": 10, "fed": 10, "feedback": 10, "few": 10, "file": [3, 9, 10], "filter": [1, 2, 10], "find": 8, "first": 5, "fit": 5, "flase": 5, "flash": [1, 2, 3, 10], "follow": [4, 5, 7, 10], "footprint": [1, 2], "forth": 4, "found": [4, 10], "foundat": 10, "four": [1, 2, 4], "frac": 10, "free": [1, 2], "frequenc": 10, "from": [4, 5, 10], "fulli": 5, "function": [1, 2, 10], "furthermor": [1, 2], "g": [1, 2], "gener": [1, 2], "gerber": 5, "get": [1, 2, 3, 4, 10], "give": [1, 2], "gnd": [1, 2, 7], "got": 5, "gpio": 0, "gpio0": [1, 2], "gpio1": [1, 2], "gpio21": [1, 2], "gpio24": [1, 2], "gpio25": 4, "gpio27": [1, 2], "gpio5": [1, 2], "great": 5, "greater": 10, "green": 4, "group": 10, "gs7533": [1, 2], "h": [1, 2, 4, 5, 9, 10], "ha": [1, 2, 4, 10], "hand": 5, "handl": 10, "happen": 4, "hardwar": [3, 5], "harwar": [1, 2], "have": [4, 5, 10], "header": [3, 9, 10], "headlight": 4, "helper": 10, "here": 4, "high": [1, 2, 4, 10], "higher": 10, "highest": [4, 10], "hold": [1, 2], "hopefulli": 10, "how": [4, 5, 10], "howev": 5, "hz": 4, "i": [1, 2, 5, 7, 10], "i_": 10, "i_n": 10, "ic": [1, 2], "ignor": 5, "ih": [1, 2], "il": [1, 2], "illustr": [1, 2, 4, 10], "impact": 10, "implement": 10, "includ": [1, 2, 10], "inclus": 4, "independ": 4, "index": 4, "indic": 4, "induct": [1, 2], "init": 4, "input": [0, 10], "insert": 10, "instead": 10, "instruct": [4, 5, 10], "interfac": 5, "intern": [1, 2], "iovdd": [1, 2], "irrelev": 4, "issu": [3, 7], "its": [1, 2], "itself": [1, 2, 5], "jlcpcb": 5, "job": 5, "jp1": 5, "just": 5, "k": 10, "k_d": 10, "k_i": 10, "k_p": 10, "keep": [1, 2], "kicad": 5, "kmb24f": [1, 2], "larg": 10, "lcsc": 5, "lead": 4, "led": [2, 10], "left": [4, 10], "leftmost": 10, "legaci": [5, 10], "length": 10, "level": [1, 2, 10], "librari": 10, "lighter": [1, 2], "like": [5, 7], "limit": [1, 2], "link": 10, "linkag": 2, "list": 6, "littl": 5, "load": [1, 2, 10], "log": [1, 2, 10], "logic": 2, "long": [1, 2], "look": 10, "loop": 10, "loss": [1, 2], "low": [1, 2, 4, 10], "lowest": 10, "ma": [1, 2], "made": [1, 2], "make": 5, "mani": 4, "manufactur": 5, "mass": 5, "match": 10, "max": [1, 2, 4, 10], "maximum": [4, 10], "mb": [1, 2], "mean": [1, 2, 4], "measur": [1, 2, 7], "memori": [1, 2, 7], "mention": 4, "mhz": 4, "microcontrol": 0, "mid": 4, "might": 5, "min": [4, 10], "mind": [1, 2], "minimum": [1, 2, 4], "mitig": 10, "mode": [2, 5, 10], "modif": 5, "modifi": 10, "more": [4, 5, 10], "mosfet": [1, 2], "most": 5, "motor": [0, 2, 7, 9], "n": [1, 2, 10], "name": [1, 2], "narrow": 7, "necessari": [1, 2], "need": [1, 2, 5, 10], "new": 5, "nmra": 10, "nois": 10, "normal": [4, 5], "note": [1, 2, 5, 6, 10], "now": 10, "off": [1, 2], "offici": 5, "offset": 10, "often": 10, "one": 4, "onli": [5, 10], "onto": [2, 5], "open": 5, "oper": [1, 2], "option": [4, 10], "order": 5, "oscil": [1, 2, 4], "other": [3, 4, 5], "otherwis": [4, 10], "out": [1, 2, 10], "outlier": 10, "output": [0, 4, 10], "overview": [0, 9], "own": 5, "p": 10, "p_n": 10, "packag": [4, 10], "pad": [1, 2], "paramet": [1, 2, 4], "part": [0, 4, 5, 10], "partli": 5, "pass": [4, 10], "pcb": 5, "percent": 4, "period": 4, "pi": [5, 10], "pick": 5, "pico": 5, "pid_control": 4, "pin": [1, 2, 7, 10], "place": 5, "pleas": 5, "plug": 5, "plugin": 5, "point": [1, 2, 10], "posit": 4, "possibl": 10, "potenti": [1, 2, 10], "power": [2, 5, 7], "precompil": 5, "prefer": 5, "prevent": 10, "procedur": [4, 5], "process": [1, 2, 5], "product": 3, "program": [1, 2, 10], "proport": 10, "protect": [1, 2], "provid": [1, 2, 10], "pt2476": [1, 2], "pt5126a": [1, 2], "public": 4, "pull": [1, 2], "purpos": [1, 2], "pwm": [1, 2, 10], "q1": [1, 2], "q2": [1, 2], "q3": [1, 2], "q4": [1, 2], "q5": [1, 2], "qfn": [1, 2], "quantiti": [1, 2], "question": 5, "r": [1, 2], "r1": [1, 2], "r11": 2, "r2": [1, 2], "r3": [1, 2], "r5": [1, 2], "r6": [1, 2], "r7": [1, 2], "r8": [1, 2], "r9": [1, 2], "rang": [4, 7], "raspberri": [5, 10], "rate": 10, "rather": [1, 2], "re": 5, "reach": 10, "read": 10, "receiv": [4, 10], "recommend": 5, "rectifi": [1, 2], "red": 4, "reduc": 10, "reed": [1, 2], "ref": [1, 2], "refer": [1, 2, 4, 5], "regard": [1, 2, 4, 10], "regist": 10, "regul": [1, 2], "relat": [1, 2], "relev": 5, "remain": 10, "repeat": 5, "repres": 4, "represent": 10, "reset": [4, 7], "resist": 2, "resistor": [1, 2], "resolv": 3, "respect": 4, "rest": 5, "restart": 5, "result": 10, "retriev": 10, "rev": [4, 5], "revers": 4, "revis": 3, "right": [1, 2, 4, 10], "rightmost": 10, "rise": [2, 10], "rm": [1, 2], "rp2040": [1, 2, 4, 5, 10], "rp2350": 5, "run": [5, 10], "same": 4, "sampl": 10, "schemat": 0, "sdk": 10, "second": 4, "section": [5, 10], "see": 4, "sensit": 10, "seri": 5, "serial": 5, "set": [1, 2, 4, 10], "setpoint": 10, "sever": 4, "share": [9, 10], "shift": [1, 2, 10], "short": 4, "shottki": 2, "should": [4, 7], "show": [4, 10], "si1308edl": 2, "side": [1, 2, 4, 5], "signal": [1, 2, 4, 9], "six": [1, 2], "size": 10, "slow": 10, "small": 5, "so": [4, 5, 10], "softwar": [1, 2, 3], "soic": [1, 2], "solder": [1, 2, 5], "sometim": 5, "somewhat": [1, 2], "somewher": 7, "soon": [1, 2], "sort": 10, "sot": [1, 2], "sourc": [5, 10], "special": [1, 2], "specif": 10, "speed": [1, 2, 6, 10], "speed_help": 10, "squar": [1, 2], "stage": 0, "standard": 10, "start": [1, 2, 3, 10], "startup": [4, 10], "state": 4, "static": [1, 2], "statu": [2, 4], "stdio": [1, 2, 10], "step": [6, 10], "still": [4, 5], "stop": 4, "storag": 5, "store": 10, "studio": 5, "subdivid": [1, 2], "suggest": 5, "suitabl": [1, 2], "suppli": [2, 5, 7], "support": [1, 2, 4, 5, 10], "switch": [1, 2, 4], "symbol": [1, 2], "system": 10, "t": [1, 2, 7], "t2n7002bk": [1, 2], "t_": 10, "take": 10, "tau": 10, "temperatur": 2, "temporarili": 5, "term": 5, "text": 10, "th": [1, 2], "than": 10, "thei": [1, 2], "them": [4, 10], "therefor": [4, 10], "thermal": 2, "thi": [1, 2, 4, 5, 7, 10], "threshold": 10, "time": 10, "todo": 10, "togeth": [1, 2], "too": [4, 5], "toolkit": 5, "total": [1, 2, 4], "tp": [1, 2], "track": [7, 10], "transform": 10, "transistor": [1, 2], "translat": [1, 2], "travel": 4, "trigger": 4, "troubl": 5, "troubleshoot": [3, 5, 6], "try": 7, "turn": [1, 2], "two": [1, 2, 4, 5], "txt": [1, 2, 5, 10], "type": [1, 2], "u1": [1, 2], "u2": [1, 2], "u3": [1, 2], "u4": [1, 2], "uart": [1, 2, 10], "uart_rx": 10, "uart_tx": 10, "understand": 10, "unit": [1, 2], "up": [1, 2, 5], "updat": 10, "us": [1, 2, 5, 10], "usb": [2, 5, 10], "usual": 4, "v": [1, 2, 7], "valid": 4, "valu": [1, 2, 4, 7, 10], "vari": 10, "variabl": [1, 2, 3, 6, 10], "vbu": 2, "vdc": 2, "version": 10, "via": [1, 2, 10], "visual": 5, "voltag": [1, 2, 4, 7], "w25q64jvssiq": [1, 2], "wai": 5, "wait": 10, "want": 5, "wave": [1, 2], "well": [1, 2, 10], "wheel": [1, 2], "when": [1, 2, 4, 5, 7, 10], "where": 3, "which": [1, 2, 4, 5, 10], "while": [4, 10], "who": 5, "wire": [0, 3, 7], "within": [1, 2], "without": 5, "work": [1, 2, 4, 5, 7, 10], "would": 4, "wrap": 4, "write": [4, 5, 7], "written": [4, 10], "x": [4, 10], "x322512msb4si": [1, 2], "xxxx": 10, "y": 10, "y1": [1, 2, 4], "y2": 4, "yet": [1, 2], "you": [4, 5, 7], "your": [4, 5, 7], "yourself": [4, 5], "z": 10, "\u03b4t": 2}, "titles": ["Hardware", "Overview", "Overview", "RP2040-Decoder Documentation", "Configuration Variables (CV)", "Getting started", "Other", "Troubleshooting", "Header files", "Software", "Software Description"], "titleterms": {"0": 0, "1": [0, 5], "14": 4, "2": 5, "3": [0, 5], "4": 5, "5": 5, "6": 5, "No": 4, "absolut": [1, 2], "acceler": 4, "adc": 4, "addit": 4, "address": 4, "altern": [1, 2], "arrai": 4, "auxiliari": [1, 2], "back": 10, "base": 4, "basic": 4, "bdr6133": [1, 2], "bit": 4, "board": 5, "bom": [1, 2], "build": 5, "characterist": [1, 2], "clock": 4, "complet": [1, 2], "config": 4, "configur": 4, "constant": 4, "content": [3, 6, 9], "control": [4, 10], "core0": 8, "core1": 8, "cutoff": 4, "cv": [4, 8], "cv_1": 4, "cv_11": 4, "cv_112": 4, "cv_113": 4, "cv_114": 4, "cv_115": 4, "cv_116": 4, "cv_12": 4, "cv_17": 4, "cv_171": 4, "cv_172": 4, "cv_173": 4, "cv_174": 4, "cv_175": 4, "cv_176": 4, "cv_177": 4, "cv_178": 4, "cv_179": 4, "cv_18": 4, "cv_2": 4, "cv_257": 4, "cv_29": 4, "cv_3": 4, "cv_31": 4, "cv_32": 4, "cv_4": 4, "cv_47": 4, "cv_48": 4, "cv_49": 4, "cv_5": 4, "cv_50": 4, "cv_51": 4, "cv_512": 4, "cv_52": 4, "cv_53": 4, "cv_54": 4, "cv_55": 4, "cv_56": 4, "cv_57": 4, "cv_58": 4, "cv_59": 4, "cv_6": 4, "cv_60": 4, "cv_61": 4, "cv_62": 4, "cv_63": 4, "cv_64": 4, "cv_65": 4, "cv_7": 4, "cv_8": 4, "cv_9": 4, "cycl": 4, "d": 4, "dcc": 10, "deceler": 4, "decod": [1, 2, 3, 4, 10], "delai": 4, "descript": 10, "divid": 4, "document": 3, "driver": 1, "electr": [1, 2], "emf": 10, "extend": 4, "factor": 4, "feed": [4, 10], "file": [5, 8], "filter": 4, "flash": [4, 5], "forward": [4, 10], "frequenc": 4, "function": 4, "gain": [4, 10], "get": 5, "gpio": [1, 2, 4], "h": 8, "hardwar": 0, "header": 8, "ht7533": [1, 2], "i": 4, "input": [1, 2], "integr": 4, "issu": 5, "iter": 4, "k_ff": 4, "k_p": 4, "level": 4, "limit": 4, "list": 4, "long": 4, "m": 4, "manufactur": 4, "map": 4, "maximum": [1, 2], "measur": [4, 10], "microcontrol": [1, 2], "mode": 4, "motor": [1, 4, 10], "new": 4, "note": 4, "offset": 4, "onli": 4, "oper": 4, "other": 6, "output": [1, 2], "overview": [1, 2, 10], "packet": 4, "part": [1, 2], "percentag": 4, "permit": 4, "pid": [4, 10], "pointer": 4, "product": 5, "pwm": 4, "rate": [1, 2, 4], "read": 4, "resolv": 5, "revis": 0, "rp2040": 3, "sampl": 4, "schedul": [4, 10], "schemat": [1, 2], "share": 8, "shift": 4, "signal": 10, "slice": 4, "softwar": [5, 9, 10], "speed": 4, "speed_help": 4, "stage": [1, 2], "start": 5, "step": 4, "swd": 5, "t": 4, "tau": 4, "time": 4, "timeout": 4, "timer": 4, "troubleshoot": 7, "uf2": 5, "us": 4, "v_max": 4, "v_mid": 4, "v_min": 4, "variabl": 4, "version": 4, "via": 5, "voltag": 10, "where": 5, "wire": [1, 2, 5], "x0": 4, "x1": 4, "x2": 4}}) \ No newline at end of file diff --git a/sphinx/html/software/index.html b/sphinx/html/software/index.html index 70ba412..1830b6f 100644 --- a/sphinx/html/software/index.html +++ b/sphinx/html/software/index.html @@ -18,6 +18,7 @@ + @@ -90,8 +91,7 @@
  • Software Description
  • diff --git a/sphinx/html/software/sw_description.html b/sphinx/html/software/sw_description.html index 0eef889..1d736c8 100644 --- a/sphinx/html/software/sw_description.html +++ b/sphinx/html/software/sw_description.html @@ -18,6 +18,7 @@ + @@ -53,10 +54,10 @@
  • Software
    • Software Description
      • Overview
      • -
      • Motor control overview
      • -
      • PID Controller
        @@ -99,82 +100,139 @@

        Software Description

        Overview

        -

        The Software is structured as follows:

        -
          -
        • Core0.c

          +

          Software files high level overview:

            +
          • core0.c / core0.h

            +
            +
            • DCC package detection & decoding

            • Programming mode (Modify and read CVs on programming track)

            • ADC-Offset measurement

            • -
            • Feed-forward base PWM measurement

            +
          • -
          • Core1.c

            -
              +
            • core1.c / core0.h

              +
              +
              • PID motor controller

              • +
              • Back-EMF voltage measurement

              +
            • -
            • CV.h

              -
                +
              • shared.c / shared.h (used by both cores)

              • +
              • Error handling

              • +
              • Helper functions for retrieving CV’s

              • +
              • CV.h

              • Default configuration variables

              • +
              • CMakeLists.txt

                +
                +
                  +
                • CMake version, SDK version, C standard version

                • +
                • Board definitions

                • +
                • Compile/Build options

                • +
                • Sources files, header files

                • +
                • Debug logging configuration (via stdio using UART/USB)

                • +
                • Linked libraries

                +
                +
              • +
              • RP2040-Decoder-board.h or RP2040-Decoder-board-legacy.h

                +
                +
                  +
                • Flash Size

                • +
                • Pin specification

                  +
                  +
                    +
                  • LED pin when available

                  • +
                  • UART_TX/UART_RX when used

                  • +
                  • DCC input pin

                  • +
                  • Motor Control PWM pins

                  • +
                  • ADC pins

                  • +
                  +
                -

                Conveniently The Raspberry Pi Foundation provides a well documented SDK for the RP2040. The SDK provides abstraction to a higher level and therefore there is no need to access any registers directly. Everything is written using the SDK so hopefully the code is easier to understand. In the following, the motor control and the decoding of the DCC signals will be explained.

                -
        -
        -

        Motor control overview

        -

        Block Diagram

        -
        -

        Block diagram - Motor control

        -

        The above block diagram in essence describes the functionality of the control loop. While the central component is the PID controller, there is an additional block called Feed-forward 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 is corresponding to the speed_helper() function which delays changing the setpoint according to the configured deceleration/acceleration rates.

        + +
      • +
      +

      Conveniently, The Raspberry Pi Foundation provides a well-documented SDK for the RP2040. The SDK provides abstraction to a higher level, and therefore there is no need to access any registers directly. Everything is written using the SDK, so hopefully, the code is easier to understand.

+
+

Motor control

+
+Block Diagram +
+

Motor control - Block diagram

+
+
+

The above block diagram in essence describes the functionality of the control loop. While the central component is the PID controller, there is an additional block called Feed-forward 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.

-

PID Controller

-

PID Controller

-

The block diagram above shows the PID controller in the s-domain. The derivative part contains an additional digital low pass filter used to filter out high-frequency noise.

-

Output = E * (KP + KI/s + (KD*s)/(sτ+1)) = P + I + D

-
    -
  • P = E * KP

  • -
  • I = E * KI/s

  • -
  • D = E * (KD*s)/(sτ+1)

  • -
-

The continuous-time system representation can now be transformed into a discrete-time representation using bilinear transform [ s = 2*(z-1) / Ts*(z+1) ].

+

PID Controller

+
+PID Controller figure +
+

PID Controller

+
+
+

The block diagram above shows the PID controller in the s-domain. The derivative part contains an additional digital low-pass filter used to filter out high-frequency noise.

+
+\[\begin{split}\begin{align} +\text{Output} &= E \cdot \left(K_P + \frac{K_I}{s} + \frac{K_D \cdot s}{s \tau + 1}\right) = P + I + D \\ +P &= E \cdot K_P \\ +I &= E \cdot \frac{K_I}{s} \\ +D &= E \cdot \frac{K_D \cdot s}{s \tau + 1} +\end{align}\end{split}\]
+

With \(T_s\) being the sampling time / controller update rate / time step of the discrete system. +And \(\tau\) being the filter time constant of the digital filter

+

The continuous-time system representation can now be transformed into a discrete-time representation using bilinear transform \(s = \frac{2 \cdot (z - 1)}{T_s \cdot (z + 1)}\).

This results in the following difference equations which are then implemented in software:

-
    -
  • pn = KP * en

  • -
  • in = 0.5KI * (en + en-1) + in-1

  • -
  • dn = [ 2KD * (en - en-1) + (2τ - Ts) * dn-1 ] / [ 2τ + Ts]

  • -
-

=> outputn = pn + in + dn

-

Also note that instead of using derivative of error, derivative on measurement is used. This is done to prevent a high derivative part in the event of a large change in setpoint.

-
-

Gain scheduling

-

K_P

-

Another aspect to consider is the implementation of gain scheduling. KP is a function of the current setpoint. Often it is favorable to have a higher proportional gain KP for slow speeds, achieving better control results. The illustration above shows the default setting for KP. CV_54 & CV_55 are used to set KP @ x0, CV_56 & CV_57 for KP @ x1 and CV_58 & CV_59 for KP @ x2. Additionally CV_60 is used to shift x1 from the leftmost point (0% = 0/255) to the rightmost point (100% = 255/255).

+
+\[\begin{split}\begin{align} +p_n &= K_P \cdot e_n \\ +i_n &= 0.5 \cdot K_I \cdot \left(e_n + e_{n-1}\right) + i_{n-1} \\ +d_n &= \frac{2 K_D \cdot \left(e_n - e_{n-1}\right) + \left(2 \tau - T_s\right) \cdot d_{n-1}}{2 \tau + T_s} \\ +\text{output}_n &= p_n + i_n + d_n +\end{align}\end{split}\]
+

Also note that instead of using the derivative of error, the derivative on measurement is used. This is done to prevent a high derivative part in the event of a large change in setpoint.

-
-

Feed-forward

-

Feed-forward -To achieve better control Feed-forward is used. On startup the decoder will check for a configuration regarding Feed-forward control - when no configuration is found the decoder automatically runs a calibration to establish a base pwm level (y1) for both directions. The base pwm level (y1) will vary depending on load, motor and voltage on the tracks and can be configured with CV_176 - CV_179. If the setpoint is greater than the threshold, y2 is corrected automatically when in reaches 0.5imin or 0.5imax. CV_47 can be used to set how sensitive this correction is.

+
+

Gain Scheduling

+
+Gain Scheduling figure +
+

Gain Scheduling

+
+
+

Another aspect to consider is the implementation of gain scheduling. KP is a function of the current setpoint. Often it is favorable to have a higher proportional gain KP for slow speeds, achieving better control results. The illustration above shows the default setting for KP. CV_54 & CV_55 are used to set KP @ x0, CV_56 & CV_57 for KP @ x1, and CV_58 & CV_59 for KP @ x2. Additionally, CV_60 is used to shift x1 from the leftmost point (0% = 0/255) to the rightmost point (100% = 255/255).

+
+
+

Feed-forward

+
+Feed forward figure +
+

Feed-forward

+
+
+

TODO: Update this part:

+

To achieve better control, Feed-forward is used. On startup, the decoder will check for a configuration regarding Feed-forward control. When no configuration is found, the decoder automatically runs a calibration to establish a base PWM level (y1) for both directions. The base PWM level (y1) will vary depending on load, motor, and voltage on the tracks and can be configured with CV_176 - CV_179. If the setpoint is greater than the threshold, y2 is corrected automatically when in reaches 0.5imin or 0.5imax. CV_47 can be used to set how sensitive this correction is.

Back-EMF voltage measurement

-

To provide a feedback signal which is proportional to the motor speed the ADC is used to measure the Back-EMF voltage. 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 are being 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. 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%.

DCC signal decoding

-

The detection of the DCC signal works by looking at every rising and falling edge and calculating the time between them. When the time between rising and falling edge is greater than 87μs then this is equivalent to “0”, else “1” - This value then gets shifted into a 64-Bit variable.

-

Decoding is done after every falling edge. It starts with an error detection which when not passed will dismiss the received command. Then the address will be decoded and compared to the address stored in the configuration. If the address matches the command/instruction will be decoded.

-

Only a few instructions are currently implemented, only 128 speed step instructions are supported.

+

The detection of the DCC signal works by looking at every rising and falling edge and calculating the time between them. When the time between rising and falling edge is greater than 87μs, then this is equivalent to “0”; otherwise, “1”. This value then gets shifted into a 64-Bit variable.

+

Decoding is done after every falling edge. It starts with an error detection, which, when not passed, dismisses the received command. Then the address will be decoded and compared to the address stored in the configuration. If the address matches, the command/instruction will be decoded.

+

Only a few instructions are currently implemented; only 128 speed step instructions are supported.

Implemented instructions:

    -
  • 0011-1111 - (128 Speed Step Control) - 2 Byte length

  • -
  • 10XX-XXXX - (Function Group Instruction) (F0 - F12)

  • -
  • 110X-XXXX - Expansion Instruction (F13 - F31)

  • +
  • 0011-1111 - (128 Speed Step Control) - 2 Byte length

  • +
  • 10XX-XXXX - (Function Group Instruction) (F0 - F12)

  • +
  • 110X-XXXX - Expansion Instruction (F13 - F31)

-

All DCC instructions can be found in Section 9.2, 9.2.1 and 9.2.1.1 of the NMRA Communications Standard

+

All DCC instructions can be found in Section 9.2, 9.2.1, and 9.2.1.1 of the NMRA Communications Standard.