From 869717b1458f61b3c1f6eeb73ea79d93631ecf51 Mon Sep 17 00:00:00 2001 From: Gabriel Koppenstein <82903393+gab-k@users.noreply.github.com> Date: Fri, 27 May 2022 15:57:17 +0200 Subject: [PATCH] Updated Software description (markdown) --- Software-description.md | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/Software-description.md b/Software-description.md index 1e41917..36d7896 100644 --- a/Software-description.md +++ b/Software-description.md @@ -9,4 +9,30 @@ The Software is structured as follows: - PID motor controller - ADC measurements * CV.h - - Default configuration variables \ No newline at end of file + - Default configuration variables + +Conveniently The Raspberry Pi Foundation provides a complete and 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 directly 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 in particular. + +Motor Control +------------------------------------- +![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 are two other blocks that have an impact on the control output variable(pid.output). Firstly there is an additional block to counteract initial friction of the motor, this block only contributes to pid.output when the desired motor speed is very low. The second additional block establishes a baseline PWM offset which is necessary due to the motor having a certain threshold PWM level after which it starts spinning. The offset is adjusted when the absolute value of pid.e_sum reaches half of its limit. The speed helper block is corresponding to the speed_helper() function which sets the current target speed according to the configured deceleration/acceleration rates. + +DCC signal decoding +------------------------------------- +The detection of the DCC is very simple, it 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". + +Decoding is done in 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 the most basic instructions is are currently implemented, for example only 126 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) + +