deploy: e8a8ac6d98
This commit is contained in:
1 parent
46ffb95c57
commit
228aa78ffa
93 files changed
+9513
No files matched your search
@@ -0,0 +1,202 @@
|
||||
# Configuration Variables (CV)
|
||||
|
||||
## Note
|
||||
CV.h contains default values for every CV. When your board is still "factory new" these values are automatically written into flash. CV_65 == 255 indicates a factory condition and resets all CVs to default. Alternatively to reset all CVs to default a value of 8 can be written to CV8. Also note that index 0 in the CV array corresponds with CV_1, index 1 corresponds with CV_2 and so forth. This list only contains CVs that are in use.
|
||||
|
||||
## Speed step configuration
|
||||

|
||||
* V_min = CV_2
|
||||
* V_mid = CV_6 * 16
|
||||
* V_max = CV_5 * 16
|
||||
|
||||
The illustration above shows how the speed steps can be configured using the corresponding CVs. The red * represents V_min which is always at speed step 1, the green * shows V_mid at speed step 64 and the blue * shows V_max at speed step 126.
|
||||
|
||||
## CV List
|
||||
|
||||
### CV_1 - Basic address
|
||||
Short DCC address
|
||||
|
||||
|
||||
### CV_2 - V_min
|
||||
Min motor voltage/speed
|
||||
|
||||
|
||||
### CV_3 - Acceleration rate
|
||||
CV_3*CV_175 = Time for one discrete speed step change in ms
|
||||
|
||||
|
||||
### CV_4 - Deceleration rate
|
||||
CV_4*CV_175 = Time for one discrete speed step change in ms
|
||||
|
||||
|
||||
### CV_5 - V_max
|
||||
Max motor voltage/speed - V_max = CV_5 * 16
|
||||
|
||||
|
||||
### CV_6 - V_mid
|
||||
Mid motor voltage/speed - V_max = CV_6 * 16
|
||||
|
||||
|
||||
### CV_7 - Version No. (Read-Only)
|
||||
Rev 0.3 = 1
|
||||
|
||||
Writing a value of 7 triggers am ADC offset adjustment.
|
||||
|
||||
### CV_8 - Manufacturer (Read-Only)
|
||||
Default = "13" = Public Domain & Do-It-Yourself Decoders
|
||||
|
||||
|
||||
Writing a value of 8 resets all CV values to the default values in CV.h.
|
||||
This will also happen if CV_65 == "255" == "0xFF".
|
||||
|
||||
|
||||
### CV_9 - Motor PWM Frequency
|
||||
f in Hz = CV_9 * 100 + 10000
|
||||
|
||||
|
||||
### CV_11 - Packet timeout
|
||||
If no package is received for x seconds (x = CV_11) the decoder will automatically stop the motor (Emergency Stop).
|
||||
|
||||
|
||||
### CV_12 - Permitted operating modes
|
||||
Currently DCC Digital mode is the only supported mode.
|
||||
|
||||
|
||||
### CV_17 & CV_18 - 14-Bit extended/long address
|
||||
Address is only used if bit5 has a value of "1" in CV_29.
|
||||
|
||||

|
||||
|
||||
Bit15 and bit14 which correspond to bit7 and bit6 of CV_17 are always "1". CV_17 = "192" & CV_18 = "0" is also not a valid address. Otherwise the valid value range of CV_17 ranges from "192" to "231" and "0" to "255" for CV_18 respectively.
|
||||
|
||||
|
||||
|
||||
### CV_29 - Decoder Configuration
|
||||
|
||||
Bit0 is used to reverse direction i.e. "0" = normal, "1" = reverse.
|
||||
Bit5 switches between basic and extended addressing modes i.e. "0" = basic address, "1" = extended address.
|
||||
The other 6 bits are currently not in use and therefore irrelevant.
|
||||
|
||||
|
||||
### CV_31 & CV_32 - Extended CV pointer (Read-Only)
|
||||
Not in use.
|
||||
|
||||
### CV_47 - Feed-forward gain k_ff
|
||||
k_ff defines the correction behavior with regard to the y2 variable. High values for k_ff lead to a faster change in the variable. Values for k_ff that are too high can lead to oscillations.
|
||||
k_ff = CV_47/10000
|
||||
|
||||
|
||||
### CV_48 - Filter time constant (tau) in ms
|
||||
The time constant tau characterizes the low-pass filter which is connected downstream in the D component of the PID controller
|
||||
|
||||
|
||||
### CV_49 - PID Control sampling time t in ms
|
||||
Every t seconds the pid_control() function gets called to compute the new control output
|
||||
|
||||
|
||||
### CV_50 - PID Control I Factor
|
||||
Integral gain factor of the PID-Controller
|
||||
|
||||
|
||||
### CV_51 - PID Control D Factor
|
||||
Derivative gain factor of the PID-Controller
|
||||
|
||||
|
||||
### CV_52 & CV_53 - PID Integral Limits
|
||||
Maximum and minimum integral part values
|
||||
|
||||
|
||||
### CV_54 & CV_55 - Gain scheduling config k_p @ x0
|
||||
CV_54 - High Byte -- CV_55 - Low Byte
|
||||
|
||||
|
||||
### CV_56 & CV_57 - Gain scheduling config k_p @ x1
|
||||
CV_56 - High Byte -- CV_57 - Low Byte
|
||||
|
||||
|
||||
### CV_58 & CV_59 - Gain scheduling config k_p @ x2
|
||||
CV_58 - High Byte -- CV_59 - Low Byte
|
||||
|
||||
|
||||
### CV_60 - Gain scheduling config x1 shift percentage
|
||||
Determines position of x1 in percent -> x1 shift in % ≙ CV_60/255
|
||||
|
||||
|
||||
### CV_61 - Measurement Iterations
|
||||
Total amount of BEMF-Voltage measurement iterations
|
||||
|
||||
|
||||
### CV_62 - Measurement Delay
|
||||
BEMF-Voltage measurement delay
|
||||
|
||||
|
||||
### CV_63 & CV_64 - Measurement array cutoffs
|
||||
CV_63 determines how many elements from the left side (beginning with index 0) of the array will be discarded while CV_64 determines how many elements from the right side (beginning from highest index) will be discarded.
|
||||
|
||||
|
||||
### CV_65 - New flash variable
|
||||
Each Byte of the factory new flash chip should have a inital state of "0xFF". This will be checked for in the beginning of core0.c (see cv_setup_check()). When CV_65 == "255" == "0xFF" the default config (CV.h) will be written to flash. Alternatively a reset to default can be done by either writing "8" to CV_8 or writing "255" to CV_65 which then triggers a reset on startup.
|
||||
|
||||
|
||||
### CV_112, CV_113, CV_114, CV_115 - GPIO PWM Configuration
|
||||
PWM enabled "1" - PWM disabled "0"
|
||||
|
||||
|
||||
### CV_116 to CV_171 - PWM Slice configuration
|
||||

|
||||
|
||||
|
||||
Every slice controls two independent output channels, duty cycle from 0% to 100% inclusive and can be configured with several parameters:
|
||||
|
||||
|
||||
* Wrap (16Bit): Sets the slice time period of x cycles - effectively determining the frequency
|
||||
* Clock Divider: Additional clock divider
|
||||
* Level Channel A / Level Channel B - (16Bit each): Determining how many of the x cycles the signal is at a high level - effectively determining the duty cycle
|
||||
|
||||
To see which CVs correspond to which slice and channel, it is advisable to use CV.h as a reference
|
||||
|
||||
The PWM-frequency is calculated as follows: f<sub>PWM</sub> = 125 MHz / [ (CV<sub>clk_div</sub> + 1) * (CV<sub>wrap</sub> + 1) ]
|
||||
|
||||
The duty-cycle can be calculated as follows: D = CV<sub>Level</sub> / CV<sub>wrap</sub> + 1
|
||||
|
||||
**Example configuration - (AUX2: PWM-Frequency f<sub>PWM</sub> = 10kHz; Duty-cycle D = 20%):**
|
||||
|
||||
AUX1 => GPIO25 => Slice 4 / Channel B => Wrap: CV_144 & CV_145; Clock-divider: CV_146; Level(B): CV_149 & CV_150
|
||||
|
||||
=> f<sub>PWM</sub> = 10kHz = 125 MHz / [ (0 + 1) * (12499 + 1) ];
|
||||
|
||||
=> CV_144 = 110000, CV_145 = 11010011, CV_146 = 0; --- (Note: "12499<sub>dec</sub>" = "11000011010011<sub>bin</sub>")
|
||||
|
||||
=> CV<sub>Level</sub> = CV_149 & CV_150 = D * (CV<sub>wrap</sub> + 1) = 0.2 * 12500 = 2500
|
||||
|
||||
=> CV_149 = 1001, CV_150 = 11000100; --- (Note: "2500<sub>dec</sub>" = "100111000100<sub>bin</sub>")
|
||||
|
||||
Another configuration which also achieves 10kHz and D = 20% would be CV<sub>clk_div</sub> = 10, CV<sub>wrap</sub> = 1249, CV<sub>Level</sub> = 250.
|
||||
|
||||
|
||||
A more detailed explanation regarding PWM can be found in the [RP2040-Datasheet - Chapter 4.5](https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf).
|
||||
|
||||
### CV_172 - ADC Offset
|
||||
If CV_172 = "0xFF" = "255" there will be a measurement procedure on startup
|
||||
|
||||
|
||||
### CV_173 - ADC offset measurement cycles
|
||||
Determines how many ADC offset measurement iterations are done.
|
||||
|
||||
|
||||
### CV_174 - Additional motor-PWM clock divider.
|
||||
Additional Clock Divider - works the same as any GPIO clock divider
|
||||
|
||||
|
||||
### CV_175 - speed_helper timer delay
|
||||
This timer delay can be used to change the time between two speed steps. So basically an additional option to adjust the deceleration and acceleration rate.
|
||||
|
||||
|
||||
### CV_176, CV_177, CV_178, CV_179 - Base PWM Level used in feed-forward control
|
||||
CV_176 - High Byte forward -- CV_177 - Low Byte forward -- CV_178 - High Byte reverse -- CV_179 - Low Byte reverse
|
||||
|
||||
These values are equivalent to y1(forward) and y1(reverse) mentioned [here](https://github.com/gab-k/RP2040-Decoder/wiki/Software-description#feed-forward). Writing "0" to all four CVs schedules a new calibration on startup.
|
||||
|
||||
|
||||
### CV_257 to CV_512 - Function Mapping CVs
|
||||
The switching status of the outputs depends both on the function instruction received and on the current direction of travel. That means you can, for example, use a function to switch two or more outputs or, as is usual with headlights, switch them depending on the direction of travel. For configuration, 32 bits (corresponding to the GPIOs) are available for each function in each direction of travel.
|
||||
@@ -0,0 +1,75 @@
|
||||
# Getting started
|
||||
In order to make use of this project, you will need the following:
|
||||
- The RP2040-Decoder board itself
|
||||
- Raspberry Pi Pico or another multi-drop SWD debug interfaces might work as well
|
||||
- Micro-USB cable
|
||||
|
||||
## 1. Where to get the board?
|
||||
You can of course choose any preferred PCB manufacturer, the PCB is designed to be compliant with JLCPCB.com 2 layer board capabilities (hole diameter/clearence/etc.). Regarding assembly, you can of course assemble the board yourself but I would not recommend it (especially the RP2040 QFN Package is not easy to solder). Alternatively you can order the board fully or partly assembled. All parts are normally available at LCSC.com who supply parts to JLCPCB.com.
|
||||
|
||||
## 2. Production files?
|
||||
In order to generate export the production files (Gerber/BOM/Pick and Place) you need [KiCad](https://www.kicad.org/download/) 6 which is open source.
|
||||
[How to do this?](https://jlcpcb.com/help/article/362-how-to-generate-gerber-and-drill-files-in-kicad-7)
|
||||
|
||||
## 3. Building and flashing
|
||||
|
||||
To build the software and run it on the Controller we need to interface the RP2040 using Serial Wire Debug. This can be done using a Raspberry Pi Pico board.
|
||||
|
||||
### Windows
|
||||
|
||||
|
||||
1. Connect Raspberry Pi Pico via USB while holding the reset button. Your Pi Pico should now be visible in Windows explorer as a mass storage device.
|
||||
2. Download the latest prebuilt "picoprobe.uf2" release binary from [here](https://github.com/raspberrypi/picoprobe/releases) or download it from the [Raspberry Pi Website](https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html#debugging-using-another-raspberry-pi-pico).
|
||||
3. Copy "picoprobe.uf2" to your Pi Pico. The Pi Pico onboard LED should now light up.
|
||||
4. Connect GND to GND, GPIO2 to SWCLK, GPIO3 to SWDIO, VBUS to +V, as shown in the picture below .
|
||||
<img src="https://github.com/gab-k/RP2040-Decoder/blob/main/docs/svg/Debug_Connections.svg" width="700"/>
|
||||
|
||||
5. Download and install [Pico setup for Windows](https://github.com/raspberrypi/pico-setup-windows)
|
||||
6. Download and install [MSYS2](https://www.msys2.org/)
|
||||
7. Open a MSYS2 MINGW64 shell window
|
||||
8. Update all pacman packages
|
||||
```sh
|
||||
pacman -Syu
|
||||
```
|
||||
9. Install mingw-w64-x86_64-toolchain (choose to install all)
|
||||
```sh
|
||||
pacman -S mingw-w64-x86_64-toolchain
|
||||
```
|
||||
10. Add "C:\msys64\mingw64\bin" to your users PATH environment variable. If you have choosen to not use the default directory for MSYS2 add the one you have choosen. [How to do this?](https://www.computerhope.com/issues/ch000549.htm)
|
||||
11. Open the Pico - Developer Powershell
|
||||
12. Navigate to a folder you like and clone the project repository
|
||||
```sh
|
||||
git clone https://github.com/gab-k/RP2040-Decoder
|
||||
```
|
||||
13. Enter cloned repository, create and enter build directory
|
||||
```sh
|
||||
cd RP2040-Decoder
|
||||
mkdir build
|
||||
cd build
|
||||
```
|
||||
14. Run CMake and the mingw32-make to build
|
||||
```sh
|
||||
cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug ..
|
||||
mingw32
|
||||
```
|
||||
15. Flash the decoders software using openocd
|
||||
```sh
|
||||
openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c"program rp2040-decoder.elf verify reset exit"
|
||||
```
|
||||
|
||||
### Other OS
|
||||
|
||||
The first four steps are identical to the steps described above for windows users. Regarding building and flashing, please refer to [Getting started - Pico](https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf). Chapter 3 & 5 and Appendix A are the most relevant but you might also refer to chapter 9.1 if you are using macOS.
|
||||
|
||||
|
||||
## 4. Wiring and initial startup
|
||||
<img src="https://github.com/gab-k/RP2040-Decoder/blob/main/docs/svg/Wiring_diagram.svg" width="700"/>
|
||||
|
||||
The illustration above shows an example wiring configuration, you can connect up to 4 outputs(up to 400mA) and 6 GPIOs for lighter loads or custom applications. A Free-wheeling diode should be used when switching inductive loads!
|
||||
|
||||
Another important note is that when the decoder is put into operation for the first time, it automatically performs a motor calibration, which is required for feedforward control. The calibration takes about one to two minutes.
|
||||
|
||||
## 5. If it's not working as expected
|
||||
|
||||
1. Follow the [Troubleshooting instructions](https://github.com/gab-k/RP2040-Decoder/wiki/Troubleshooting)
|
||||
2. If you still have trouble create a new [discussion](https://github.com/gab-k/RP2040-Decoder/discussions) or [issue](https://github.com/gab-k/RP2040-Decoder/issues) and describe your question/issue.
|
||||
@@ -0,0 +1,14 @@
|
||||
# Troubleshooting
|
||||
|
||||
To narrow down the issue when your decoder is not working as expected, you can do the following:
|
||||
|
||||
Check the power supply of the decoder:
|
||||
* +3V3 to GND should be 3.3V
|
||||
* +V to GND should be somewhere in the range of around +10V to +20V
|
||||
* If you dont measure the correct voltages, try to [measure Track Voltage](https://dccwiki.com/Measuring_Track_Voltage)
|
||||
|
||||
Check your motor:
|
||||
* Desolder your motor and try the motor with a analog power supply 0...+-16V to check if the motor is working or not (desolder the wires because the decoder doesn't like voltage on these pins!)
|
||||
|
||||
Reset:
|
||||
* Try to reset the decoder by writing a value of 8 to CV8 (beware, this will reset the complete CV memory!)
|
||||
Reference in new issue
Block a user