158 Commits
Author SHA1 Message Date
gab-k 5a00f5af2c remove fab_outputs.yml moving fabrication output generation to prerelease.yml and release.yml 2025-01-03 15:47:59 +01:00
gab-k a2f30d0654 Update fab_outputs.yml wf 2025-01-03 14:49:36 +01:00
gab-k 87e4aff24f Replaced solder bridge with tactile button; Fixed Footprint Rotation in position file; Fixed .gitignore for production outputs 2025-01-03 11:02:30 +01:00
gab-k 8c34f55877 Update fab_outputs.yml 2025-01-02 20:13:30 +01:00
gab-k e215212025 Update fab_outputs.yml 2025-01-02 20:06:54 +01:00
gab-k 86df810a49 Update fab_outputs.yml 2025-01-02 20:02:20 +01:00
gab-k 0d0c182ba4 Update fab_outputs wf 2025-01-02 19:29:39 +01:00
gab-k 1c7b833c63 Update fab_outputs wf 2025-01-02 19:18:12 +01:00
gab-k 2442853c45 Update fab_outputs wf 2025-01-02 19:06:20 +01:00
gab-k 0b71d556f8 Update fab_outputs wf 2025-01-02 19:03:05 +01:00
gab-k a3d63f2d53 Update fab_outputs wf 2025-01-02 19:01:43 +01:00
gab-k 73e88a86bb Update fab_outputs wf 2025-01-02 18:59:01 +01:00
gab-k de77d8465f Update fab_outputs wf 2025-01-02 18:54:39 +01:00
gab-k e4d352fe0e Update fab_outputs wf 2025-01-02 18:52:12 +01:00
gab-k 20736ad7f0 Update fab_outputs wf 2025-01-02 18:50:23 +01:00
gab-k 8fdce91e64 Update fab_outputs wf 2025-01-02 18:47:26 +01:00
gab-k 7ab22c439d Update fab_outputs wf 2025-01-02 18:46:12 +01:00
gab-k 501d9470f3 Update fab_outputs wf 2025-01-02 18:45:22 +01:00
gab-k 509466c61a Update fab_outputs wf 2025-01-02 18:39:50 +01:00
gab-k 7befd2cdaf Update fab_outputs wf 2025-01-02 18:36:15 +01:00
gab-k 0ceb24a79f Update fab_outputs wf 2025-01-02 18:31:01 +01:00
gab-k 56c7b394dd Update fab_outputs wf 2025-01-02 18:27:41 +01:00
gab-k 454889162b Add fab outputs workflow 2025-01-02 18:24:08 +01:00
gab-k ed98553e49 Update release/prerelease workflow 2025-01-02 17:40:55 +01:00
gab-k 11b9a62142 Update workflows 2025-01-02 17:33:26 +01:00
gab-k 5752f277e2 Update workflows 2025-01-02 17:14:53 +01:00
gab-k 5e72e8538b Update build_sw.yml 2025-01-02 17:02:19 +01:00
gab-k d333dffdb4 Update build_sw.yml 2025-01-02 16:57:17 +01:00
gab-k 82ce5e24aa Update build_sw.yml 2025-01-02 16:54:29 +01:00
gab-k f2b944b6c9 Update build_sw.yml 2025-01-02 16:50:58 +01:00
gab-k 390dd32671 Update Workflows and Cmakelists.txt 2025-01-02 16:48:54 +01:00
gab-k 1d08f5a88f Update release.yml and prerelease.yml 2025-01-02 11:02:49 +01:00
gab-k 4096171fb4 Update release.yml and prerelease.yml 2025-01-02 10:55:43 +01:00
gab-k a93617de60 Update workflow files 2025-01-02 10:37:18 +01:00
Gabriel Koppenstein 738575263f Update docs.yml 2025-01-02 10:14:07 +01:00
Gabriel Koppenstein 50290e059d Update build_sw.yml 2025-01-02 10:02:22 +01:00
gab-k d0e7406627 Update build_sw.yml 2025-01-02 09:54:07 +01:00
gab-k be49c1b43f Update build_sw.yml 2025-01-02 09:46:38 +01:00
gab-k 21bee73f01 Update docs and build/release action 2025-01-02 09:20:46 +01:00
Gabriel Koppenstein ad888dd4a0 Update build_sw.yml 2025-01-02 08:27:07 +01:00
Gabriel Koppenstein 17c67b5ba8 Update build_sw.yml 2025-01-02 08:22:27 +01:00
Gabriel Koppenstein a573e36d2f Update build_sw.yml 2025-01-02 08:18:41 +01:00
Gabriel Koppenstein 7ab3f74cba Update build_sw.yml 2025-01-02 07:53:27 +01:00
Gabriel Koppenstein a7531be0e6 Update build_sw.yml 2025-01-02 07:50:08 +01:00
Gabriel Koppenstein 91eb160833 Update and rename cmake-single-platform.yml to build_sw.yml 2025-01-02 07:47:08 +01:00
gab-k d17660f018 Update docs 2025-01-01 22:25:25 +01:00
gab-k e648e5dfa2 Remove true expression used for debugging 2024-12-31 11:31:38 +01:00
gab-k 0368a22ce7 Removed images as they are automatically deployed to gh-pages branch 2024-12-31 11:07:21 +01:00
gab-k 7e1c079e10 Merge branch 'dev' of https://github.com/gab-k/RP2040-Decoder into dev 2024-12-31 08:01:44 +01:00
gab-k f1961fa5bd Change C18 to be 0603 - 25V and rotate on PCB for easier soldering; Small logging changes; Speed step enums are actually used now for better clarity; Introduced cv_setup_check_done and flash_safe_execute_core_init_done flags for coordinating the two cores better; Incremented version no. CV_7 to 2; 2024-12-31 07:55:14 +01:00
Gabriel Koppenstein 521c8e6b7b Update pcb_render.yml
Fix wrong folder due to new subfolder for revisions
2024-12-30 08:18:04 +01:00
gab-k 0462d3f6b7 Put both HW revisions into subfolders of KiCad folder 2024-12-30 08:12:51 +01:00
gab-k 97b92fd9d8 Update CMake configuration, move post-build program size check to seperate post_build.cmake script 2024-12-30 08:04:30 +01:00
gab-k d970170795 - Updated CMakeLists.txt and board config .h files
- Refactored core0.c to most functions are now static functions.
- Introduced new structures (`dcc_packet_t` and `dcc_ring_buffer_t`) for DCC packet data handling and packet detection.
- DCC pin interrupt now only does packet detection and no evaluation, evaluation is now done inside the main loop.
- Refactor message evaluation logic.
- Implemented hard fault handler, now rebooting when hardfault is encountered.
- Optimized initialization sequence in main().
- Controller and speed helper functions now run outside the timer interrupts, instead flags are set, which are checked inside the core1 main loop.
- Added enumeration for speed steps to improve readability. (However they are yet to be used)
- Added various documentation comments.
- Added various LOG() messages.
- Added python script for generating speed_step typedef definition.
2024-12-29 17:06:50 +01:00
gab-k acdbf3cffe Update Docs; Add 3D-Models for flash and Motor driver; Update Readme; Check program code for exceeding size in CMakeLists.txt; Moved measure() function to core1.c/core1.h; Added direction enum typedef; Update Control Loop Block Diagram; 2024-12-25 21:47:52 +01:00
gab-k 7d2c80574a Update documentation and docs folder structure; Add abs() function using bit operators; Remove LED pin definition from legacy board definition as it does not have an LED; Implement watchdog timer; Add and modify various comments for documentation purposes 2024-12-23 22:03:41 +01:00
gab-k f8b99de801 Expanded on stdio logging functionality, also configuration of logging is now entirely in CMakeLists.txt for convenience, also warns now for logging configurations that make no sense; Clarification in CV table comment; Moved pin definitions into board definition files; two_std_dev() now works mostly with integers; Added function for resetting all CVs saved in flash; Added various LOG() messages; 2024-12-22 21:48:41 +01:00
gab-k 7b1d5ed152 Moved all software related files to Software folder; Now using flash safe execution functions of pico_flash (pico SDK) lib; Added error handling; Added RP2040-Decoder-board.h definition; Adapted CMakeLists.txt for use with vscode pi pico extension; 2024-12-22 11:39:03 +01:00
Gabriel Koppenstein e8a8ac6d98 Update docs.yml 2024-11-27 23:15:51 +01:00
Gabriel Koppenstein bce1405a60 Update docs.yml 2024-11-27 23:12:54 +01:00
Gabriel Koppenstein fa3791c781 Update docs.yml 2024-11-27 23:09:41 +01:00
Gabriel Koppenstein a0d775f081 Update docs.yml 2024-11-27 23:03:08 +01:00
Gabriel Koppenstein ab2a7e17ea Update docs.yml 2024-11-27 23:01:36 +01:00
Gabriel Koppenstein 5b25cd2f7a Update docs.yml 2024-11-27 22:57:43 +01:00
Gabriel Koppenstein 6863502e22 Update docs.yml 2024-11-27 22:55:15 +01:00
gab-k 01bac1ba00 update docs workflow 2024-11-27 22:50:02 +01:00
gab-k 5ca892610e update workflow 2024-11-27 22:44:08 +01:00
gab-k fb165f6e08 Modify docs.yml 2024-11-27 22:35:00 +01:00
gab-k 251d71e73f update docs workflow 2024-11-27 22:33:06 +01:00
gab-k c0f61511ce Update docs 2024-11-27 21:59:54 +01:00
gab-k 72bd29ddbc Update documentation system with doxygen/breathe/sphinx 2024-11-27 11:33:22 +01:00
Gabriel Koppenstein fad8b68e01 Update pcb_render.yml 2024-11-26 17:29:59 +01:00
Gabriel Koppenstein 12b45b9da3 Update doxygen-gh-pages.yml 2024-11-26 17:27:19 +01:00
Gabriel Koppenstein 3f7f092b2c Update doxygen-gh-pages.yml 2024-11-26 17:21:48 +01:00
Gabriel Koppenstein cf79990b51 Update pcb_render.yml 2024-11-26 17:08:41 +01:00
Gabriel Koppenstein 70846f5336 Update pcb_render.yml 2024-11-26 16:52:09 +01:00
Gabriel Koppenstein babe18c758 Update pcb_render.yml 2024-11-26 16:46:23 +01:00
Gabriel Koppenstein d05bd6ef33 Update pcb_render.yml 2024-11-26 16:41:11 +01:00
Gabriel Koppenstein b7a5aa8960 Update pcb_render.yml 2024-11-26 16:31:24 +01:00
Gabriel Koppenstein 5c3525c82e Update pcb_render.yml 2024-11-26 16:23:46 +01:00
Gabriel Koppenstein 304e7f3faa Update pcb_render.yml 2024-11-26 16:14:55 +01:00
Gabriel Koppenstein 8b37c6ead4 Update pcb_render.yml 2024-11-26 16:03:33 +01:00
Gabriel Koppenstein a099ef67ed Update pcb_render.yml 2024-11-26 15:58:43 +01:00
Gabriel Koppenstein 0c225ee7f0 Update pcb_render.yml 2024-11-26 15:46:01 +01:00
Gabriel Koppenstein f8fcd77449 Update pcb_render.yml 2024-11-26 15:27:15 +01:00
Gabriel Koppenstein cb6669992f Update pcb_render.yml 2024-11-26 15:11:52 +01:00
Gabriel Koppenstein c65afef54f Update pcb_render.yml 2024-11-26 15:08:04 +01:00
github-actions d862355199 Add rendered PCB images 2024-11-26 14:02:56 +00:00
gab-k 7779207858 fix file extension and pcb path 2024-11-26 15:01:44 +01:00
Gabriel Koppenstein 0736054a49 Update pcb_render.yaml 2024-11-26 14:58:20 +01:00
gab-k b765f80048 Update action workflows 2024-11-26 14:54:02 +01:00
Gabriel Koppenstein cc81e4ed4c Update render-pcbdraw.yml 2024-11-25 23:37:38 +01:00
Gabriel Koppenstein 5d82d0c3f7 Update render-pcbdraw.yml 2024-11-25 23:15:11 +01:00
Gabriel Koppenstein 42d6fe3ef6 Update render-pcbdraw.yml 2024-11-25 23:11:19 +01:00
Gabriel Koppenstein 6d04cfb8b3 Update render-pcbdraw.yml 2024-11-25 23:07:53 +01:00
Gabriel Koppenstein a83f53d3d8 Update render-pcbdraw.yml 2024-11-25 23:03:36 +01:00
Gabriel Koppenstein fc8653ad74 Update render-pcbdraw.yml 2024-11-25 22:54:33 +01:00
Gabriel Koppenstein c6ee7b2564 Create render-pcbdraw.yml 2024-11-25 22:47:03 +01:00
gab-k 0380b398fc modify gitignore 2024-11-25 22:41:54 +01:00
gab-k 201d521be8 add auto generate .svg python scripts 2024-11-25 20:52:21 +01:00
gab-k dc53d98fda Moving some components on the schematic 2024-11-25 20:46:09 +01:00
gab-k a9c3c60b81 Changed 'LCSC Part Number' Field to 'LCSC Part #' 2024-11-24 23:23:50 +01:00
gab-k 78187ec19f Add LCSC Part numbers 2024-11-24 22:59:27 +01:00
gab-k 9240e5b1a7 New 4-Layer Board with USB; Update gitignore; Change Speed Table Comment; 2024-11-24 19:45:49 +01:00
gab-k d417235df5 remove measure_base_pwm; add comments 2024-01-09 21:30:32 +01:00
gab-k c1564feb4b Mostly renaming, remove control_parameter_t.output, add control_parameter_t.startup.level, ... 2024-01-06 22:56:31 +01:00
gab-k f3ffb73b62 Copy code from flash to ram in order to not use XIP allowing writing to flash memory while both cores are running;
Motor control now operates with two states/modes;
Extended Default CV Range to 1024 - refers to NMRA/RCN standards
2024-01-05 00:37:21 +01:00
gab-k 577bc5dd5c Merge branch 'main' into dev 2024-01-03 12:05:45 +01:00
gab-k 9b8906f476 Replace '≙' with '=' 2024-01-03 09:44:56 +01:00
gab-k baf9ea6081 Update .gitignore 2024-01-02 22:15:45 +01:00
Gabriel Koppenstein 1810541e48 Update Doxyfile 2024-01-02 18:40:23 +01:00
Gabriel Koppenstein b5b5de89dd Update doxygen-gh-pages.yml 2024-01-02 18:39:38 +01:00
Gabriel Koppenstein 3ef7fb99c7 Update doxygen-gh-pages.yml 2024-01-02 18:30:19 +01:00
Gabriel Koppenstein 461f65c88d Update doxygen-gh-pages.yml 2024-01-02 18:14:56 +01:00
gk6394s 7f870bcf71 Merge remote-tracking branch 'origin/main' 2024-01-02 17:07:35 +01:00
gk6394s 38ec9bf60d Change Doxyfile paths to relative paths 2024-01-02 17:07:18 +01:00
Gabriel Koppenstein f529859eff Create doxygen-gh-pages.yml
Create doxygen docs and deploy them
2024-01-02 16:33:38 +01:00
gk6394s e0c0424f87 Refactor Motor PWM init and ADC init; Added doxygen documentation for some functions; Changed some settings in Doxyfile 2024-01-02 16:10:00 +01:00
gk6394s 8fb10e212e Simplify get_speed_step_table_index_of_speed_step(); Removed unnecessary parameter from adjust_pwm_level function; Removed some redundant else statements and redundant "== true" from some expressions; Fixed reset_message_check() function; Added const to some function parameters and local variables; 2024-01-02 12:56:25 +01:00
gab-k 9ee13b67e7 Merge local branch 'changes' into main. 2024-01-01 22:01:17 +01:00
gab-k df9b0ba633 Reformatting and renaming some functions; replaced get_direction() with get_direction_of_speed_step() in order to simplify handling of direction; additional explanation comment in CV.h; add doxygen config file; 2024-01-01 19:21:47 +01:00
r3drock df009a5430 Update cmake-single-platform.yml 2023-12-31 21:21:25 +00:00
r3drock 0ca6f2ca13 Update cmake-single-platform.yml 2023-12-31 21:20:04 +00:00
r3drock 3f27046838 Create cmake-single-platform.yml 2023-12-31 21:18:26 +00:00
r3drock 5f0b51b043 Merge pull request #21 from gab-k/const
make more variables const
2023-12-31 21:13:17 +00:00
r3drock 02e1fdf156 make more variables const 2023-12-31 22:12:07 +01:00
r3drock 5ae65b301d Merge pull request #20 from gab-k/warnings
remove some warnings
2023-12-31 20:23:51 +00:00
r3drock 78123663ce remove some warnings 2023-12-31 21:20:51 +01:00
gab-k d7f4621b96 Completly remove .idea files and update .gitignore accordingly 2023-12-30 17:48:24 +01:00
gab-k 3364793a6f Completly remove .idea files and update .gitignore accordingly 2023-12-30 17:46:43 +01:00
gab-k 6df051019d Modified .gitignore 2023-12-30 16:09:45 +01:00
gab-k 9cf7301af7 Update .gitignore 2023-12-30 16:01:01 +01:00
gab-k 5ec8f953b4 Merge branch 'main' into dev 2023-12-30 15:37:54 +01:00
gab-k 52ec79105d Revert changes to LOG macro 2023-12-30 15:37:38 +01:00
gab-k 4b125c3488 Merge branch 'main' into dev 2023-12-30 15:25:10 +01:00
gab-k 12e54994a8 PCB routing 2023-12-30 15:23:39 +01:00
gab-k c8b75ee71f Fix missing Bitmask in F0-F4 function evaluation, Handle NULL-pointer in get_direction(), CMakelists.txt disable optimizing, Upload CLion config 2023-12-26 18:59:58 +01:00
Gabriel Koppenstein 27d68d3d24 Merge pull request #19 from gab-k/refactorlogging
always append a new line to log
2023-12-23 18:13:34 +01:00
r3drock 626e20fa5f add more lines 2023-12-23 18:07:08 +01:00
r3drock 992d6ae800 always append a new line to log 2023-12-23 17:58:42 +01:00
gab-k 721e5d5a65 PCB Routing 2023-12-20 18:35:24 +01:00
gab-k f28e594051 USB PCB routing, minor changes to schematic 2023-12-14 21:41:58 +01:00
gab-k 4c1be24278 added pcb constraints, changed designators, updated footprints and 3d-models, created board outline 2023-12-05 23:27:29 +01:00
gab-k 1ce384943e Changes to schematic, Created PCB 2023-12-04 21:00:05 +01:00
gab-k 07b792ac13 created USB and non-USB folders; added USB schematic 2023-12-04 19:54:08 +01:00
gab-k f0a23c208e corrected .gitignore 2023-12-04 19:18:19 +01:00
gab-k 570401489b fixed wrong parameter in measure() function call 2023-10-15 14:46:59 +02:00
Gabriel Koppenstein 10fbcb5815 Merge pull request #10 from questor/main
- Printf debugging with different logging levels, disabled by default
- Disabled UART, USB by default
2023-07-15 11:27:28 +02:00
questor/Inter 562258e433 remove ALL logging if not enabled 2023-05-27 22:41:52 +02:00
questor/Inter 36f20a8ca3 some more comments 2023-05-27 22:04:56 +02:00
questor/Inter 8877e4862d disable logging by default, added comments how to enable it and what are the consequences 2023-05-12 21:05:48 +02:00
questor/Inter 995dca15c8 more debug printfs, disabled function usage of gpio0/1, disabled usb interface to save some 25kb in the firmware image 2023-05-08 22:50:19 +02:00
questor/Inter 23b69d6823 more debug output 2023-04-27 23:07:19 +02:00
questor a0408c28ed some refactoring 2023-04-27 15:53:59 +02:00
Gabriel Koppenstein a57295817e Merge pull request #2 from WolfgangGitHub/main
Fix writing CV_1 - The default case was missing - Thank you Wolfgang
2023-01-11 22:28:15 +01:00
Wolfgang 3a3dbb4b63 fix writing CV_1 - the default case was missing 2023-01-08 22:07:59 -05:00
Gabriel Koppenstein 39056097d9 Update README.md 2022-08-11 23:25:32 +02:00
1nct 8f1f5cf915 - added/changed files for documentation
- added comment regarding CV array addresses
2022-08-06 13:54:26 +02:00
94 changed files with 633572 additions and 3824 deletions

No files matched your search

+53
View File
@@ -0,0 +1,53 @@
# This starter workflow is for a CMake project running on a single platform. There is a different starter workflow if you need cross-platform coverage.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml
name: Build Software and create release on tag
on:
push:
branches:
- dev # Trigger on push to 'dev' branch
- main # Trigger on push to 'main' branch
paths:
- '.github/workflows/build_sw.yml' # Trigger if this workflow file changes
- 'Software/**' # Trigger if any file in the 'Software' directory changes
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Debug
jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: install build packages
run: sudo apt-get update && sudo apt-get install cmake gcc-arm-none-eabi libnewlib-arm-none-eabi g++ libstdc++-arm-none-eabi-newlib build-essential
- name: Get SDK and add PICO_SDK_PATH
run: git clone https://github.com/raspberrypi/pico-sdk.git && echo "PICO_SDK_PATH=$GITHUB_WORKSPACE/pico-sdk" >> $GITHUB_ENV
- name: Init submodules to get tinyUSB stack
run: ls && cd pico-sdk && git submodule update --init && cd ..
- name: Configure and run CMake for Hardware Rev 0.3
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/Software/build-Rev-0_3 -S ${{github.workspace}}/Software -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DPICO_BOARD=RP2040-Decoder-board-Rev-0_3
- name: Build for Hardware Rev 0.3
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/Software/build-Rev-0_3 --config ${{env.BUILD_TYPE}}
- name: Configure and run CMake for Hardware Rev 1.0
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/Software/build-Rev-1_0 -S ${{github.workspace}}/Software -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DPICO_BOARD=RP2040-Decoder-board-Rev-1_0
- name: Build for Hardware Rev 1.0
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/Software/build-Rev-1_0 --config ${{env.BUILD_TYPE}}
+77
View File
@@ -0,0 +1,77 @@
name: Doxygen Action
on:
push:
branches:
- dev # Trigger on push to 'dev' branch
- main # Trigger on push to 'main' branch
paths:
- '.github/workflows/docs.yml' # Trigger if this workflow file changes
- 'Software/**' # Trigger if any file in the 'Software' directory changes
- 'docs/**' # Trigger if any file in the 'docs' directory changes
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Doxygen build
uses: mattnotmitt/doxygen-action@v1.9.5
with:
# Path to Doxyfile
doxyfile-path: './Doxyfile'
working-directory: 'docs/doxygen'
- name: Sphinx build
uses: ammaraskar/sphinx-action@0.4
with:
docs-folder: "docs/sphinx/"
- name: Upload sphinx files as artifact
uses: actions/upload-artifact@v4
with:
name: sphinx_files
path: docs/sphinx/build
deploy-main:
if: github.ref == 'refs/heads/main' # Only deploy on 'main' branch
runs-on: ubuntu-latest
needs: build
steps:
- name: Download sphinx files artifact
uses: actions/download-artifact@v4
with:
name: sphinx_files
path: docs/sphinx
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./html
publish_branch: gh-pages
destination_dir: docs/sphinx/build
deploy-dev:
if: github.ref == 'refs/heads/dev' # Only deploy on 'dev' branch
runs-on: ubuntu-latest
needs: build
steps:
- name: Download doxygen files artifact
uses: actions/download-artifact@v4
with:
name: sphinx_files
path: docs/sphinx
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/sphinx
publish_branch: gh-pages-dev # Specify the target branch (gh-pages-dev in this case)
destination_dir: sphinx
+70
View File
@@ -0,0 +1,70 @@
name: pcb_image
on:
push:
branches:
- dev # Trigger on push to 'dev' branch
- main # Trigger on push to 'main' branch
paths:
- '.github/workflows/pcb_render.yml' # Trigger if this workflow file changes
- 'KiCad/**' # Trigger if any file in the 'KiCad' directory changes
jobs:
render-image:
name: render-image
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Render PCB image
uses: linalinn/kicad-render@main
with:
pcb_file: KiCad/Rev_1_0/RP2040-Decoder.kicad_pcb
output_path: ${{ github.workspace }}/images
animation: gif
- name: Upload images as artifact
uses: actions/upload-artifact@v4
with:
name: pcb-images
path: images/
deploy-pages-main:
if: github.ref == 'refs/heads/main' # Only deploy on 'main' branch
runs-on: ubuntu-latest
needs: render-image
steps:
- name: Download pcb-images artifact
uses: actions/download-artifact@v4
with:
name: pcb-images
path: images/
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./images
publish_branch: gh-pages # Specify the target branch (gh-pages in this case)
destination_dir: img
deploy-pages-dev:
if: github.ref == 'refs/heads/dev' # Only deploy on 'dev' branch
runs-on: ubuntu-latest
needs: render-image
steps:
- name: Download pcb-images artifact
uses: actions/download-artifact@v4
with:
name: pcb-images
path: images/
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./images
publish_branch: gh-pages-dev # Specify the target branch (gh-pages-dev in this case)
destination_dir: img
+131
View File
@@ -0,0 +1,131 @@
name: Build Software and create release on tag
on:
push:
tags:
- "v[0-9]+.[0-9]+-PRERELEASE" # Trigger on PRERELEASE version tag push
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Debug
jobs:
build_sw:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: install build packages
run: sudo apt-get update && sudo apt-get install cmake gcc-arm-none-eabi libnewlib-arm-none-eabi g++ libstdc++-arm-none-eabi-newlib build-essential
- name: Get SDK and add PICO_SDK_PATH
run: git clone https://github.com/raspberrypi/pico-sdk.git && echo "PICO_SDK_PATH=$GITHUB_WORKSPACE/pico-sdk" >> $GITHUB_ENV
- name: Init submodules to get tinyUSB stack
run: ls && cd pico-sdk && git submodule update --init && cd ..
- name: Configure and run CMake for Hardware Rev 0.3
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/Software/build-Rev-0_3 -S ${{github.workspace}}/Software -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DPICO_BOARD=RP2040-Decoder-board-Rev-0_3
- name: Build for Hardware Rev 0.3
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/Software/build-Rev-0_3 --config ${{env.BUILD_TYPE}}
- name: Configure and run CMake for Hardware Rev 1.0
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/Software/build-Rev-1_0 -S ${{github.workspace}}/Software -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DPICO_BOARD=RP2040-Decoder-board-Rev-1_0
- name: Build for Hardware Rev 1.0
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/Software/build-Rev-1_0 --config ${{env.BUILD_TYPE}}
- name: Upload build files as artifact Rev 0.3
uses: actions/upload-artifact@v4
with:
name: build_files_Rev-0_3
path: ${{github.workspace}}/Software/build-Rev-0_3
- name: Upload build files as artifact Rev 1.0
uses: actions/upload-artifact@v4
with:
name: build_files_Rev-1_0
path: ${{github.workspace}}/Software/build-Rev-1_0
generate-fabrication-files:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Install KiCad
run: |
sudo add-apt-repository --yes ppa:kicad/kicad-8.0-releases
sudo apt update
sudo apt install --install-recommends kicad
- name: Clone Fabrication Toolkit
run: |
git clone https://github.com/bennymeg/Fabrication-Toolkit.git
- name: Run fab toolkit CLI
run: |
cd Fabrication-Toolkit
python3 -m plugins.cli -p ../KiCad/Rev_1_0/RP2040-Decoder.kicad_pcb --autoTranslate --autoFill
cd ..
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: fab_outputs_rev_1_0
path: ./KiCad/Rev_1_0/production
prerelease:
runs-on: ubuntu-latest
needs: [build_sw, generate-fabrication-files]
steps:
- name: install zip package
run: sudo apt-get install zip
- name: Download fabrication outputs artifact
uses: actions/download-artifact@v4
with:
name: fab_outputs_rev_1_0
path: fab_outputs_rev_1_0
- name: Download build files artifact for Rev 0.3
uses: actions/download-artifact@v4
with:
name: build_files_Rev-0_3
path: build_files_Rev-0_3
- name: Download build files artifact for Rev 1.0
uses: actions/download-artifact@v4
with:
name: build_files_Rev-1_0
path: build_files_Rev-1_0
- name: ls
run: ls
- name: Zip fabrication outputs
run: zip -r FABRICATION_OUTPUTS-REV-1_0.zip fab_outputs_rev_1_0
- name: Zip Rev 0.3 build files
run: zip -r SW_BUILD-REV-0_3.zip build_files_Rev-0_3
- name: Zip Rev 1.0 build files
run: zip -r SW_BUILD-REV-1_0.zip build_files_Rev-1_0
- name: Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
prerelease: true
files: |
SW_BUILD-REV-0_3.zip
SW_BUILD-REV-1_0.zip
FABRICATION_OUTPUTS-REV-1_0.zip
+131
View File
@@ -0,0 +1,131 @@
name: Build Software and create release on tag
on:
push:
tags:
- "v[0-9]+.[0-9]+-RELEASE" # Trigger on RELEASE version tag push
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Debug
jobs:
build_sw:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: install build packages
run: sudo apt-get update && sudo apt-get install cmake gcc-arm-none-eabi libnewlib-arm-none-eabi g++ libstdc++-arm-none-eabi-newlib build-essential
- name: Get SDK and add PICO_SDK_PATH
run: git clone https://github.com/raspberrypi/pico-sdk.git && echo "PICO_SDK_PATH=$GITHUB_WORKSPACE/pico-sdk" >> $GITHUB_ENV
- name: Init submodules to get tinyUSB stack
run: ls && cd pico-sdk && git submodule update --init && cd ..
- name: Configure and run CMake for Hardware Rev 0.3
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/Software/build-Rev-0_3 -S ${{github.workspace}}/Software -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DPICO_BOARD=RP2040-Decoder-board-Rev-0_3
- name: Build for Hardware Rev 0.3
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/Software/build-Rev-0_3 --config ${{env.BUILD_TYPE}}
- name: Configure and run CMake for Hardware Rev 1.0
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/Software/build-Rev-1_0 -S ${{github.workspace}}/Software -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DPICO_BOARD=RP2040-Decoder-board-Rev-1_0
- name: Build for Hardware Rev 1.0
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/Software/build-Rev-1_0 --config ${{env.BUILD_TYPE}}
- name: Upload build files as artifact Rev 0.3
uses: actions/upload-artifact@v4
with:
name: build_files_Rev-0_3
path: ${{github.workspace}}/Software/build-Rev-0_3
- name: Upload build files as artifact Rev 1.0
uses: actions/upload-artifact@v4
with:
name: build_files_Rev-1_0
path: ${{github.workspace}}/Software/build-Rev-1_0
generate-fabrication-files:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Install KiCad
run: |
sudo add-apt-repository --yes ppa:kicad/kicad-8.0-releases
sudo apt update
sudo apt install --install-recommends kicad
- name: Clone Fabrication Toolkit
run: |
git clone https://github.com/bennymeg/Fabrication-Toolkit.git
- name: Run fab toolkit CLI
run: |
cd Fabrication-Toolkit
python3 -m plugins.cli -p ../KiCad/Rev_1_0/RP2040-Decoder.kicad_pcb --autoTranslate --autoFill
cd ..
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: fab_outputs_rev_1_0
path: ./KiCad/Rev_1_0/production
release:
runs-on: ubuntu-latest
needs: [build_sw, generate-fabrication-files]
steps:
- name: install zip package
run: sudo apt-get install zip
- name: Download fabrication outputs artifact
uses: actions/download-artifact@v4
with:
name: fab_outputs_rev_1_0
path: fab_outputs_rev_1_0
- name: Download build files artifact for Rev 0.3
uses: actions/download-artifact@v4
with:
name: build_files_Rev-0_3
path: build_files_Rev-0_3
- name: Download build files artifact for Rev 1.0
uses: actions/download-artifact@v4
with:
name: build_files_Rev-1_0
path: build_files_Rev-1_0
- name: ls
run: ls
- name: Zip fabrication outputs
run: zip -r FABRICATION_OUTPUTS-REV-1_0.zip fab_outputs_rev_1_0
- name: Zip Rev 0.3 build files
run: zip -r SW_BUILD-REV-0_3.zip build_files_Rev-0_3
- name: Zip Rev 1.0 build files
run: zip -r SW_BUILD-REV-1_0.zip build_files_Rev-1_0
- name: Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
SW_BUILD-REV-0_3.zip
SW_BUILD-REV-1_0.zip
FABRICATION_OUTPUTS-REV-1_0.zip
+28 -3
View File
@@ -1,10 +1,35 @@
.idea
# IDE Configurations
.vscode
.idea
# Doxygen generated files
docs/doxygen/build
# Sphinx generated files
docs/sphinx/build
# Build folders
build
cmake-build-debug
cmake-build-release
KiCad/RP2040-Decoder-Rev_0_2-backups
# KiCad ignored files
KiCad/RP2040-Decoder-backups
KiCad/*.bak
KiCad/fp-info-cache
KiCad/_autosave-*
KiCad/*.kicad_prl
KiCad/*.kicad_prl
KiCad/*/RP2040-Decoder-backups
KiCad/*/*.bak
KiCad/*/fp-info-cache
KiCad/*/_autosave-*
KiCad/*/*.kicad_prl
KiCad/*.kicad_sch-bak
KiCad/*.kicad_pcb-bak
KiCad/*.kicad_pcb.lck
KiCad/*/production
KiCad/*/fabrication-toolkit-options.json
KiCad/*/output
# Temporary files
scripts/temp
-51
View File
@@ -1,51 +0,0 @@
cmake_minimum_required(VERSION 3.12)
# Pull in SDK (must be before project)
include(pico_sdk_import.cmake)
project(RP2040-Decoder C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(PICO_DECODER_PATH ${PROJECT_SOURCE_DIR})
# Initialize the SDK
pico_sdk_init()
add_compile_options(-Wall
-Wno-format # int != int32 _t as far as the compiler is concerned because gcc has int32_t as long int
-Wno-unused-function # we have some for the docs that aren't called
-Wno-maybe-uninitialized
)
add_executable(
RP2040-Decoder
core0.c
core0.h
core1.c
core1.h
shared.c
shared.h)
# Multiplier to lengthen XOSC startup delay to accommodate slow-starting oscillator
target_compile_definitions(
RP2040-Decoder PUBLIC
PICO_XOSC_STARTUP_DELAY_MULTIPLIER=64
)
# Add pico_multicore which is required for multicore functionality
target_link_libraries(
RP2040-Decoder
pico_stdlib
hardware_pwm
hardware_adc
hardware_flash
pico_multicore
)
# enable usb output, disable uart output
pico_enable_stdio_usb(RP2040-Decoder 1)
pico_enable_stdio_uart(RP2040-Decoder 1)
# create map/bin/hex file etc.
pico_add_extra_outputs(RP2040-Decoder)
File renamed without changes.
File diff suppressed because it is too large. Load diff
@@ -1,5 +1,6 @@
{
"board": {
"3dviewports": [],
"design_settings": {
"defaults": {
"board_outline_line_width": 0.09999999999999999,
@@ -62,20 +63,26 @@
"rule_severities": {
"annular_width": "error",
"clearance": "error",
"connection_width": "warning",
"copper_edge_clearance": "error",
"copper_sliver": "warning",
"courtyards_overlap": "warning",
"diff_pair_gap_out_of_range": "error",
"diff_pair_uncoupled_length_too_long": "error",
"drill_out_of_range": "error",
"duplicate_footprints": "warning",
"extra_footprint": "warning",
"footprint": "error",
"footprint_type_mismatch": "error",
"hole_clearance": "error",
"hole_near_hole": "error",
"invalid_outline": "error",
"isolated_copper": "warning",
"item_on_disabled_layer": "error",
"items_not_allowed": "error",
"length_out_of_range": "error",
"lib_footprint_issues": "warning",
"lib_footprint_mismatch": "warning",
"malformed_courtyard": "error",
"microvia_drill_out_of_range": "error",
"missing_courtyard": "ignore",
@@ -85,9 +92,14 @@
"padstack": "error",
"pth_inside_courtyard": "ignore",
"shorting_items": "error",
"silk_edge_clearance": "warning",
"silk_over_copper": "warning",
"silk_overlap": "warning",
"skew_out_of_range": "error",
"solder_mask_bridge": "error",
"starved_thermal": "error",
"text_height": "warning",
"text_thickness": "warning",
"through_hole_pad_without_hole": "error",
"too_many_vias": "error",
"track_dangling": "warning",
@@ -96,7 +108,6 @@
"unconnected_items": "error",
"unresolved_variable": "error",
"via_dangling": "warning",
"zone_has_empty_net": "error",
"zones_intersect": "error"
},
"rules": {
@@ -104,20 +115,65 @@
"allow_microvias": false,
"max_error": 0.005,
"min_clearance": 0.127,
"min_connection": 0.0,
"min_copper_edge_clearance": 0.19999999999999998,
"min_hole_clearance": 0.19999999999999998,
"min_hole_to_hole": 0.254,
"min_microvia_diameter": 0.19999999999999998,
"min_microvia_drill": 0.09999999999999999,
"min_resolved_spokes": 2,
"min_silk_clearance": 0.0,
"min_text_height": 0.7999999999999999,
"min_text_thickness": 0.08,
"min_through_hole_diameter": 0.19999999999999998,
"min_track_width": 0.127,
"min_via_annular_width": 0.13,
"min_via_diameter": 0.39999999999999997,
"solder_mask_clearance": 0.0,
"solder_mask_min_width": 0.0,
"solder_mask_to_copper_clearance": 0.0,
"use_height_for_length_calcs": true
},
"teardrop_options": [
{
"td_allow_use_two_tracks": true,
"td_curve_segcount": 5,
"td_on_pad_in_zone": false,
"td_onpadsmd": true,
"td_onroundshapesonly": false,
"td_ontrackend": false,
"td_onviapad": true
}
],
"teardrop_parameters": [
{
"td_curve_segcount": 0,
"td_height_ratio": 1.0,
"td_length_ratio": 0.5,
"td_maxheight": 2.0,
"td_maxlen": 1.0,
"td_target_name": "td_round_shape",
"td_width_to_size_filter_ratio": 0.9
},
{
"td_curve_segcount": 0,
"td_height_ratio": 1.0,
"td_length_ratio": 0.5,
"td_maxheight": 2.0,
"td_maxlen": 1.0,
"td_target_name": "td_rect_shape",
"td_width_to_size_filter_ratio": 0.9
},
{
"td_curve_segcount": 0,
"td_height_ratio": 1.0,
"td_length_ratio": 0.5,
"td_maxheight": 2.0,
"td_maxlen": 1.0,
"td_target_name": "td_track_end",
"td_width_to_size_filter_ratio": 0.9
}
],
"track_widths": [
0.0,
0.127,
@@ -154,7 +210,15 @@
"zones_allow_external_fillets": false,
"zones_use_no_outline": true
},
"layer_presets": []
"ipc2581": {
"dist": "",
"distpn": "",
"internal_id": "",
"mfg": "",
"mpn": ""
},
"layer_presets": [],
"viewports": []
},
"boards": [],
"cvpcb": {
@@ -341,15 +405,21 @@
"bus_label_syntax": "error",
"bus_to_bus_conflict": "error",
"bus_to_net_conflict": "error",
"conflicting_netclasses": "error",
"different_unit_footprint": "error",
"different_unit_net": "error",
"duplicate_reference": "error",
"duplicate_sheet_names": "error",
"endpoint_off_grid": "warning",
"extra_units": "error",
"global_label_dangling": "warning",
"hier_label_mismatch": "error",
"label_dangling": "error",
"lib_symbol_issues": "warning",
"missing_bidi_pin": "warning",
"missing_input_pin": "warning",
"missing_power_pin": "error",
"missing_unit": "warning",
"multiple_net_names": "warning",
"net_not_bus_member": "warning",
"no_connect_connected": "warning",
@@ -359,6 +429,7 @@
"pin_to_pin": "warning",
"power_pin_not_driven": "error",
"similar_labels": "warning",
"simulation_model_issue": "ignore",
"unannotated": "error",
"unit_value_mismatch": "error",
"unresolved_variable": "error",
@@ -376,7 +447,7 @@
"net_settings": {
"classes": [
{
"bus_width": 12.0,
"bus_width": 12,
"clearance": 0.2,
"diff_pair_gap": 0.25,
"diff_pair_via_gap": 0.25,
@@ -390,28 +461,94 @@
"track_width": 0.25,
"via_diameter": 0.8,
"via_drill": 0.4,
"wire_width": 6.0
"wire_width": 6
}
],
"meta": {
"version": 2
"version": 3
},
"net_colors": null
"net_colors": null,
"netclass_assignments": null,
"netclass_patterns": []
},
"pcbnew": {
"last_paths": {
"gencad": "",
"idf": "",
"netlist": "",
"plot": "",
"pos_files": "",
"specctra_dsn": "",
"step": "",
"svg": "",
"vrml": ""
},
"page_layout_descr_file": ""
},
"schematic": {
"annotate_start_num": 0,
"bom_export_filename": "",
"bom_fmt_presets": [],
"bom_fmt_settings": {
"field_delimiter": ",",
"keep_line_breaks": false,
"keep_tabs": false,
"name": "CSV",
"ref_delimiter": ",",
"ref_range_delimiter": "",
"string_delimiter": "\""
},
"bom_presets": [],
"bom_settings": {
"exclude_dnp": false,
"fields_ordered": [
{
"group_by": false,
"label": "Reference",
"name": "Reference",
"show": true
},
{
"group_by": true,
"label": "Value",
"name": "Value",
"show": true
},
{
"group_by": false,
"label": "Datasheet",
"name": "Datasheet",
"show": true
},
{
"group_by": false,
"label": "Footprint",
"name": "Footprint",
"show": true
},
{
"group_by": false,
"label": "Qty",
"name": "${QUANTITY}",
"show": true
},
{
"group_by": true,
"label": "DNP",
"name": "${DNP}",
"show": true
}
],
"filter_string": "",
"group_symbols": true,
"name": "Grouped By Value",
"sort_asc": true,
"sort_field": "Reference"
},
"connection_grid_size": 50.0,
"drawing": {
"dashed_lines_dash_length_ratio": 12.0,
"dashed_lines_gap_length_ratio": 3.0,
"default_line_thickness": 6.0,
"default_text_size": 50.0,
"field_names": [],
@@ -422,6 +559,11 @@
"intersheets_ref_suffix": "",
"junction_size_choice": 3,
"label_size_ratio": 0.25,
"operating_point_overlay_i_precision": 3,
"operating_point_overlay_i_range": "~A",
"operating_point_overlay_v_precision": 3,
"operating_point_overlay_v_range": "~V",
"overbar_offset_ratio": 1.23,
"pin_symbol_size": 0.0,
"text_offset_ratio": 0.08
},
@@ -443,7 +585,12 @@
"page_layout_descr_file": "",
"plot_directory": "/home/gab/Documents/",
"spice_adjust_passive_values": false,
"spice_current_sheet_as_root": false,
"spice_external_command": "spice \"%I\"",
"spice_model_current_sheet_as_root": true,
"spice_save_all_currents": false,
"spice_save_all_dissipations": false,
"spice_save_all_voltages": false,
"subpart_first_id": 65,
"subpart_id_separator": 0
},
File diff suppressed because it is too large. Load diff
File renamed without changes.
@@ -1,21 +1,21 @@
(kicad_symbol_lib (version 20211014) (generator kicad_symbol_editor)
(kicad_symbol_lib (version 20220914) (generator kicad_symbol_editor)
(symbol "+V" (power) (pin_names (offset 0)) (in_bom yes) (on_board yes)
(property "Reference" "#PWR" (id 0) (at 0 -3.81 0)
(property "Reference" "#PWR" (at 0 -3.81 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Value" "+V" (id 1) (at 0 3.556 0)
(property "Value" "+V" (at 0 3.556 0)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "" (id 2) (at 0 0 0)
(property "Footprint" "" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "" (id 3) (at 0 0 0)
(property "Datasheet" "" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_keywords" "power-flag" (id 4) (at 0 0 0)
(property "ki_keywords" "power-flag" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_description" "Power symbol creates a global label with name \"+12V\"" (id 5) (at 0 0 0)
(property "ki_description" "Power symbol creates a global label with name \"+12V\"" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(symbol "+V_0_1"
@@ -24,7 +24,7 @@
(xy -0.762 1.27)
(xy 0 2.54)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
@@ -32,7 +32,7 @@
(xy 0 0)
(xy 0 2.54)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
@@ -40,7 +40,7 @@
(xy 0 2.54)
(xy 0.762 1.27)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
)
@@ -52,30 +52,30 @@
)
)
(symbol "BDR6133" (in_bom yes) (on_board yes)
(property "Reference" "U" (id 0) (at 6.35 11.43 0)
(property "Reference" "U" (at 6.35 11.43 0)
(effects (font (size 1.27 1.27)))
)
(property "Value" "BDR6133" (id 1) (at -10.16 11.43 0)
(property "Value" "BDR6133" (at -10.16 11.43 0)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "Package_SO:SOIC-8-1EP_3.9x4.9mm_P1.27mm_EP2.29x3mm" (id 2) (at 0 -21.59 0)
(property "Footprint" "Package_SO:SOIC-8-1EP_3.9x4.9mm_P1.27mm_EP2.29x3mm" (at 0 -21.59 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "https://datasheet.lcsc.com/lcsc/2101211904_Bardeen-Micro--BDR6133_C2687793.pdf" (id 3) (at 6.35 -24.13 0)
(property "Datasheet" "https://datasheet.lcsc.com/lcsc/2101211904_Bardeen-Micro--BDR6133_C2687793.pdf" (at 6.35 -24.13 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_keywords" "half bridge driver" (id 4) (at 0 0 0)
(property "ki_keywords" "half bridge driver" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_description" "H-Bridge driver, 1A, Low Voltage, PWM input, WSON-8" (id 5) (at 0 0 0)
(property "ki_description" "H-Bridge driver, 1A, Low Voltage, PWM input, WSON-8" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_fp_filters" "WSON*1EP*2x2mm*P0.5mm*" (id 6) (at 0 0 0)
(property "ki_fp_filters" "WSON*1EP*2x2mm*P0.5mm*" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(symbol "BDR6133_0_1"
(rectangle (start -7.62 10.16) (end 7.62 -10.16)
(stroke (width 0.254) (type default) (color 0 0 0 0))
(stroke (width 0.254) (type default))
(fill (type background))
)
)
@@ -119,25 +119,25 @@
)
)
(symbol "BZT52C3V3S" (pin_numbers hide) (pin_names (offset 1.016) hide) (in_bom yes) (on_board yes)
(property "Reference" "D" (id 0) (at 0 2.54 0)
(property "Reference" "D" (at 0 2.54 0)
(effects (font (size 1.27 1.27)))
)
(property "Value" "BZT52C3V3S" (id 1) (at 0 -2.54 0)
(property "Value" "BZT52C3V3S" (at 0 -2.54 0)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "Diode_SMD:D_SOD-323" (id 2) (at 0 -4.445 0)
(property "Footprint" "Diode_SMD:D_SOD-323" (at 0 -4.445 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "https://datasheet.lcsc.com/lcsc/2109071430_YONGYUTAI-BZT52C3V3S_C2892655.pdf" (id 3) (at 0 -6.35 0)
(property "Datasheet" "https://datasheet.lcsc.com/lcsc/2109071430_YONGYUTAI-BZT52C3V3S_C2892655.pdf" (at 0 -6.35 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_keywords" "zener diode" (id 4) (at 0 0 0)
(property "ki_keywords" "zener diode" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_description" "200mW Zener Diode, SOD-323" (id 5) (at 0 0 0)
(property "ki_description" "200mW Zener Diode, SOD-323" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_fp_filters" "D?SOD?123*" (id 6) (at 0 0 0)
(property "ki_fp_filters" "D?SOD?123*" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(symbol "BZT52C3V3S_0_1"
@@ -146,7 +146,7 @@
(xy 1.27 0)
(xy -1.27 0)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
@@ -155,7 +155,7 @@
(xy -1.27 1.27)
(xy -0.762 1.27)
)
(stroke (width 0.254) (type default) (color 0 0 0 0))
(stroke (width 0.254) (type default))
(fill (type none))
)
(polyline
@@ -165,7 +165,7 @@
(xy -1.27 0)
(xy 1.27 -1.27)
)
(stroke (width 0.254) (type default) (color 0 0 0 0))
(stroke (width 0.254) (type default))
(fill (type none))
)
)
@@ -181,25 +181,25 @@
)
)
(symbol "Conn_01x02_Male" (pin_names (offset 1.016) hide) (in_bom yes) (on_board yes)
(property "Reference" "J1" (id 0) (at -0.7112 2.9972 0)
(property "Reference" "J1" (at -0.7112 2.9972 0)
(effects (font (size 1.27 1.27)) (justify right))
)
(property "Value" "DCC_IN" (id 1) (at -0.7112 0.6858 0)
(property "Value" "DCC_IN" (at -0.7112 0.6858 0)
(effects (font (size 1.27 1.27)) (justify right))
)
(property "Footprint" "" (id 2) (at 0 0 0)
(property "Footprint" "" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "~" (id 3) (at 0 0 0)
(property "Datasheet" "~" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_keywords" "connector" (id 4) (at 0 0 0)
(property "ki_keywords" "connector" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_description" "Generic connector, single row, 01x02, script generated (kicad-library-utils/schlib/autogen/connector/)" (id 5) (at 0 0 0)
(property "ki_description" "Generic connector, single row, 01x02, script generated (kicad-library-utils/schlib/autogen/connector/)" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_fp_filters" "Connector*:*_1x??_*" (id 6) (at 0 0 0)
(property "ki_fp_filters" "Connector*:*_1x??_*" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(symbol "Conn_01x02_Male_1_1"
@@ -208,7 +208,7 @@
(xy 1.27 -2.54)
(xy 0.8636 -2.54)
)
(stroke (width 0.1524) (type default) (color 0 0 0 0))
(stroke (width 0.1524) (type default))
(fill (type none))
)
(polyline
@@ -216,15 +216,15 @@
(xy 1.27 0)
(xy 0.8636 0)
)
(stroke (width 0.1524) (type default) (color 0 0 0 0))
(stroke (width 0.1524) (type default))
(fill (type none))
)
(rectangle (start 0.8636 -2.413) (end 0 -2.667)
(stroke (width 0.1524) (type default) (color 0 0 0 0))
(stroke (width 0.1524) (type default))
(fill (type outline))
)
(rectangle (start 0.8636 0.127) (end 0 -0.127)
(stroke (width 0.1524) (type default) (color 0 0 0 0))
(stroke (width 0.1524) (type default))
(fill (type outline))
)
(pin power_out line (at 5.08 0 180) (length 3.81)
@@ -237,29 +237,72 @@
)
)
)
(symbol "HT7533S" (pin_names (offset 0.254)) (in_bom yes) (on_board yes)
(property "Reference" "U" (at -3.81 3.175 0)
(effects (font (size 1.27 1.27)))
)
(property "Value" "HT7533S" (at 0 3.175 0)
(effects (font (size 1.27 1.27)) (justify left))
)
(property "Footprint" "Package_TO_SOT_SMD:SOT-23" (at 1.27 -8.89 0)
(effects (font (size 1.27 1.27) italic) hide)
)
(property "Datasheet" "https://datasheet.lcsc.com/lcsc/2311091732_UMW-Youtai-Semiconductor-Co---Ltd--HT7533S_C347215.pdf" (at 2.54 -11.43 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_keywords" "ldo linear fixed positive" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_description" "100mA, Low Dropout Voltage Regulator, 3.3V positive fixed output, SOT-23 package" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_fp_filters" "SOT?23*" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(symbol "HT7533S_0_1"
(rectangle (start -5.08 1.905) (end 5.08 -5.08)
(stroke (width 0.254) (type default))
(fill (type background))
)
)
(symbol "HT7533S_1_1"
(pin power_in line (at 0 -7.62 90) (length 2.54)
(name "GND" (effects (font (size 1.27 1.27))))
(number "1" (effects (font (size 1.27 1.27))))
)
(pin power_out line (at 7.62 0 180) (length 2.54)
(name "VOUT" (effects (font (size 1.27 1.27))))
(number "2" (effects (font (size 1.27 1.27))))
)
(pin power_in line (at -7.62 0 0) (length 2.54)
(name "VIN" (effects (font (size 1.27 1.27))))
(number "3" (effects (font (size 1.27 1.27))))
)
)
)
(symbol "KMB24F" (pin_names (offset 0)) (in_bom yes) (on_board yes)
(property "Reference" "D" (id 0) (at 2.54 6.985 0)
(property "Reference" "D" (at 2.54 6.985 0)
(effects (font (size 1.27 1.27)) (justify left))
)
(property "Value" "KMB24F" (id 1) (at 2.54 5.08 0)
(property "Value" "KMB24F" (at 2.54 5.08 0)
(effects (font (size 1.27 1.27)) (justify left))
)
(property "Footprint" "Package_TO_SOT_SMD:TO-269AA" (id 2) (at -33.02 -11.43 0)
(property "Footprint" "Package_TO_SOT_SMD:TO-269AA" (at -33.02 -11.43 0)
(effects (font (size 1.27 1.27)) (justify left) hide)
)
(property "Datasheet" "https://datasheet.lcsc.com/lcsc/2010151636_FUXINSEMI-KMB24F_C880910.pdf" (id 3) (at 6.35 -13.97 0)
(property "Datasheet" "https://datasheet.lcsc.com/lcsc/2010151636_FUXINSEMI-KMB24F_C880910.pdf" (at 6.35 -13.97 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Comment" "TO-269AA = MBS" (id 4) (at -11.43 -8.89 0)
(property "Comment" "TO-269AA = MBS" (at -11.43 -8.89 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_keywords" "rectifier acdc" (id 5) (at 0 0 0)
(property "ki_keywords" "rectifier acdc" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_description" "Schottky Surface Mount Bridge Rectifiers, 40V Vrms, 2A If, MBS (TO-269AA)" (id 6) (at 0 0 0)
(property "ki_description" "Schottky Surface Mount Bridge Rectifiers, 40V Vrms, 2A If, MBS (TO-269AA)" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_fp_filters" "TO?269AA*" (id 7) (at 0 0 0)
(property "ki_fp_filters" "TO?269AA*" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(symbol "KMB24F_0_1"
@@ -268,7 +311,7 @@
(xy -2.54 3.81)
(xy -1.27 2.54)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
@@ -276,7 +319,7 @@
(xy -1.27 -2.54)
(xy -2.54 -3.81)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
@@ -284,7 +327,7 @@
(xy 2.54 -1.27)
(xy 3.81 -2.54)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
@@ -292,7 +335,7 @@
(xy 2.54 1.27)
(xy 3.81 2.54)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
@@ -302,7 +345,7 @@
(xy -1.905 3.175)
(xy -3.81 2.54)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
@@ -312,7 +355,7 @@
(xy -1.905 -3.175)
(xy -2.54 -1.27)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
@@ -322,7 +365,7 @@
(xy 3.175 1.905)
(xy 1.27 2.54)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
@@ -332,7 +375,7 @@
(xy 2.54 -3.81)
(xy 3.175 -1.905)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
@@ -343,7 +386,7 @@
(xy 0 5.08)
(xy -5.08 0)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
)
@@ -367,30 +410,30 @@
)
)
(symbol "PJ75AL33SA" (pin_names (offset 0.254)) (in_bom yes) (on_board yes)
(property "Reference" "U" (id 0) (at -3.81 3.175 0)
(property "Reference" "U" (at -3.81 3.175 0)
(effects (font (size 1.27 1.27)))
)
(property "Value" "PJ75AL33SA" (id 1) (at 0 3.175 0)
(property "Value" "PJ75AL33SA" (at 0 3.175 0)
(effects (font (size 1.27 1.27)) (justify left))
)
(property "Footprint" "Package_TO_SOT_SMD:SOT-23" (id 2) (at 1.27 -8.89 0)
(property "Footprint" "Package_TO_SOT_SMD:SOT-23" (at 1.27 -8.89 0)
(effects (font (size 1.27 1.27) italic) hide)
)
(property "Datasheet" "https://datasheet.lcsc.com/lcsc/1912111437_PJSEMI-PJ75AL33SA_C411736.pdf" (id 3) (at 2.54 -11.43 0)
(property "Datasheet" "https://datasheet.lcsc.com/lcsc/1912111437_PJSEMI-PJ75AL33SA_C411736.pdf" (at 2.54 -11.43 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_keywords" "ldo linear fixed positive" (id 4) (at 0 0 0)
(property "ki_keywords" "ldo linear fixed positive" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_description" "100mA, Low Dropout Voltage Regulator, 3.3V positive fixed output, SOT-23 package" (id 5) (at 0 0 0)
(property "ki_description" "100mA, Low Dropout Voltage Regulator, 3.3V positive fixed output, SOT-23 package" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_fp_filters" "SOT?23*" (id 6) (at 0 0 0)
(property "ki_fp_filters" "SOT?23*" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(symbol "PJ75AL33SA_0_1"
(rectangle (start -5.08 1.905) (end 5.08 -5.08)
(stroke (width 0.254) (type default) (color 0 0 0 0))
(stroke (width 0.254) (type default))
(fill (type background))
)
)
@@ -410,30 +453,30 @@
)
)
(symbol "R" (pin_numbers hide) (pin_names (offset 0)) (in_bom yes) (on_board yes)
(property "Reference" "R3" (id 0) (at 0 5.08 90)
(property "Reference" "R3" (at 0 5.08 90)
(effects (font (size 1.27 1.27)))
)
(property "Value" "200" (id 1) (at 0 2.54 90)
(property "Value" "200" (at 0 2.54 90)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "Resistor_SMD:R_0603_1608Metric" (id 2) (at 1.778 0 90)
(property "Footprint" "Resistor_SMD:R_0603_1608Metric" (at 1.778 0 90)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "~" (id 3) (at 0 0 0)
(property "Datasheet" "~" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_keywords" "R res resistor" (id 4) (at 0 0 0)
(property "ki_keywords" "R res resistor" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_description" "Resistor" (id 5) (at 0 0 0)
(property "ki_description" "Resistor" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_fp_filters" "R_*" (id 6) (at 0 0 0)
(property "ki_fp_filters" "R_*" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(symbol "R_0_1"
(rectangle (start -1.016 -2.54) (end 1.016 2.54)
(stroke (width 0.254) (type default) (color 0 0 0 0))
(stroke (width 0.254) (type default))
(fill (type none))
)
)
@@ -449,16 +492,16 @@
)
)
(symbol "RP2040" (pin_names (offset 1.016)) (in_bom yes) (on_board yes)
(property "Reference" "U" (id 0) (at -29.21 49.53 0)
(property "Reference" "U" (at -29.21 49.53 0)
(effects (font (size 1.27 1.27)))
)
(property "Value" "RP2040" (id 1) (at 24.13 -49.53 0)
(property "Value" "RP2040" (at 24.13 -49.53 0)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "RP2040-Decoder_Additional_Footprints:QFN-56-1EP_7x7mm_P0.4mm_EP3.2x3.2mm" (id 2) (at -21.59 -60.96 0)
(property "Footprint" "RP2040-Decoder_Additional_Footprints:QFN-56-1EP_7x7mm_P0.4mm_EP3.2x3.2mm" (at -21.59 -60.96 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf" (id 3) (at -6.35 -64.77 0)
(property "Datasheet" "https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf" (at -6.35 -64.77 0)
(effects (font (size 1.27 1.27)) hide)
)
(symbol "RP2040_0_0"
@@ -471,7 +514,7 @@
)
(symbol "RP2040_0_1"
(rectangle (start 29.21 48.26) (end -29.21 -48.26)
(stroke (width 0.254) (type default) (color 0 0 0 0))
(stroke (width 0.254) (type default))
(fill (type background))
)
)
@@ -707,25 +750,25 @@
)
)
(symbol "T2N7002BK" (pin_names (offset 0) hide) (in_bom yes) (on_board yes)
(property "Reference" "Q" (id 0) (at 5.08 1.905 0)
(property "Reference" "Q" (at 5.08 1.905 0)
(effects (font (size 1.27 1.27)) (justify left))
)
(property "Value" "T2N7002BK" (id 1) (at 5.08 0 0)
(property "Value" "T2N7002BK" (at 5.08 0 0)
(effects (font (size 1.27 1.27)) (justify left))
)
(property "Footprint" "Package_TO_SOT_SMD:SOT-23" (id 2) (at -27.94 -8.89 0)
(property "Footprint" "Package_TO_SOT_SMD:SOT-23" (at -27.94 -8.89 0)
(effects (font (size 1.27 1.27)) (justify left) hide)
)
(property "Datasheet" "https://datasheet.lcsc.com/lcsc/1810271831_TOSHIBA-T2N7002BK-LM_C146372.pdf" (id 3) (at 13.97 -11.43 0)
(property "Datasheet" "https://datasheet.lcsc.com/lcsc/1810271831_TOSHIBA-T2N7002BK-LM_C146372.pdf" (at 13.97 -11.43 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_keywords" "N-Channel MOSFET 2N7002" (id 4) (at 0 0 0)
(property "ki_keywords" "N-Channel MOSFET 2N7002" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_description" "60V Vds, 0.4A Id, N-Channel MOSFET with ESD protection, SOT-23" (id 5) (at 0 0 0)
(property "ki_description" "60V Vds, 0.4A Id, N-Channel MOSFET with ESD protection, SOT-23" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_fp_filters" "SOT?723*" (id 6) (at 0 0 0)
(property "ki_fp_filters" "SOT?723*" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(symbol "T2N7002BK_0_1"
@@ -735,13 +778,13 @@
(xy -2.286 -3.81)
(xy -2.286 0)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
)
(symbol "T2N7002BK_1_1"
(circle (center -2.286 0) (radius 0.254)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type outline))
)
(polyline
@@ -749,7 +792,7 @@
(xy 0.254 0)
(xy -2.54 0)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
@@ -757,7 +800,7 @@
(xy 0.254 1.905)
(xy 0.254 -1.905)
)
(stroke (width 0.254) (type default) (color 0 0 0 0))
(stroke (width 0.254) (type default))
(fill (type none))
)
(polyline
@@ -765,7 +808,7 @@
(xy 0.762 -1.27)
(xy 0.762 -2.286)
)
(stroke (width 0.254) (type default) (color 0 0 0 0))
(stroke (width 0.254) (type default))
(fill (type none))
)
(polyline
@@ -773,7 +816,7 @@
(xy 0.762 0.508)
(xy 0.762 -0.508)
)
(stroke (width 0.254) (type default) (color 0 0 0 0))
(stroke (width 0.254) (type default))
(fill (type none))
)
(polyline
@@ -781,7 +824,7 @@
(xy 0.762 2.286)
(xy 0.762 1.27)
)
(stroke (width 0.254) (type default) (color 0 0 0 0))
(stroke (width 0.254) (type default))
(fill (type none))
)
(polyline
@@ -789,7 +832,7 @@
(xy 2.54 2.54)
(xy 2.54 1.778)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
@@ -798,7 +841,7 @@
(xy 2.54 0)
(xy 0.762 0)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
@@ -808,7 +851,7 @@
(xy -0.889 -3.429)
(xy -0.762 -3.302)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
@@ -818,7 +861,7 @@
(xy -0.254 -3.429)
(xy -0.889 -3.81)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
@@ -828,7 +871,7 @@
(xy 3.302 1.778)
(xy 0.762 1.778)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
@@ -838,7 +881,7 @@
(xy 2.032 -0.381)
(xy 1.016 0)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type outline))
)
(polyline
@@ -848,7 +891,7 @@
(xy 0.508 -4.191)
(xy 1.143 -3.81)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
@@ -858,7 +901,7 @@
(xy 1.143 -4.191)
(xy 1.016 -4.318)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
@@ -868,7 +911,7 @@
(xy 3.683 0.381)
(xy 3.81 0.254)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
@@ -878,23 +921,23 @@
(xy 3.683 -0.254)
(xy 3.302 0.381)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(circle (center 1.651 0) (radius 2.794)
(stroke (width 0.254) (type default) (color 0 0 0 0))
(stroke (width 0.254) (type default))
(fill (type none))
)
(circle (center 2.54 -3.81) (radius 0.254)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type outline))
)
(circle (center 2.54 -1.778) (radius 0.254)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type outline))
)
(circle (center 2.54 1.778) (radius 0.254)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type outline))
)
(pin input line (at -5.08 0 0) (length 2.54)
@@ -912,30 +955,30 @@
)
)
(symbol "W25Q64JVSSIQ" (in_bom yes) (on_board yes)
(property "Reference" "U" (id 0) (at -8.89 -10.16 0)
(property "Reference" "U" (at -8.89 -10.16 0)
(effects (font (size 1.27 1.27)))
)
(property "Value" "W25Q64JVSSIQ" (id 1) (at 3.81 -10.16 0)
(property "Value" "W25Q64JVSSIQ" (at 3.81 -10.16 0)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "Package_SO:SOIC-8_5.23x5.23mm_P1.27mm" (id 2) (at 1.27 -13.97 0)
(property "Footprint" "Package_SO:SOIC-8_5.23x5.23mm_P1.27mm" (at 1.27 -13.97 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "https://www.winbond.com/resource-files/w25q64jv%20revj%2003272018%20plus.pdf" (id 3) (at 0 -16.51 0)
(property "Datasheet" "https://www.winbond.com/resource-files/w25q64jv%20revj%2003272018%20plus.pdf" (at 0 -16.51 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_keywords" "flash memory SPI" (id 4) (at 0 0 0)
(property "ki_keywords" "flash memory SPI" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_description" "64Mb Serial Flash Memory, Standard/Dual/Quad SPI, SOIC-8" (id 5) (at 0 0 0)
(property "ki_description" "64Mb Serial Flash Memory, Standard/Dual/Quad SPI, SOIC-8" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_fp_filters" "SOIC*5.23x5.23mm*P1.27mm*" (id 6) (at 0 0 0)
(property "ki_fp_filters" "SOIC*5.23x5.23mm*P1.27mm*" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(symbol "W25Q64JVSSIQ_0_1"
(rectangle (start -10.16 7.62) (end 10.16 -8.89)
(stroke (width 0.254) (type default) (color 0 0 0 0))
(stroke (width 0.254) (type default))
(fill (type background))
)
)
@@ -975,33 +1018,33 @@
)
)
(symbol "X322512MSB4SI" (pin_names (offset 1.016) hide) (in_bom yes) (on_board yes)
(property "Reference" "Y" (id 0) (at 3.175 5.08 0)
(property "Reference" "Y" (at 3.175 5.08 0)
(effects (font (size 1.27 1.27)) (justify left))
)
(property "Value" "X322512MSB4SI" (id 1) (at 3.175 3.175 0)
(property "Value" "X322512MSB4SI" (at 3.175 3.175 0)
(effects (font (size 1.27 1.27)) (justify left))
)
(property "Footprint" "Crystal:Crystal_SMD_3225-4Pin_3.2x2.5mm" (id 2) (at 0 -13.97 0)
(property "Footprint" "Crystal:Crystal_SMD_3225-4Pin_3.2x2.5mm" (at 0 -13.97 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "https://datasheet.lcsc.com/lcsc/2103291203_Yangxing-Tech-X322512MSB4SI_C9002.pdf" (id 3) (at 22.86 -11.43 0)
(property "Datasheet" "https://datasheet.lcsc.com/lcsc/2103291203_Yangxing-Tech-X322512MSB4SI_C9002.pdf" (at 22.86 -11.43 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Frequency" "12MHz" (id 4) (at 6.35 -2.54 0)
(property "Frequency" "12MHz" (at 6.35 -2.54 0)
(effects (font (size 1.27 1.27)))
)
(property "ki_keywords" "quartz ceramic resonator oscillator" (id 5) (at 0 0 0)
(property "ki_keywords" "quartz ceramic resonator oscillator" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_description" "Four pin crystal 12MHz, GND on pins 2 and 4, SMD3225-4P Package" (id 6) (at 0 0 0)
(property "ki_description" "Four pin crystal 12MHz, GND on pins 2 and 4, SMD3225-4P Package" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_fp_filters" "Crystal*" (id 7) (at 0 0 0)
(property "ki_fp_filters" "Crystal*" (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(symbol "X322512MSB4SI_0_1"
(rectangle (start -1.143 2.54) (end 1.143 -2.54)
(stroke (width 0.3048) (type default) (color 0 0 0 0))
(stroke (width 0.3048) (type default))
(fill (type none))
)
(polyline
@@ -1009,7 +1052,7 @@
(xy -2.54 0)
(xy -2.032 0)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
@@ -1017,7 +1060,7 @@
(xy -2.032 -1.27)
(xy -2.032 1.27)
)
(stroke (width 0.508) (type default) (color 0 0 0 0))
(stroke (width 0.508) (type default))
(fill (type none))
)
(polyline
@@ -1025,7 +1068,7 @@
(xy 0 -3.81)
(xy 0 -3.556)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
@@ -1033,7 +1076,7 @@
(xy 0 3.556)
(xy 0 3.81)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
@@ -1041,7 +1084,7 @@
(xy 2.032 -1.27)
(xy 2.032 1.27)
)
(stroke (width 0.508) (type default) (color 0 0 0 0))
(stroke (width 0.508) (type default))
(fill (type none))
)
(polyline
@@ -1049,7 +1092,7 @@
(xy 2.032 0)
(xy 2.54 0)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
@@ -1059,7 +1102,7 @@
(xy 2.54 -3.556)
(xy 2.54 -2.286)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
(polyline
@@ -1069,7 +1112,7 @@
(xy 2.54 3.556)
(xy 2.54 2.286)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(stroke (width 0) (type default))
(fill (type none))
)
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+705
View File
@@ -0,0 +1,705 @@
{
"board": {
"3dviewports": [],
"design_settings": {
"defaults": {
"apply_defaults_to_fp_fields": false,
"apply_defaults_to_fp_shapes": false,
"apply_defaults_to_fp_text": false,
"board_outline_line_width": 0.1,
"copper_line_width": 0.2,
"copper_text_italic": false,
"copper_text_size_h": 1.5,
"copper_text_size_v": 1.5,
"copper_text_thickness": 0.3,
"copper_text_upright": false,
"courtyard_line_width": 0.05,
"dimension_precision": 4,
"dimension_units": 3,
"dimensions": {
"arrow_length": 1270000,
"extension_offset": 500000,
"keep_text_aligned": true,
"suppress_zeroes": false,
"text_position": 0,
"units_format": 1
},
"fab_line_width": 0.1,
"fab_text_italic": false,
"fab_text_size_h": 1.0,
"fab_text_size_v": 1.0,
"fab_text_thickness": 0.15,
"fab_text_upright": false,
"other_line_width": 0.15,
"other_text_italic": false,
"other_text_size_h": 1.0,
"other_text_size_v": 1.0,
"other_text_thickness": 0.15,
"other_text_upright": false,
"pads": {
"drill": 0.0,
"height": 0.5,
"width": 1.0
},
"silk_line_width": 0.15,
"silk_text_italic": false,
"silk_text_size_h": 1.0,
"silk_text_size_v": 1.0,
"silk_text_thickness": 0.15,
"silk_text_upright": false,
"zones": {
"45_degree_only": false,
"min_clearance": 0.2
}
},
"diff_pair_dimensions": [
{
"gap": 0.0,
"via_gap": 0.0,
"width": 0.0
}
],
"drc_exclusions": [],
"meta": {
"version": 2
},
"rule_severities": {
"annular_width": "error",
"clearance": "error",
"connection_width": "warning",
"copper_edge_clearance": "error",
"copper_sliver": "warning",
"courtyards_overlap": "warning",
"diff_pair_gap_out_of_range": "error",
"diff_pair_uncoupled_length_too_long": "error",
"drill_out_of_range": "error",
"duplicate_footprints": "warning",
"extra_footprint": "warning",
"footprint": "error",
"footprint_symbol_mismatch": "warning",
"footprint_type_mismatch": "error",
"hole_clearance": "error",
"hole_near_hole": "error",
"holes_co_located": "warning",
"invalid_outline": "error",
"isolated_copper": "warning",
"item_on_disabled_layer": "error",
"items_not_allowed": "error",
"length_out_of_range": "error",
"lib_footprint_issues": "warning",
"lib_footprint_mismatch": "warning",
"malformed_courtyard": "error",
"microvia_drill_out_of_range": "error",
"missing_courtyard": "ignore",
"missing_footprint": "warning",
"net_conflict": "warning",
"npth_inside_courtyard": "ignore",
"padstack": "error",
"pth_inside_courtyard": "ignore",
"shorting_items": "error",
"silk_edge_clearance": "warning",
"silk_over_copper": "warning",
"silk_overlap": "warning",
"skew_out_of_range": "error",
"solder_mask_bridge": "error",
"starved_thermal": "error",
"text_height": "warning",
"text_thickness": "warning",
"through_hole_pad_without_hole": "error",
"too_many_vias": "error",
"track_dangling": "warning",
"track_width": "error",
"tracks_crossing": "error",
"unconnected_items": "error",
"unresolved_variable": "error",
"via_dangling": "warning",
"zones_intersect": "error"
},
"rules": {
"allow_blind_buried_vias": false,
"allow_microvias": false,
"max_error": 0.005,
"min_clearance": 0.1,
"min_connection": 0.0,
"min_copper_edge_clearance": 0.2,
"min_hole_clearance": 0.19,
"min_hole_to_hole": 0.254,
"min_microvia_diameter": 0.2,
"min_microvia_drill": 0.1,
"min_resolved_spokes": 2,
"min_silk_clearance": 0.0,
"min_text_height": 0.8,
"min_text_thickness": 0.08,
"min_through_hole_diameter": 0.2,
"min_track_width": 0.1,
"min_via_annular_width": 0.05,
"min_via_diameter": 0.4,
"solder_mask_clearance": 0.0,
"solder_mask_min_width": 0.0,
"solder_mask_to_copper_clearance": 0.005,
"use_height_for_length_calcs": true
},
"teardrop_options": [
{
"td_onpadsmd": true,
"td_onroundshapesonly": false,
"td_ontrackend": false,
"td_onviapad": true
}
],
"teardrop_parameters": [
{
"td_allow_use_two_tracks": true,
"td_curve_segcount": 0,
"td_height_ratio": 1.0,
"td_length_ratio": 0.5,
"td_maxheight": 2.0,
"td_maxlen": 1.0,
"td_on_pad_in_zone": false,
"td_target_name": "td_round_shape",
"td_width_to_size_filter_ratio": 0.9
},
{
"td_allow_use_two_tracks": true,
"td_curve_segcount": 0,
"td_height_ratio": 1.0,
"td_length_ratio": 0.5,
"td_maxheight": 2.0,
"td_maxlen": 1.0,
"td_on_pad_in_zone": false,
"td_target_name": "td_rect_shape",
"td_width_to_size_filter_ratio": 0.9
},
{
"td_allow_use_two_tracks": true,
"td_curve_segcount": 0,
"td_height_ratio": 1.0,
"td_length_ratio": 0.5,
"td_maxheight": 2.0,
"td_maxlen": 1.0,
"td_on_pad_in_zone": false,
"td_target_name": "td_track_end",
"td_width_to_size_filter_ratio": 0.9
}
],
"track_widths": [
0.0,
0.127,
0.2,
0.25,
0.4,
0.5,
0.6,
0.75,
0.8
],
"tuning_pattern_settings": {
"diff_pair_defaults": {
"corner_radius_percentage": 80,
"corner_style": 1,
"max_amplitude": 1.0,
"min_amplitude": 0.2,
"single_sided": false,
"spacing": 1.0
},
"diff_pair_skew_defaults": {
"corner_radius_percentage": 80,
"corner_style": 1,
"max_amplitude": 1.0,
"min_amplitude": 0.2,
"single_sided": false,
"spacing": 0.6
},
"single_track_defaults": {
"corner_radius_percentage": 80,
"corner_style": 1,
"max_amplitude": 1.0,
"min_amplitude": 0.2,
"single_sided": false,
"spacing": 0.6
}
},
"via_dimensions": [
{
"diameter": 0.0,
"drill": 0.0
},
{
"diameter": 0.4,
"drill": 0.3
},
{
"diameter": 0.45,
"drill": 0.3
},
{
"diameter": 0.6,
"drill": 0.3
},
{
"diameter": 0.75,
"drill": 0.375
},
{
"diameter": 0.8,
"drill": 0.4
}
],
"zones_allow_external_fillets": false,
"zones_use_no_outline": true
},
"ipc2581": {
"dist": "",
"distpn": "",
"internal_id": "",
"mfg": "",
"mpn": ""
},
"layer_presets": [],
"viewports": []
},
"boards": [],
"cvpcb": {
"equivalence_files": []
},
"erc": {
"erc_exclusions": [],
"meta": {
"version": 0
},
"pin_map": [
[
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
2
],
[
0,
2,
0,
1,
0,
0,
1,
0,
2,
2,
2,
2
],
[
0,
0,
0,
0,
0,
0,
1,
0,
1,
0,
1,
2
],
[
0,
1,
0,
0,
0,
0,
1,
1,
2,
1,
1,
2
],
[
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
2
],
[
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
2
],
[
1,
1,
1,
1,
1,
0,
1,
1,
1,
1,
1,
2
],
[
0,
0,
0,
1,
0,
0,
1,
0,
0,
0,
0,
2
],
[
0,
2,
1,
2,
0,
0,
1,
0,
2,
2,
2,
2
],
[
0,
2,
0,
1,
0,
0,
1,
0,
2,
0,
0,
2
],
[
0,
2,
1,
1,
0,
0,
1,
0,
2,
0,
0,
2
],
[
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2
]
],
"rule_severities": {
"bus_definition_conflict": "error",
"bus_entry_needed": "error",
"bus_label_syntax": "error",
"bus_to_bus_conflict": "error",
"bus_to_net_conflict": "error",
"conflicting_netclasses": "error",
"different_unit_footprint": "error",
"different_unit_net": "error",
"duplicate_reference": "error",
"duplicate_sheet_names": "error",
"endpoint_off_grid": "warning",
"extra_units": "error",
"global_label_dangling": "warning",
"hier_label_mismatch": "error",
"label_dangling": "error",
"lib_symbol_issues": "warning",
"missing_bidi_pin": "warning",
"missing_input_pin": "warning",
"missing_power_pin": "error",
"missing_unit": "warning",
"multiple_net_names": "warning",
"net_not_bus_member": "warning",
"no_connect_connected": "warning",
"no_connect_dangling": "warning",
"pin_not_connected": "error",
"pin_not_driven": "error",
"pin_to_pin": "error",
"power_pin_not_driven": "error",
"similar_labels": "warning",
"simulation_model_issue": "ignore",
"unannotated": "error",
"unit_value_mismatch": "error",
"unresolved_variable": "error",
"wire_dangling": "error"
}
},
"libraries": {
"pinned_footprint_libs": [],
"pinned_symbol_libs": []
},
"meta": {
"filename": "RP2040-Decoder.kicad_pro",
"version": 1
},
"net_settings": {
"classes": [
{
"bus_width": 12,
"clearance": 0.2,
"diff_pair_gap": 0.25,
"diff_pair_via_gap": 0.25,
"diff_pair_width": 0.2,
"line_style": 0,
"microvia_diameter": 0.3,
"microvia_drill": 0.1,
"name": "Default",
"pcb_color": "rgba(0, 0, 0, 0.000)",
"schematic_color": "rgba(0, 0, 0, 0.000)",
"track_width": 0.25,
"via_diameter": 0.8,
"via_drill": 0.4,
"wire_width": 6
}
],
"meta": {
"version": 3
},
"net_colors": {
"+3V3": "rgb(255, 8, 12)",
"GND": "rgb(250, 0, 255)"
},
"netclass_assignments": null,
"netclass_patterns": []
},
"pcbnew": {
"last_paths": {
"gencad": "",
"idf": "",
"netlist": "",
"plot": "output/",
"pos_files": "output/",
"specctra_dsn": "",
"step": "",
"svg": "",
"vrml": ""
},
"page_layout_descr_file": ""
},
"schematic": {
"annotate_start_num": 0,
"bom_export_filename": "",
"bom_fmt_presets": [],
"bom_fmt_settings": {
"field_delimiter": ",",
"keep_line_breaks": false,
"keep_tabs": false,
"name": "CSV",
"ref_delimiter": ",",
"ref_range_delimiter": "",
"string_delimiter": "\""
},
"bom_presets": [],
"bom_settings": {
"exclude_dnp": false,
"fields_ordered": [
{
"group_by": false,
"label": "Reference",
"name": "Reference",
"show": true
},
{
"group_by": true,
"label": "Value",
"name": "Value",
"show": true
},
{
"group_by": false,
"label": "Datasheet",
"name": "Datasheet",
"show": true
},
{
"group_by": false,
"label": "Footprint",
"name": "Footprint",
"show": true
},
{
"group_by": false,
"label": "Qty",
"name": "${QUANTITY}",
"show": true
},
{
"group_by": true,
"label": "DNP",
"name": "${DNP}",
"show": true
},
{
"group_by": false,
"label": "#",
"name": "${ITEM_NUMBER}",
"show": false
},
{
"group_by": false,
"label": "Comment",
"name": "Comment",
"show": false
},
{
"group_by": false,
"label": "Frequency",
"name": "Frequency",
"show": false
},
{
"group_by": false,
"label": "Tolerance",
"name": "Tolerance",
"show": false
},
{
"group_by": false,
"label": "Voltage",
"name": "Voltage",
"show": false
},
{
"group_by": false,
"label": "Description",
"name": "Description",
"show": false
},
{
"group_by": false,
"label": "GPIO_PIN",
"name": "GPIO_PIN",
"show": false
},
{
"group_by": false,
"label": "Alternative Part",
"name": "Alternative Part",
"show": true
},
{
"group_by": false,
"label": "LCSC Part #",
"name": "LCSC Part #",
"show": true
},
{
"group_by": false,
"label": "FT Rotation Offset",
"name": "FT Rotation Offset",
"show": true
}
],
"filter_string": "",
"group_symbols": true,
"name": "",
"sort_asc": true,
"sort_field": "Reference"
},
"connection_grid_size": 50.0,
"drawing": {
"dashed_lines_dash_length_ratio": 12.0,
"dashed_lines_gap_length_ratio": 3.0,
"default_line_thickness": 6.0,
"default_text_size": 50.0,
"field_names": [],
"intersheets_ref_own_page": false,
"intersheets_ref_prefix": "",
"intersheets_ref_short": false,
"intersheets_ref_show": false,
"intersheets_ref_suffix": "",
"junction_size_choice": 3,
"label_size_ratio": 0.25,
"operating_point_overlay_i_precision": 3,
"operating_point_overlay_i_range": "~A",
"operating_point_overlay_v_precision": 3,
"operating_point_overlay_v_range": "~V",
"overbar_offset_ratio": 1.23,
"pin_symbol_size": 0.0,
"text_offset_ratio": 0.08
},
"legacy_lib_dir": "",
"legacy_lib_list": [],
"meta": {
"version": 1
},
"net_format_name": "",
"ngspice": {
"fix_include_paths": true,
"fix_passive_vals": false,
"meta": {
"version": 0
},
"model_mode": 0,
"workbook_filename": ""
},
"page_layout_descr_file": "",
"plot_directory": "/home/gab/Documents/",
"spice_adjust_passive_values": false,
"spice_current_sheet_as_root": false,
"spice_external_command": "spice \"%I\"",
"spice_model_current_sheet_as_root": true,
"spice_save_all_currents": false,
"spice_save_all_dissipations": false,
"spice_save_all_voltages": false,
"subpart_first_id": 65,
"subpart_id_separator": 0
},
"sheets": [
[
"11d18738-0f49-4d63-b61c-22a93efd5959",
"Root"
]
],
"text_variables": {}
}
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,363 @@
(footprint "SOIC-8-1EP_3.9x4.9mm_P1.27mm_EP2.41x3.3mm_ThermalVias"
(version 20240108)
(generator "pcbnew")
(generator_version "8.0")
(layer "F.Cu")
(descr "SOIC, 8 Pin (http://www.allegromicro.com/~/media/Files/Datasheets/A4950-Datasheet.ashx#page=8), generated with kicad-footprint-generator ipc_gullwing_generator.py")
(tags "SOIC SO")
(property "Reference" "REF**"
(at -0.2 -4.3 0)
(layer "F.SilkS")
(uuid "0d0f734b-55d5-4594-866a-ce6819cf8228")
(effects
(font
(size 1 1)
(thickness 0.15)
)
)
)
(property "Value" "SOIC-8-1EP_3.9x4.9mm_P1.27mm_EP2.41x3.3mm_ThermalVias"
(at 0 3.4 0)
(layer "F.Fab")
(uuid "22956637-17bd-4c2e-acb6-b78772616ce1")
(effects
(font
(size 1 1)
(thickness 0.15)
)
)
)
(property "Footprint" ""
(at 0 0 0)
(layer "F.Fab")
(hide yes)
(uuid "eab511bc-cc50-48a3-8b5e-cf001a34725a")
(effects
(font
(size 1.27 1.27)
(thickness 0.15)
)
)
)
(property "Datasheet" ""
(at 0 0 0)
(layer "F.Fab")
(hide yes)
(uuid "e79328cd-44bc-4aab-96c5-6030b6195730")
(effects
(font
(size 1.27 1.27)
(thickness 0.15)
)
)
)
(property "Description" ""
(at 0 0 0)
(layer "F.Fab")
(hide yes)
(uuid "e794e907-2974-4aa5-b0e8-8009bf377504")
(effects
(font
(size 1.27 1.27)
(thickness 0.15)
)
)
)
(attr smd)
(fp_line
(start -1.55 -2.56)
(end -3.4 -2.56)
(stroke
(width 0.12)
(type solid)
)
(layer "F.SilkS")
(uuid "5e1b6593-5e9b-46a9-b77d-e8857a7019a7")
)
(fp_line
(start -1.55 2.56)
(end -3.4 2.56)
(stroke
(width 0.12)
(type solid)
)
(layer "F.SilkS")
(uuid "d2f4f71b-dad4-477c-9332-cfa0b1762c3c")
)
(fp_line
(start 1.55 -2.56)
(end 3.4 -2.56)
(stroke
(width 0.12)
(type solid)
)
(layer "F.SilkS")
(uuid "d8ebe137-f5d5-4c2e-b1be-05e2e860bfc2")
)
(fp_line
(start 1.55 2.56)
(end 3.4 2.56)
(stroke
(width 0.12)
(type solid)
)
(layer "F.SilkS")
(uuid "4215d5a7-1062-44a9-96e2-c894457eb6a9")
)
(fp_line
(start -3.7 -2.7)
(end -3.7 2.7)
(stroke
(width 0.05)
(type solid)
)
(layer "F.CrtYd")
(uuid "3b0dc4e4-bdc2-4b50-aa3f-9e14820b2751")
)
(fp_line
(start -3.7 2.7)
(end 3.7 2.7)
(stroke
(width 0.05)
(type solid)
)
(layer "F.CrtYd")
(uuid "839afce9-2060-4cb0-b78e-caadc6bdbef9")
)
(fp_line
(start 3.7 -2.7)
(end -3.7 -2.7)
(stroke
(width 0.05)
(type solid)
)
(layer "F.CrtYd")
(uuid "e48a8fea-d898-4d03-99fa-28f365900862")
)
(fp_line
(start 3.7 2.7)
(end 3.7 -2.7)
(stroke
(width 0.05)
(type solid)
)
(layer "F.CrtYd")
(uuid "03434c57-aec9-4997-bdac-bd6bc0877cdd")
)
(fp_line
(start -1.95 -1.475)
(end -0.975 -2.45)
(stroke
(width 0.1)
(type solid)
)
(layer "F.Fab")
(uuid "27208f4d-f461-4f50-a941-8886d9234066")
)
(fp_line
(start -1.95 2.45)
(end -1.95 -1.475)
(stroke
(width 0.1)
(type solid)
)
(layer "F.Fab")
(uuid "7b8850b8-629b-406b-a955-153bdfac67a7")
)
(fp_line
(start -0.975 -2.45)
(end 1.95 -2.45)
(stroke
(width 0.1)
(type solid)
)
(layer "F.Fab")
(uuid "2c3326d8-8f3d-40cb-a7dd-fa99c40b6598")
)
(fp_line
(start 1.95 -2.45)
(end 1.95 2.45)
(stroke
(width 0.1)
(type solid)
)
(layer "F.Fab")
(uuid "5c93c3a4-8b42-477a-892d-3a4116ce4a83")
)
(fp_line
(start 1.95 2.45)
(end -1.95 2.45)
(stroke
(width 0.1)
(type solid)
)
(layer "F.Fab")
(uuid "d594cbf2-5861-4bce-8ea6-54b69faa1bde")
)
(fp_text user "${REFERENCE}"
(at 0 0 0)
(layer "F.Fab")
(uuid "114d50fb-c631-48ec-b90f-efb4be58d6c8")
(effects
(font
(size 0.98 0.98)
(thickness 0.15)
)
)
)
(pad "" smd roundrect
(at -0.6 -0.825)
(size 1.01 1.38)
(layers "F.Paste")
(roundrect_rratio 0.247525)
(uuid "0eda8a60-9156-494c-b248-9f23876b9c97")
)
(pad "" smd roundrect
(at -0.6 0.825)
(size 1.01 1.38)
(layers "F.Paste")
(roundrect_rratio 0.247525)
(uuid "02654062-e307-48a2-a672-ab6985eb502c")
)
(pad "" smd roundrect
(at 0.6 -0.825)
(size 1.01 1.38)
(layers "F.Paste")
(roundrect_rratio 0.247525)
(uuid "2ff99c2d-e844-44d0-bfc9-4f54f1b985ca")
)
(pad "" smd roundrect
(at 0.6 0.825)
(size 1.01 1.38)
(layers "F.Paste")
(roundrect_rratio 0.247525)
(uuid "275e7eda-80dc-4dae-8d5a-d69839ef7060")
)
(pad "1" smd roundrect
(at -2.475 -1.905)
(size 1.95 0.6)
(layers "F.Cu" "F.Paste" "F.Mask")
(roundrect_rratio 0.25)
(uuid "8dcf9965-4b38-4f4e-969f-578bcad555e9")
)
(pad "2" smd roundrect
(at -2.475 -0.635)
(size 1.95 0.6)
(layers "F.Cu" "F.Paste" "F.Mask")
(roundrect_rratio 0.25)
(uuid "425dcc81-ccb1-492a-ac99-b0bf1be89e2d")
)
(pad "3" smd roundrect
(at -2.475 0.635)
(size 1.95 0.6)
(layers "F.Cu" "F.Paste" "F.Mask")
(roundrect_rratio 0.25)
(uuid "56d4d9c4-0452-47df-88a8-5979c8feb2db")
)
(pad "4" smd roundrect
(at -2.475 1.905)
(size 1.95 0.6)
(layers "F.Cu" "F.Paste" "F.Mask")
(roundrect_rratio 0.25)
(uuid "53106e3f-8345-4981-a96d-68820362ebea")
)
(pad "5" smd roundrect
(at 2.475 1.905)
(size 1.95 0.6)
(layers "F.Cu" "F.Paste" "F.Mask")
(roundrect_rratio 0.25)
(uuid "ef1eddff-7709-4257-916a-36fa2baed22e")
)
(pad "6" smd roundrect
(at 2.475 0.635)
(size 1.95 0.6)
(layers "F.Cu" "F.Paste" "F.Mask")
(roundrect_rratio 0.25)
(uuid "b401095e-aca0-4b4a-8e85-319099d7598c")
)
(pad "7" smd roundrect
(at 2.475 -0.635)
(size 1.95 0.6)
(layers "F.Cu" "F.Paste" "F.Mask")
(roundrect_rratio 0.25)
(uuid "4ab1bb28-4236-42fc-aa5d-09e01f4abe45")
)
(pad "8" smd roundrect
(at 2.475 -1.905)
(size 1.95 0.6)
(layers "F.Cu" "F.Paste" "F.Mask")
(roundrect_rratio 0.25)
(uuid "61ad49d1-2f42-4f33-afdd-01be938e7e56")
)
(pad "9" thru_hole circle
(at -0.7 -1.2)
(size 0.5 0.5)
(drill 0.2)
(layers "*.Cu")
(remove_unused_layers no)
(uuid "e44650f7-3103-408b-ac51-7088faf35d1a")
)
(pad "9" thru_hole circle
(at -0.7 0)
(size 0.5 0.5)
(drill 0.2)
(layers "*.Cu")
(remove_unused_layers no)
(uuid "d63c1844-7ca4-4d96-92d7-088888b2e2e0")
)
(pad "9" thru_hole circle
(at -0.7 1.2)
(size 0.5 0.5)
(drill 0.2)
(layers "*.Cu")
(remove_unused_layers no)
(uuid "dac580e0-d592-40c4-a6a3-32f4156ddde6")
)
(pad "9" smd rect
(at 0 0)
(size 1.9 2.9)
(layers "B.Cu")
(uuid "a267eaa8-2c1c-4f35-9bdd-c1551668d64b")
)
(pad "9" smd rect
(at 0 0)
(size 2.41 3.3)
(layers "F.Cu" "F.Mask")
(uuid "492dc4b9-8891-40fa-9726-31f4ba6ae3a0")
)
(pad "9" thru_hole circle
(at 0.7 -1.2)
(size 0.5 0.5)
(drill 0.2)
(layers "*.Cu")
(remove_unused_layers no)
(uuid "1327a571-9408-4f2e-b3bb-b550b6d3a0be")
)
(pad "9" thru_hole circle
(at 0.7 0)
(size 0.5 0.5)
(drill 0.2)
(layers "*.Cu")
(remove_unused_layers no)
(uuid "38ad4bee-e334-45b6-98b3-91580c43f314")
)
(pad "9" thru_hole circle
(at 0.7 1.2)
(size 0.5 0.5)
(drill 0.2)
(layers "*.Cu")
(remove_unused_layers no)
(uuid "c6fc29d8-1848-4d54-9ceb-e114b4dd89d9")
)
(model "${KICAD8_3DMODEL_DIR}/Package_SO.3dshapes/SOIC-8_3.9x4.9mm_P1.27mm.wrl"
(offset
(xyz 0 0 0)
)
(scale
(xyz 1 1 1)
)
(rotate
(xyz 0 0 0)
)
)
)
@@ -0,0 +1,325 @@
(footprint "SOIC-8_5.23x5.23mm_P1.27mm"
(version 20240108)
(generator "pcbnew")
(generator_version "8.0")
(layer "F.Cu")
(descr "SOIC, 8 Pin (http://www.winbond.com/resource-files/w25q32jv%20revg%2003272018%20plus.pdf#page=68), generated with kicad-footprint-generator ipc_gullwing_generator.py")
(tags "SOIC SO")
(property "Reference" "REF**"
(at 0 -3.56 0)
(layer "F.SilkS")
(uuid "892c99ea-5410-4a65-9ee4-bdc09fdc90ee")
(effects
(font
(size 1 1)
(thickness 0.15)
)
)
)
(property "Value" "SOIC-8_5.23x5.23mm_P1.27mm"
(at 0 3.56 0)
(layer "F.Fab")
(uuid "c04ec0d1-7f0d-4019-91be-a6614badf406")
(effects
(font
(size 1 1)
(thickness 0.15)
)
)
)
(property "Footprint" ""
(at 0 0 0)
(layer "F.Fab")
(hide yes)
(uuid "923f8285-757f-444c-b89a-cc7fe1233c67")
(effects
(font
(size 1.27 1.27)
(thickness 0.15)
)
)
)
(property "Datasheet" ""
(at 0 0 0)
(layer "F.Fab")
(hide yes)
(uuid "a0de60f8-d40b-48e6-89a5-4fe2362b0757")
(effects
(font
(size 1.27 1.27)
(thickness 0.15)
)
)
)
(property "Description" ""
(at 0 0 0)
(layer "F.Fab")
(hide yes)
(uuid "da4bc971-83cf-41f4-9d7f-5dab7b7dde0f")
(effects
(font
(size 1.27 1.27)
(thickness 0.15)
)
)
)
(attr smd)
(fp_line
(start -2.725 -2.725)
(end -2.725 -2.465)
(stroke
(width 0.12)
(type solid)
)
(layer "F.SilkS")
(uuid "1faa07e6-bd78-437e-b4e2-cd00c2b8018d")
)
(fp_line
(start -2.725 -2.465)
(end -4.4 -2.465)
(stroke
(width 0.12)
(type solid)
)
(layer "F.SilkS")
(uuid "0ad895a6-0c83-484a-8b80-3635647eb60a")
)
(fp_line
(start -2.725 2.725)
(end -2.725 2.465)
(stroke
(width 0.12)
(type solid)
)
(layer "F.SilkS")
(uuid "00138a61-23f0-45f3-9f28-2bbd8494a1fc")
)
(fp_line
(start 0 -2.725)
(end -2.725 -2.725)
(stroke
(width 0.12)
(type solid)
)
(layer "F.SilkS")
(uuid "0ef6c909-3192-40ee-a6d7-49ae09a79a2d")
)
(fp_line
(start 0 -2.725)
(end 2.725 -2.725)
(stroke
(width 0.12)
(type solid)
)
(layer "F.SilkS")
(uuid "e0b94375-2281-4987-b4d4-78e8e535972c")
)
(fp_line
(start 0 2.725)
(end -2.725 2.725)
(stroke
(width 0.12)
(type solid)
)
(layer "F.SilkS")
(uuid "7563e6d6-e180-4d92-9939-ff14aba164c5")
)
(fp_line
(start 0 2.725)
(end 2.725 2.725)
(stroke
(width 0.12)
(type solid)
)
(layer "F.SilkS")
(uuid "599161f8-efef-47ec-8f3f-69142e759f9f")
)
(fp_line
(start 2.725 -2.725)
(end 2.725 -2.465)
(stroke
(width 0.12)
(type solid)
)
(layer "F.SilkS")
(uuid "bd45a508-6e93-4f9b-948f-0868d234cca2")
)
(fp_line
(start 2.725 2.725)
(end 2.725 2.465)
(stroke
(width 0.12)
(type solid)
)
(layer "F.SilkS")
(uuid "3a26b0fd-8ddd-4bb6-8f59-5d8caaf547d2")
)
(fp_line
(start -4.65 -2.86)
(end -4.65 2.86)
(stroke
(width 0.05)
(type solid)
)
(layer "F.CrtYd")
(uuid "d364a3b0-54fd-4659-8dce-a730d0a819b4")
)
(fp_line
(start -4.65 2.86)
(end 4.65 2.86)
(stroke
(width 0.05)
(type solid)
)
(layer "F.CrtYd")
(uuid "48c8ef75-8bc0-4249-b6fc-f564812177b5")
)
(fp_line
(start 4.65 -2.86)
(end -4.65 -2.86)
(stroke
(width 0.05)
(type solid)
)
(layer "F.CrtYd")
(uuid "15719beb-6925-433d-810a-8c40136a730d")
)
(fp_line
(start 4.65 2.86)
(end 4.65 -2.86)
(stroke
(width 0.05)
(type solid)
)
(layer "F.CrtYd")
(uuid "343b8478-4e57-4c34-a00f-f6c76028fbb0")
)
(fp_line
(start -2.615 -1.615)
(end -1.615 -2.615)
(stroke
(width 0.1)
(type solid)
)
(layer "F.Fab")
(uuid "a9e3aef9-f101-4095-bdca-1439a0a3a462")
)
(fp_line
(start -2.615 2.615)
(end -2.615 -1.615)
(stroke
(width 0.1)
(type solid)
)
(layer "F.Fab")
(uuid "02b4b413-8363-4d1b-994e-188513d8ddc7")
)
(fp_line
(start -1.615 -2.615)
(end 2.615 -2.615)
(stroke
(width 0.1)
(type solid)
)
(layer "F.Fab")
(uuid "6d79fd42-415e-413e-9d9a-317a78780624")
)
(fp_line
(start 2.615 -2.615)
(end 2.615 2.615)
(stroke
(width 0.1)
(type solid)
)
(layer "F.Fab")
(uuid "0de79bc8-6e35-4f27-a959-67075a5c995d")
)
(fp_line
(start 2.615 2.615)
(end -2.615 2.615)
(stroke
(width 0.1)
(type solid)
)
(layer "F.Fab")
(uuid "f6066510-5931-4b5c-bd2e-aa73c2658e09")
)
(fp_text user "${REFERENCE}"
(at 0 0 0)
(layer "F.Fab")
(uuid "77985a68-90d4-4d27-872a-c400b51090e9")
(effects
(font
(size 1 1)
(thickness 0.15)
)
)
)
(pad "1" smd roundrect
(at -3.6 -1.905)
(size 1.6 0.6)
(layers "F.Cu" "F.Paste" "F.Mask")
(roundrect_rratio 0.25)
(uuid "27b69982-b2ed-4600-967a-124075f92a47")
)
(pad "2" smd roundrect
(at -3.6 -0.635)
(size 1.6 0.6)
(layers "F.Cu" "F.Paste" "F.Mask")
(roundrect_rratio 0.25)
(uuid "6d25bce9-3e60-4ced-b5a9-08751e8b6fc4")
)
(pad "3" smd roundrect
(at -3.6 0.635)
(size 1.6 0.6)
(layers "F.Cu" "F.Paste" "F.Mask")
(roundrect_rratio 0.25)
(uuid "20c0617b-b9fa-402b-acac-3d6d0fd080c9")
)
(pad "4" smd roundrect
(at -3.6 1.905)
(size 1.6 0.6)
(layers "F.Cu" "F.Paste" "F.Mask")
(roundrect_rratio 0.25)
(uuid "f866660d-6ba6-48d1-8140-3aea9f62e041")
)
(pad "5" smd roundrect
(at 3.6 1.905)
(size 1.6 0.6)
(layers "F.Cu" "F.Paste" "F.Mask")
(roundrect_rratio 0.25)
(uuid "84c5eefd-df9f-4bf1-ada6-d7c8e324cafa")
)
(pad "6" smd roundrect
(at 3.6 0.635)
(size 1.6 0.6)
(layers "F.Cu" "F.Paste" "F.Mask")
(roundrect_rratio 0.25)
(uuid "8cae02d5-3e1a-460e-ab20-8d0d15978bd7")
)
(pad "7" smd roundrect
(at 3.6 -0.635)
(size 1.6 0.6)
(layers "F.Cu" "F.Paste" "F.Mask")
(roundrect_rratio 0.25)
(uuid "bfac6452-2417-4786-863e-60ca15ff175c")
)
(pad "8" smd roundrect
(at 3.6 -1.905)
(size 1.6 0.6)
(layers "F.Cu" "F.Paste" "F.Mask")
(roundrect_rratio 0.25)
(uuid "de3c0f07-7b33-4a21-a1da-0aaa6ffb3b32")
)
(model "${KICAD8_3DMODEL_DIR}/Package_SO.3dshapes/SOIC-8_5.275x5.275mm_P1.27mm.wrl"
(offset
(xyz 0 0 0)
)
(scale
(xyz 1 1 1)
)
(rotate
(xyz 0 0 0)
)
)
)
@@ -0,0 +1,318 @@
(footprint "SW_Push_1P1T_NO_Vertical_Wuerth_434133025816"
(version 20240108)
(generator "pcbnew")
(generator_version "8.0")
(layer "F.Cu")
(descr "https://katalog.we-online.com/em/datasheet/434133025816.pdf")
(tags "tactile switch Wurth Wuerth")
(property "Reference" "REF**"
(at 0.15 -2.6 0)
(layer "F.SilkS")
(uuid "a9f4af6c-1a4d-4c2a-921d-287f9a6460cc")
(effects
(font
(size 1 1)
(thickness 0.15)
)
)
)
(property "Value" "SW_Push_1P1T_NO_Vertical_Wuerth_434133025816"
(at 0 2.55 0)
(layer "F.Fab")
(uuid "bead97d6-e2d9-43ba-b967-78fdffae901d")
(effects
(font
(size 1 1)
(thickness 0.15)
)
)
)
(property "Footprint" ""
(at 0 0 0)
(unlocked yes)
(layer "F.Fab")
(hide yes)
(uuid "d8494eb8-283a-4665-be40-c5bc370c0fe3")
(effects
(font
(size 1.27 1.27)
(thickness 0.15)
)
)
)
(property "Datasheet" ""
(at 0 0 0)
(unlocked yes)
(layer "F.Fab")
(hide yes)
(uuid "4cfc36c1-5358-449f-bda2-6d0d839548a3")
(effects
(font
(size 1.27 1.27)
(thickness 0.15)
)
)
)
(property "Description" ""
(at 0 0 0)
(unlocked yes)
(layer "F.Fab")
(hide yes)
(uuid "c37b62f2-dbc1-4d71-9e15-e319984b877d")
(effects
(font
(size 1.27 1.27)
(thickness 0.15)
)
)
)
(attr smd)
(fp_line
(start -2.2 0.05)
(end -2.2 -0.05)
(stroke
(width 0.12)
(type solid)
)
(layer "F.SilkS")
(uuid "ceb53bab-ddc7-4ff9-b2de-e83d8572f116")
)
(fp_line
(start -2.2 1.75)
(end 2.2 1.75)
(stroke
(width 0.12)
(type solid)
)
(layer "F.SilkS")
(uuid "12c526c3-32a4-470b-93bb-dbf407333418")
)
(fp_line
(start 2.2 -1.75)
(end -2.2 -1.75)
(stroke
(width 0.12)
(type solid)
)
(layer "F.SilkS")
(uuid "7dd9260b-55dd-42a6-90ec-094dcfaff6b2")
)
(fp_line
(start 2.2 0.05)
(end 2.2 -0.05)
(stroke
(width 0.12)
(type solid)
)
(layer "F.SilkS")
(uuid "da0e3716-2c9e-4ac5-b2c3-d6a1a5098034")
)
(fp_line
(start -2.85 -1.85)
(end 2.85 -1.85)
(stroke
(width 0.05)
(type solid)
)
(layer "F.CrtYd")
(uuid "a0fd66f8-9e74-45e4-a67a-1218e3422a82")
)
(fp_line
(start -2.85 1.85)
(end -2.85 -1.85)
(stroke
(width 0.05)
(type solid)
)
(layer "F.CrtYd")
(uuid "fe2c281c-c2c3-4958-9d44-5cad75d0b194")
)
(fp_line
(start 2.85 -1.85)
(end 2.85 1.85)
(stroke
(width 0.05)
(type solid)
)
(layer "F.CrtYd")
(uuid "c70dcf49-d773-4e5f-a235-6b0699407a03")
)
(fp_line
(start 2.85 1.85)
(end -2.85 1.85)
(stroke
(width 0.05)
(type solid)
)
(layer "F.CrtYd")
(uuid "cab4cd64-574a-4a52-932e-d254f66e002b")
)
(fp_line
(start -2.1 -1.6)
(end 2.1 -1.6)
(stroke
(width 0.1)
(type solid)
)
(layer "F.Fab")
(uuid "5bae3724-7d31-49dc-84c5-aa6f63fc9c26")
)
(fp_line
(start -2.1 -1.1)
(end -1.6 -1.6)
(stroke
(width 0.1)
(type solid)
)
(layer "F.Fab")
(uuid "3a178eda-7cc8-40cf-8c89-7cb4dc8a7a0a")
)
(fp_line
(start -2.1 1.1)
(end -1.6 1.6)
(stroke
(width 0.1)
(type solid)
)
(layer "F.Fab")
(uuid "50203e2b-6fd4-4cea-87d2-703f09c0e45a")
)
(fp_line
(start -2.1 1.6)
(end -2.1 -1.6)
(stroke
(width 0.1)
(type solid)
)
(layer "F.Fab")
(uuid "f575139d-3730-409a-93b8-0ed720da29e8")
)
(fp_line
(start -0.9 -1.1)
(end 0.8 -1.1)
(stroke
(width 0.1)
(type solid)
)
(layer "F.Fab")
(uuid "f02dddc1-1070-4d43-b76b-5d313c254800")
)
(fp_line
(start 0.8 1.1)
(end -0.9 1.1)
(stroke
(width 0.1)
(type solid)
)
(layer "F.Fab")
(uuid "74306571-f6d4-4374-a16b-77c5c2982723")
)
(fp_line
(start 1.6 -1.6)
(end 2.1 -1.1)
(stroke
(width 0.1)
(type solid)
)
(layer "F.Fab")
(uuid "c6ea45e9-1b0b-4390-9f54-e519b3eb83e1")
)
(fp_line
(start 1.6 1.6)
(end 2.1 1.1)
(stroke
(width 0.1)
(type solid)
)
(layer "F.Fab")
(uuid "a743549d-ee13-4212-9744-42ed8529ed3a")
)
(fp_line
(start 2.1 -1.6)
(end 2.1 1.6)
(stroke
(width 0.1)
(type solid)
)
(layer "F.Fab")
(uuid "8803e8b9-0976-49b1-bd25-78f6f796f285")
)
(fp_line
(start 2.1 1.6)
(end -2.1 1.6)
(stroke
(width 0.1)
(type solid)
)
(layer "F.Fab")
(uuid "25af75f2-944c-4139-a67f-1b5e9791fa6c")
)
(fp_arc
(start -0.9 1.099999)
(mid -1.460147 0)
(end -0.9 -1.099999)
(stroke
(width 0.1)
(type solid)
)
(layer "F.Fab")
(uuid "abfb9586-4ac0-4ba1-a499-bd184116803d")
)
(fp_arc
(start 0.8 -1.099999)
(mid 1.40384 0)
(end 0.799999 1.099999)
(stroke
(width 0.1)
(type solid)
)
(layer "F.Fab")
(uuid "b77730ba-7e92-4243-9e30-d378944aba33")
)
(fp_text user "${REFERENCE}"
(at 0.05 0 0)
(layer "F.Fab")
(uuid "682222be-9c4e-4642-ab4b-85af8d4f11f3")
(effects
(font
(size 1 1)
(thickness 0.15)
)
)
)
(pad "1" smd rect
(at -2.075 -1.075)
(size 1.05 0.65)
(layers "F.Cu" "F.Paste" "F.Mask")
(uuid "cbe7fb4a-7a24-4701-91b1-bb5498e198db")
)
(pad "1" smd rect
(at 2.075 -1.075)
(size 1.05 0.65)
(layers "F.Cu" "F.Paste" "F.Mask")
(uuid "f83bd855-34b5-443b-83cd-22c5a803e55d")
)
(pad "2" smd rect
(at -2.075 1.075)
(size 1.05 0.65)
(layers "F.Cu" "F.Paste" "F.Mask")
(uuid "65e74ebe-b92b-42ae-8e79-6e76f3539250")
)
(pad "2" smd rect
(at 2.05 1.075)
(size 1.05 0.65)
(layers "F.Cu" "F.Paste" "F.Mask")
(uuid "cc3e09e2-232b-4826-aa79-e19bc91e38da")
)
(model "${KIPRJMOD}/434133025816.stp"
(offset
(xyz 0 0 0)
)
(scale
(xyz 1 1 1)
)
(rotate
(xyz -90 0 -90)
)
)
)
+3
View File
@@ -0,0 +1,3 @@
(fp_lib_table
(lib (name "RP2040-Decoder_Additional_Footprints")(type "KiCad")(uri "${KIPRJMOD}")(options "")(descr ""))
)
+3
View File
@@ -0,0 +1,3 @@
(sym_lib_table
(lib (name "RP2040-Decoder_Additional_Symbols")(type "KiCad")(uri "${KIPRJMOD}/RP2040-Decoder_Additional_Symbols.kicad_sym")(options "")(descr ""))
)
+10 -10
View File
@@ -8,35 +8,35 @@ Features
- DCC digital signal decoding
- Motor load/speed control
- 4 Outputs to drive loads up to 400mA each
- 6 GPIO for lighter loads or custom applications
- 4 Outputs switched by transistors with configurable optional PWM
- 6 additional GPIO for lighter loads or custom applications
- Programmable on programming track
- CV Function Mapping
- Board size of 25x20 mm
- Pre-compiled software available and flashable via USB using your regular file explorer
- Debugging via Serial Wire Debug or optional logging via stdio and UART/USB serial port
Getting Started
------------
The [Wiki - Getting started](https://github.com/gab-k/RP2040-Decoder/wiki/Getting-started) page provides a brief overview.
A Description on how to compile and flash the decoder using Windows can be found [here](https://github.com/gab-k/RP2040-Decoder/wiki/Quick-start-guide-(Windows)).
The ["Getting Started"](https://github.com/gab-k/RP2040-Decoder/wiki/Getting-started) page provides an overview of the steps required to use the decoder as well as brief instructions for all the necessary steps.
License
-------
- Software - MIT license
- Hardware - CERN Open Hardware Licence Version 2 - Permissive
- [LICENSE](https://github.com/1nct/RP2040-Decoder/blob/main/LICENSE)
- [LICENSE](https://github.com/gab-k/RP2040-Decoder/blob/main/LICENSE)
------------
Further details about the project can be found here: [RP2040-Decoder Wiki](https://github.com/GabrielKoppenstein/pico-decoder/wiki)
Further details about the project can be found here: [RP2040-Decoder Wiki](https://github.com/gab-k/RP2040-Decoder/wiki)
Note: The decoder is still in early development, there might (will) be bugs as its not tested that much yet.
So suggestions on how to improve things and bug reports are always much appreciated.
The wiki is also work in progress and will be updated to be as comprehensive as possible.
------------
<p float="left">
<img src="/docs/png/RP2040-Decoder-Rev_0_2_front.png" alt="PCB Front Side Image" title="Front" width="400"/>
<img src="/docs/png/RP2040-Decoder-Rev_0_2_back.png" alt="PCB Back Side Image" title="Back" width="400"/>
</p>
![rotating gif of RP2040-Decoder](https://raw.githubusercontent.com/gab-k/RP2040-Decoder/refs/heads/gh-pages-dev/img/rotating.gif)
+1
View File
@@ -0,0 +1 @@
build
+141
View File
@@ -0,0 +1,141 @@
# Generated Cmake Pico project file
cmake_minimum_required(VERSION 3.13)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Initialise pico_sdk from installed location
# (note this can come from environment, CMake cache etc)
# == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work ==
if(WIN32)
set(USERHOME $ENV{USERPROFILE})
else()
set(USERHOME $ENV{HOME})
endif()
set(sdkVersion 2.1.0)
set(toolchainVersion 13_3_Rel1)
set(picotoolVersion 2.1.0)
set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake)
if (EXISTS ${picoVscode})
include(${picoVscode})
endif()
# ====================================================================================
set(PICO_BOARD_HEADER_DIRS ${CMAKE_SOURCE_DIR})
# Board type selection:
#
# Please select RP2040-Decoder-board-Rev-1_0 for Rev >= 1.0 or RP2040-Decoder-board-Rev-0_3 for Rev <= 0.3
# running cmake with -DPICO_BOARD=RP2040-Decoder-board-Rev-X_Y explicitly from command line overrides this setting
set(PICO_BOARD RP2040-Decoder-board-Rev-1_0 CACHE STRING "Board type")
# Pull in Raspberry Pi Pico SDK (must be before project)
include(pico_sdk_import.cmake)
project(RP2040-Decoder C CXX ASM)
# Initialise the Raspberry Pi Pico SDK
pico_sdk_init()
# Manual compiler options, these generally override configuration set by CMAKE_BUILD_TYPE
add_compile_options(-Wall
# -O0 # Overrides optimization flags specified by CMAKE_BUILD_TYPE
# -g3 # Overrides debug flags specified by CMAKE_BUILD_TYPE
-Wno-format # unsigned int = uint32_t using gcc so don't warn about format
-Wno-unused-function # Some defined functions used for debugging are never called or not used when logging is disabled
)
# Add executable
add_executable( RP2040-Decoder
core0.c
core0.h
core1.c
core1.h
shared.c
shared.h )
pico_set_program_name(RP2040-Decoder "RP2040-Decoder")
# Build type
message("CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
message("PICO_DEOPTIMIZED_DEBUG: ${PICO_DEOPTIMIZED_DEBUG}")
if(NOT CMAKE_BUILD_TYPE)
message(WARNING "CMAKE_BUILD_TYPE is not set. Defaulting to 'Release'")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type" FORCE)
endif()
# Logging configuration:
#
# LOGLEVEL>0 enables logging messages via stdio, this can be done either via USB or alternatively,
# directly with the UART TX/RX pins (see pin definition in RP2040-Decoder-board.h).
#
# In order to use stdio via USB please set STDIO_USB_ENABLED to 1 below
# In order to use stdio via UART TX/RX pins please set STDIO_UART_ENABLED to 1 below
#
# Additional Notes:
# - When logging is disabled (LOGLEVEL 0), all logging functions will be completely excluded during compilation.
# - Be cautious: Logging can alter timing behavior. For example, the PID controller is time critical,
# limit the frequency of log outputs—such as logging only every 100th iteration.
# - Note that with UART logging enabled, PICO_DEFAULT_UART_TX_PIN and PICO_DEFAULT_UART_RX_PIN are disabled for decoder functions.
# These pins are used for UART communication. Disabling is done automatically in RP2040-Decoder-board.h or RP2040-Decoder-board-legacy.h respectively.
set(LOGLEVEL 1)
# Additionally, the LOG_WAIT parameter can be configured to make the controller wait for user input via stdio before continuing.
# This is useful for ensuring that all stdio logging outputs are captured.
# If disabled, there may not be enough time to connect the serial terminal before most of the logging has already been completed.
set(LOG_WAIT 0)
# Modify the below lines to enable/disable output over UART and/or USB
set(STDIO_USB_ENABLED 1)
set(STDIO_UART_ENABLED 0)
# Leave those two unmodified
pico_enable_stdio_uart(RP2040-Decoder ${STDIO_UART_ENABLED})
pico_enable_stdio_usb(RP2040-Decoder ${STDIO_USB_ENABLED})
# Add a preprocessor definition which defines whether UART is used or not.
# This is done to make the C-Code know whether pins used for UART need to be reserved and restricted from setting them as PWM/GPIO.
target_compile_definitions( RP2040-Decoder PRIVATE
LOGLEVEL=${LOGLEVEL}
LOG_WAIT=${LOG_WAIT}
STDIO_UART_ENABLED=${STDIO_UART_ENABLED}
STDIO_USB_ENABLED=${STDIO_USB_ENABLED}
)
# Warn when logging is enabled (LOGLEVEL>0) and neither stdio is enabled
if (LOGLEVEL GREATER 0 AND (STDIO_USB_ENABLED EQUAL 0 AND STDIO_UART_ENABLED EQUAL 0))
message(WARNING "\nWARNING: Logging (LOGLEVEL>0) enabled with both STDIO_USB_ENABLED and STDIO_UART_ENABLED disabled!")
endif()
if (LOGLEVEL EQUAL 0 AND LOG_WAIT EQUAL 1)
message(WARNING "\nWARNING: LOG_WAIT enabled with Logging disabled (LOGLEVEL==0)!")
endif()
# Add the standard library to the build
target_link_libraries( RP2040-Decoder
pico_stdlib
pico_multicore
pico_flash
hardware_pwm
hardware_adc
hardware_flash
hardware_watchdog
hardware_exception )
# Add the standard include files to the build
target_include_directories(RP2040-Decoder PRIVATE ${CMAKE_CURRENT_LIST_DIR})
# create map/bin/hex file etc.
pico_add_extra_outputs(RP2040-Decoder)
# Program size check
#
# Check for program size exceeding limits as CVs are stored at the end of flash, the program could theoretically overwrite this.
# In practice the program size is usually does not exceed about 100KiB, the actual size is printed by CMake from arm-none-eabi-size.
# Extract the directory of the C compiler and construct the path to the 'arm-none-eabi-size' tool
get_filename_component(C_COMPILER_DIR ${CMAKE_C_COMPILER} DIRECTORY)
set(SIZE_TOOL ${C_COMPILER_DIR}/arm-none-eabi-size)
set(BOARD_HEADER "${CMAKE_SOURCE_DIR}/${PICO_BOARD}.h")
set(ELF_FILE "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.elf")
add_custom_command(TARGET RP2040-Decoder POST_BUILD
COMMAND ${CMAKE_COMMAND}
-D BOARD_HEADER=${BOARD_HEADER}
-D SIZE_TOOL=${SIZE_TOOL}
-D ELF_FILE=${ELF_FILE}
-P ${CMAKE_SOURCE_DIR}/post_build.cmake
)
+1136 -616
View File
File diff suppressed because it is too large. Load diff
+91
View File
@@ -0,0 +1,91 @@
/*
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
// -----------------------------------------------------
// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO
// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES
// -----------------------------------------------------
// Modified version of "boards/pico.h" for using the RP2040-Decoder board
// NOTE: THIS IS FOR THE "LEGACY" Version without a USB-C Connector
// pico_cmake_set PICO_PLATFORM=rp2040
#ifndef _BOARDS_RP2040_DECODER_H
#define _BOARDS_RP2040_DECODER_H
// For board detection
#define RP2040_DECODER
// In case the xosc takes longer to stabilize than usual
#ifndef PICO_XOSC_STARTUP_DELAY_MULTIPLIER
#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64
#endif
// --- UART ---
#ifndef PICO_DEFAULT_UART
#define PICO_DEFAULT_UART 0
#endif
#ifndef PICO_DEFAULT_UART_TX_PIN
#define PICO_DEFAULT_UART_TX_PIN 0
#endif
#ifndef PICO_DEFAULT_UART_RX_PIN
#define PICO_DEFAULT_UART_RX_PIN 1
#endif
// --- FLASH ---
// Flash size is 8 MiB for W25Q64JVSSIQ if you decide to use another capacity flash IC change the size to the corresponding value
// 8MiB = (8 * 1024 * 1024) bytes = 8388608 bytes
#ifndef PICO_FLASH_SIZE_BYTES
#define PICO_FLASH_SIZE_BYTES 8388608
#endif
// Offset from base address used for saving CV_ARRAY_FLASH - in this case one sector size from the end of flash
#define FLASH_TARGET_OFFSET (PICO_FLASH_SIZE_BYTES-FLASH_SECTOR_SIZE)
// For some reason the clock divider of 4 is necessary, otherwise the controller occasionally hard faults
// Another workaround could be to run code from RAM but this seems to work fine
#ifndef PICO_FLASH_SPI_CLKDIV
#define PICO_FLASH_SPI_CLKDIV 4
#endif
#ifndef PICO_RP2040_B0_SUPPORTED
#define PICO_RP2040_B0_SUPPORTED 1
#endif
// Other pins
// GPIO used for DCC-Signal, Motor PWM or ADC
#define DCC_INPUT_PIN 21u
#define MOTOR_FWD_PIN 23u
#define MOTOR_REV_PIN 22u
#define FWD_V_EMF_ADC_PIN 28u
#define REV_V_EMF_ADC_PIN 29u
#define FWD_V_EMF_ADC_CHANNEL (FWD_V_EMF_ADC_PIN-26u)
#define REV_V_EMF_ADC_CHANNEL (REV_V_EMF_ADC_PIN-26u)
#if LOGLEVEL != 0
// GPIO used directly (GPIO 2-5 incl.) as outputs or to switch auxiliary output transistors (GPIO 24-27 incl.)
#define GPIO_OUTPUT_PIN_MASK ((1u<<24) | (1u<<25) | (1u<<26) | (1u<<27) | (1u<<5) | (1u<<4) | (1u<<3) | (1u<<2))
#else
// GPIO used directly (GPIO 0-5 incl.) as outputs or to switch auxiliary output transistors (GPIO 24-27 incl.)
#define GPIO_OUTPUT_PIN_MASK ((1u<<24) | (1u<<25) | (1u<<26) | (1u<<27) | (1u<<5) | (1u<<4) | (1u<<3) | (1u<<2) | (1u<<1) | (1u<<0))
#endif
// GPIO pin mask to prevent setting illegal GPIOs (ADC, Motor, DCC Input Pin)
// When logging to stdio using UART is enabled do NOT use PICO_DEFAULT_UART_TX_PIN and PICO_DEFAULT_UART_RX_PIN as GPIO/PWM outputs
#if (LOGLEVEL != 0) && (STDIO_UART_ENABLED != 0)
#define GPIO_ILLEGAL_MASK ((1u<<DCC_INPUT_PIN) | (1u<<MOTOR_FWD_PIN) | (1u<<MOTOR_REV_PIN) | (1u<<FWD_V_EMF_ADC_PIN) | (1u<<REV_V_EMF_ADC_PIN) | (1u<<PICO_DEFAULT_UART_TX_PIN) | (1u<<PICO_DEFAULT_UART_RX_PIN))
#else
#define GPIO_ILLEGAL_MASK ((1u<<DCC_INPUT_PIN) | (1u<<MOTOR_FWD_PIN) | (1u<<MOTOR_REV_PIN) | (1u<<FWD_V_EMF_ADC_PIN) | (1u<<REV_V_EMF_ADC_PIN))
#endif
// GPIO pin mask with allowed outputs (AUX & GPIO (configured as outputs))
#define GPIO_ALLOWED_OUTPUTS (GPIO_OUTPUT_PIN_MASK) & ~(GPIO_ILLEGAL_MASK)
#endif
+96
View File
@@ -0,0 +1,96 @@
/*
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
// -----------------------------------------------------
// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO
// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES
// -----------------------------------------------------
// Modified version of "boards/pico.h" for using the RP2040-Decoder board
// pico_cmake_set PICO_PLATFORM=rp2040
#ifndef _BOARDS_RP2040_DECODER_H
#define _BOARDS_RP2040_DECODER_H
// For board detection
#define RP2040_DECODER
// In case the xosc takes longer to stabilize than usual
#ifndef PICO_XOSC_STARTUP_DELAY_MULTIPLIER
#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64
#endif
// --- UART ---
#ifndef PICO_DEFAULT_UART
#define PICO_DEFAULT_UART 0
#endif
#ifndef PICO_DEFAULT_UART_TX_PIN
#define PICO_DEFAULT_UART_TX_PIN 0
#endif
#ifndef PICO_DEFAULT_UART_RX_PIN
#define PICO_DEFAULT_UART_RX_PIN 1
#endif
// --- LED ---
#ifndef RP2040_DECODER_DEFAULT_LED_PIN
#define RP2040_DECODER_DEFAULT_LED_PIN 12
#endif
// --- FLASH ---
// Flash size is 8 MiB for W25Q64JVSSIQ if you decide to use another capacity flash IC change the size to the corresponding value
// 8MiB = (8 * 1024 * 1024) bytes = 8388608 bytes
#ifndef PICO_FLASH_SIZE_BYTES
#define PICO_FLASH_SIZE_BYTES 8388608
#endif
// Offset from base address used for saving CV_ARRAY_FLASH - in this case one sector size from the end of flash
#define FLASH_TARGET_OFFSET (PICO_FLASH_SIZE_BYTES-FLASH_SECTOR_SIZE)
// For some reason the clock divider of 4 is necessary, otherwise the controller occasionally hard faults
// Another workaround could be to run code from RAM but this seems to work fine
#ifndef PICO_FLASH_SPI_CLKDIV
#define PICO_FLASH_SPI_CLKDIV 4
#endif
#ifndef PICO_RP2040_B0_SUPPORTED
#define PICO_RP2040_B0_SUPPORTED 1
#endif
// Other pins
// GPIO used for DCC-Signal, Motor PWM or ADC
#define DCC_INPUT_PIN 21u
#define MOTOR_FWD_PIN 23u
#define MOTOR_REV_PIN 22u
#define FWD_V_EMF_ADC_PIN 29u
#define REV_V_EMF_ADC_PIN 28u
#define FWD_V_EMF_ADC_CHANNEL (FWD_V_EMF_ADC_PIN-26u)
#define REV_V_EMF_ADC_CHANNEL (REV_V_EMF_ADC_PIN-26u)
#if LOGLEVEL != 0
// GPIO used directly (GPIO 2-5 incl.) as outputs or to switch auxiliary output transistors (GPIO 24-27 incl.)
#define GPIO_OUTPUT_PIN_MASK ((1u<<24) | (1u<<25) | (1u<<26) | (1u<<27) | (1u<<5) | (1u<<4) | (1u<<3) | (1u<<2))
#else
// GPIO used directly (GPIO 0-5 incl.) as outputs or to switch auxiliary output transistors (GPIO 24-27 incl.)
#define GPIO_OUTPUT_PIN_MASK ((1u<<24) | (1u<<25) | (1u<<26) | (1u<<27) | (1u<<5) | (1u<<4) | (1u<<3) | (1u<<2) | (1u<<1) | (1u<<0))
#endif
// GPIO pin mask to prevent setting illegal GPIOs (ADC, Motor, DCC Input Pin)
// When logging to stdio using UART is enabled do NOT use PICO_DEFAULT_UART_TX_PIN and PICO_DEFAULT_UART_RX_PIN as GPIO/PWM outputs
#if (LOGLEVEL != 0) && (STDIO_UART_ENABLED != 0)
#define GPIO_ILLEGAL_MASK ((1u<<DCC_INPUT_PIN) | (1u<<MOTOR_FWD_PIN) | (1u<<MOTOR_REV_PIN) | (1u<<FWD_V_EMF_ADC_PIN) | (1u<<REV_V_EMF_ADC_PIN) | (1u<<PICO_DEFAULT_UART_TX_PIN) | (1u<<PICO_DEFAULT_UART_RX_PIN))
#else
#define GPIO_ILLEGAL_MASK ((1u<<DCC_INPUT_PIN) | (1u<<MOTOR_FWD_PIN) | (1u<<MOTOR_REV_PIN) | (1u<<FWD_V_EMF_ADC_PIN) | (1u<<REV_V_EMF_ADC_PIN))
#endif
// GPIO pin mask with allowed outputs (AUX & GPIO (configured as outputs))
#define GPIO_ALLOWED_OUTPUTS (GPIO_OUTPUT_PIN_MASK) & ~(GPIO_ILLEGAL_MASK)
#endif
+826
View File
@@ -0,0 +1,826 @@
//////////////////////////
// RP2040-Decoder //
// Gabriel Koppenstein //
// core0.c //
//////////////////////////
#include "core0.h"
// Define pointer to CV array stored in flash memory, FLASH_TARGET_OFFSET is defined in CMakeLists.txt and depending on flash size,
// it gets stored in the highest address flash sector possible, to avoid interference with the program code.
// CMakelists.txt also checks for program code exceeding past the last sector. Just have to make sure the correct flash size is set in CMakeLists.txt
const uint8_t *CV_ARRAY_FLASH = (const uint8_t *) (XIP_BASE + FLASH_TARGET_OFFSET);
// level_table is used to store pwm levels for any output using PWM
uint16_t level_table[sizeof(uint32_t)*8] = {0};
// Volatile due to modification in gpio interrupt context
volatile absolute_time_t falling_edge_time, rising_edge_time;
// Input bit buffer for DCC signal
uint64_t input_bit_buffer = 0;
dcc_ring_buffer_t dcc_r_buf = {0};
static void increment_ring_buffer_idx(size_t * idx, uint8_t ring_buffer_length) {
// Takes index variable as a pointer and increments it by 1. When index reaches the end of the ring buffer, it wraps around.
// The wrap around value is the length of the ring buffer.
*idx = (*idx + 1) % ring_buffer_length;
}
static size_t get_flash_size() {
// Function to read the flash size of the chip, used for debugging/testing purposes
// Prepare TX and RX buffers for reading the JEDEC ID
uint8_t tx_buf[4] = { FLASH_CMD_READ_JEDEC_ID, 0, 0, 0 }; // Send the 0x9F command
uint8_t rx_buf[4] = { 0, 0, 0, 0 }; // RX buffer for the response
size_t buf_size = sizeof(tx_buf);
void * params[] = {tx_buf, rx_buf, &buf_size};
int ret_val = flash_safe_execute(call_flash_do_cmd, params, FLASH_TIMEOUT_IN_MS);
if (ret_val != PICO_OK){
set_error(FLASH_SIZE_READBACK_FAILURE);
return 0;
}
// The third byte of the response (rxbuf[3]) contains the log2 size (e.g., 0x18 for 16 MB)
if (rx_buf[3] == 0) {
set_error(FLASH_SIZE_READBACK_FAILURE);
return 0;
}
// Calculate the actual size (2^size_code bytes)
size_t flash_size = (1u<<rx_buf[3]);
// Return the flash size in bytes
return flash_size;
}
void hardfault_handler(void) {
// Custom HardFault handler
// Log hardfault
LOG(1, "HARDFAULT @ core%u!\n", get_core_num());
LOG(1, "Rebooting...\n")
// Hardfault can't be recovered, trigger the watchdog to reset the system
watchdog_reboot(0, 0, 1);
}
static void trigger_hardfault(void) {
// Force a hardfault, used for debugging/testing purposes
__asm volatile("UDF #0"); // Undefined instruction
}
static void call_flash_range_erase(void *param) {
// This function will be called when it's safe to call flash_range_erase
// Always erases one sector, see FLASH_SECTOR_SIZE
// Flash can only be erased in sectors, which effectively sets all bits to 1
// Flash can than be programmed by setting bits to 0
// Extract the parameters
uint32_t offset = ((uintptr_t*)param)[0];
uint32_t byte_count = ((uintptr_t*)param)[1];
// Check for offset alignment (Must be aligned to a 4096-byte flash sector)
// Check byte count (Must be a multiple of 4096 bytes (one sector))
if ((offset % FLASH_SECTOR_SIZE != 0) || (byte_count % FLASH_SECTOR_SIZE !=0)) {
set_error(FLASH_SAFE_EXECUTE_PROGRAM_FAILURE);
return;
}
flash_range_erase(offset, byte_count);
}
static void call_flash_range_program(void *param) {
// This function will be called when it's safe to call flash_range_program
// Extract the parameters
uint32_t offset = ((uintptr_t*)param)[0];
uint32_t byte_count = ((uintptr_t*)param)[1];
const uint8_t *data = (const uint8_t *)((uintptr_t*)param)[2];
// Check for offset alignment (Must be aligned to a 256-byte flash page)
// Check byte count (Must be a multiple of 256 bytes (one page))
if ((offset % FLASH_PAGE_SIZE != 0) || (byte_count % FLASH_PAGE_SIZE != 0)) {
set_error(FLASH_SAFE_EXECUTE_PROGRAM_FAILURE);
return;
}
flash_range_program(offset, data, byte_count);
}
static void call_flash_do_cmd(void *param) {
// This function will be called when it's safe to call flash_do_cmd
// Cast void pointer to void pointer array
void **params = (void **)param;
// Extract the parameters
uint8_t * tx_buf = (uint8_t *)params[0];
uint8_t * rx_buf = (uint8_t *)params[1];
uint8_t * size_ptr = (uint8_t *)params[2];
flash_do_cmd(tx_buf, rx_buf, *size_ptr);
}
unsigned int absolute_val(int x) {
// Extract the sign bit
int mask = x >> (sizeof(x) * 8 - 1);
return (x + mask) ^ mask;
}
static uint16_t two_std_dev(const uint16_t arr[], const uint32_t length) {
// Calculate arithmetic average
uint64_t sum = 0;
for (uint32_t i = 0; i < length; ++i) {
sum += arr[i];
}
const uint64_t x_avg = sum / length;
// Calculate sample variance and sampled standard deviation
sum = 0;
for (uint32_t i = 0; i < length; ++i) {
sum += (arr[i] - x_avg) * (arr[i] - x_avg);
}
const uint16_t variance = sum / (length-1);
const uint16_t std_dev = (uint16_t) sqrtf((float) variance);
// Sum every element that is within two times the sampled standard deviation and compute new average
sum = 0;
uint32_t counter = 0;
for (uint32_t i = 0; i < length; ++i) {
const uint32_t diff = absolute_val(arr[i] - x_avg);
if ( diff <= 2*std_dev ){
sum += arr[i];
counter++;
}
}
return sum / counter;
}
static void adc_offset_adjustment(uint32_t const n) {
// Measures constant adc offset and programs the offset into flash
LOG(1, "ADC offset adjustment with %u iterations...\n", n);
uint16_t offsets_fwd[n];
uint16_t offsets_rev[n];
// Set PWM level to 0 just to be sure
pwm_set_gpio_level(MOTOR_FWD_PIN, 0);
pwm_set_gpio_level(MOTOR_REV_PIN, 0);
busy_wait_ms(1000);
// Measure n times in (reverse direction)
LOG(1, "Measuring ADC offset in reverse direction (input channel: %u)...\n", REV_V_EMF_ADC_CHANNEL);
adc_select_input(REV_V_EMF_ADC_CHANNEL);
adc_run(true);
for (uint32_t i = 0; i < n; i++) {
offsets_rev[i] = adc_fifo_get_blocking();
}
adc_run(false);
adc_fifo_drain();
LOG(1, "Done measuring in reverse direction...\n");
busy_wait_ms(1000);
// Measure n times in (forward direction)
LOG(1, "Measuring ADC offset in forward direction (input channel: %u)...\n", FWD_V_EMF_ADC_CHANNEL);
adc_select_input(FWD_V_EMF_ADC_CHANNEL);
adc_run(true);
for (uint32_t i = 0; i < n; i++) {
offsets_fwd[i] = adc_fifo_get_blocking();
}
adc_run(false);
adc_fifo_drain();
LOG(1, "Done measuring in forward direction...\n");
// Find overall average discarding outliers in measurement
const uint16_t offset_avg_fwd = two_std_dev(offsets_fwd, n);
const uint16_t offset_avg_rev = two_std_dev(offsets_rev, n);
const uint16_t overall_avg_offset = (offset_avg_fwd + offset_avg_rev) / 2;
LOG(1, "New ADC Offset value CV_172 = %u\n", overall_avg_offset);
// Create temporary array -> change CV 172 in temp array -> erase flash -> write temp array to flash
uint8_t CV_ARRAY_TEMP[CV_ARRAY_SIZE];
memcpy(CV_ARRAY_TEMP, CV_ARRAY_FLASH, sizeof(CV_ARRAY_TEMP));
CV_ARRAY_TEMP[171] = overall_avg_offset;
uintptr_t params_erase[] = {FLASH_TARGET_OFFSET, FLASH_SECTOR_SIZE};
int ret_val = flash_safe_execute(call_flash_range_erase, params_erase, FLASH_TIMEOUT_IN_MS);
if (ret_val != PICO_OK){
set_error(FLASH_SAFE_EXECUTE_ERASE_FAILURE);
return;
}
uintptr_t params_program[] = {FLASH_TARGET_OFFSET, sizeof(CV_ARRAY_TEMP), (uintptr_t)CV_ARRAY_TEMP};
ret_val = flash_safe_execute(call_flash_range_program, params_program, FLASH_TIMEOUT_IN_MS);
if(ret_val != PICO_OK){
set_error(FLASH_SAFE_EXECUTE_PROGRAM_FAILURE);
return;
}
}
static void acknowledge() {
// Acknowledge a CV rd/wr instruction by pulsing the motor in both directions
const uint16_t max_lvl = _125M / (CV_ARRAY_FLASH[8] * 100 + 10000);
pwm_set_gpio_level(MOTOR_FWD_PIN, max_lvl);
busy_wait_ms(3);
pwm_set_gpio_level(MOTOR_FWD_PIN, 0);
pwm_set_gpio_level(MOTOR_REV_PIN, max_lvl);
busy_wait_ms(3);
pwm_set_gpio_level(MOTOR_REV_PIN, 0);
}
static void verify_cv_bit(uint16_t const cv_address, const bool bit_val, uint8_t const bit_pos) {
// Check for matching bit, when found call acknowledge()
const uint8_t mask = 0b00000001;
const bool res = ((CV_ARRAY_FLASH[cv_address] >> bit_pos) & mask) == bit_val;
if (res) {
acknowledge();
}
}
static void verify_cv_byte(uint16_t const cv_address, uint8_t const cv_data) {
// Check for matching byte, when found call acknowledge()
if (CV_ARRAY_FLASH[cv_address] == cv_data) acknowledge();
}
static void write_cv_byte(uint16_t cv_address, uint8_t cv_data) {
// Write the specified CV byte to flash
uint8_t CV_ARRAY_TEMP[CV_ARRAY_SIZE];
memcpy(CV_ARRAY_TEMP, CV_ARRAY_FLASH, sizeof(CV_ARRAY_TEMP));
CV_ARRAY_TEMP[cv_address] = cv_data;
// First erase necessary amount of blocks in flash and then rewrite to flash
uintptr_t params_erase[] = {FLASH_TARGET_OFFSET, FLASH_SECTOR_SIZE};
int ret_val = flash_safe_execute(call_flash_range_erase, params_erase, FLASH_TIMEOUT_IN_MS);
if (ret_val != PICO_OK){
set_error(FLASH_SAFE_EXECUTE_ERASE_FAILURE);
return;
}
uintptr_t params_program[] = { FLASH_TARGET_OFFSET, sizeof(CV_ARRAY_TEMP), (uintptr_t)CV_ARRAY_TEMP};
ret_val = flash_safe_execute(call_flash_range_program, params_program, FLASH_TIMEOUT_IN_MS);
if(ret_val != PICO_OK){
set_error(FLASH_SAFE_EXECUTE_PROGRAM_FAILURE);
return;
}
acknowledge();
}
static void reset_cv_array_to_default(){
// Reset all CVs to default (CV_ARRAY_DEFAULT)
uintptr_t params_erase[] = {FLASH_TARGET_OFFSET, FLASH_SECTOR_SIZE};
int ret_val = flash_safe_execute(call_flash_range_erase, params_erase, FLASH_TIMEOUT_IN_MS);
if (ret_val != PICO_OK){
set_error(FLASH_SAFE_EXECUTE_ERASE_FAILURE);
return;
}
uintptr_t params_program[] = {FLASH_TARGET_OFFSET, sizeof(CV_ARRAY_DEFAULT), (uintptr_t)CV_ARRAY_DEFAULT};
ret_val = flash_safe_execute(call_flash_range_program, params_program, FLASH_TIMEOUT_IN_MS);
if(ret_val != PICO_OK){
set_error(FLASH_SAFE_EXECUTE_PROGRAM_FAILURE);
return;
}
}
static void write_cv_handler(uint16_t const cv_index, uint8_t const cv_data) {
// There are some exceptions to writing CVs - e.g. writing to a read only CV is not valid - this gets handled here
switch (cv_index) {
case 0: //CV_1
// CV_1 => Value = 0 is not allowed
if (cv_data == 0 || cv_data > 127) {
break;
}
else {
write_cv_byte(cv_index, cv_data);
}
break;
case 6: //CV_7
// Read only (CV_7 - Version no.)
// ADC offset Adjustment is triggered when setting CV_7 = 7
if (cv_data == 7) {
LOG(1, "Triggered ADC offset adjustment via CV_7 = 7\n");
adc_offset_adjustment(ADC_CALIBRATION_ITERATIONS);
}
break;
case 7: //CV_8
// Read only (CV_8 - Manufacturer ID)
// Reset all CVs to default (CV_ARRAY_DEFAULT) when setting CV_8 = 8)
if (cv_data == 8) {
LOG(1, "reset of flash triggered via CV_8 = 8\n");
reset_cv_array_to_default();
}
break;
case 16: // CV_17
// CV_17 must have a value between 11000000->(192dec) and 11100111->(231dec) inclusive
// CV_17 == 192 && CV_18 == 0 -> Address = 0 is also not valid and therefore shall not be set
if ((cv_data < 192 || cv_data > 231) || (CV_ARRAY_FLASH[17] == 0 && cv_data == 192)) {
break;
}
write_cv_byte(cv_index, cv_data);
break;
case 17: // CV_18
if(CV_ARRAY_FLASH[16] == 192 && cv_data == 0){
break;
}
write_cv_byte(cv_index, cv_data);
break;
case 30: // CV_31 & CV_32 Index isn't implemented and shall not be set
break;
case 31: // CV_31 & CV_32 Index isn't implemented and shall not be set
break;
default: // Regular CV write is carried out
write_cv_byte(cv_index, cv_data);
}
}
static void program_mode(size_t const number_of_bytes, const uint8_t *const byte_array) {
//First check for valid programming command ("address" 112-127)
if (byte_array[number_of_bytes - 1] < 128 && byte_array[number_of_bytes - 1] > 111) {
const uint8_t instruction_type_mask = 0b00001100;
const uint8_t instruction_type = instruction_type_mask & byte_array[number_of_bytes - 1];
const uint8_t cv_address_ms_bits_mask = 0b00000011;
const uint16_t cv_address_ms_bits = cv_address_ms_bits_mask & byte_array[number_of_bytes - 1];
const uint16_t cv_address = byte_array[number_of_bytes - 2] + (cv_address_ms_bits << 8);
if (instruction_type == 0b000001000) {
// Verify CV bit instruction
const uint8_t bit_pos_mask = 0b00000111;
const uint8_t bit_pos = bit_pos_mask & byte_array[number_of_bytes - 3];
const uint8_t bit_val_mask = 0b00000001;
const uint8_t bit_val_uint = (byte_array[number_of_bytes - 3] >> 3) & bit_val_mask;
const bool bit_val = bit_val_uint;
verify_cv_bit(cv_address, bit_val, bit_pos);
}
else if (instruction_type == 0b000000100) {
// Verify CV byte instruction
const uint8_t cv_data = byte_array[number_of_bytes - 3];
verify_cv_byte(cv_address, cv_data);
}
else if (instruction_type == 0b000001100) {
// Write CV byte instruction
const uint8_t cv_data = byte_array[number_of_bytes - 3];
write_cv_handler(cv_address, cv_data);
}
busy_wait_ms(5);
}
}
static void set_outputs(uint32_t const functions_to_set_bitmask) {
// Get outputs with pwm enabled and preset outputs_to_set_PWM variable with resulting GPIO Bitmask
const uint32_t PWM_enabled_outputs = get_32bit_CV(111);
uint32_t outputs_to_set_PWM = PWM_enabled_outputs;
// Get enabled output configuration corresponding to set functions and direction
uint32_t outputs_to_set = 0;
uint32_t temp_mask = 1;
for (uint8_t i = 0; i < 32; i++) {
if (temp_mask & functions_to_set_bitmask) {
const direction_t dir = get_direction_of_speed_step(speed_step_target);
outputs_to_set |= get_32bit_CV(i * 8 + 260 - 4 * dir);
}
temp_mask <<= 1;
}
outputs_to_set_PWM &= outputs_to_set; // Outputs with PWM to be enabled
outputs_to_set &= ~outputs_to_set_PWM; // Outputs without PWM to be enabled
// Set regular outputs without PWM, preventing illegal GPIO by masking with GPIO_ALLOWED_OUTPUTS
gpio_put_masked(GPIO_ALLOWED_OUTPUTS, outputs_to_set);
// Set PWM enabled outputs to desired level
temp_mask = 1;
for (uint8_t i = 0; i < 32; ++i) {
if (temp_mask & outputs_to_set_PWM) {
pwm_set_gpio_level(i, level_table[i]);
pwm_gpio_to_channel(i);
pwm_gpio_to_slice_num(i);
}
else if (temp_mask & PWM_enabled_outputs) {
pwm_set_gpio_level(i, 0);
}
temp_mask <<= 1;
}
}
static void update_active_functions(uint32_t new_function_bitmask, const uint8_t clr_bit_ind, bool const direction_change) {
// Update functions F0 - F31 when function command is received or in case of direction change
static uint32_t active_functions;
static uint32_t prev_active_func;
// Outputs depend on direction, therefore on direction change outputs need to be set for the other direction.
if (direction_change) {
// In case of a direction change every output needs to be set according to configuration for the other direction
set_outputs(active_functions);
}
else {
// In case of a change in active functions only the function group corresponding to the instruction is considered for updating the outputs
// First, check for changes
new_function_bitmask &= ~(clr_bit_arr[clr_bit_ind]); // Clear every bit except bits corresponding to group of functions
active_functions &= clr_bit_arr[clr_bit_ind]; // Clear bits corresponding to group of functions
active_functions |= new_function_bitmask; // Write bits corresponding to group of functions
const uint32_t changes = active_functions ^ prev_active_func; // Checks for changes from previous state
// When there is changes, set outputs accordingly
if (changes) {
set_outputs(active_functions);
}
// Update previously active function variable
prev_active_func = active_functions;
}
}
static bool error_detection(size_t const number_of_bytes, const uint8_t *const byte_array) {
// Bitwise XOR for all Bytes -> when result is: "0b00000000" error check is passed.
uint8_t xor_byte = 0;
for (int i = 0; i < number_of_bytes; i++) {
xor_byte = xor_byte ^ byte_array[i];
}
return (0 == xor_byte);
}
static bool is_long_address(size_t const number_of_bytes, const uint8_t *const byte_array) {
// Check for long address. Function returns true for long address, false for short address.
if ((byte_array[number_of_bytes - 1] >> 6) == 0b00000011) {
return true;
}
return false;
}
static bool address_evaluation(size_t const number_of_bytes, const uint8_t *const byte_array) {
// First checks for idle message and then evaluates address included in byte_array[] which contains the received DCC message
// Check for idle message
if (byte_array[number_of_bytes - 1] == 255) {
return false;
}
// Long/extended address decoder configuration (CV_29 Bit5)
const bool CV_29_bit5 = (CV_ARRAY_FLASH[28] & 0b00100000) >> 5;
uint16_t read_address;
// Check if decoder is configured to receive long/extended address (CV_29 Bit5 set)
if (CV_29_bit5) {
// Check DCC message for long address format
if (is_long_address(number_of_bytes, byte_array)) {
// DCC message received has long address format
// start of transmission -> address_byte_1 -> address_byte_0 -> ... -> end of transmission
const uint16_t address_byte_1 = (byte_array[number_of_bytes - 1]) - 192; // Remove long address identifier bits
const uint16_t address_byte_0 = (byte_array[number_of_bytes - 2]);
read_address = (address_byte_1 << 8) + address_byte_0;
const uint16_t long_address = get_16bit_CV(16) & 0x3FFF; // &Mask to remove long address identifier bits
return (long_address == read_address);
}
else {
// DCC message received does not have long address format
return false;
}
}
else {
// Else decoder is configured to receive short address (CV_29 Bit5 not set)
// Short address message:
// start of transmission -> address_byte_0 -> ... -> end of transmission
read_address = byte_array[number_of_bytes - 1];
return CV_ARRAY_FLASH[0] == read_address;
}
}
static void instruction_evaluation(size_t const number_of_bytes, const uint8_t *const byte_array) {
// Evaluate the type of instruction
// start of transmission -> ... -> command_byte_n -> ... -> command_byte_0 -> ... -> end of transmission
// The position of command bytes depend on whether the address is long or not
uint8_t command_byte_start_index;
if (is_long_address(number_of_bytes, byte_array)) {
command_byte_start_index = number_of_bytes - 3;
}
else {
command_byte_start_index = number_of_bytes - 2;
}
const uint8_t command_byte_n = byte_array[command_byte_start_index];
if (command_byte_n == 0b00111111) {
// 0011-1111 (128 Speed Step Control) - 2 Byte length
speed_step_target_prev = speed_step_target;
speed_step_target = byte_array[command_byte_start_index - 1];
// Check for direction change
const bool direction_changed = get_direction_of_speed_step(speed_step_target) !=
get_direction_of_speed_step(speed_step_target_prev);
// In case of a direction change, functions need to be updated because functions depend on direction
if (direction_changed) {
update_active_functions(0, 0, true);
}
}
else if (command_byte_n >> 6 == 0b00000010) {
// 10XX-XXXX (Function Group Instruction)
switch (command_byte_n >> 4) {
case 0b00001011: // F5-F8
update_active_functions((command_byte_n << 5), 1, false);
break;
case 0b00001010: // F9-F12
update_active_functions((command_byte_n << 9), 2, false);
break;
default: // F0-F4
update_active_functions((((command_byte_n & 0b00001111) << 1) + ((command_byte_n & 0b00010000) >> 4)), 0, false);
break;
}
}
else if (command_byte_n >> 5 == 0b00000110) {
// Feature Expansion Instruction 110X-XXXX
switch (command_byte_n) {
case 0b11011110: // F13-F20
update_active_functions((byte_array[command_byte_start_index - 1] << 13), 3, false);
break;
case 0b11011111: // F21-F28
update_active_functions((byte_array[command_byte_start_index - 1] << 21), 4, false);
break;
case 0b11011000: // F29-F31
update_active_functions((byte_array[command_byte_start_index - 1] << 29), 5, false);
break;
default:
break;
}
}
}
static bool reset_message_check(size_t const number_of_bytes, const uint8_t *const byte_array) {
// Check for reset message - When reset message is found, stop the motor and disable all functions.
if (byte_array[number_of_bytes - 1] == 0b00000000 && byte_array[number_of_bytes - 2] == 0b00000000) {
const direction_t dir = get_direction_of_speed_step(speed_step_target);
// Set previous speed step target to current speed step target
speed_step_target_prev = speed_step_target;
// Set speed step target to emergency stop speed step ( 1 for Reverse direction / 129 for forward direction)
// for details see get_direction_of_speed_step() comment in "shared.h"
if(dir == DIRECTION_FORWARD) speed_step_target = SPEED_STEP_FORWARD_EMERGENCY_STOP;
else if(dir == DIRECTION_REVERSE) speed_step_target = SPEED_STEP_REVERSE_EMERGENCY_STOP;
update_active_functions(0,0,0); // Disables all functions
return true;
}
return false;
}
static size_t detect_dcc_packet() {
// Checks for valid package - looking for correct preamble using bitmasks
// returns number of bytes if valid bit-pattern is found. Otherwise INVALID_PACKAGE is returned.
// INVALID_PACKAGE is defined in core0.h as SIZE_MAX (maximum value of size_t)
size_t number_of_bytes = INVALID_PACKAGE;
const uint64_t masked_message_3_bytes = input_bit_buffer & MESSAGE_MASK_3_BYTES;
if (masked_message_3_bytes == MESSAGE_3_BYTES) number_of_bytes = 3;
const uint64_t masked_message_4_bytes = input_bit_buffer & MESSAGE_MASK_4_BYTES;
if (masked_message_4_bytes == MESSAGE_4_BYTES) number_of_bytes = 4;
const uint64_t masked_message_5_bytes = input_bit_buffer & MESSAGE_MASK_5_BYTES;
if (masked_message_5_bytes == MESSAGE_5_BYTES) number_of_bytes = 5;
return number_of_bytes;
}
static void bits_to_dcc_packet_data(dcc_packet_t * packet) {
// Writes data in input_bit_buffer to dcc_packet_t struct instance
//start of transmission -> byte_n(address byte) -> ... -> byte_0(error detection byte) -> end of transmission
for (uint8_t i = 0; i < packet->length; i++) {
packet->data[i] = input_bit_buffer >> (i * 9 + 1);
}
}
static void evaluate_packet(dcc_packet_t * packet) {
// DCC packet evaluation
static bool reset_message_flag;
// Check for errors
if (error_detection(packet->length, packet->data)) {
// Check for matching address
if (address_evaluation(packet->length, packet->data)) {
reset_message_flag = false;
instruction_evaluation(packet->length, packet->data);
}
else if (reset_message_flag) {
// When previous packet was a reset message -> enter program mode
program_mode(packet->length, packet->data);
}
else {
// Check for reset message and set flag when reset message is received
reset_message_flag = reset_message_check(packet->length, packet->data);
}
}
}
static void gpio_irq_cb(uint gpio, uint32_t events) {
absolute_time_t start_time = get_absolute_time();
// Check for rising edge on DCC input pin
if ((events & GPIO_IRQ_EDGE_RISE) && (gpio == DCC_INPUT_PIN)) {
track_signal_rise(gpio, events);
}
// Check for falling edge on DCC input pin
else if ((events & GPIO_IRQ_EDGE_FALL) && (gpio == DCC_INPUT_PIN)) {
track_signal_fall(gpio, events);
}
absolute_time_t end_time = get_absolute_time();
if (absolute_time_diff_us(start_time, end_time) > 20) {
LOG(1, "Time gpio_irq_cb: %lld us\n", absolute_time_diff_us(start_time, end_time));
}
}
static void track_signal_rise() {
// DCC-Signal pin rising edge. Write current time to rising_edge_time
rising_edge_time = get_absolute_time();
}
static void track_signal_fall() {
// DCC-Signal pin falling edge. Write current time to falling_edge_time
falling_edge_time = get_absolute_time();
// Time difference is equal to the time the signal was in a logical high state
const int64_t time_logical_high = absolute_time_diff_us(rising_edge_time, falling_edge_time);
// When logical high was longer than 87us write 0 bit into buffer otherwise 1
bool bit;
if (time_logical_high > 87) bit = 0;
else bit = 1;
input_bit_buffer <<= 1;
input_bit_buffer |= bit;
// Check if input buffer contains a valid dcc packet
// number_of_bytes contains the length of the packet when detected, otherwise -1
dcc_r_buf.packets[dcc_r_buf.wr_idx].length = detect_dcc_packet();
if (dcc_r_buf.packets[dcc_r_buf.wr_idx].length != INVALID_PACKAGE) {
// Write data into ring buffer containing dcc_packet_t struct instances
bits_to_dcc_packet_data(&dcc_r_buf.packets[dcc_r_buf.wr_idx]);
// Increment write index of ring buffer
increment_ring_buffer_idx(&dcc_r_buf.wr_idx, RING_BUFFER_PACKETS);
}
}
static void init_outputs() {
LOG(1, "Initializing Outputs...\n");
gpio_init_mask(GPIO_ALLOWED_OUTPUTS);
gpio_set_dir_out_masked(GPIO_ALLOWED_OUTPUTS); // Note: This might also disable UART on GPIO0 & GPIO1
const uint32_t PWM_enabled_outputs = get_32bit_CV(111) & GPIO_ALLOWED_OUTPUTS;
uint32_t mask = 1;
for (uint8_t i = 0; i < sizeof(uint32_t)*8; ++i) {
if (PWM_enabled_outputs & mask) {
const uint32_t slice = pwm_gpio_to_slice_num(i);
const uint32_t channel = pwm_gpio_to_channel(i); // Channel A = "0"; Channel B = "1"
const uint16_t wrap = get_16bit_CV(115 + 7 * slice);
const uint16_t level = get_16bit_CV(118 + 7 * slice + 2 * channel);
const uint8_t clock_divider = CV_ARRAY_FLASH[117 + 7 * slice] + 1;
gpio_set_function(i, GPIO_FUNC_PWM);
pwm_set_wrap(slice, wrap);
pwm_set_gpio_level(i, 0);
level_table[i] = level;
pwm_set_clkdiv_int_frac(slice, clock_divider, 0);
pwm_set_enabled(slice, true);
LOG(1, "Set GPIO pin: %u as PWM output; PWM slice: %u; PWM channel: %u; Duty cycle: %f; Clock divider: %u\n", i, slice, channel, (float) level/wrap, clock_divider);
}
mask <<= 1;
}
}
static void cv_setup_check() {
LOG(1, "Checking CV array for factory state of flash or missing ADC offset setup...\n");
// Check for flash factory setting and set CV_FLASH_ARRAY to default values when factory condition ("0xFF") is found.
if (CV_ARRAY_FLASH[64] == 0xFF) {
LOG(1, "Detected flash memory factory condidition (CV_65 == %u), resetting all CVs to default values...\n", CV_ARRAY_FLASH[64]);
reset_cv_array_to_default();
}
// Check for existing ADC offset setup
if (CV_ARRAY_FLASH[171] == 0xFF) {
LOG(1, "Detected ADC offset factory condidition (CV_172 == %u), running offset adjustment measurement function...\n", CV_ARRAY_FLASH[171]);
adc_offset_adjustment(ADC_CALIBRATION_ITERATIONS);
}
LOG(1, "CV check done! Setting wait_for_cv_setup_check flag to false!\n");
cv_setup_check_done = true;
}
static void init_motor_pwm(uint8_t const gpio) {
// Motor PWM initialization
LOG(2, "Initializing Motor PWM on GPIO pin: %u...\n", gpio);
// Set GPIO pin to PWM functionality
gpio_set_function(gpio, GPIO_FUNC_PWM);
// Set wrap counter value saved in CV
const uint16_t wrap_counter = (_125M / (CV_ARRAY_FLASH[8] * 100 + 10000)) - 1;
const uint32_t slice_num = pwm_gpio_to_slice_num(gpio);
pwm_set_clkdiv_int_frac(slice_num, CV_ARRAY_FLASH[173], 0);
pwm_set_wrap(slice_num, wrap_counter);
// Set initial level to 0
pwm_set_gpio_level(gpio, 0);
// Enable PWM
pwm_set_enabled(slice_num, true);
LOG(2, "Initialized motor PWM on pin: %u; wrap_counter %u; clkdiv %d;\n", gpio, wrap_counter, CV_ARRAY_FLASH[173]);
}
static void init_adc() {
LOG(1, "Initializing ADC...\n")
// Initialize ADC
adc_init();
// Set ADC GPIO pins to ADC functionality
adc_gpio_init(FWD_V_EMF_ADC_PIN);
adc_gpio_init(REV_V_EMF_ADC_PIN);
// Configure ADC FIFO
adc_fifo_setup(true, false, 0, false, false);
LOG(1, "ADC initialization done!\n")
}
static void init_digital_input() {
LOG(1, "Initializing DCC input pin...\n");
gpio_init(DCC_INPUT_PIN);
gpio_set_dir(DCC_INPUT_PIN, GPIO_IN);
gpio_pull_up(DCC_INPUT_PIN);
LOG(1, "DCC input pin initialization done!\n");
}
static void wait_for_stdio_input() {
while (true) {
//watchdog_update();
// Send a message to the user asking them to acknowledge it by sending a reply
LOG(1, "Send any character to continue.\n");
// Wait for a character
int received_char = getchar_timeout_us(1e6);
if ((received_char != PICO_ERROR_TIMEOUT) && (received_char > 0)) {
// If a character is received, exit the function
LOG(1, "Character '%c' received. Continuing...\n", (char)received_char);
return;
}
// If no character is received, retry...
}
}
int main() {
exception_set_exclusive_handler(HARDFAULT_EXCEPTION, hardfault_handler);
#ifdef RP2040_DECODER_DEFAULT_LED_PIN
// Initialize LED GPIO pin
gpio_init(RP2040_DECODER_DEFAULT_LED_PIN);
gpio_set_dir(RP2040_DECODER_DEFAULT_LED_PIN, GPIO_OUT);
// Blink LED once for 200ms to indicate startup
gpio_put(RP2040_DECODER_DEFAULT_LED_PIN, 1);
busy_wait_ms(200);
gpio_put(RP2040_DECODER_DEFAULT_LED_PIN, 0);
busy_wait_ms(200);
#endif
// Initialize stdio when enabled
#if (STDIO_UART_ENABLED || STDIO_USB_ENABLED)
if(stdio_init_all() != true){
set_error(STDIO_INIT_FAILURE);
}
// When LOG_WAIT == 1 and LOGLEVEL > 0 wait for user input before continuing. User input can be any character.
#if (LOGLEVEL > 0 && LOG_WAIT == 1)
wait_for_stdio_input();
printf("%u", STDIO_UART_ENABLED);
#endif
#endif
LOG(1, "core0 Initialization...\n");
// Check for reboot by watchdog and set error when true
if (watchdog_caused_reboot()) {
LOG(1, "Reboot by watchdog detected!\n");
set_error(REBOOT_BY_WATCHDOG);
}
// Initialize Motor PWM pins
init_motor_pwm(MOTOR_FWD_PIN);
init_motor_pwm(MOTOR_REV_PIN);
// Initialize outputs
init_outputs();
// Initialize ADC
init_adc();
// Initialize digital inputs and track signal irq
init_digital_input();
LOG(1, "core0 initialization done!\n");
// Launch core1
multicore_launch_core1(core1_entry);
// Wait for core1 to call flash_safe_execute_core_init() and set the flash_safe_execute_core_init_done flag
LOG(1, "Waiting for flash_safe_execute_core_init_done flag...\n");
while (!flash_safe_execute_core_init_done) {
watchdog_update();
}
busy_wait_ms(100);
// Check for error calling flash_safe_execute_core_init() on core1
if(get_error_state() & FLASH_SAFE_EXECUTE_CORE_INIT_FAILURE){
panic("Error calling flash_safe_execute_core_init() on core1!"); //TODO: test
}
// Check CV array for factory state of flash or missing ADC offset setup
cv_setup_check();
// Register GPIO IRQ callback
gpio_set_irq_callback(gpio_irq_cb);
// Enable IRQ
gpio_set_irq_enabled(DCC_INPUT_PIN, GPIO_IRQ_EDGE_RISE | GPIO_IRQ_EDGE_FALL, true);
irq_set_enabled(IO_IRQ_BANK0, true);
// Enable the watchdog, requiring the watchdog to be updated every WATCHDOG_TIMER_IN_MS milliseconds or the chip will reboot
// second arg is pause on debug which means the watchdog will pause when stepping through code
// Watchdog is updated by core0 and core1 whenever there is time and hopefully soon enough to prevent a reboot.
watchdog_enable(WATCHDOG_TIMER_IN_MS, 1);
// Endless loop
while (true) {
// Check for new messages in ring buffer
if (dcc_r_buf.wr_idx != dcc_r_buf.rd_idx) {
absolute_time_t start_time = get_absolute_time();
evaluate_packet(&dcc_r_buf.packets[dcc_r_buf.rd_idx]);
increment_ring_buffer_idx(&dcc_r_buf.rd_idx, RING_BUFFER_PACKETS);
absolute_time_t end_time = get_absolute_time();
if (absolute_time_diff_us(start_time, end_time) > 40) {
LOG(1, "Time to evaluate message: %lld us\n", absolute_time_diff_us(start_time, end_time));
}
}
else {
watchdog_update();
}
}
}
+372
View File
@@ -0,0 +1,372 @@
/*!
*
* \file core0.h
* Used exclusively by core0
*
*/
#pragma once
#include "shared.h"
#include "CV.h"
#define MESSAGE_3_BYTES 0b11111111110000000000000000000000000001
#define MESSAGE_MASK_3_BYTES 0b11111111111000000001000000001000000001
#define MESSAGE_4_BYTES 0b11111111110000000000000000000000000000000000001
#define MESSAGE_MASK_4_BYTES 0b11111111111000000001000000001000000001000000001
#define MESSAGE_5_BYTES 0b11111111110000000000000000000000000000000000000000000001
#define MESSAGE_MASK_5_BYTES 0b11111111111000000001000000001000000001000000001000000001
#define INVALID_PACKAGE SIZE_MAX
#define RING_BUFFER_PACKETS 8
#define RING_BUFFER_BYTES 5
#define FLASH_CMD_READ_JEDEC_ID 0x9F
#define FLASH_TIMEOUT_IN_MS 500
#define ADC_CALIBRATION_ITERATIONS 8192
#define WATCHDOG_TIMER_IN_MS 5000
/*!
* \brief Bitmasks used for clearing bits corresponding to function blocks
*
* [0] = F0-F4
* [1] = F5-F8
* [2] = F9-F12
* [3] = F13-F20
* [4] = F21-F28
* [5] = F29-F31
*
*/
const uint32_t clr_bit_arr[6] = {
0b11111111111111111111111111100000, // Clear Bits 0-4 (F0-F4)
0b11111111111111111111111000011111, // Clear Bits 5-8 (F5-F8)
0b11111111111111111110000111111111, // Clear Bits 9-12 (F9-F12)
0b11111111111000000001111111111111, // Clear Bits 13-20 (F13-F20)
0b11100000000111111111111111111111, // Clear Bits 21-28 (F21-F28)
0b00011111111111111111111111111111, // Clear Bits 29-31 (F29-F31)
};
/**
* @brief Structure representing a DCC packet.
*
* This structure is used to store the data and length of a DCC packet.
*
* @struct dcc_packet_t
*
* @param data An array of bytes representing the DCC packet data.
* @param length The length of the DCC packet data.
*/
typedef struct dcc_packet_t {
/*! An array of bytes representing the DCC packet data. */
uint8_t data[RING_BUFFER_BYTES];
/*! The length of the DCC packet data. */
size_t length;
}dcc_packet_t;
/**
* @brief Structure representing a ring buffer for DCC packets.
*
* This structure is used to manage a ring buffer that stores DCC packets.
* It contains an array of packets and indices for writing and reading.
*
* @struct dcc_ring_buffer_t
*/
typedef struct dcc_ring_buffer_t {
/*! Array of DCC packets stored in the ring buffer. */
dcc_packet_t packets[RING_BUFFER_PACKETS];
/*! Index for the next write operation in the ring buffer. */
size_t wr_idx;
/*! Index for the next read operation in the ring buffer. */
size_t rd_idx;
} dcc_ring_buffer_t;
/**
* @brief Increment the index of a ring buffer.
*
* This function increments the provided index of a ring buffer, wrapping around
* to zero if the end of the buffer is reached.
*
* @param idx Pointer to the index to be incremented.
* @param ring_buffer_length The length of the ring buffer.
*/
static void increment_ring_buffer_idx(size_t * idx, uint8_t ring_buffer_length);
/*!
* \brief Function for erasing a sector of flash memory.
*
* This function erases a specified range of flash memory sectors.
*
* \param param Pointer to parameters.
* - First parameter: Offset into flash, in bytes. Must be aligned to a 4096-byte flash sector.
* - Second parameter: Number of bytes to be erased. Must be a multiple of 4096 bytes (one sector).
*/
static void call_flash_range_erase(void *param);
/*!
* \brief Function for programming a range of flash memory
*
* This function programs a specified range of flash memory with the provided data.
*
* \param param Pointer to parameters
* - First parameter: The Flash address of the first byte to be programmed. Must be aligned to a 256-byte flash page.
* - Second parameter: The number of bytes to program. Must be a multiple of 256 bytes (one page).
* - Third parameter: Pointer to the data to program into flash.
*/
static void call_flash_range_program(void *param);
/*!
* \brief Function for executing a flash command via QSPI
*
* \param param Pointer to parameters
* First parameter is the pointer to a byte buffer which will be transmitted to the flash
* Second parameter is the pointer to a byte buffer where data received from the flash will be written.
* Third parameter is the length in bytes of any of the two buffers (same size).
*/
static void call_flash_do_cmd(void *param);
/*!
* \brief Function for calculating the absolute value of an integer.
*
* This function takes an integer as input and returns its absolute value.
*
* \param x The input integer whose absolute value is to be calculated.
* \return The absolute value of the input integer.
*/
static unsigned int absolute_val(int x);
/*!
* \brief Computes the average of values in an array that deviate less than twice the standard deviation from the original average.
*
* This function calculates the average of the elements in the input array that are within two standard deviations of the mean of the array.
*
* \param arr The input array of values.
* \param length The number of elements in the input array.
* \return The average value of the elements that deviate less than twice the standard deviation from the original average.
*/
static uint16_t two_std_dev(const uint16_t arr[], uint32_t length);
/*!
* \brief Measures ADC offset and saves the offset value to flash memory.
*
* This function performs a series of ADC measurements to determine the offset
* and then stores this offset value in the flash memory for future use.
*
* \param n The number of measurements to be performed to calculate the offset.
*/
static void adc_offset_adjustment(uint32_t n);
/*!
* \brief Function for acknowledging a CV write or CV verify instruction
*
* Acknowledgement works by creating a spike in current consumption, normally realized by running the motor in alternating directions.
* This current increase is detected by the command station.
*
* \note Refers to NMRA S-9.2.3 Section D and RCN-216 Section 3
*/
static void acknowledge();
/*!
* \brief Function for verifying a single bit of a CV
* \param cv_address CV Address
* \param bit_val Value of bit to be verified
* \param bit_pos Position of bit to be verified
*/
static void verify_cv_bit(uint16_t cv_address, bool bit_val, uint8_t bit_pos);
/*!
* \brief Function for verifying a CV byte
*
* This function verifies the byte of a Configuration Variable (CV) at the specified address.
*
* \param cv_address The address of the CV to be verified.
* \param cv_data The byte value to be verified against the CV.
*/
static void verify_cv_byte(uint16_t cv_address, uint8_t cv_data);
/*!
* \brief Writes a byte to a Configuration Variable (CV).
*
* This function writes a byte of data to a specified CV address.
*
* \param cv_address The address of the CV to write to.
* \param cv_data The data byte to write to the CV.
*/
static void write_cv_byte(uint16_t cv_address, uint8_t cv_data);
/*!
* \brief This function sets all the CV values stored in flash back to their default settings (CV_ARRAY_DEFAULT).
*/
static void reset_cv_array_to_default();
/*!
* \brief CV Programming mode function
*
* This function is used to enter programming mode in order to write CV values to persistent flash memory or verify/read bits/bytes from flash memory.
*
* Procedure:
* 1. Checks for a valid programming command.
* 2. Evaluates the type of programming instruction (Write byte / Verify byte / Verify bit) and runs the corresponding function. See verify_cv_byte(), verify_cv_bit() and write_cv_byte().
*
* @param number_of_bytes The number of bytes in the array.
* @param byte_array A pointer to the byte array.
*
* @note Refer to NMRA Standard 9.2.3 ("Service Mode Programming") or RCN-216 for more details.
*/
static void program_mode(size_t number_of_bytes, const uint8_t *const byte_array);
/*!
* \brief Set outputs according to function mapping in CV257 to CV512
*
* This function maps the functions and direction to the mapped outputs configured in CV257 to CV512.
* Also enables PWM when enabled according to CV112 to CV115.
*
* \param functions_to_set_bitmask Function bitmask F0 is bit0, F1 is bit1, ...
*/
static void set_outputs(uint32_t functions_to_set_bitmask);
/**
* @brief Update functions F0 - F31 when function command is received or in case of direction change.
*
* This function updates the active functions based on the provided bitmask. It can also clear a specific bit
* and handle changes in direction.
*
* @param new_function_bitmask New function bitmask representing the state of functions F0 - F31.
* @param clr_bit_ind Index of the bit to be cleared in the bitmask.
* @param direction_change Flag indicating if there is a change in direction.
*/
static void update_active_functions(uint32_t new_function_bitmask, uint8_t clr_bit_ind, bool direction_change);
/**
* @brief Detect errors in the byte array using exor of all bytes.
*
* Exor of all bytes is expected to be "0b00000000".
*
* @param number_of_bytes Number of bytes in the array.
* @param byte_array Pointer to the byte array.
* @return true if no error is detected, false otherwise.
*/
static bool error_detection(size_t number_of_bytes, const uint8_t *byte_array);
/**
* @brief Check if the address is a long address.
*
* @param number_of_bytes Number of bytes in the array.
* @param byte_array Pointer to the byte array.
* @return true if it is a long address, false otherwise.
*/
static bool is_long_address(size_t number_of_bytes, const uint8_t byte_array[]);
/**
* @brief Evaluate the address of the message.
*
* @param number_of_bytes Number of bytes in the array.
* @param byte_array Pointer to the byte array.
* @return true if the address is correct, false otherwise.
*/
static bool address_evaluation(size_t number_of_bytes, const uint8_t byte_array[]);
/**
* @brief Evaluate the instruction of the message.
*
* @param number_of_bytes Number of bytes in the array.
* @param byte_array Pointer to the byte array.
*/
static void instruction_evaluation(size_t number_of_bytes, const uint8_t byte_array[]);
/**
* @brief Check for reset message - When reset message is found, stop the motor and disable all functions.
*
* @return Number of bytes if valid reset message bit-pattern is found. Otherwise -1 is returned.
*/
static bool reset_message_check(size_t number_of_bytes, const uint8_t *const byte_array);
/**
* @brief Verify DCC message
*
* Procedure:
* 1. Check for valid preamble using bitmasks
* 2. Return number of bytes if valid bit-pattern is found. Otherwise -1 is returned.
*
* \return Number of bytes if valid bit-pattern is found. Otherwise return -1.
*/
static size_t detect_dcc_packet();
/**
* @brief Convert sequence of bits to byte array
*
* For each byte in the byte array, shift the input bit buffer by 9 bits and save the result in the byte array.
* Bytes are ordered as follows:
* Start of transmission -> byte_n(address byte) -> ... -> byte_0(error detection byte) -> end of transmission
*
* \param packet Pointer to dcc packet struct which contains data and length of packet.
*/
static void bits_to_dcc_packet_data(dcc_packet_t * packet);
/**
* @brief Main message evaluation function
*
* Procedure:
* 1. Check if input buffer contains a valid DCC message
* 2. Split data into array of bytes
* 3. Check for errors
* 4. Check for matching address
* 5. Check for reset message and set flag when reset message is received
*
*/
static void evaluate_packet();
/*!
* \brief Track signal rising edge interrupt callback function
*
* Saves timer counter value using get_absolute_time(), then disables rising edge IRQ and enables falling edge IRQ.
*
*/
static void track_signal_rise();
/*!
* \brief Track signal falling edge interrupt callback function
*
* Saves timer counter value using get_absolute_time(), then calculates time difference between rising and falling edge.
* When the time difference is greater than 87us, this bit is interpreted as a logical 0. Otherwise, it is interpreted as a logical 1.
* Refers to NMRA S-9.1 and RCN-210 standards
* Puts the latest bit value into 64 bit unsigned integer "buffer", then checks if the buffer contains a valid DCC packet.
* When a valid packet is found, it is written into the ring buffer, and the write index gets incremented.
*
*/
static void track_signal_fall();
/*!
* \brief Output initialization function
*
* Initializes all allowed GPIO outputs as outputs <br>
* Sets PWM functionality for GPIOs configured as PWM pins CV_112 - CV_115 (see CV.h for reference) <br>
* PWM frequency and clock divider are configured according to CV_116 - CV_171 (see CV.h for reference) <br>
*/
static void init_outputs();
/*!
* \brief Checks various CV values in order to detect factory condition or pending calibrations
*
* Procedure:
* 1. Check for flash memory factory condition when found write default values specified in CV.h to flash memory
* 2. Check for existing ADC offset setup when not found write 7 to read-only CV_7 in order to trigger a ADC offset measurement/calibration
* 3. Check for base PWM configuration/calibration, run calibration when none is found
*/
static void cv_setup_check();
/*!
* \brief Function initializes motor PWM for pin specified in CMakeLists.txt
* \param gpio GPIO pin
*/
static void init_motor_pwm(uint8_t gpio);
/*!
* \brief Initializes ADC
*
* Function initializes ADC, corresponding GPIO pins specified in CMakeLists.txt, also configures ADC FIFO.
*/
static void init_adc();
+393
View File
@@ -0,0 +1,393 @@
//////////////////////////
// RP2040-Decoder //
// Gabriel Koppenstein //
// core1.c //
//////////////////////////
#include "core1.h"
struct repeating_timer pid_control_timer, speed_helper_timer;
bool controller_flag, speed_helper_flag = false;
// Measures Back-EMF voltage (proportional to the rotational speed of the motor) on GPIO 28 and GPIO 29 respectively (depending on direction)
float measure(uint8_t total_iterations,
uint8_t measurement_delay_us,
uint8_t l_side_arr_cutoff,
uint8_t r_side_arr_cutoff,
direction_t direction){
uint32_t sum = 0;
uint16_t adc_val[total_iterations];
int32_t j = 0;
uint16_t key;
pwm_set_gpio_level(MOTOR_FWD_PIN, 0);
pwm_set_gpio_level(MOTOR_REV_PIN, 0);
if (direction == DIRECTION_FORWARD) {
adc_select_input(FWD_V_EMF_ADC_CHANNEL);
} else if(direction == DIRECTION_REVERSE) {
adc_select_input(REV_V_EMF_ADC_CHANNEL);
} else{
set_error(INVALID_DIRECTION);
}
busy_wait_us(measurement_delay_us);
adc_run(true);
for (int32_t i = 0; i < total_iterations; ++i) {
//Take adc value out of fifo when available, then do one step of insertion sort.
adc_val[i] = adc_fifo_get_blocking();
key = adc_val[i];
j = i - 1;
while (j >= 0 && adc_val[j] > key) {
adc_val[j + 1] = adc_val[j];
j--;
}
adc_val[j + 1] = key;
}
adc_run(false);
//adc_fifo_drain();
//discard x entries beginning from the lowest entry of the array (counting up); x = msr.l_side_arr_cutoff
//discard y entries beginning from the highest index of the array (counting down); y = msr.r_side_arr_cutoff
for (int32_t i = l_side_arr_cutoff; i < total_iterations - r_side_arr_cutoff ; ++i) {
sum += adc_val[i];
}
float res = (float)sum / (float)( total_iterations - (l_side_arr_cutoff + r_side_arr_cutoff) );
// return true to keep the repeating timer active
return res;
}
// Get speed_step_table_index depending on speed_step
uint8_t get_speed_step_table_index_of_speed_step(uint8_t speed_step) {
// Clear direction information in bit7
speed_step = speed_step & 0b01111111;
// Check for Stop or Emergency Stop speed step
if (speed_step == 0 || speed_step == 1) {
return 0;
}
// In any other case i.e. speed steps 1 to 126:
return speed_step-1;
}
// This function gets called every x milliseconds where x is CV_175.
// The purpose of this function is to implement a time delay in acceleration or deceleration
void speed_helper(controller_parameter_t * ctrl_par) {
// ctrl_par->setpoint only gets adjusted when the speed_helper_counter is equal to the accel_rate/decel_rate
// -> Time for 1 Speed Step := (speed_helper timer delay)*(accel_rate) or CV_175*CV_3 or CV_175*CV_4
const uint8_t accel_rate = CV_ARRAY_FLASH[2];
const uint8_t decel_rate = CV_ARRAY_FLASH[3];
static uint8_t speed_helper_counter;
static uint8_t speed_table_index;
// Get speed_step_table_end_index corresponding to current speed_step_target
const uint8_t speed_step_table_end_index = get_speed_step_table_index_of_speed_step(speed_step_target);
const bool direction_changed = get_direction_of_speed_step(speed_step_target) !=
get_direction_of_speed_step(speed_step_target_prev);
if (speed_step_target == SPEED_STEP_FORWARD_EMERGENCY_STOP || speed_step_target == SPEED_STEP_REVERSE_EMERGENCY_STOP) {
// Emergency Stop
speed_table_index = 0;
speed_helper_counter = 0;
ctrl_par->setpoint = ctrl_par->speed_table[speed_table_index];
}
else if (speed_step_table_end_index > speed_table_index && speed_helper_counter == accel_rate) {
// Acceleration
if (!accel_rate) speed_table_index = speed_step_table_end_index; // directly accelerate to end target speed
else speed_table_index++;
ctrl_par->setpoint = ctrl_par->speed_table[speed_table_index];
speed_helper_counter = 0;
}
else if (speed_step_table_end_index < speed_table_index && speed_helper_counter == decel_rate) {
// Deceleration
if (!decel_rate) speed_table_index = speed_step_table_end_index; // directly decelerate to end target speed
else speed_table_index--;
ctrl_par->setpoint = ctrl_par->speed_table[speed_table_index];
speed_helper_counter = 0;
}
else if (direction_changed) {
// Change of direction while decelerating -> jump to most recent speed_step without delay (other direction)
speed_table_index = speed_step_table_end_index;
ctrl_par->setpoint = ctrl_par->speed_table[speed_table_index];
speed_helper_counter = 0;
}
else if (speed_step_table_end_index != speed_table_index) {
// Acceleration/Deceleration "scheduled"
speed_helper_counter++;
}
else {
// Target reached -> Reset Counter
speed_helper_counter = 0;
}
}
// Helper function to adjust pwm level/duty cycle.
void adjust_pwm_level(const uint16_t level) {
direction_t dir = get_direction_of_speed_step(speed_step_target);
if (dir == DIRECTION_FORWARD) {
// Forward
pwm_set_gpio_level(MOTOR_REV_PIN, 0);
pwm_set_gpio_level(MOTOR_FWD_PIN, level);
}
else if (dir == DIRECTION_REVERSE){
// Reverse
pwm_set_gpio_level(MOTOR_FWD_PIN, 0);
pwm_set_gpio_level(MOTOR_REV_PIN, level);
}
}
// Returns proportional gain value corresponding to current setpoint
float get_kp(const controller_parameter_t *const ctrl_par) {
const float sp = (float) ctrl_par->setpoint;
if (sp < ctrl_par->pid.k_p_x_1) {
return ctrl_par->pid.k_p_m_1 * sp + ctrl_par->pid.k_p_y_0;
}
return ctrl_par->pid.k_p_m_2 * (sp - ctrl_par->pid.k_p_x_1) + ctrl_par->pid.k_p_y_1;
}
uint16_t get_initial_level(controller_parameter_t *const ctrl_par){
uint32_t sum = 0;
uint32_t i = 0;
while (i < 16) {
if (ctrl_par->startup.base_pwm_arr[i] > 0) {
sum += ctrl_par->startup.base_pwm_arr[i];
i++;
}
else {
break;
}
}
return ((sum / i)*2)/3;
}
// Controller - Startup mode
void controller_startup_mode(controller_parameter_t *const ctrl_par) {
if(ctrl_par->startup.level == 0) {
ctrl_par->startup.level = get_initial_level(ctrl_par);
}
if (ctrl_par->measurement_corrected < 7.5f){
const uint16_t max_level = _125M / (CV_ARRAY_FLASH[8] * 100 + 10000);
adjust_pwm_level(ctrl_par->startup.level);
ctrl_par->startup.level += max_level / 250;
if (ctrl_par->startup.level > max_level) {
// Try again with half value...
ctrl_par->startup.level = get_initial_level(ctrl_par)/2;
}
}
else {
// Save level value in array
ctrl_par->startup.base_pwm_arr[ctrl_par->startup.base_pwm_arr_i] = ctrl_par->startup.level;
// Update index
ctrl_par->startup.base_pwm_arr_i = (ctrl_par->startup.base_pwm_arr_i+1)%16;
// Set ramp_up_mode flag to true
ctrl_par->mode = PID_MODE;
// multiply with constant value of 0.9 and set as current feed forward value for pid mode
ctrl_par->feed_fwd = 0.9f * (float)ctrl_par->startup.level;
}
}
// Controller - PID control mode
void controller_pid_mode(controller_parameter_t *const ctrl_par) {
ctrl_par->pid.k_p = get_kp(ctrl_par);
// Proportional part, integral part and derivative part (including digital low-pass-filter with time constant tau)
float p = ctrl_par->pid.k_p * ctrl_par->pid.e;
float i = ctrl_par->pid.ci_0 * (ctrl_par->pid.e + ctrl_par->pid.e_prev) + ctrl_par->pid.i_prev;
float d = ctrl_par->pid.cd_0 * (ctrl_par->measurement - ctrl_par->measurement_prev) + ctrl_par->pid.cd_1 * ctrl_par->pid.d_prev;
// Check for limits on the integral part
if (i > ctrl_par->pid.int_lim_max) {
i = ctrl_par->pid.int_lim_max;
}
else if (i < ctrl_par->pid.int_lim_min) {
i = ctrl_par->pid.int_lim_min;
}
// Sum feed forward + all controller terms (p+i+d). Limit Output from 0% to 100% duty cycle
float output_f = ctrl_par->feed_fwd + p + i + d;
if (output_f < 0) {
output_f = 0.0f;
}
else if (output_f > ctrl_par->pid.max_output) {
output_f = ctrl_par->pid.max_output;
}
if (LOGLEVEL >= 1) {
static int counter = 0;
counter++;
if (counter > 200) {
LOG(1, "ctrl_par error(%f) output(%f)\n", ctrl_par->pid.e, output_f);
counter = 0;
}
}
// Set PWM Level and discard results in adc fifo
//adjust_pwm_level((uint16_t) roundf(output_f));
adjust_pwm_level((uint16_t) output_f);
// Save previous error, integrator, differentiator values
ctrl_par->pid.e_prev = ctrl_par->pid.e;
ctrl_par->pid.i_prev = i;
ctrl_par->pid.d_prev = d;
}
// General controller function gets called every x milliseconds where x is CV_49 i.e. sampling time (pid->t)
// TODO: Consider fixed point arithmetic to improve performance...
void controller_general(controller_parameter_t * ctrl_par) {
// Change in direction -> reset previous derivative, error and integral parts and pwm_base_done
const bool direction_changed = get_direction_of_speed_step(speed_step_target) !=
get_direction_of_speed_step(speed_step_target_prev);
// When setpoint == 0 there is nothing to control -> set output to 0, reset values and return
if (!ctrl_par->setpoint || direction_changed) {
ctrl_par->pid.d_prev = 0.0f;
ctrl_par->pid.i_prev = 0.0f;
ctrl_par->pid.e_prev = 0.0f;
ctrl_par->mode = STARTUP_MODE;
ctrl_par->startup.level = 0;
adjust_pwm_level(0);
return;
}
// Measure BEMF voltage and compute error
ctrl_par->measurement = measure(ctrl_par->msr_total_iterations,
ctrl_par->msr_delay_in_us,
ctrl_par->l_side_arr_cutoff,
ctrl_par->r_side_arr_cutoff,
get_direction_of_speed_step(speed_step_target));
ctrl_par->measurement_corrected = ctrl_par->measurement - ctrl_par->adc_offset;
ctrl_par->pid.e = (float) ctrl_par->setpoint - ctrl_par->measurement_corrected;
switch (ctrl_par->mode){
case STARTUP_MODE:
controller_startup_mode(ctrl_par);
break;
case PID_MODE:
controller_pid_mode(ctrl_par);
break;
}
adc_fifo_drain();
// Save measurement value
ctrl_par->measurement_prev = ctrl_par->measurement;
}
// PID controller and measurement parameter, and speed_table initialization
void init_controller(controller_parameter_t *const ctrl_par) {
LOG(1, "Motor controller initialization...\n")
// General controller variables
ctrl_par->mode = STARTUP_MODE;
ctrl_par->feed_fwd = 0;
// Startup controller variables
ctrl_par->startup.level = 0;
ctrl_par->startup.base_pwm_arr_i = 0;
for (int i = 0; i < BASE_PWM_ARR_LEN; ++i) {
ctrl_par->startup.base_pwm_arr[i] = 0;
}
// Measurement variables initialization
ctrl_par->adc_offset = (float) CV_ARRAY_FLASH[171];
ctrl_par->msr_total_iterations = CV_ARRAY_FLASH[60];
ctrl_par->msr_delay_in_us = CV_ARRAY_FLASH[61];
ctrl_par->l_side_arr_cutoff = CV_ARRAY_FLASH[62];
ctrl_par->r_side_arr_cutoff = CV_ARRAY_FLASH[63];
// Speed table initialization
// Calculate speed setpoint table according to V_min, V_max and V_mid CVs
const double v_min = (double) CV_ARRAY_FLASH[1];
const double v_mid = (double) CV_ARRAY_FLASH[5] * 16;
const double v_max = (double) CV_ARRAY_FLASH[4] * 16;
const double delta_x = 63;
const double m_1 = (v_mid - v_min) / delta_x;
const double m_2 = (v_max - v_mid) / delta_x;
ctrl_par->speed_table[0] = 0;
for (uint8_t i = 1; i < 64; ++i) {
ctrl_par->speed_table[i] = (uint16_t) lround(m_1 * (i - 1) + v_min);
}
for (uint8_t i = 64; i < 127; ++i) {
ctrl_par->speed_table[i] = (uint16_t) lround(m_2 * (i - 63) + v_mid);
}
// PID Controller initialization
ctrl_par->pid.k_i = (float) CV_ARRAY_FLASH[49] / 10;
ctrl_par->pid.k_d = (float) CV_ARRAY_FLASH[50] / 10000;
ctrl_par->pid.tau = (float) CV_ARRAY_FLASH[47] / 1000;
ctrl_par->pid.t = (float) CV_ARRAY_FLASH[48] / 1000;
ctrl_par->pid.ci_0 = (ctrl_par->pid.k_i * ctrl_par->pid.t) / 2;
ctrl_par->pid.cd_0 = -(2 * ctrl_par->pid.k_d) / (2 * ctrl_par->pid.tau + ctrl_par->pid.t);
ctrl_par->pid.cd_1 = (2 * ctrl_par->pid.tau - ctrl_par->pid.t) / (2 * ctrl_par->pid.tau + ctrl_par->pid.t);
ctrl_par->pid.int_lim_max = 10 * (float) CV_ARRAY_FLASH[51];
ctrl_par->pid.int_lim_min = -10 * (float) CV_ARRAY_FLASH[52];
ctrl_par->pid.max_output = (float) (_125M / (CV_ARRAY_FLASH[8] * 100 + 10000));
ctrl_par->pid.e_prev = 0.0f;
ctrl_par->pid.i_prev = 0.0f;
ctrl_par->pid.d_prev = 0.0f;
ctrl_par->pid.k_p_x_1_shift = (float) CV_ARRAY_FLASH[59] / 255.0f;
ctrl_par->pid.k_p_x_1 = (float) ctrl_par->speed_table[126] * ctrl_par->pid.k_p_x_1_shift;
ctrl_par->pid.k_p_x_2 = (float) ctrl_par->speed_table[126] * (1.0f - ctrl_par->pid.k_p_x_1_shift);
ctrl_par->pid.k_p_y_0 = (float) get_16bit_CV(53) / 100.0f;
ctrl_par->pid.k_p_y_1 = (float) get_16bit_CV(55) / 100.0f;
ctrl_par->pid.k_p_y_2 = (float) get_16bit_CV(57) / 100.0f;
ctrl_par->pid.k_p_m_1 = (ctrl_par->pid.k_p_y_1 - ctrl_par->pid.k_p_y_0) / ctrl_par->pid.k_p_x_1;
ctrl_par->pid.k_p_m_2 = (ctrl_par->pid.k_p_y_2 - ctrl_par->pid.k_p_y_1) / ctrl_par->pid.k_p_x_2;
// General Controller initialization
ctrl_par->measurement = 0.0f;
ctrl_par->measurement_prev = 0.0f;
ctrl_par->measurement_corrected = 0.0f;
ctrl_par->setpoint = 0;
LOG(1, "Motor controller initialization done!\n")
}
bool controller_timer_callback(__unused struct repeating_timer *t) {
controller_flag = true;
return true;
}
bool speed_helper_timer_callback(__unused struct repeating_timer *t) {
speed_helper_flag = true;
return true;
}
void core1_entry() {
LOG(1, "core1 Initialization...\n");
flash_safe_execute_core_init_done = flash_safe_execute_core_init();
if (flash_safe_execute_core_init_done != true){
set_error(FLASH_SAFE_EXECUTE_CORE_INIT_FAILURE);
return;
}
// Wait for core0 to finish CV check (see cv_setup_check)
LOG(1, "Waiting for CV check flag...\n");
while(!cv_setup_check_done){
watchdog_update(); // Update watchdog while waiting on core0
}
controller_parameter_t control_parameter;
controller_parameter_t *ctrl_par = &control_parameter;
init_controller(ctrl_par);
struct repeating_timer timer_controller, timer_speed_helper;
add_repeating_timer_ms(-CV_ARRAY_FLASH[48], controller_timer_callback, NULL, &timer_controller);
add_repeating_timer_ms(-CV_ARRAY_FLASH[174], speed_helper_timer_callback, NULL, &timer_speed_helper);
LOG(1, "core1 initialization done!\n");
// Endless loop
while (true) {
if (controller_flag) {
controller_general(ctrl_par);
controller_flag = false;
}
else if (speed_helper_flag) {
speed_helper(ctrl_par);
speed_helper_flag = false;
}
else {
watchdog_update();
}
}
}
+181
View File
@@ -0,0 +1,181 @@
/*!
*
* \file core1.h
* Used exclusively by core1
*
*/
#pragma once
#include "shared.h"
#define BASE_PWM_ARR_LEN 16
typedef enum {
STARTUP_MODE,
PID_MODE,
} controller_mode_t;
typedef struct startup_parameters_t {
uint16_t level;
uint16_t base_pwm_arr[BASE_PWM_ARR_LEN];
uint16_t base_pwm_arr_i;
}startup_parameters_t;
typedef struct pid_parameters_t{
// PID Controller variables
float k_i; // Integral gain
float k_d; // Derivative gain
float t; // Sampling time
float tau; // Low-pass-filter time constant
float ci_0; // (k_i*t)/2
float cd_0; // (k_d*2)/(2*tau+t)
float cd_1; // (2*tau-t)/(2*tau+t)
float int_lim_max; // max limit for integrator
float int_lim_min; // min limit for integrator
float max_output; // max possible pwm output value
float k_p; // Proportional gain
float e; // Error
float e_prev; // Previous Error
float i_prev; // Previous Integral Value
float d_prev; // Previous Derivative Value
// Variable gain variables
float k_p_x_1_shift;
float k_p_x_1;
float k_p_x_2;
float k_p_y_0;
float k_p_y_1;
float k_p_y_2;
float k_p_m_1;
float k_p_m_2;
} pid_parameter_t;
typedef struct controller_parameter_t{
/*!
* General Variables
*/
controller_mode_t mode; // Controller mode
float feed_fwd; // Feed forward value
uint32_t setpoint; // Current setpoint
uint16_t speed_table[127]; // Array with setpoint values corresponding to every speed step
/*!
* Startup controller mode specific variables
*/
startup_parameters_t startup;
/*!
* PID Controller variables
*/
pid_parameter_t pid;
/*!
* Measurement Variables
*/
float measurement; // Newest Measurement value
float measurement_prev; // Previous Measurement
float measurement_corrected; // measurement - adc_offset = measurement_corrected
float adc_offset; // ADC offset value
uint8_t msr_delay_in_us; // Delay before VEMF Measurement
uint8_t msr_total_iterations; // Amount of samples
uint8_t l_side_arr_cutoff; // Discarded samples (left side)
uint8_t r_side_arr_cutoff; // Discarded samples (right side)
} controller_parameter_t;
/**
* @brief Measures Back-EMF voltage (proportional to the rotational speed of the motor) on GPIO 28 and GPIO 29 respectively (depending on direction).
*
* This function performs multiple ADC measurements, sorts the results using insertion sort, and calculates the average of the middle values,
* discarding a specified number of the lowest and highest values.
*
* @param total_iterations The total number of ADC measurements to perform.
* @param measurement_delay_us The delay in microseconds between the switch-off of the motor PWM and the measurement.
* @param l_side_arr_cutoff The number of lowest ADC values to discard.
* @param r_side_arr_cutoff The number of highest ADC values to discard.
* @param direction The direction of the motor.
* @return The average of the middle ADC values after discarding the specified number of lowest and highest values.
*/
float measure(uint8_t total_iterations,
uint8_t measurement_delay_us,
uint8_t l_side_arr_cutoff,
uint8_t r_side_arr_cutoff,
direction_t direction);
/**
* @brief Get the speed step table index based on the speed step value.
*
* @param speed_step The speed step value.
* @return The index in the speed step table.
*/
uint8_t get_speed_step_table_index_of_speed_step(uint8_t speed_step);
/**
* @brief Repeating timer callback function called every x milliseconds to implement a time delay in acceleration or deceleration.
*
* x is CV_175
*
* @param ctrl_par Pointer to the controller parameter structure.
*/
void speed_helper(controller_parameter_t * ctrl_par);
/**
* @brief Function to adjust the PWM level/duty cycle.
*
* @param level The new PWM level.
*/
void adjust_pwm_level(uint16_t level);
/**
* @brief Function to calculate and return the proportional gain based on the speed step.
*
* This is done in order to make kp dependent on the speed step (gain scheduling).
*
* @param ctrl_par Pointer to the controller parameter structure.
* @return The proportional gain.
*/
float get_kp(const controller_parameter_t *ctrl_par);
/**
* @brief Calculate and return the initial PWM level.
*
* Calculation is done by taking the last 16 initial levels (when available) and calculating the average.
* The average is the multiplied by a factor of 2/3.
*
* @param ctrl_par Pointer to the controller parameter structure.
* @return The initial PWM level.
*/
uint16_t get_initial_level(controller_parameter_t * ctrl_par);
/**
* @brief Controller function for startup mode.
*
* This is called inside the controller_general() function when the controller mode is set to STARTUP_MODE.
*
* @param ctrl_par Pointer to the controller parameter structure.
*/
void controller_startup_mode(controller_parameter_t * ctrl_par);
/**
* @brief Controller function for PID mode.
*
* This is called inside the controller_general() function when the controller mode is set to PID_MODE.
*
* @param ctrl_par Pointer to the controller parameter structure.
*/
void controller_pid_mode(controller_parameter_t *const ctrl_par);
/**
* @brief General controller function called every x milliseconds.
*
* @param ctrl_par Pointer to the controller parameter structure.
*/
void controller_general(controller_parameter_t * ctrl_par);
/**
* @brief Initialize controller variables, measurement parameters, and speed table.
*
* @param ctrl_par Pointer to the controller parameter structure.
*/
void init_controller(controller_parameter_t * ctrl_par);
@@ -18,9 +18,20 @@ if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_P
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
endif ()
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_TAG} AND (NOT PICO_SDK_FETCH_FROM_GIT_TAG))
set(PICO_SDK_FETCH_FROM_GIT_TAG $ENV{PICO_SDK_FETCH_FROM_GIT_TAG})
message("Using PICO_SDK_FETCH_FROM_GIT_TAG from environment ('${PICO_SDK_FETCH_FROM_GIT_TAG}')")
endif ()
if (PICO_SDK_FETCH_FROM_GIT AND NOT PICO_SDK_FETCH_FROM_GIT_TAG)
set(PICO_SDK_FETCH_FROM_GIT_TAG "master")
message("Using master as default value for PICO_SDK_FETCH_FROM_GIT_TAG")
endif()
set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable")
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
set(PICO_SDK_FETCH_FROM_GIT_TAG "${PICO_SDK_FETCH_FROM_GIT_TAG}" CACHE FILEPATH "release tag for SDK")
if (NOT PICO_SDK_PATH)
if (PICO_SDK_FETCH_FROM_GIT)
@@ -29,11 +40,22 @@ if (NOT PICO_SDK_PATH)
if (PICO_SDK_FETCH_FROM_GIT_PATH)
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
endif ()
FetchContent_Declare(
pico_sdk
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG master
)
# GIT_SUBMODULES_RECURSE was added in 3.17
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
FetchContent_Declare(
pico_sdk
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
GIT_SUBMODULES_RECURSE FALSE
)
else ()
FetchContent_Declare(
pico_sdk
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
)
endif ()
if (NOT pico_sdk)
message("Downloading Raspberry Pi Pico SDK")
FetchContent_Populate(pico_sdk)
+65
View File
@@ -0,0 +1,65 @@
# Check if the required arguments are provided
if(NOT DEFINED BOARD_HEADER)
message(FATAL_ERROR "BOARD_HEADER argument is missing")
else()
message(STATUS "BOARD_HEADER: ${BOARD_HEADER}")
endif()
if(NOT DEFINED SIZE_TOOL)
message(FATAL_ERROR "SIZE_TOOL argument is missing")
else()
message(STATUS "SIZE_TOOL: ${SIZE_TOOL}")
endif()
if(NOT DEFINED ELF_FILE)
message(FATAL_ERROR "ELF_FILE argument is missing")
else()
message(STATUS "ELF_FILE: ${ELF_FILE}")
endif()
# Post build checks
# Run the size tool and read the output
execute_process(
COMMAND ${SIZE_TOOL} "${ELF_FILE}"
OUTPUT_VARIABLE SIZE_OUTPUT
RESULT_VARIABLE SIZE_RESULT
)
if(SIZE_RESULT)
message(FATAL_ERROR "Failed to run arm-none-eabi-size on ${ELF_FILE}")
else()
# Print the content of SIZE_OUTPUT
message(STATUS "arm-none-eabi-size output:\n${SIZE_OUTPUT}")
endif()
# Use regex to match all numbers
string(REGEX MATCHALL "[0-9]+" MATCHED_VALUES "${SIZE_OUTPUT}")
# Get third element from list of matches, this corresponds with dec table value in "size_output.txt"
list(GET MATCHED_VALUES 3 PROGRAM_SIZE_DEC)
# Check for success of program size extraction from "size_output.txt"
if(PROGRAM_SIZE_DEC)
message(STATUS "PROGRAM_SIZE_DEC: ${PROGRAM_SIZE_DEC} bytes")
else()
message(FATAL_ERROR "Could not extract program size from size_output.txt")
endif()
# Path to the header file that defines PICO_FLASH_SIZE_BYTES
set(FLASH_CONFIG_HEADER ${BOARD_HEADER})
# Read the contents of the header file into a variable
file(READ ${FLASH_CONFIG_HEADER} HEADER_CONTENT)
# Extract the value of PICO_FLASH_SIZE_BYTES using a regular expression
string(REGEX MATCHALL "#define PICO_FLASH_SIZE_BYTES [0-9]+" MACRO_MATCH "${HEADER_CONTENT}")
string(REGEX MATCHALL "[0-9]+" PICO_FLASH_SIZE_BYTES "${MACRO_MATCH}")
# Check for success of PICO_FLASH_SIZE_BYTES extraction from board header file
if(PICO_FLASH_SIZE_BYTES)
message(STATUS "PICO_FLASH_SIZE_BYTES: ${PICO_FLASH_SIZE_BYTES} bytes")
else()
message(FATAL_ERROR "Failed to find PICO_FLASH_SIZE_BYTES in the header file.")
endif()
# Sector size is always 4096 bytes
set(FLASH_SECTOR_SIZE 4096)
message(STATUS "FLASH_SECTOR_SIZE: ${FLASH_SECTOR_SIZE} bytes")
# Subtract flash sector size from flash size
math(EXPR FLASH_TARGET_OFFSET "${PICO_FLASH_SIZE_BYTES} - ${FLASH_SECTOR_SIZE}")
message(STATUS "FLASH_TARGET_OFFSET: ${FLASH_TARGET_OFFSET} bytes")
if(PROGRAM_SIZE_DEC GREATER FLASH_TARGET_OFFSET)
message(FATAL_ERROR "Program size exceeds allowed flash size. Flash sector containing the CVs would be overwritten! Please reduce the size of the program.")
endif()
+66
View File
@@ -0,0 +1,66 @@
//////////////////////////
// RP2040-Decoder //
// Gabriel Koppenstein //
// shared.c //
//////////////////////////
#include "shared.h"
// TODO: Implement enum typedef for speed steps, also getter and setter functions checking validity of speed step values.
speed_step_t speed_step_target = SPEED_STEP_REVERSE_STOP;
speed_step_t speed_step_target_prev = SPEED_STEP_REVERSE_STOP;
bool cv_setup_check_done = false;
bool flash_safe_execute_core_init_done = false;
static error_t error_state = 0;
// Functions in shared.c are accessed by both cores
// retrieve 4Bytes from CV_ARRAY_FLASH at once and return 32-Bit value
uint32_t get_32bit_CV (uint16_t CV_start_index){
uint8_t byte_3 = CV_ARRAY_FLASH[CV_start_index];
uint8_t byte_2 = CV_ARRAY_FLASH[CV_start_index+1];
uint8_t byte_1 = CV_ARRAY_FLASH[CV_start_index+2];
uint8_t byte_0 = CV_ARRAY_FLASH[CV_start_index+3];
return (byte_0) + (byte_1<<8) + (byte_2<<16) + (byte_3<<24);
}
// retrieve 2Bytes from CV_ARRAY_FLASH at once and return 16-Bit value
uint16_t get_16bit_CV (uint16_t CV_start_index){
uint8_t byte_1 = CV_ARRAY_FLASH[CV_start_index];
uint8_t byte_0 = CV_ARRAY_FLASH[CV_start_index+1];
return (byte_0) + (byte_1<<8);
}
direction_t get_direction_of_speed_step(speed_step_t speed_step){
// Bit 7 is the direction bit.
// Shift by 7 bits to move bit7 into bit0 position and return direction.
return speed_step >> 7;
}
void set_error(error_t err){
error_state |= err;
#ifdef RP2040_DECODER_DEFAULT_LED_PIN
gpio_put(RP2040_DECODER_DEFAULT_LED_PIN, true);
#endif
}
void clear_error(error_t err){
error_state &= (~err);
if (error_state == 0){
#ifdef RP2040_DECODER_DEFAULT_LED_PIN
gpio_put(RP2040_DECODER_DEFAULT_LED_PIN, false);
#endif
}
}
void clear_all_errors(){
error_state = 0;
#ifdef RP2040_DECODER_DEFAULT_LED_PIN
gpio_put(RP2040_DECODER_DEFAULT_LED_PIN, false);
#endif
}
error_t get_error_state(){
return error_state;
}
+360
View File
@@ -0,0 +1,360 @@
/*!
*
* \file shared.h
* Used by both cores
*
*/
#pragma once
#include "string.h"
#include "pico/float.h"
#include "pico/stdlib.h"
#include "pico/multicore.h"
#include "pico/printf.h"
#include "pico/flash.h"
#include "hardware/pwm.h"
#include "hardware/adc.h"
#include "hardware/flash.h"
#include "hardware/gpio.h"
#include "hardware/watchdog.h"
#include "hardware/exception.h"
#define LOG(level, ...) { \
if (level <= LOGLEVEL) { \
printf("[core%u @ %u ms] ", get_core_num(), to_ms_since_boot(get_absolute_time())); \
printf(__VA_ARGS__); \
} \
}
// Constant Value of 125 x 10^6
#define _125M 125000000
typedef enum {
FLASH_SAFE_EXECUTE_CORE_INIT_FAILURE = (1<<0),
FLASH_SAFE_EXECUTE_ERASE_FAILURE = (1<<1),
FLASH_SAFE_EXECUTE_PROGRAM_FAILURE = (1<<2),
FLASH_SIZE_READBACK_FAILURE = (1<<3),
STDIO_INIT_FAILURE = (1<<4),
REBOOT_BY_WATCHDOG = (1<<5),
INVALID_DIRECTION = (1<<6),
} error_t;
typedef enum {
DIRECTION_FORWARD = 1,
DIRECTION_REVERSE = 0,
} direction_t;
//TODO: Continue implementation of speed step enum
typedef enum {
SPEED_STEP_REVERSE_STOP = 0x00, // 00000000bin 000dec
SPEED_STEP_REVERSE_EMERGENCY_STOP = 0x01, // 00000001bin 001dec
SPEED_STEP_REVERSE_001 = 0x02, // 00000010bin 002dec
SPEED_STEP_REVERSE_002 = 0x03, // 00000011bin 003dec
SPEED_STEP_REVERSE_003 = 0x04, // 00000100bin 004dec
SPEED_STEP_REVERSE_004 = 0x05, // 00000101bin 005dec
SPEED_STEP_REVERSE_005 = 0x06, // 00000110bin 006dec
SPEED_STEP_REVERSE_006 = 0x07, // 00000111bin 007dec
SPEED_STEP_REVERSE_007 = 0x08, // 00001000bin 008dec
SPEED_STEP_REVERSE_008 = 0x09, // 00001001bin 009dec
SPEED_STEP_REVERSE_009 = 0x0A, // 00001010bin 010dec
SPEED_STEP_REVERSE_010 = 0x0B, // 00001011bin 011dec
SPEED_STEP_REVERSE_011 = 0x0C, // 00001100bin 012dec
SPEED_STEP_REVERSE_012 = 0x0D, // 00001101bin 013dec
SPEED_STEP_REVERSE_013 = 0x0E, // 00001110bin 014dec
SPEED_STEP_REVERSE_014 = 0x0F, // 00001111bin 015dec
SPEED_STEP_REVERSE_015 = 0x10, // 00010000bin 016dec
SPEED_STEP_REVERSE_016 = 0x11, // 00010001bin 017dec
SPEED_STEP_REVERSE_017 = 0x12, // 00010010bin 018dec
SPEED_STEP_REVERSE_018 = 0x13, // 00010011bin 019dec
SPEED_STEP_REVERSE_019 = 0x14, // 00010100bin 020dec
SPEED_STEP_REVERSE_020 = 0x15, // 00010101bin 021dec
SPEED_STEP_REVERSE_021 = 0x16, // 00010110bin 022dec
SPEED_STEP_REVERSE_022 = 0x17, // 00010111bin 023dec
SPEED_STEP_REVERSE_023 = 0x18, // 00011000bin 024dec
SPEED_STEP_REVERSE_024 = 0x19, // 00011001bin 025dec
SPEED_STEP_REVERSE_025 = 0x1A, // 00011010bin 026dec
SPEED_STEP_REVERSE_026 = 0x1B, // 00011011bin 027dec
SPEED_STEP_REVERSE_027 = 0x1C, // 00011100bin 028dec
SPEED_STEP_REVERSE_028 = 0x1D, // 00011101bin 029dec
SPEED_STEP_REVERSE_029 = 0x1E, // 00011110bin 030dec
SPEED_STEP_REVERSE_030 = 0x1F, // 00011111bin 031dec
SPEED_STEP_REVERSE_031 = 0x20, // 00100000bin 032dec
SPEED_STEP_REVERSE_032 = 0x21, // 00100001bin 033dec
SPEED_STEP_REVERSE_033 = 0x22, // 00100010bin 034dec
SPEED_STEP_REVERSE_034 = 0x23, // 00100011bin 035dec
SPEED_STEP_REVERSE_035 = 0x24, // 00100100bin 036dec
SPEED_STEP_REVERSE_036 = 0x25, // 00100101bin 037dec
SPEED_STEP_REVERSE_037 = 0x26, // 00100110bin 038dec
SPEED_STEP_REVERSE_038 = 0x27, // 00100111bin 039dec
SPEED_STEP_REVERSE_039 = 0x28, // 00101000bin 040dec
SPEED_STEP_REVERSE_040 = 0x29, // 00101001bin 041dec
SPEED_STEP_REVERSE_041 = 0x2A, // 00101010bin 042dec
SPEED_STEP_REVERSE_042 = 0x2B, // 00101011bin 043dec
SPEED_STEP_REVERSE_043 = 0x2C, // 00101100bin 044dec
SPEED_STEP_REVERSE_044 = 0x2D, // 00101101bin 045dec
SPEED_STEP_REVERSE_045 = 0x2E, // 00101110bin 046dec
SPEED_STEP_REVERSE_046 = 0x2F, // 00101111bin 047dec
SPEED_STEP_REVERSE_047 = 0x30, // 00110000bin 048dec
SPEED_STEP_REVERSE_048 = 0x31, // 00110001bin 049dec
SPEED_STEP_REVERSE_049 = 0x32, // 00110010bin 050dec
SPEED_STEP_REVERSE_050 = 0x33, // 00110011bin 051dec
SPEED_STEP_REVERSE_051 = 0x34, // 00110100bin 052dec
SPEED_STEP_REVERSE_052 = 0x35, // 00110101bin 053dec
SPEED_STEP_REVERSE_053 = 0x36, // 00110110bin 054dec
SPEED_STEP_REVERSE_054 = 0x37, // 00110111bin 055dec
SPEED_STEP_REVERSE_055 = 0x38, // 00111000bin 056dec
SPEED_STEP_REVERSE_056 = 0x39, // 00111001bin 057dec
SPEED_STEP_REVERSE_057 = 0x3A, // 00111010bin 058dec
SPEED_STEP_REVERSE_058 = 0x3B, // 00111011bin 059dec
SPEED_STEP_REVERSE_059 = 0x3C, // 00111100bin 060dec
SPEED_STEP_REVERSE_060 = 0x3D, // 00111101bin 061dec
SPEED_STEP_REVERSE_061 = 0x3E, // 00111110bin 062dec
SPEED_STEP_REVERSE_062 = 0x3F, // 00111111bin 063dec
SPEED_STEP_REVERSE_063 = 0x40, // 01000000bin 064dec
SPEED_STEP_REVERSE_064 = 0x41, // 01000001bin 065dec
SPEED_STEP_REVERSE_065 = 0x42, // 01000010bin 066dec
SPEED_STEP_REVERSE_066 = 0x43, // 01000011bin 067dec
SPEED_STEP_REVERSE_067 = 0x44, // 01000100bin 068dec
SPEED_STEP_REVERSE_068 = 0x45, // 01000101bin 069dec
SPEED_STEP_REVERSE_069 = 0x46, // 01000110bin 070dec
SPEED_STEP_REVERSE_070 = 0x47, // 01000111bin 071dec
SPEED_STEP_REVERSE_071 = 0x48, // 01001000bin 072dec
SPEED_STEP_REVERSE_072 = 0x49, // 01001001bin 073dec
SPEED_STEP_REVERSE_073 = 0x4A, // 01001010bin 074dec
SPEED_STEP_REVERSE_074 = 0x4B, // 01001011bin 075dec
SPEED_STEP_REVERSE_075 = 0x4C, // 01001100bin 076dec
SPEED_STEP_REVERSE_076 = 0x4D, // 01001101bin 077dec
SPEED_STEP_REVERSE_077 = 0x4E, // 01001110bin 078dec
SPEED_STEP_REVERSE_078 = 0x4F, // 01001111bin 079dec
SPEED_STEP_REVERSE_079 = 0x50, // 01010000bin 080dec
SPEED_STEP_REVERSE_080 = 0x51, // 01010001bin 081dec
SPEED_STEP_REVERSE_081 = 0x52, // 01010010bin 082dec
SPEED_STEP_REVERSE_082 = 0x53, // 01010011bin 083dec
SPEED_STEP_REVERSE_083 = 0x54, // 01010100bin 084dec
SPEED_STEP_REVERSE_084 = 0x55, // 01010101bin 085dec
SPEED_STEP_REVERSE_085 = 0x56, // 01010110bin 086dec
SPEED_STEP_REVERSE_086 = 0x57, // 01010111bin 087dec
SPEED_STEP_REVERSE_087 = 0x58, // 01011000bin 088dec
SPEED_STEP_REVERSE_088 = 0x59, // 01011001bin 089dec
SPEED_STEP_REVERSE_089 = 0x5A, // 01011010bin 090dec
SPEED_STEP_REVERSE_090 = 0x5B, // 01011011bin 091dec
SPEED_STEP_REVERSE_091 = 0x5C, // 01011100bin 092dec
SPEED_STEP_REVERSE_092 = 0x5D, // 01011101bin 093dec
SPEED_STEP_REVERSE_093 = 0x5E, // 01011110bin 094dec
SPEED_STEP_REVERSE_094 = 0x5F, // 01011111bin 095dec
SPEED_STEP_REVERSE_095 = 0x60, // 01100000bin 096dec
SPEED_STEP_REVERSE_096 = 0x61, // 01100001bin 097dec
SPEED_STEP_REVERSE_097 = 0x62, // 01100010bin 098dec
SPEED_STEP_REVERSE_098 = 0x63, // 01100011bin 099dec
SPEED_STEP_REVERSE_099 = 0x64, // 01100100bin 100dec
SPEED_STEP_REVERSE_100 = 0x65, // 01100101bin 101dec
SPEED_STEP_REVERSE_101 = 0x66, // 01100110bin 102dec
SPEED_STEP_REVERSE_102 = 0x67, // 01100111bin 103dec
SPEED_STEP_REVERSE_103 = 0x68, // 01101000bin 104dec
SPEED_STEP_REVERSE_104 = 0x69, // 01101001bin 105dec
SPEED_STEP_REVERSE_105 = 0x6A, // 01101010bin 106dec
SPEED_STEP_REVERSE_106 = 0x6B, // 01101011bin 107dec
SPEED_STEP_REVERSE_107 = 0x6C, // 01101100bin 108dec
SPEED_STEP_REVERSE_108 = 0x6D, // 01101101bin 109dec
SPEED_STEP_REVERSE_109 = 0x6E, // 01101110bin 110dec
SPEED_STEP_REVERSE_110 = 0x6F, // 01101111bin 111dec
SPEED_STEP_REVERSE_111 = 0x70, // 01110000bin 112dec
SPEED_STEP_REVERSE_112 = 0x71, // 01110001bin 113dec
SPEED_STEP_REVERSE_113 = 0x72, // 01110010bin 114dec
SPEED_STEP_REVERSE_114 = 0x73, // 01110011bin 115dec
SPEED_STEP_REVERSE_115 = 0x74, // 01110100bin 116dec
SPEED_STEP_REVERSE_116 = 0x75, // 01110101bin 117dec
SPEED_STEP_REVERSE_117 = 0x76, // 01110110bin 118dec
SPEED_STEP_REVERSE_118 = 0x77, // 01110111bin 119dec
SPEED_STEP_REVERSE_119 = 0x78, // 01111000bin 120dec
SPEED_STEP_REVERSE_120 = 0x79, // 01111001bin 121dec
SPEED_STEP_REVERSE_121 = 0x7A, // 01111010bin 122dec
SPEED_STEP_REVERSE_122 = 0x7B, // 01111011bin 123dec
SPEED_STEP_REVERSE_123 = 0x7C, // 01111100bin 124dec
SPEED_STEP_REVERSE_124 = 0x7D, // 01111101bin 125dec
SPEED_STEP_REVERSE_125 = 0x7E, // 01111110bin 126dec
SPEED_STEP_REVERSE_126 = 0x7F, // 01111111bin 127dec
SPEED_STEP_FORWARD_STOP = 0x80, // 10000000bin 128dec
SPEED_STEP_FORWARD_EMERGENCY_STOP = 0x81, // 10000001bin 129dec
SPEED_STEP_FORWARD_001 = 0x82, // 10000010bin 130dec
SPEED_STEP_FORWARD_002 = 0x83, // 10000011bin 131dec
SPEED_STEP_FORWARD_003 = 0x84, // 10000100bin 132dec
SPEED_STEP_FORWARD_004 = 0x85, // 10000101bin 133dec
SPEED_STEP_FORWARD_005 = 0x86, // 10000110bin 134dec
SPEED_STEP_FORWARD_006 = 0x87, // 10000111bin 135dec
SPEED_STEP_FORWARD_007 = 0x88, // 10001000bin 136dec
SPEED_STEP_FORWARD_008 = 0x89, // 10001001bin 137dec
SPEED_STEP_FORWARD_009 = 0x8A, // 10001010bin 138dec
SPEED_STEP_FORWARD_010 = 0x8B, // 10001011bin 139dec
SPEED_STEP_FORWARD_011 = 0x8C, // 10001100bin 140dec
SPEED_STEP_FORWARD_012 = 0x8D, // 10001101bin 141dec
SPEED_STEP_FORWARD_013 = 0x8E, // 10001110bin 142dec
SPEED_STEP_FORWARD_014 = 0x8F, // 10001111bin 143dec
SPEED_STEP_FORWARD_015 = 0x90, // 10010000bin 144dec
SPEED_STEP_FORWARD_016 = 0x91, // 10010001bin 145dec
SPEED_STEP_FORWARD_017 = 0x92, // 10010010bin 146dec
SPEED_STEP_FORWARD_018 = 0x93, // 10010011bin 147dec
SPEED_STEP_FORWARD_019 = 0x94, // 10010100bin 148dec
SPEED_STEP_FORWARD_020 = 0x95, // 10010101bin 149dec
SPEED_STEP_FORWARD_021 = 0x96, // 10010110bin 150dec
SPEED_STEP_FORWARD_022 = 0x97, // 10010111bin 151dec
SPEED_STEP_FORWARD_023 = 0x98, // 10011000bin 152dec
SPEED_STEP_FORWARD_024 = 0x99, // 10011001bin 153dec
SPEED_STEP_FORWARD_025 = 0x9A, // 10011010bin 154dec
SPEED_STEP_FORWARD_026 = 0x9B, // 10011011bin 155dec
SPEED_STEP_FORWARD_027 = 0x9C, // 10011100bin 156dec
SPEED_STEP_FORWARD_028 = 0x9D, // 10011101bin 157dec
SPEED_STEP_FORWARD_029 = 0x9E, // 10011110bin 158dec
SPEED_STEP_FORWARD_030 = 0x9F, // 10011111bin 159dec
SPEED_STEP_FORWARD_031 = 0xA0, // 10100000bin 160dec
SPEED_STEP_FORWARD_032 = 0xA1, // 10100001bin 161dec
SPEED_STEP_FORWARD_033 = 0xA2, // 10100010bin 162dec
SPEED_STEP_FORWARD_034 = 0xA3, // 10100011bin 163dec
SPEED_STEP_FORWARD_035 = 0xA4, // 10100100bin 164dec
SPEED_STEP_FORWARD_036 = 0xA5, // 10100101bin 165dec
SPEED_STEP_FORWARD_037 = 0xA6, // 10100110bin 166dec
SPEED_STEP_FORWARD_038 = 0xA7, // 10100111bin 167dec
SPEED_STEP_FORWARD_039 = 0xA8, // 10101000bin 168dec
SPEED_STEP_FORWARD_040 = 0xA9, // 10101001bin 169dec
SPEED_STEP_FORWARD_041 = 0xAA, // 10101010bin 170dec
SPEED_STEP_FORWARD_042 = 0xAB, // 10101011bin 171dec
SPEED_STEP_FORWARD_043 = 0xAC, // 10101100bin 172dec
SPEED_STEP_FORWARD_044 = 0xAD, // 10101101bin 173dec
SPEED_STEP_FORWARD_045 = 0xAE, // 10101110bin 174dec
SPEED_STEP_FORWARD_046 = 0xAF, // 10101111bin 175dec
SPEED_STEP_FORWARD_047 = 0xB0, // 10110000bin 176dec
SPEED_STEP_FORWARD_048 = 0xB1, // 10110001bin 177dec
SPEED_STEP_FORWARD_049 = 0xB2, // 10110010bin 178dec
SPEED_STEP_FORWARD_050 = 0xB3, // 10110011bin 179dec
SPEED_STEP_FORWARD_051 = 0xB4, // 10110100bin 180dec
SPEED_STEP_FORWARD_052 = 0xB5, // 10110101bin 181dec
SPEED_STEP_FORWARD_053 = 0xB6, // 10110110bin 182dec
SPEED_STEP_FORWARD_054 = 0xB7, // 10110111bin 183dec
SPEED_STEP_FORWARD_055 = 0xB8, // 10111000bin 184dec
SPEED_STEP_FORWARD_056 = 0xB9, // 10111001bin 185dec
SPEED_STEP_FORWARD_057 = 0xBA, // 10111010bin 186dec
SPEED_STEP_FORWARD_058 = 0xBB, // 10111011bin 187dec
SPEED_STEP_FORWARD_059 = 0xBC, // 10111100bin 188dec
SPEED_STEP_FORWARD_060 = 0xBD, // 10111101bin 189dec
SPEED_STEP_FORWARD_061 = 0xBE, // 10111110bin 190dec
SPEED_STEP_FORWARD_062 = 0xBF, // 10111111bin 191dec
SPEED_STEP_FORWARD_063 = 0xC0, // 11000000bin 192dec
SPEED_STEP_FORWARD_064 = 0xC1, // 11000001bin 193dec
SPEED_STEP_FORWARD_065 = 0xC2, // 11000010bin 194dec
SPEED_STEP_FORWARD_066 = 0xC3, // 11000011bin 195dec
SPEED_STEP_FORWARD_067 = 0xC4, // 11000100bin 196dec
SPEED_STEP_FORWARD_068 = 0xC5, // 11000101bin 197dec
SPEED_STEP_FORWARD_069 = 0xC6, // 11000110bin 198dec
SPEED_STEP_FORWARD_070 = 0xC7, // 11000111bin 199dec
SPEED_STEP_FORWARD_071 = 0xC8, // 11001000bin 200dec
SPEED_STEP_FORWARD_072 = 0xC9, // 11001001bin 201dec
SPEED_STEP_FORWARD_073 = 0xCA, // 11001010bin 202dec
SPEED_STEP_FORWARD_074 = 0xCB, // 11001011bin 203dec
SPEED_STEP_FORWARD_075 = 0xCC, // 11001100bin 204dec
SPEED_STEP_FORWARD_076 = 0xCD, // 11001101bin 205dec
SPEED_STEP_FORWARD_077 = 0xCE, // 11001110bin 206dec
SPEED_STEP_FORWARD_078 = 0xCF, // 11001111bin 207dec
SPEED_STEP_FORWARD_079 = 0xD0, // 11010000bin 208dec
SPEED_STEP_FORWARD_080 = 0xD1, // 11010001bin 209dec
SPEED_STEP_FORWARD_081 = 0xD2, // 11010010bin 210dec
SPEED_STEP_FORWARD_082 = 0xD3, // 11010011bin 211dec
SPEED_STEP_FORWARD_083 = 0xD4, // 11010100bin 212dec
SPEED_STEP_FORWARD_084 = 0xD5, // 11010101bin 213dec
SPEED_STEP_FORWARD_085 = 0xD6, // 11010110bin 214dec
SPEED_STEP_FORWARD_086 = 0xD7, // 11010111bin 215dec
SPEED_STEP_FORWARD_087 = 0xD8, // 11011000bin 216dec
SPEED_STEP_FORWARD_088 = 0xD9, // 11011001bin 217dec
SPEED_STEP_FORWARD_089 = 0xDA, // 11011010bin 218dec
SPEED_STEP_FORWARD_090 = 0xDB, // 11011011bin 219dec
SPEED_STEP_FORWARD_091 = 0xDC, // 11011100bin 220dec
SPEED_STEP_FORWARD_092 = 0xDD, // 11011101bin 221dec
SPEED_STEP_FORWARD_093 = 0xDE, // 11011110bin 222dec
SPEED_STEP_FORWARD_094 = 0xDF, // 11011111bin 223dec
SPEED_STEP_FORWARD_095 = 0xE0, // 11100000bin 224dec
SPEED_STEP_FORWARD_096 = 0xE1, // 11100001bin 225dec
SPEED_STEP_FORWARD_097 = 0xE2, // 11100010bin 226dec
SPEED_STEP_FORWARD_098 = 0xE3, // 11100011bin 227dec
SPEED_STEP_FORWARD_099 = 0xE4, // 11100100bin 228dec
SPEED_STEP_FORWARD_100 = 0xE5, // 11100101bin 229dec
SPEED_STEP_FORWARD_101 = 0xE6, // 11100110bin 230dec
SPEED_STEP_FORWARD_102 = 0xE7, // 11100111bin 231dec
SPEED_STEP_FORWARD_103 = 0xE8, // 11101000bin 232dec
SPEED_STEP_FORWARD_104 = 0xE9, // 11101001bin 233dec
SPEED_STEP_FORWARD_105 = 0xEA, // 11101010bin 234dec
SPEED_STEP_FORWARD_106 = 0xEB, // 11101011bin 235dec
SPEED_STEP_FORWARD_107 = 0xEC, // 11101100bin 236dec
SPEED_STEP_FORWARD_108 = 0xED, // 11101101bin 237dec
SPEED_STEP_FORWARD_109 = 0xEE, // 11101110bin 238dec
SPEED_STEP_FORWARD_110 = 0xEF, // 11101111bin 239dec
SPEED_STEP_FORWARD_111 = 0xF0, // 11110000bin 240dec
SPEED_STEP_FORWARD_112 = 0xF1, // 11110001bin 241dec
SPEED_STEP_FORWARD_113 = 0xF2, // 11110010bin 242dec
SPEED_STEP_FORWARD_114 = 0xF3, // 11110011bin 243dec
SPEED_STEP_FORWARD_115 = 0xF4, // 11110100bin 244dec
SPEED_STEP_FORWARD_116 = 0xF5, // 11110101bin 245dec
SPEED_STEP_FORWARD_117 = 0xF6, // 11110110bin 246dec
SPEED_STEP_FORWARD_118 = 0xF7, // 11110111bin 247dec
SPEED_STEP_FORWARD_119 = 0xF8, // 11111000bin 248dec
SPEED_STEP_FORWARD_120 = 0xF9, // 11111001bin 249dec
SPEED_STEP_FORWARD_121 = 0xFA, // 11111010bin 250dec
SPEED_STEP_FORWARD_122 = 0xFB, // 11111011bin 251dec
SPEED_STEP_FORWARD_123 = 0xFC, // 11111100bin 252dec
SPEED_STEP_FORWARD_124 = 0xFD, // 11111101bin 253dec
SPEED_STEP_FORWARD_125 = 0xFE, // 11111110bin 254dec
SPEED_STEP_FORWARD_126 = 0xFF, // 11111111bin 255dec
} speed_step_t;
extern repeating_timer_t pid_control_timer;
extern repeating_timer_t speed_helper_timer;
extern const uint8_t *CV_ARRAY_FLASH;
extern speed_step_t speed_step_target;
extern speed_step_t speed_step_target_prev;
extern bool cv_setup_check_done;
extern bool flash_safe_execute_core_init_done;
void core1_entry();
uint32_t get_32bit_CV (uint16_t CV_start_index);
uint16_t get_16bit_CV (uint16_t CV_start_index);
/*!
* @brief Calculates the direction based on a speed step byte.
*
* This function calculates the direction of movement based on the value of
* the `speed_step` byte. It refers to the "128 Speed Control" standard as outlined
* in NMRA Standard 9.2.1 section 2.3.2.1 or RCN-212 section 2.2.2.
*
* The following speed steps are defined:
*
* | DEC | BIN | DIRECTION | DEFINITION |
* |-----|-----------|-----------|----------------------|
* | 000 | 0000 0000 | Reverse | STOP |
* | 001 | 0000 0001 | Reverse | EMERGENCY STOP |
* | 002 | 0000 0010 | Reverse | Speed step 001 |
* | 003 | 0000 0011 | Reverse | Speed step 002 |
* | 004 | 0000 0100 | Reverse | Speed step 003 |
* | ... | .... .... | Reverse | ... |
* | 126 | 0111 1110 | Reverse | Speed step 125 |
* | 127 | 0111 1111 | Reverse | Speed step 126 |
* | 128 | 1000 0000 | Forward | STOP |
* | 129 | 1000 0001 | Forward | EMERGENCY STOP |
* | 130 | 1000 0010 | Forward | Speed step 001 |
* | 131 | 1000 0011 | Forward | Speed step 002 |
* | 132 | 1000 0100 | Forward | Speed step 003 |
* | ... | .... .... | Forward | ... |
* | 254 | 1111 1110 | Forward | Speed step 125 |
* | 255 | 1111 1111 | Forward | Speed step 126 |
*
* @param speed_step The speed step byte.
* @return `DIRECTION_FORWARD` for forward direction, `DIRECTION_REVERSE` for reverse direction.
*/
direction_t get_direction_of_speed_step(speed_step_t speed_step);
void set_error(error_t err);
void clear_error(error_t err);
void clear_all_errors();
error_t get_error_state();
-638
View File
@@ -1,638 +0,0 @@
//////////////////////////
// RP2040-Decoder //
// Gabriel Koppenstein //
// core0.c //
//////////////////////////
#include "core0.h"
// XIP_BASE + FLASH_TARGET_OFFSET = "0x101FF000"
const uint8_t *CV_ARRAY_FLASH = (const uint8_t *) (XIP_BASE + FLASH_TARGET_OFFSET);
uint64_t input_bit_buffer = 0;
uint16_t level_table[32] = {0};
absolute_time_t falling_edge_time,rising_edge_time;
// Function returns average of values deviating less than twice the standard deviation from original average
float two_std_dev(const float arr[], uint32_t length){
// Calculate arithmetic average
float sum = 0;
for (uint32_t i = 0; i < length; ++i) {
sum += arr[i];
}
float x_avg = sum / (float)length;
// Calculate sample variance and sampled standard deviation
sum = 0;
for (uint32_t i = 0; i < length; ++i) {
sum += (arr[i]-x_avg)*(arr[i]-x_avg);
}
float variance = sum / (float)(length-1);
float std_dev = sqrtf(variance);
// Sum every element that is within two times the sampled standard deviation and compute new average
sum = 0;
uint32_t counter = 0;
for (uint32_t i = 0; i < length; ++i) {
float diff = fabsf(arr[i]-x_avg);
if ( diff < std_dev*2.0f ){
sum += arr[i];
counter++;
}
}
return sum / (float)counter;
}
// Measures constant adc offset and programs the offset into flash
void adc_offset_adjustment(uint32_t n){
float offsets_fwd[n];
float offsets_rev[n];
// Set PWM level to 0 just to be sure
pwm_set_gpio_level(MOTOR_FWD_PIN, 0);
pwm_set_gpio_level(MOTOR_REV_PIN, 0);
busy_wait_ms(1000);
// Measure n times in "reverse direction" (GPIO 28)
adc_select_input(2);
adc_run(true);
for (uint32_t i = 0; i < n; i++) {
offsets_rev[i] = (float)adc_fifo_get_blocking();
}
adc_run(false);
adc_fifo_drain();
busy_wait_ms(1000);
// Measure n times in "forward direction" (GPIO 29)
adc_select_input(3);
adc_run(true);
for (uint32_t i = 0; i < n; i++) {
offsets_fwd[i] = (float)adc_fifo_get_blocking();
}
adc_run(false);
adc_fifo_drain();
// Find overall average discarding outliers in measurement
float offset_avg_fwd = two_std_dev(offsets_fwd, n);
float offset_avg_rev = two_std_dev(offsets_rev, n);
float overall_avg = (offset_avg_fwd+offset_avg_rev)/2;
uint8_t offset = (uint8_t)roundf(overall_avg);
// Create temporary array -> change CV 172 in temp array -> erase flash -> write temp array to flash
uint8_t CV_ARRAY_TEMP[CV_ARRAY_SIZE];
memcpy(CV_ARRAY_TEMP, CV_ARRAY_FLASH, sizeof(CV_ARRAY_TEMP));
CV_ARRAY_TEMP[171] = offset;
flash_range_erase(FLASH_TARGET_OFFSET, FLASH_SECTOR_SIZE);
flash_range_program(FLASH_TARGET_OFFSET, CV_ARRAY_TEMP, FLASH_PAGE_SIZE * 2);
}
// Confirmation after writing or verifying a CV
// Works by creating a spike in current consumption, this is detected by the command station
void acknowledge() {
uint16_t max_lvl = _125M/(CV_ARRAY_FLASH[8]*100+10000);
pwm_set_gpio_level(MOTOR_FWD_PIN, max_lvl);
busy_wait_ms(3);
pwm_set_gpio_level(MOTOR_FWD_PIN, 0);
pwm_set_gpio_level(MOTOR_REV_PIN, max_lvl);
busy_wait_ms(3);
pwm_set_gpio_level(MOTOR_REV_PIN, 0);
}
// When bit matches sent byte -> acknowledge()
void verify_cv_bit(uint16_t cv_address,bool bit_val, uint8_t bit_pos) {
uint8_t mask = 0b00000001;
bool res = ( (CV_ARRAY_FLASH[cv_address] >> bit_pos) &mask ) == bit_val;
if (res) {
acknowledge();
}
}
// When byte matches sent byte -> acknowledge()
void verify_cv_byte(uint16_t cv_address, uint8_t cv_data){
if (CV_ARRAY_FLASH[cv_address] == cv_data) acknowledge();
}
// CV writing function first erases necessary amount of blocks in flash and then rewrites to flash
void regular_cv_write(uint16_t cv_index, uint8_t cv_data){
uint8_t CV_ARRAY_TEMP[CV_ARRAY_SIZE];
memcpy(CV_ARRAY_TEMP, CV_ARRAY_FLASH, sizeof(CV_ARRAY_TEMP));
CV_ARRAY_TEMP[cv_index] = cv_data;
flash_range_erase(FLASH_TARGET_OFFSET, FLASH_SECTOR_SIZE);
flash_range_program(FLASH_TARGET_OFFSET, CV_ARRAY_TEMP, FLASH_PAGE_SIZE * 2);
acknowledge();
}
// There are some exceptions to writing CVs - e.g. writing to a read only CV is not valid - this gets handled here
void write_cv_handler(uint16_t cv_index, uint8_t cv_data){
switch (cv_index) {
case 0: //CV_1
// CV_1 => Value = 0 is not allowed
if (cv_data == 0 || cv_data > 127) break;
case 6: //CV_7
// Read only (CV_7 - Version no.)
// ADC offset Adjustment (CV_7; Value = 7);
if (cv_data == 7) adc_offset_adjustment(8192);
break;
case 7: //CV_8
// Read only (CV_8 - Manufacturer ID)
// Reset all CVs to Default (CV_8; Value = 8)
if (cv_data == 8){
flash_range_erase(FLASH_TARGET_OFFSET, FLASH_SECTOR_SIZE);
flash_range_program(FLASH_TARGET_OFFSET, CV_ARRAY_DEFAULT, FLASH_PAGE_SIZE * 2);
}
break;
// CV_17 must have a value between 11000000->(192dec) and 11100111->(231dec) inclusive
// CV_17 == 192 && CV_18 == 0 -> Address = 0 is also not valid and therefore shall not be set
case 16: //CV_17
if ( (cv_data < 192 || cv_data > 231) || (CV_ARRAY_FLASH[17] == 0 && cv_data == 192) ) break;
else regular_cv_write(cv_index,cv_data);
break;
case 17: //CV_18
if(CV_ARRAY_FLASH[16] == 192 && cv_data == 0) break;
else regular_cv_write(cv_index,cv_data);
break;
// CV_31 & CV_32 Index high byte isn't implemented and shall not be set
case 30: //CV_31
case 31: //CV_32
break;
// Regular CV write is carried out
default:
regular_cv_write(cv_index,cv_data);
}
}
// CV Programming function resets core1 and evaluates the type of programming instruction (e.g. write byte)
void program_mode(uint8_t number_of_bytes, const uint8_t * const byte_array){
//First check for valid programming command ("address" 112-127)
if (byte_array[number_of_bytes - 1]<128 && byte_array[number_of_bytes - 1]>111){
uint8_t instruction_type_mask = 0b00001100;
uint8_t instruction_type = instruction_type_mask & byte_array[number_of_bytes - 1];
uint8_t cv_address_ms_bits_mask = 0b00000011;
uint16_t cv_address_ms_bits = cv_address_ms_bits_mask & byte_array[number_of_bytes - 1];
uint16_t cv_address = byte_array[number_of_bytes - 2] + (cv_address_ms_bits << 8);
// Before accessing flash, timers and interrupts need to be disabled and core1 needs to be shut down.
if(pid_control_timer.pool)alarm_pool_destroy(pid_control_timer.pool);
if(speed_helper_timer.pool)alarm_pool_destroy(speed_helper_timer.pool);
multicore_reset_core1();
uint32_t saved_interrupts = save_and_disable_interrupts();
// Verify CV bit instruction
if (instruction_type == 0b000001000) {
uint8_t bit_pos_mask = 0b00000111;
uint8_t bit_pos = bit_pos_mask&byte_array[number_of_bytes - 3];
uint8_t bit_val_mask = 0b00000001;
uint8_t bit_val_uint = (byte_array[number_of_bytes - 3]>>3) & bit_val_mask;
bool bit_val = bit_val_uint;
verify_cv_bit(cv_address, bit_val, bit_pos);
}
// Verify CV byte instruction
else if (instruction_type == 0b000000100) {
uint8_t cv_data = byte_array[number_of_bytes - 3];
verify_cv_byte(cv_address, cv_data);
}
// Write CV byte instruction
else if (instruction_type == 0b000001100) {
uint8_t cv_data = byte_array[number_of_bytes - 3];
write_cv_handler(cv_address, cv_data);
}
// Restore interrupts
restore_interrupts(saved_interrupts);
busy_wait_ms(5);
}
}
// Set outputs according to configuration (PWM on/off, PWM duty cycle/level, ...)
void set_outputs(uint32_t functions_to_set_bitmask) {
// Get outputs with pwm enabled and preset outputs_to_set_PWM variable with resulting GPIO Bitmask
uint32_t PWM_enabled_outputs = get_32bit_CV(111);
uint32_t outputs_to_set_PWM = PWM_enabled_outputs;
// Get enabled output configuration corresponding to set functions and direction
uint32_t outputs_to_set = 0;
uint32_t temp_mask = 1;
for (uint8_t i = 0; i < 32; i++) {
if (temp_mask & functions_to_set_bitmask ){
outputs_to_set |= get_32bit_CV(i * 8 + 260 - 4 * get_direction(0));
}
temp_mask<<=1;
}
outputs_to_set_PWM &= outputs_to_set; // Outputs with PWM to be enabled
outputs_to_set &= ~outputs_to_set_PWM; // Outputs without PWM to be enabled
// Set regular outputs without PWM, preventing illegal GPIO by masking with GPIO_ALLOWED_OUTPUTS
gpio_put_masked(GPIO_ALLOWED_OUTPUTS, outputs_to_set);
// Set PWM enabled outputs to desired level
temp_mask = 1;
for (uint8_t i = 0; i < 32; ++i) {
if(temp_mask & outputs_to_set_PWM){
pwm_set_gpio_level(i, level_table[i]);
pwm_gpio_to_channel(i);
pwm_gpio_to_slice_num(i);
}
else if (temp_mask & PWM_enabled_outputs){
pwm_set_gpio_level(i,0);
}
temp_mask<<=1;
}
}
// Update functions F0 - F31 when function command is received or in case of direction change
void update_active_functions(uint32_t new_function_bitmask, uint8_t clr_bit_ind, bool direction_change) {
static uint32_t active_functions;
static uint32_t prev_active_func;
// Outputs depend on direction
// In case of a direction change every output needs to be set according to configuration for the other direction
if (direction_change) set_outputs(active_functions);
// In case of a change in active functions only the function group corresponding to the instruction is considered
// Check for changes and set outputs accordingly
else{
new_function_bitmask &= ~(clr_bit_arr[clr_bit_ind]); // Clear every bit except bits corresponding to group of functions
active_functions &= clr_bit_arr[clr_bit_ind]; // Clear bits corresponding to group of functions
active_functions |= new_function_bitmask; // Write bits corresponding to group of functions
uint32_t changes = active_functions ^ prev_active_func; // Checks for changes from previous state
if(changes) set_outputs(active_functions);
prev_active_func = active_functions;
}
}
// Bitwise XOR for all Bytes -> Successful result is: "0000 0000"
bool error_detection(int8_t number_of_bytes, const uint8_t * const byte_array) {
uint8_t xor_byte = 0;
for (int i = 0; i < number_of_bytes; i++) {
xor_byte = xor_byte ^ byte_array[i];
}
return (0 == xor_byte);
}
// Check for long address. Function returns true for long address.
bool is_long_address(uint8_t number_of_bytes, const uint8_t * const byte_array) {
if ((byte_array[number_of_bytes - 1]>>6) == 0b00000011) return true;
return false;
}
// First checks for idle package and then evaluates address included in byte_array[]
bool address_evaluation(uint8_t number_of_bytes,const uint8_t * const byte_array) {
// Check for Idle Package
if (byte_array[number_of_bytes - 1] == 255)
{
return false;
}
// Long/extended address decoder configuration (CV_29 Bit5)
bool CV_29_bit5 = (CV_ARRAY_FLASH[28]&0b00100000)>>5;
uint16_t read_address;
// Decoder configured to receive long/extended address
if (CV_29_bit5){
// Package received does contain a long address -> Check for accordance
if (is_long_address(number_of_bytes, byte_array))
{
// start of transmission -> address_byte_1 -> address_byte_0 -> ... -> end of transmission
uint16_t address_byte_1 = (byte_array[number_of_bytes - 1]) - 192; // Remove long address identifier bits
uint16_t address_byte_0 = (byte_array[number_of_bytes - 2]);
read_address = (address_byte_1 << 8) + address_byte_0;
uint16_t long_address = get_16bit_CV(16) & 0x3FFF; // &Mask to remove long address identifier bits
return (long_address == read_address);
}
// Package received does not contain a long address
else return false;
}
// Short address decoder configuration (CV_29 Bit5)
else
{
// Short Address Package
// start of transmission -> address_byte_0 -> ... -> end of transmission
read_address = (byte_array[number_of_bytes - 1]);
return (CV_ARRAY_FLASH[0] == read_address);
}
}
// Evaluate the type of instruction
void instruction_evaluation(uint8_t number_of_bytes,const uint8_t * const byte_array) {
// start of transmission -> ... -> command_byte_n -> ... -> command_byte_0 -> ... -> end of transmission
// The position of command bytes depend on whether the address is long or not
uint8_t command_byte_n;
uint8_t command_byte_start_index;
if (is_long_address(number_of_bytes,byte_array)) {
command_byte_start_index = number_of_bytes - 3;
}
else {
command_byte_start_index = number_of_bytes - 2;
}
command_byte_n = byte_array[command_byte_start_index];
//0011-1111 (128 Speed Step Control) - 2 Byte length
if (command_byte_n == 0b00111111){
static bool prev_dir;
uint32_t speed_step = byte_array[command_byte_start_index - 1];
multicore_fifo_push_blocking(speed_step);
// In case of a direction change, functions need to be updated because functions might depend on direction state
if (get_direction(0) != prev_dir) {
update_active_functions(0,0,true);
prev_dir = get_direction(0);
}
}
// 10XX-XXXX (Function Group Instruction)
else if (command_byte_n >> 6 == 0b00000010){
switch (command_byte_n >> 4) {
case 0b00001011: // F5-F8
update_active_functions((command_byte_n << 5),1,false);
break;
case 0b00001010: // F9-F12
update_active_functions((command_byte_n << 9),2,false);
break;
default: // F0-F4
update_active_functions(((command_byte_n << 1) + (command_byte_n >> 4)),0,false);
break;
}
}
//Feature Expansion Instruction 110X-XXXX
else if (command_byte_n >> 5 == 0b00000110) {
switch (command_byte_n) {
case 0b11011110: // F13-F20
update_active_functions((byte_array[command_byte_start_index - 1] << 13),3,false);
break;
case 0b11011111: // F21-F28
update_active_functions((byte_array[command_byte_start_index - 1] << 21),4,false);
break;
case 0b11011000: // F29-F31
update_active_functions((byte_array[command_byte_start_index - 1] << 29),5,false);
break;
default:
break;
}
}
}
// Check for reset package - When reset package is found stop the motor and disable all functions
bool reset_package_check(uint8_t number_of_bytes,const uint8_t * const byte_array){
if (byte_array[number_of_bytes-1] == 0b00000000 && byte_array[number_of_bytes-2] == 0b00000000){
uint32_t speed_step = 1;
multicore_fifo_push_blocking(speed_step); // Emergency Stop
update_active_functions(0,0,0); // Disables all functions
return true;
}
else return false;
}
// Checks for valid package - looking for correct preamble
int8_t check_for_package() { //returns number of bytes if valid bit-pattern is found. Otherwise -1 is returned.
uint64_t package3Masked = input_bit_buffer & PACKAGE_MASK_3_BYTES;
if (package3Masked == PACKAGE_3_BYTES) return 3;
uint64_t package4Masked = input_bit_buffer & PACKAGE_MASK_4_BYTES;
if (package4Masked == PACKAGE_4_BYTES) return 4;
uint64_t package5Masked = input_bit_buffer & PACKAGE_MASK_5_BYTES;
if (package5Masked == PACKAGE_5_BYTES) return 5;
return -1;
}
//start of transmission -> byte_n(address byte) -> ... -> byte_0(error detection byte) -> end of transmission
void bits_to_byte_array(int8_t number_of_bytes,uint8_t byte_array[]) {
for (uint8_t i = 0; i < number_of_bytes; i++) {
byte_array[i] = input_bit_buffer >> (i * 9 + 1);
}
}
// Sequence of bits gets evaluated
void evaluation(){
static bool core1_launched = false;
static bool reset_package_flag;
int8_t number_of_bytes = check_for_package();
// number_of_bytes contains the amount of bytes when the package is valid, otherwise -1
if (number_of_bytes != -1) {
// Split data into 8Bit array
uint8_t byte_array[SIZE_BYTE_ARRAY] = {0};
bits_to_byte_array(number_of_bytes,byte_array);
// Check for errors
if (error_detection(number_of_bytes,byte_array)) {
// Check for matching address
if (address_evaluation(number_of_bytes,byte_array)) {
reset_package_flag = false;
if (!core1_launched){
multicore_launch_core1(core1_entry);
// Wait for pid.direction pointer via multicore fifo also signalizing that core1 initialization is finished.
get_direction((bool *) multicore_fifo_pop_blocking());
core1_launched = true;
}
instruction_evaluation(number_of_bytes,byte_array);
}
// When previous packet was a reset package -> enter program mode
else if (reset_package_flag) {
program_mode(number_of_bytes,byte_array);
}
// Check for reset package and set flag when reset package is received
else {
reset_package_flag = reset_package_check(number_of_bytes,byte_array);
}
}
}
}
// DCC-Signal (GPIO 21) rising edge interrupt
void track_signal_rise(unsigned int gpio, long unsigned int events) {
// Save current timer value
rising_edge_time = get_absolute_time();
// Disable rising edge interrupt and enable falling edge interrupt
gpio_set_irq_enabled_with_callback(DCC_INPUT_PIN, GPIO_IRQ_EDGE_RISE, false, &track_signal_rise);
gpio_set_irq_enabled_with_callback(DCC_INPUT_PIN, GPIO_IRQ_EDGE_FALL, true, &track_signal_fall);
}
// DCC-Signal (GPIO 21) falling edge interrupt
void track_signal_fall(unsigned int gpio, long unsigned int events) {
// Save current timer value
falling_edge_time = get_absolute_time();
// Time difference is equal to the time the signal was in a logical high state
int64_t time_logical_high = absolute_time_diff_us(rising_edge_time,falling_edge_time);
// When logical high was longer than 87us write 0 bit into buffer otherwise 1
bool bit;
if(time_logical_high > 87) bit = 0;
else bit = 1;
input_bit_buffer <<= 1;
input_bit_buffer |= bit;
// evaluate sequence of bits saved in buffer
evaluation();
// Disable falling edge interrupt and enable rising edge interrupt
gpio_set_irq_enabled_with_callback(DCC_INPUT_PIN, GPIO_IRQ_EDGE_FALL, false, &track_signal_fall);
gpio_set_irq_enabled_with_callback(DCC_INPUT_PIN, GPIO_IRQ_EDGE_RISE, true, &track_signal_rise);
}
// Output initialization function - Configures pwm frequency and clock divider according to CV_111 - CV_171
void init_outputs(){
gpio_init_mask(GPIO_ALLOWED_OUTPUTS);
gpio_set_dir_out_masked(GPIO_ALLOWED_OUTPUTS); // Note: This might also disable UART on GPIO0 & GPIO1
uint32_t PWM_enabled_outputs = get_32bit_CV(111) & GPIO_ALLOWED_OUTPUTS;
uint32_t slice, channel;
uint16_t wrap, level;
uint8_t clock_divider;
uint32_t mask = 1;
for (uint8_t i = 0; i < 32; ++i) {
if (PWM_enabled_outputs & mask){
slice = pwm_gpio_to_slice_num(i);
channel = pwm_gpio_to_channel(i); // Channel A = "0"; Channel B = "1"
wrap = get_16bit_CV(115 + 7*slice);
level = get_16bit_CV(118 + 7*slice + 2*channel);
clock_divider = CV_ARRAY_FLASH[117+7*slice] + 1;
gpio_set_function(i,GPIO_FUNC_PWM);
pwm_set_wrap(slice,wrap);
pwm_set_gpio_level(i,0);
level_table[i] = level;
pwm_set_clkdiv_int_frac(slice,clock_divider,0);
pwm_set_enabled(slice,true);
}
mask<<=1;
}
}
// Measures "base" pwm duty cycle needed to overcome friction
uint16_t measure_base_pwm(bool direction, uint8_t iterations){
uint gpio;
if (direction) gpio = MOTOR_FWD_PIN;
else gpio = MOTOR_REV_PIN;
float level_arr[iterations];
for (int i = 0; i < iterations; ++i) {
uint16_t max_level = _125M/(CV_ARRAY_FLASH[8]*100+10000);
uint16_t level = max_level/20;
float measurement;
do {
pwm_set_gpio_level(gpio, level);
busy_wait_ms(30);
level += max_level/500;
measurement = measure(CV_ARRAY_FLASH[60],
CV_ARRAY_FLASH[61],
CV_ARRAY_FLASH[62],
CV_ARRAY_FLASH[63],
direction);
// Abort measurement and write default value of 0 to flash
if (level > max_level) return 0;
}
while((measurement - (float)CV_ARRAY_FLASH[171]) < 5.0f);
level_arr[i] = (float)level;
busy_wait_ms(100);
}
// Find and return overall average discarding outliers in measurement - multiply with 0.9
return (uint16_t)(0.9f*two_std_dev(level_arr,5));
}
// Check for flash memory factory condition and adc offset setup
// When factory condition is found the CV_ARRAY_DEFAULT will be written into flash
// When ADC Setup is not configured run adc offset adjustment function and write adc offset into flash
void cv_setup_check(){
// Check for flash factory setting and set CV_FLASH_ARRAY to default values when factory condition ("0xFF") is found.
if ( CV_ARRAY_FLASH[64] == 0xFF ){
uint8_t arr[4] = {125,8,7,124};
program_mode(4,arr); //reset to CV_ARRAY_DEFAULT (write CV_8 = 8)
}
// Check for adc offset setup
if ( CV_ARRAY_FLASH[171] == 0xFF ){
uint8_t arr[4] = {125,7,6,124};
program_mode(4,arr); //ADC offset adjustment (write CV_7 = 7)
}
// Check for base PWM configuration - used for feed-forward
// Forward Direction
if (get_16bit_CV(175) == 0){
uint16_t base_pwm_fwd = measure_base_pwm(true,10);
uint8_t base_pwm_fwd_high_byte = base_pwm_fwd>>8;
uint8_t base_pwm_fwd_low_byte = base_pwm_fwd&0x00FF;
uint8_t arr0[4] = {125,base_pwm_fwd_high_byte,175,124};
program_mode(4,arr0);
uint8_t arr1[4] = {125,base_pwm_fwd_low_byte,176,124};
program_mode(4,arr1);
}
// Reverse Direction
if (get_16bit_CV(177) == 0){
uint16_t base_pwm_rev = measure_base_pwm(false,10);
uint8_t base_pwm_rev_high_byte = base_pwm_rev>>8;
uint8_t base_pwm_rev_low_byte = base_pwm_rev&0x00FF;
uint8_t arr0[4] = {125,base_pwm_rev_high_byte,177,124};
program_mode(4,arr0);
uint8_t arr1[4] = {125,base_pwm_rev_low_byte,178,124};
program_mode(4,arr1);
}
}
// This function ensures that the direction pointer can only be written once.
// After first initialization this function can be called with arbitrary input to get the current direction
bool get_direction(bool *direction_ptr){
static bool set_flag;
static bool *dir_ptr;
if(!set_flag) {
dir_ptr = direction_ptr;
set_flag = true;
}
return *dir_ptr;
}
// Motor PWM initialization
void init_motor_pwm(uint8_t gpio) {
uint16_t wrap_counter = (_125M/(CV_ARRAY_FLASH[8]*100+10000)) - 1;
uint32_t slice_num = pwm_gpio_to_slice_num(gpio);
pwm_set_clkdiv_int_frac(slice_num,CV_ARRAY_FLASH[173],0);
pwm_set_wrap(slice_num, wrap_counter);
pwm_set_gpio_level(gpio,0);
pwm_set_enabled(slice_num, true);
}
// Main initialization - GPIO Config / ADC Config
void init_main(){
if(gpio_get_function(MOTOR_FWD_PIN) != 4){
gpio_set_function(MOTOR_FWD_PIN, GPIO_FUNC_PWM);
gpio_set_function(MOTOR_REV_PIN, GPIO_FUNC_PWM);
adc_init();
adc_gpio_init(FWD_V_EMF_ADC_PIN);
adc_gpio_init(REV_V_EMF_ADC_PIN);
adc_fifo_setup(true,false,0,false,false);
}
}
int main() {
stdio_init_all();
printf("core0 init...\n");
init_main();
init_motor_pwm(MOTOR_FWD_PIN);
init_motor_pwm(MOTOR_REV_PIN);
cv_setup_check();
init_outputs();
gpio_init(DCC_INPUT_PIN);
gpio_set_dir(DCC_INPUT_PIN, GPIO_IN);
gpio_pull_up(DCC_INPUT_PIN);
gpio_set_irq_enabled_with_callback(DCC_INPUT_PIN, GPIO_IRQ_EDGE_RISE, true, &track_signal_rise);
printf("core0 done\n");
while (1);
}
-51
View File
@@ -1,51 +0,0 @@
//////////////////////////
// RP2040-Decoder //
// Gabriel Koppenstein //
// core0.h //
//////////////////////////
#pragma once
#include "shared.h"
#include "CV.h"
#define SIZE_BYTE_ARRAY 5
#define PACKAGE_3_BYTES 0b11111111110000000000000000000000000001
#define PACKAGE_MASK_3_BYTES 0b11111111111000000001000000001000000001
#define PACKAGE_4_BYTES 0b11111111110000000000000000000000000000000000001
#define PACKAGE_MASK_4_BYTES 0b11111111111000000001000000001000000001000000001
#define PACKAGE_5_BYTES 0b11111111110000000000000000000000000000000000000000000001
#define PACKAGE_MASK_5_BYTES 0b11111111111000000001000000001000000001000000001000000001
const uint32_t clr_bit_arr[6] = {
0b11111111111111111111111111100000, // Clear Bits 0-4 (F0-F4)
0b11111111111111111111111000011111, // Clear Bits 5-8 (F5-F8)
0b11111111111111111110000111111111, // Clear Bits 9-12 (F9-F12)
0b11111111111000000001111111111111, // Clear Bits 13-20 (F13-F20)
0b11100000000111111111111111111111, // Clear Bits 21-28 (F21-F28)
0b00011111111111111111111111111111, // Clear Bits 29-31 (F29-F31)
};
float two_std_dev(const float arr[], uint32_t length);
void adc_offset_adjustment(uint32_t length);
void acknowledge();
void verify_cv_bit(uint16_t cv_address,bool bit_val, uint8_t bit_pos);
void verify_cv_byte(uint16_t cv_address, uint8_t cv_data);
void regular_cv_write(uint16_t cv_index, uint8_t cv_data);
void write_cv_handler(uint16_t cv_index, uint8_t cv_data);
void program_mode(uint8_t number_of_bytes, const uint8_t byte_array[]);
void set_outputs(uint32_t functions_to_set_bitmask);
void update_active_functions(uint32_t byte, uint8_t clr_bit_ind,bool direction_change);
bool error_detection(int8_t number_of_bytes, const uint8_t byte_array[]);
bool is_long_address(uint8_t number_of_bytes, const uint8_t byte_array[]);
bool address_evaluation(uint8_t number_of_bytes,const uint8_t byte_array[]);
void instruction_evaluation(uint8_t number_of_bytes,const uint8_t byte_array[]);
bool reset_package_check(uint8_t number_of_bytes,const uint8_t byte_array[]);
int8_t check_for_package();
void bits_to_byte_array(int8_t number_of_bytes,uint8_t byte_array[]);
void evaluation();
void track_signal_rise(unsigned int gpio, long unsigned int events);
void track_signal_fall(unsigned int gpio, long unsigned int events);
void init_outputs();
uint16_t measure_base_pwm(bool direction, uint8_t iterations);
void cv_setup_check();
bool get_direction(bool *direction_ptr);
void init_motor_pwm(uint8_t gpio);
void init_main();
-321
View File
@@ -1,321 +0,0 @@
//////////////////////////
// RP2040-Decoder //
// Gabriel Koppenstein //
// core1.c //
//////////////////////////
#include "core1.h"
struct repeating_timer pid_control_timer,speed_helper_timer;
// Update speed_step_target, end_target_index and direction on receiving data from core0
void update_speed_dir(pid_params *pid, uint32_t speed_step_target){
pid->speed_step_target = speed_step_target;
// When CV_29 Bit 0 is set direction is reversed
bool reverse_dir = CV_ARRAY_FLASH[28] & 0b00000001;
// Forward
if(speed_step_target > 127) {
pid->direction = true^reverse_dir;
if (pid->speed_step_target == 128) pid->end_target_index = 0;
else pid->end_target_index = (pid->speed_step_target-129);
}
// Reverse
else {
pid->direction = false^reverse_dir;
if (pid->speed_step_target == 0) pid->end_target_index = 0;
else pid->end_target_index = (pid->speed_step_target-1);
}
}
// This function gets called every x milliseconds where x is CV_175.
// The purpose of this function is to implement a time delay in acceleration or deceleration
bool speed_helper(struct repeating_timer *t) {
// pid->setpoint only gets adjusted when the speed_helper_counter is equal to the accel_rate/decel_rate
// -> Time for 1 Speed Step := (speed_helper timer delay)*(accel_rate) or CV_175*CV_3 or CV_175*CV_4
pid_params *pid = (pid_params *)(t->user_data);
uint8_t accel_rate = CV_ARRAY_FLASH[2];
uint8_t decel_rate = CV_ARRAY_FLASH[3];
static bool prev_dir;
static uint8_t speed_helper_counter;
static uint8_t speed_table_index;
// Emergency Stop
if (pid->speed_step_target == 129 || pid->speed_step_target==1) {
speed_table_index = 0;
speed_helper_counter = 0;
pid->setpoint = pid->speed_table[speed_table_index];
}
// Acceleration
else if (pid->end_target_index > speed_table_index && speed_helper_counter == accel_rate) {
if(!accel_rate) speed_table_index = pid->end_target_index; // directly accelerate to end target speed
else speed_table_index++;
pid->setpoint = pid->speed_table[speed_table_index];
speed_helper_counter = 0;
}
// Deceleration
else if (pid->end_target_index < speed_table_index && speed_helper_counter == decel_rate) {
if(!decel_rate) speed_table_index = pid->end_target_index; // directly decelerate to end target speed
else speed_table_index--;
pid->setpoint = pid->speed_table[speed_table_index];
speed_helper_counter = 0;
}
// Change of direction while decelerating -> jump to most recent speed_step without delay (other direction)
else if (pid->direction != prev_dir){
speed_table_index = pid->end_target_index;
pid->setpoint = pid->speed_table[speed_table_index];
speed_helper_counter = 0;
}
// Acceleration/Deceleration "scheduled"
else if (pid->end_target_index != speed_table_index) speed_helper_counter++;
// Target reached -> Reset Counter
else speed_helper_counter = 0;
// Save prev speed_helper direction - not to be confused with pid->prev_direction
prev_dir = pid->direction;
// return true to schedule the repeating timer again
return true;
}
// Helper function to adjust pwm level/duty cycle.
void adjust_pwm_level(uint16_t level, pid_params *pid) {
// Forward
if (pid->direction) {
pwm_set_gpio_level(MOTOR_REV_PIN, 0);
pwm_set_gpio_level(MOTOR_FWD_PIN, level);
}
// Reverse
else {
pwm_set_gpio_level(MOTOR_FWD_PIN, 0);
pwm_set_gpio_level(MOTOR_REV_PIN, level);
}
}
// Update feed-forward slope/gradient for both directions
void update_m(pid_params *pid){
pid->m_fwd = (pid->y_2_fwd-pid->y_1_fwd)/(pid->x_2_fwd-pid->x_1_fwd);
pid->m_rev = (pid->y_2_rev-pid->y_1_rev)/(pid->x_2_rev-pid->x_1_rev);
}
// Update feedforward function value y_2 in both directions
void update_y(pid_params *pid,float i){
// Forward
if(pid->direction) {
pid->y_2_fwd += i*pid->k_ff;
// Limit y_2_fwd
if(pid->y_2_fwd > pid->max_output) pid->y_2_fwd = pid->max_output;
else if(pid->y_2_fwd < pid->y_1_fwd) pid->y_2_fwd = pid->y_1_fwd;
}
// Reverse
else{
pid->y_2_rev += i*pid->k_ff;
// Limit y_2_rev
if(pid->y_2_rev > pid->max_output) pid->y_2_rev = pid->max_output;
else if(pid->y_2_rev < pid->y_1_rev) pid->y_2_rev = pid->y_1_rev;
}
update_m(pid);
}
// Returns feedforward value corresponding to current setpoint
float get_ff_val(pid_params *pid){
float val;
// Forward
if(pid->direction){
val = pid->m_fwd*((float)pid->setpoint-pid->x_1_fwd)+pid->y_1_fwd;
}
// Reverse
else{
val = pid->m_rev*((float)pid->setpoint-pid->x_1_rev)+pid->y_1_rev;
}
return val;
}
// Returns proportional gain value corresponding to current setpoint
float get_kp(pid_params *pid){
float sp = (float)pid->setpoint;
if (sp < pid->k_p_x_1){
return pid->k_p_m_1 * sp + pid->k_p_y_0;
}
else{
return pid->k_p_m_2 * (sp - pid->k_p_x_1) + pid->k_p_y_1;
}
}
// PID controller function gets called every x milliseconds where x is CV_49 aka sampling time (pid->t)
bool pid_control(struct repeating_timer *t){
// Cast (void *) to (pid_params *)
pid_params *pid = (pid_params *)(t->user_data);
// Acceleration from standstill or change in direction -> reset previous derivative, error and integral parts
if((!pid->setpoint_prev && !pid->setpoint) || (pid->direction != pid->direction_prev)){
pid->d_prev = 0.0f;
pid->i_prev = 0.0f;
pid->e_prev = 0.0f;
}
// Get feed-forward and proportional gain values
float feed_fwd = get_ff_val(pid);
pid->k_p = get_kp(pid);
// Measure BEMF voltage and compute error
pid->measurement = measure(pid->msr_total_iterations,
pid->msr_total_iterations,
pid->l_side_arr_cutoff,
pid->r_side_arr_cutoff,
pid->direction);
float e = (float)pid->setpoint - (pid->measurement - pid->adc_offset);
// Proportional part, integral part and derivative part (including digital low-pass-filter with time constant tau)
float p = pid->k_p * e;
float i = pid->ci_0*(e + pid->e_prev) + pid->i_prev;
float d = pid->cd_0*(pid->measurement-pid->measurement_prev)+pid->cd_1*pid->d_prev;
// Check for limits on the integral part
if (i > pid->int_lim_max)i = pid->int_lim_max;
else if (i < pid->int_lim_min)i = pid->int_lim_min;
// Sum feed forward + all controller terms (p+i+d). Limit Output from 0% to 100% duty cycle
float output = feed_fwd+p+i+d;
if (output < 0 || !pid->setpoint) output = 0.0f;
else if (output > pid->max_output) output = pid->max_output;
// Set PWM Level and discard results in adc fifo
adjust_pwm_level((uint16_t)roundf(output),pid);
adc_fifo_drain();
// Check for High or Low Integrator values -> Update x,y values of feedforward function
if( (output < pid->max_output && output > pid->max_output/2) && ((i > pid->int_lim_max/2) || (i < pid->int_lim_min/2)) ) update_y(pid,i);
// Save previous error, integrator, differentiator, direction, setpoint and measured value also sum error to e_sum
pid->e_prev = e;
pid->i_prev = i;
pid->d_prev = d;
pid->direction_prev = pid->direction;
pid->setpoint_prev = pid->setpoint;
pid->measurement_prev = pid->measurement;
// return true to schedule the repeating timer again
return true;
}
// PID controller and measurement parameter, and speed_table initialization
void init_pid(pid_params *pid){
// Measurement variables initialization
pid->adc_offset = (float)CV_ARRAY_FLASH[171];
pid->msr_total_iterations = CV_ARRAY_FLASH[60];
pid->msr_delay_in_us = CV_ARRAY_FLASH[61];
pid->l_side_arr_cutoff = CV_ARRAY_FLASH[62];
pid->r_side_arr_cutoff = CV_ARRAY_FLASH[63];
// Speed table initialization
// Calculate speed setpoint table according to V_min, V_max and V_mid CVs
double v_min = (double)CV_ARRAY_FLASH[1];
double v_mid = (double)CV_ARRAY_FLASH[5]*16;
double v_max = (double)CV_ARRAY_FLASH[4]*16;
double delta_x = 63;
double m_1 = (v_mid-v_min)/delta_x;
double m_2 = (v_max-v_mid)/delta_x;
pid->speed_table[0] = 0;
for (uint8_t i = 1; i < 64; ++i) {
pid->speed_table[i] = (uint16_t)lround(m_1*(i-1)+v_min);
}
for (uint8_t i = 64; i < 127; ++i) {
pid->speed_table[i] = (uint16_t)lround(m_2*(i-63)+v_mid);
}
// Controller constants initialization
pid->k_i = (float)CV_ARRAY_FLASH[49]/10;
pid->k_d = (float)CV_ARRAY_FLASH[50]/10000;
pid->tau = (float)CV_ARRAY_FLASH[47]/1000;
pid->t = (float)CV_ARRAY_FLASH[48]/1000;
pid->ci_0 = (pid->k_i*pid->t)/2;
pid->cd_0 = -(2*pid->k_d)/(2*pid->tau+pid->t);
pid->cd_1 = (2*pid->tau-pid->t)/(2*pid->tau+pid->t);
pid->int_lim_max = 10*(float)CV_ARRAY_FLASH[51];
pid->int_lim_min = -10*(float)CV_ARRAY_FLASH[52];
pid->k_ff = (float)CV_ARRAY_FLASH[46]/10000;
pid->max_output = (float)(_125M/(CV_ARRAY_FLASH[8]*100+10000));
pid->x_1_rev = 0.0f;
pid->x_1_fwd = 0.0f;
pid->y_1_fwd = (float)get_16bit_CV(175);
pid->y_1_rev = (float)get_16bit_CV(177);
pid->x_2_rev = (float)pid->speed_table[126];
pid->x_2_fwd = (float)pid->speed_table[126];
// Controller variables initialization
pid->y_2_fwd = pid->max_output;
pid->y_2_rev = pid->max_output;
pid->measurement = 0.0f;
pid->measurement_prev = 0.0f;
pid->e_prev = 0.0f;
pid->i_prev = 0.0f;
pid->d_prev = 0.0f;
pid->direction = false;
pid->direction_prev = false;
pid->speed_step_target = 0;
pid->setpoint = 0;
// Gain scheduling initialization
pid->k_p_x_1_shift = (float)CV_ARRAY_FLASH[59] / 255.0f;
pid->k_p_x_1 = (float)pid->speed_table[126] * pid->k_p_x_1_shift;
pid->k_p_x_2 = (float)pid->speed_table[126] * (1.0f - pid->k_p_x_1_shift);
pid->k_p_y_0 = (float)get_16bit_CV(53) / 100.0f;
pid->k_p_y_1 = (float)get_16bit_CV(55) / 100.0f;
pid->k_p_y_2 = (float)get_16bit_CV(57) / 100.0f;
pid->k_p_m_1 = (pid->k_p_y_1 - pid->k_p_y_0) / pid->k_p_x_1;
pid->k_p_m_2 = (pid->k_p_y_2 - pid->k_p_y_1) / pid->k_p_x_2;
update_m(pid);
}
void core1_entry() {
printf("core1 init...\n");
pid_params pid_parameters;
pid_params *pid = &pid_parameters;
init_pid(pid);
alarm_pool_add_repeating_timer_ms(alarm_pool_create(0,1),
CV_ARRAY_FLASH[48],
pid_control,
pid,
&pid_control_timer);
irq_set_priority(0,0x00); // 0x00 = highest priority
alarm_pool_add_repeating_timer_ms(alarm_pool_create(1,1),
CV_ARRAY_FLASH[174],
speed_helper,
pid,
&speed_helper_timer);
// Send direction pointer for access and to let core0 know that core1 is done with initialization,
// Note: Pointer will be cast into uint32_t and then back into bool * on core0 (Both 32-Bit Datatype).
// This is done only to accommodate the correct data type associated with multicore_fifo_push_blocking().
multicore_fifo_push_blocking((uint32_t) &(pid->direction));
uint64_t packet_timeout_threshold_in_us = CV_ARRAY_FLASH[10]*1000000;
absolute_time_t time_last_update = get_absolute_time();
printf("core1 done\n");
while (1){
// Check for time difference between last packet and current time (Packet Timeout)
absolute_time_t current_time = get_absolute_time();
if (absolute_time_diff_us(time_last_update,current_time) > packet_timeout_threshold_in_us){
update_speed_dir(pid,1 + 128*pid->direction); // Emergency stop on timeout
}
// If core0 sends new speed data to core1 speed_step_target and direction variables get updated
if(multicore_fifo_rvalid()) {
update_speed_dir(pid, multicore_fifo_pop_blocking());
time_last_update = get_absolute_time();
}
}
}
-71
View File
@@ -1,71 +0,0 @@
//////////////////////////
// RP2040-Decoder //
// Gabriel Koppenstein //
// core1.h //
//////////////////////////
#pragma once
#include "shared.h"
typedef struct pid_params{
// Controller variables - won't change after init
float k_i; // Integral gain
float k_d; // Derivative gain
float t; // Sampling time
float tau; // Low-pass-filter time constant
float k_ff; // Feed-Forward gain
float ci_0; // (k_i*t)/2
float cd_0; // (k_d*2)/(2*tau+t)
float cd_1; // (2*tau-t)/(2*tau+t)
float int_lim_max; // max limit for integrator
float int_lim_min; // min limit for integrator
float max_output; // max possible pwm output value
float k_p_x_1_shift;
float k_p_x_1;
float k_p_x_2;
float k_p_y_0;
float k_p_y_1;
float k_p_y_2;
float k_p_m_1;
float k_p_m_2;
// Controller variables - might change on runtime
float k_p; // Proportional gain
float e_prev; // Previous Error
float i_prev; // Previous Integral Value
float d_prev; // Previous Derivative Value
float measurement_prev; // Previous Measurement
float x_1_fwd; // Base Speed; forward direction
float x_2_fwd; // High Speed; forward direction
float y_1_fwd; // Base PWM; forward direction
float y_2_fwd; // High PWM; forward direction
float x_1_rev; // Base Speed; reverse direction
float x_2_rev; // High Speed; reverse direction
float y_1_rev; // Base PWM; reverse direction
float y_2_rev; // High PWM; reverse direction
float m_fwd; // Slope forward direction
float m_rev; // Slope reverse direction
uint16_t speed_table[127]; // Array with setpoint values corresponding to every speed step
uint32_t speed_step_target; // End target speed step
uint16_t end_target_index; // Index for speed table array corresponding to end target speed step
uint32_t setpoint; // Current setpoint
uint32_t setpoint_prev; // Previous setpoint
bool direction; // Current Direction
bool direction_prev; // Previous Direction
// Measurement Variables
float measurement; // Newest Measurement value
float adc_offset; // ADC offset value
uint8_t msr_delay_in_us; // Delay before VEMF Measurement
uint8_t msr_total_iterations; // Amount of samples
uint8_t l_side_arr_cutoff; // Discarded samples (left side)
uint8_t r_side_arr_cutoff; // Discarded samples (right side)
}pid_params;
void update_speed_dir(pid_params *pid, uint32_t speed_step_target);
bool speed_helper(struct repeating_timer *t);
void adjust_pwm_level(uint16_t level, pid_params *pid);
void update_m(pid_params *pid);
void update_y(pid_params *pid,float i);
float get_ff_val(pid_params *pid);
float get_kp(pid_params *pid);
bool pid_control(struct repeating_timer *t);
void init_pid(pid_params *pid);
File diff suppressed because it is too large. Load diff
+20
View File
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
+35
View File
@@ -0,0 +1,35 @@
@ECHO OFF
pushd %~dp0
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build
%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)
if "%1" == "" goto help
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end
:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
:end
popd
+2
View File
@@ -0,0 +1,2 @@
sphinx-rtd-theme>=3.0.2
breathe>=4.35.0
+34
View File
@@ -0,0 +1,34 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
project = 'RP2040-Decoder'
copyright = '2024, Gabriel Koppenstein'
author = 'Gabriel Koppenstein'
release = '0.3, 1.0'
# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
extensions = ['breathe']
templates_path = ['_templates']
exclude_patterns = []
# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
html_theme = "sphinx_rtd_theme"
html_static_path = ['_static']
# Breathe Configuration
breathe_projects = {
"RP2040-Decoder": "../../doxygen/build/xml"
}
breathe_default_project = "RP2040-Decoder"
+18
View File
@@ -0,0 +1,18 @@
Hardware
======================
Revision 1.0
------------
.. toctree::
:maxdepth: 1
rev_1_0/hw_description
Revision 0.3
------------
.. toctree::
:maxdepth: 1
rev_0_3/hw_description
@@ -0,0 +1,132 @@
Overview
==============================
.. figure:: ../../../../svg/hw/rev_0_3/Block_Diagram_Hardware.svg
:alt: Block Diagram
:align: center
Harware block diagram
The above block diagram gives a general overview regarding the operation of components. For better illustration it has been divided into four functional blocks. Furthermore, these functional blocks can be subdivided and will be explained below.
- **Input Stage**
- DCC Signal Level Shift
- Bridge Rectifier & Voltage Regulator
- **Motor Driver**
- Motor Driver
- Back EMF measurement (ADC)
- **General Purpose**
- GPIO
- Auxiliary output
- **Microcontroller**
- Flash memory
- Crystal oscillator
Electrical Characteristics
==============================
.. table:: Electrical Characteristics & Absolute Maximum Ratings
:widths: auto
===================================================== ============================= ========= ========= =====
Parameter Symbol Minimum Maximum Unit
===================================================== ============================= ========= ========= =====
Absolute max. DCC Input Voltage difference V\ :sub:`DCC`\ 0 +24 V
Absolute max. GPIO Voltage\ :sup:`(0)`\ V\ :sub:`PIN`\ -0.5 3.3+0.5 V
Input Voltage High\ :sup:`(0)`\ V\ :sub:`IH`\ 2.145 3.6 V
Input Voltage Low\ :sup:`(0)`\ V\ :sub:`IL`\ 0 1.155 V
Total GPIO Current\ :sup:`(0)`\ I\ :sub:`IOVDD`\ 50 mA
Absolute max. motor output current\ :sup:`(1)`\ I\ :sub:`MOTOR`\ 2.8 A
Absolute max. auxiliary output current \ :sup:`(2)`\ I\ :sub:`AUX`\ 400 mA
===================================================== ============================= ========= ========= =====
(0): According to: `RP2040 Datasheet <https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf>`_ (assuming V\ :sub:`DD`\ = 3.3V)
(1): According to: `BDR6133 Datasheet <https://www.lcsc.com/datasheet/lcsc_datasheet_2409291808_Bardeen-Micro--BDR6133_C2687793.pdf>`_
(2): According to: `T2N7002BK Datasheet <https://toshiba.semicon-storage.com/info/T2N7002BK_datasheet_en_20191025.pdf?did=30376&prodName=T2N7002BK>`_
.. note:: Keep in mind that realistically these maximum ratings can't be reached in practice due to thermal limitations. For example the motor current can probably not exceed 1.5A for continuous operation.
Input Stage
==============================
.. figure:: ../../../../svg/hw/rev_0_3/Input_Stage.svg
:alt: Input Stage
:align: center
Input stage
D1 Rectifies the DCC square-wave into +V, the amplitude is not critical as long as it's within the 25V limit. The rectified voltage +V is then provided to the 3.3V voltage regulator (U1) and to the motor driver (U2).
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
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_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
==============================
please see **PLACEHOLDER-AUTOGENERATED-BOM** for the complete BOM.
.. _wiring_rev_0_3:
Wiring the Decoder
==============================
.. figure:: ../../../../svg/hw/rev_0_3/Wiring_diagram.svg
:align: center
:width: 700
:alt: 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.
When switching inductive loads, always include a free-wheeling diode to protect the circuit.
@@ -0,0 +1,134 @@
Overview
==============================
.. figure:: ../../../../svg/hw/rev_1_0/Block_Diagram_Hardware.svg
:align: center
:alt: Block Diagram
Harware block diagram
The above block diagram gives a general overview regarding the operation of components. For better illustration it has been divided into four functional blocks. Furthermore, these functional blocks can be subdivided and will be explained below.
- **Input Stage**
- DCC Signal Level Shift
- Bridge Rectifier & Voltage Regulator
- **Motor Driver**
- Motor Driver
- Back EMF measurement (ADC)
- **General Purpose**
- GPIO
- Auxiliary output
- **Microcontroller**
- Flash memory
- Crystal oscillator
- USB Connector
Electrical Characteristics
==============================
.. table:: Electrical Characteristics & Absolute Maximum Ratings
:widths: auto
======================================================== ============================= ========= ========= =====
Parameter Symbol Minimum Maximum Unit
======================================================== ============================= ========= ========= =====
Absolute max. DCC input voltage difference V\ :sub:`DCC`\ +24 V
Absolute max. GPIO voltage\ :sup:`(0)`\ V\ :sub:`PIN`\ -0.5 3.3+0.5 V
Input voltage high\ :sup:`(0)`\ V\ :sub:`IH`\ 2.145 3.6 V
Input voltage low\ :sup:`(0)`\ V\ :sub:`IL`\ 0 1.155 V
Total GPIO Current\ :sup:`(0)`\ I\ :sub:`IOVDD`\ 50 mA
Absolute max. motor output current\ :sup:`(1)`\ I\ :sub:`MOTOR`\ 2.8 A
Absolute max. auxiliary output current \ :sup:`(2)(3)`\ I\ :sub:`AUX`\ 1.4 A
======================================================== ============================= ========= ========= =====
(0): According to: `RP2040 Datasheet <https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf>`_ (assuming V\ :sub:`DD`\ = 3.3V)
(1): According to: `BDR6133 Datasheet <https://www.lcsc.com/datasheet/lcsc_datasheet_2409291808_Bardeen-Micro--BDR6133_C2687793.pdf>`_
(2): According to: `Si1308EDL Datasheet <https://www.vishay.com/docs/63399/si1308edl.pdf>`_
(3): T\ :sub:`Case`\ = 25°C, keep power dissipation, thermal resistance the corresponding temperature rise ΔT and switching losses in PWM mode in mind!
.. note:: Keep in mind that realistically these maximum ratings can't be reached in practice due to thermal limitations. For example the motor current can probably not exceed 1.5A for continuous operation.
Input Stage
==============================
.. figure:: ../../../../svg/hw/rev_1_0/Input_Stage.svg
:align: center
:alt: Input Stage
Input stage
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, meaning that the decoder can be powered either by the DCC track signal or by the VBUS supply voltage which is supplied via USB connector.
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
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
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, ...
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
==============================
please see **PLACEHOLDER-AUTOGENERATED-BOM** for the complete BOM.
.. _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
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.
When switching inductive loads, always include a free-wheeling diode to protect the circuit.
+17
View File
@@ -0,0 +1,17 @@
.. RP2040-Decoder documentation master file, created by
sphinx-quickstart on Wed Nov 27 08:19:47 2024.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
RP2040-Decoder Documentation
============================
.. toctree::
:maxdepth: 3
:caption: Contents:
other/getting_started
hardware/index
software/index
other/index
other/troubleshooting
+202
View File
@@ -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
![Speed Table](https://github.com/gab-k/RP2040-Decoder/blob/main/docs/svg/speed_table.svg)
* 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.
![Long Address](https://github.com/gab-k/RP2040-Decoder/blob/main/docs/svg/Long_address.svg)
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
![GPIO Slices](https://github.com/gab-k/RP2040-Decoder/blob/main/docs/svg/GPIO_slices.svg)
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,69 @@
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 <https://www.kicad.org/download/>`_ which is open source.
In case you are ordering from JLCPCB it is recommended to use the `Fabrication-Toolkit KiCad plugin by bennymeg <https://github.com/bennymeg/Fabrication-Toolkit>`_
.. _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.
However sometimes you might want to build by yourself, be it for debugging or to make your own modifications to the source code.
The easiest way to do this is to just use `Visual Studio Code <https://code.visualstudio.com/>`_ and the Raspberry Pi Pico extension.
The `official documentation <https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf#vscode-extension>`_ 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:
1. Flashing via USB using the .uf2 file by copying it with your preferred file explorer.
2. Using Serial Wire Debug (SWD)
2.1. Using another RP2040/RP2350-based board with `debugprobe software <https://github.com/raspberrypi/debugprobe>`_ on it. (Could be the RP2040-Decoder itself)
2.2. Using any other supported SWD debug interface
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 <https://datasheets.raspberrypi.com/pico/pico-datasheet.pdf#_programming_the_flash>`_
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 <https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf>`_ does a great job of explaining how debugging works.
As already suggested in :ref:`3. <building_the_software>` it is recommended to use the `Visual Studio Code Extension <https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf#vscode-extension>`_.
Most relevant in the book are `Chapter 4.3. Debug <https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf#_debug>`_ and `Appendix A: Debugprobe <https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf#debugprobe_section>`_
5. Wiring
----------------------------------
| Please refer to the hardware section for your board:
| :ref:`Wiring Rev 1.0 <wiring_rev_1_0>`
| :ref:`Wiring Rev 0.3 <wiring_rev_0_3>`
6. Resolving issues
----------------------------------
If the decoder is 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.
+9
View File
@@ -0,0 +1,9 @@
Other
======================
.. toctree::
:maxdepth: 2
:caption: Contents:
CV_list
troubleshooting
@@ -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!)
@@ -0,0 +1,22 @@
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
+9
View File
@@ -0,0 +1,9 @@
Software
=================
.. toctree::
:maxdepth: 3
:caption: Contents:
sw_description
header_files
@@ -0,0 +1,182 @@
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-Rev-X_Y.h**
- Flash Size
- Pin definitions
- LED pin when available
- UART_TX/UART_RX pins when used for logging
- DCC input pin
- Motor Control PWM pins
- ADC pins
- **post_build.cmake**
- Post build script for checking whether the size of the binary is within the limits of the flash size minus one sector (used for storing CVs).
- **pico_sdk_import.cmake**
- Helps to locate and import the Pico SDK
The `Raspberry Pi Pico SDK <https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-c-sdk.pdf>`_ is a dependency of the decoder software. The SDK provides abstraction to a higher level, so hopefully, in combination with the comments included in header and source files, the code is easy enough to understand.
Control Loop & Digital Controller
------------------------------------
.. figure:: ../../../svg/sw/Block_Diagram_Control_Loop.svg
:alt: Block Diagram - Control Loop
:align: center
Control Loop - Block diagram
The block diagram above shows the complete control loop. The actual digital controller block is explained below.
The Speed Helper block effectively sets the setpoint of the controller according to the CV configured acceleration and deceleration rates and actual target speedstep.
For feedback the back EMF voltage V_EMF is measured via voltage divider and ADC. V_EMF is proportional to the motor speed in RPM.
TODO: rewrite this: While the central component is the PID controller, there is an additional block called `Feed-forward <https://en.wikipedia.org/wiki/Feed_forward_(control)>`_ that has an impact on the control output variable. The Feed-forward block adds an additional offset to the output depending on the setpoint; this is done to achieve better control. A more detailed explanation regarding Feed-forward can be found below. The speed helper block corresponds to the ``speed_helper()`` function, which delays changing the setpoint according to the configured deceleration/acceleration rates.
.. figure:: ../../../svg/sw/Block_Diagram_Digital_Controller.svg
:alt: Block Diagram - Digital Controller
:align: center
Digital Controller - Block diagram
The controller is divided into two parts, depending on whether the motor is stationary or in motion. The startup controller handles overcoming friction of the motor, and finding base PWM level for overcoming friction. The base PWM level is saved and added to the output of the PID controller which handles motor control when the motor is in motion.
Startup Controller
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Used on startup, meaning when the motor is not moving. The startup controller sets a PWM duty cycle level of :math:`\frac{2}{3} \cdot \text{base_pwm}` and then ramps up the duty cycle/PWM level until the motor starts moving. This is done in order to overcome the friction of the drive train and motor. :math:`\text{base_pwm}` is the average value of the 16 previous startup PWM levels. When no previous startup PWM levels are saved the startup controller begins ramping up from 0. The actual value at which the motor started moving is used as a reference for the :ref:`feed forward <feed_forward>` block.
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 <https://en.wikipedia.org/wiki/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}
.. note::
- 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.
- The previously explained base PWM is added to the actual output as well, meaning the formula above only shows the actual PID control part without feed forward.
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 <https://en.wikipedia.org/wiki/Gain_scheduling>`_. K\ :sub:`P` is a function of the current setpoint. Often it is favorable to have a higher proportional gain K\ :sub:`P` for slow speeds, achieving better control results. The illustration above shows the default setting for K\ :sub:`P`. CV_54 & CV_55 are used to set K\ :sub:`P` @ x\ :sub:`0`, CV_56 & CV_57 for K\ :sub:`P` @ x\ :sub:`1`, and CV_58 & CV_59 for K\ :sub:`P` @ x\ :sub:`2`. Additionally, CV_60 is used to shift x\ :sub:`1` from the leftmost point (0% = 0/255) to the rightmost point (100% = 255/255).
.. _feed_forward:
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 <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 (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 <https://en.wikipedia.org/wiki/Counter-electromotive_force>`_. The measurement works by setting the PWM duty cycle to 0%, waiting for a certain delay time (CV_62), and then measuring x times (x = CV_63). While measuring, the array with measurement values is sorted using insertion sort. Afterwards, y elements (y = CV_63) from the left (lowest values) and z elements (z = CV_64) from the right (highest values) will be dismissed to mitigate the impact of potential outliers in measurement. The average value of the remaining values will be computed and fed back into the control algorithm. Considering default settings (100us delay, 100 samples, ~2µs sampling time), the complete measurement run, including averaging, takes about 0.3ms to 0.35ms, which effectively reduces the maximum possible duty cycle to about 93% to 94%.
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 <https://www.nmra.org/index-nmra-standards-and-recommended-practices>`_.
-3
View File
@@ -1,3 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="1570px" height="733px" viewBox="-0.5 -0.5 1570 733"><defs/><g><rect x="245" y="97" width="150" height="70" fill="#647687" stroke="#314354" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 148px; height: 1px; padding-top: 132px; margin-left: 246px;"><div style="box-sizing: border-box; font-size: 0px; text-align: center;" data-drawio-colors="color: #ffffff; "><div style="display: inline-block; font-size: 18px; font-family: Verdana; color: rgb(255, 255, 255); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">Speed Helper</div></div></div></foreignObject><text x="320" y="137" fill="#ffffff" font-family="Verdana" font-size="18px" text-anchor="middle">Speed Helper</text></switch></g><path d="M 900 367 L 1043.63 367" fill="none" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 1048.88 367 L 1041.88 370.5 L 1043.63 367 L 1041.88 363.5 Z" fill="rgb(0, 0, 0)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><rect x="590" y="332" width="150" height="70" fill="#647687" stroke="#314354" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 148px; height: 1px; padding-top: 367px; margin-left: 591px;"><div style="box-sizing: border-box; font-size: 0px; text-align: center;" data-drawio-colors="color: #ffffff; "><div style="display: inline-block; font-size: 18px; font-family: Verdana; color: rgb(255, 255, 255); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">PID Controller</div></div></div></foreignObject><text x="665" y="372" fill="#ffffff" font-family="Verdana" font-size="18px" text-anchor="middle">PID Controller</text></switch></g><path d="M 820 367 L 746.37 367" fill="none" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 741.12 367 L 748.12 363.5 L 746.37 367 L 748.12 370.5 Z" fill="rgb(0, 0, 0)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><rect x="1050" y="332" width="150" height="70" fill="#647687" stroke="#314354" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 148px; height: 1px; padding-top: 367px; margin-left: 1051px;"><div style="box-sizing: border-box; font-size: 0px; text-align: center;" data-drawio-colors="color: #ffffff; "><div style="display: inline-block; font-size: 18px; font-family: Verdana; color: rgb(255, 255, 255); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">Motor Driver</div></div></div></foreignObject><text x="1125" y="372" fill="#ffffff" font-family="Verdana" font-size="18px" text-anchor="middle">Motor Driver</text></switch></g><rect x="590" y="662" width="150" height="70" fill="#647687" stroke="#314354" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 148px; height: 1px; padding-top: 697px; margin-left: 591px;"><div style="box-sizing: border-box; font-size: 0px; text-align: center;" data-drawio-colors="color: #ffffff; "><div style="display: inline-block; font-size: 18px; font-family: Verdana; color: rgb(255, 255, 255); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">ADC</div></div></div></foreignObject><text x="665" y="702" fill="#ffffff" font-family="Verdana" font-size="18px" text-anchor="middle">ADC</text></switch></g><path d="M 741 383.5 L 741 350.5 L 781.99 350.5 L 781.99 339.5 L 819 367 L 781.99 394.5 L 781.99 383.5 Z" fill="rgb(255, 255, 255)" stroke="#647687" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><rect x="1305" y="332" width="150" height="70" fill="#647687" stroke="#314354" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignLine truncated

Before

Width:  |  Height:  |  Size: 22 KiB

-4
View File
@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Do not edit this file with editors other than diagrams.net -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="2551px" height="1551px" viewBox="-0.5 -0.5 2551 1551" content="&lt;mxfile host=&quot;app.diagrams.net&quot; modified=&quot;2022-08-05T21:46:24.297Z&quot; agent=&quot;5.0 (X11)&quot; etag=&quot;3xPXZ7MIIq7wi2-Z9Vb2&quot; version=&quot;20.2.2&quot; type=&quot;device&quot;&gt;&lt;diagram id=&quot;fYnpBcbPwy3h1yrhEr7x&quot; name=&quot;Page-1&quot;&gt;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 truncated

Before

Width:  |  Height:  |  Size: 521 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 630 KiB

After

Width:  |  Height:  |  Size: 630 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Do not edit this file with editors other than diagrams.net -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="2037px" height="1191px" viewBox="-0.5 -0.5 2037 1191" content="&lt;mxfile host=&quot;app.diagrams.net&quot; modified=&quot;2022-08-06T10:29:12.145Z&quot; agent=&quot;5.0 (X11)&quot; etag=&quot;IjcCWwMyXrMXf420IuKe&quot; version=&quot;20.2.3&quot; type=&quot;device&quot;&gt;&lt;diagram id=&quot;fYnpBcbPwy3h1yrhEr7x&quot; name=&quot;Page-1&quot;&gt;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 truncated

After

Width:  |  Height:  |  Size: 521 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 630 KiB

After

Width:  |  Height:  |  Size: 630 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 609 KiB

After

Width:  |  Height:  |  Size: 609 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 630 KiB

After

Width:  |  Height:  |  Size: 630 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 518 KiB

After

Width:  |  Height:  |  Size: 518 KiB

+4
View File
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Do not edit this file with editors other than diagrams.net -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="1507px" height="895px" viewBox="-0.5 -0.5 1507 895" content="&lt;mxfile host=&quot;app.diagrams.net&quot; modified=&quot;2022-08-06T11:02:18.786Z&quot; agent=&quot;5.0 (X11)&quot; etag=&quot;NKSu-nPPOk6CyOgIXUhc&quot; version=&quot;20.2.3&quot; type=&quot;device&quot;&gt;&lt;diagram id=&quot;fYnpBcbPwy3h1yrhEr7x&quot; name=&quot;Page-1&quot;&gt;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 truncated

After

Width:  |  Height:  |  Size: 524 KiB

File diff suppressed because it is too large. Load diff

After

Width:  |  Height:  |  Size: 6.9 MiB

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Do not edit this file with editors other than draw.io -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="1043px" height="543px" viewBox="-0.5 -0.5 1043 543" content="&lt;mxfile host=&quot;app.diagrams.net&quot; agent=&quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0&quot; version=&quot;24.9.0&quot; scale=&quot;1&quot; border=&quot;0&quot;&gt;&#xA; &lt;diagram id=&quot;4yrCjKYynwCaxiwjl_Zd&quot; name=&quot;Page-1&quot;&gt;&#xA; &lt;mxGraphModel dx=&quot;1434&quot; dy=&quot;734&quot; grid=&quot;0&quot; gridSize=&quot;10&quot; guides=&quot;1&quot; tooltips=&quot;1&quot; connect=&quot;1&quot; arrows=&quot;1&quot; fold=&quot;1&quot; page=&quot;1&quot; pageScale=&quot;1&quot; pageWidth=&quot;1169&quot; pageHeight=&quot;827&quot; background=&quot;none&quot; math=&quot;0&quot; shadow=&quot;0&quot;&gt;&#xA; &lt;root&gt;&#xA; &lt;mxCell id=&quot;0&quot; /&gt;&#xA; &lt;mxCell id=&quot;1&quot; parent=&quot;0&quot; /&gt;&#xA; &lt;mxCell id=&quot;C1jbzQCqpV-uhOoT1oVn-1&quot; value=&quot;&amp;lt;div style=&amp;quot;font-size: 20px&amp;quot;&amp;gt;&amp;lt;font style=&amp;quot;font-size: 20px&amp;quot;&amp;gt;RP2040&amp;lt;/font&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;div style=&amp;quot;font-size: 20px&amp;quot;&amp;gt;&amp;lt;font style=&amp;quot;font-size: 20px&amp;quot;&amp;gt;Microcontroller&amp;lt;br&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/div&amp;gt;&quot; style=&quot;rounded=0;whiteSpace=wrap;html=1;fillColor=#647687;fontColor=#ffffff;strokeColor=#314354;&quot; parent=&quot;1&quot; vertex=&quot;1&quot;&gt;&#xA; &lt;mxGeometry x=&quot;560&quot; y=&quot;340&quot; width=&quot;200&quot; height=&quot;200&quot; as=&quot;geometry&quot; /&gt;&#xA; &lt;/mxCell&gt;&#xA; &lt;mxCell id=&quot;C1jbzQCqpV-uhOoT1oVn-4&quot; value=&quot;&quot; style=&quot;endArrow=classic;startArrow=classic;html=1;rounded=0;fontFamily=Helvetica;fontSize=11;fontColor=default;exitX=0.75;exitY=1;exitDx=0;exitDy=0;strokeColor=#647687;entryX=0.25;entryY=0;entryDx=0;entryDy=0;shape=flexArrow;strokeWidth=2;fillColor=default;gradientColor=none;&quot; parent=&quot;1&quot; source=&quot;C1jbzQCqpV-uhOoT1oVn-1&quot; target=&quot;C1jbzQCqpV-uhOoT1oVn-5&quot; edge=&quot;1&quot;&gt;&#xA; &lt;mxGeometry width=&quot;50&quot; height=&quot;50&quot; relative=&quot;1&quot; as=&quot;geometry&quot;&gt;&#xA; &lt;mxPoint x=&quot;595&quot; y=&quot;450&quot; as=&quot;sourcePoint&quot; /&gt;&#xA; &lt;mxPoint x=&quot;485&quot; y=&quot;440&quot; as=&quot;targetPoint&quot; /&gt;&#xA; &lt;/mxGeometry&gt;&#xA; &lt;/mxCell&gt;&#xA; &lt;mxCell id=&quot;C1jbzQCqpV-uhOoT1oVn-5&quot; value=&quot;GPIO&quot; style=&quot;rounded=0;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=18;fontColor=#ffffff;fillColor=#647687;strokeColor=#314354;&quot; parent=&quot;1&quot; vertex=&quot;1&quot;&gt;&#xA; &lt;mxGeometry x=&quot;680&quot; y=&quot;600&quot; width=&quot;120&quot; height=&quot;60&quot; as=&quot;geometry&quot; /&gt;&#xA; &lt;/mxCell&gt;&#xA; &lt;mxCell id=&quot;UgZSE7u6rpuSXDGsVSFL-2&quot; value=&quot;&amp;lt;div&amp;gt;Auxillary outputs&amp;lt;/div&amp;gt;&quot; style=&quot;rounded=0;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=18;fontColor=#ffffff;fillColor=#647687;strokeColor=#314354;&quot; parent=&quot;1&quot; vertex=&quot;1&quot;&gt;&#xA; &lt;mxGeometry x=&quot;520&quot; y=&quot;600&quot; width=&quot;120&quot; height=&quot;60&quot; as=&quot;geometry&quot; /&gt;&#xA; &lt;/mxCell&gt;&#xA; &lt;mxCell id=&quot;UgZSE7u6rpuSXDGsVSFL-5&quot; value=&quot;&quot; style=&quot;endArrow=classic;html=1;rounded=0;strokeColor=#647687;entryX=0.75;entryY=0;entryDx=0;entryDy=0;exitX=0.25;exitY=1;exitDx=0;exitDy=0;shape=flexArrow;strokeWidth=2;fillColor=default;gradientColor=none;&quot; parent=&quot;1&quot; source=&quot;C1jbzQCqpV-uhOoT1oVn-1&quot; target=&quot;UgZSE7u6rpuSXDGsVSFL-2&quot; edge=&quot;1&quot;&gt;&#xA; &lt;mxGeometry width=&quot;50&quot; height=&quot;50&quot; relative=&quot;1&quot; as=&quot;geometry&quot;&gt;&#xA; &lt;mxPoint x=&quot;645&quot; y=&quot;440&quot; as=&quot;sourcePoint&quot; /&gt;&#xA; &lt;mxPoint x=&quot;695&quot; y=&quot;390&quot; as=&quot;targetPoint&quot; /&gt;&#xA; &lt;/mxGeometry&gt;&#xA; &lt;/mxCell&gt;&#xA; &lt;mxCell id=&quot;UgZSE7u6rpuSXDGsVSFL-7&quot; value=&quot;Motor Driver&quot; style=&quot;rounded=0;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=18;fontColor=#ffffff;fillColor=#647687;strokeColor=#314354;&quot; parent=&quot;1&quot; vertex=&quot;1&quot;&gt;&#xA; &lt;mxGeometry x=&quot;960&quot; y=&quot;360&quot; width=&quot;120&quot; height=&quot;60&quot; as=&quot;geometry&quot; /&gt;&#xA; &lt;/mxCell&gt;&#xA; &lt;mxCell id=&quot;UgZSE7u6rpuSXDGsVSFL-9&quot; value=&quot;&quot; style=&quot;endArrow=classic;html=1;rounded=0;strokeColor=#647687;exitX=1;exitY=0.25;exitDx=0;exitDy=0;entryX=0;entryY=0.Line truncated

After

Width:  |  Height:  |  Size: 140 KiB

File diff suppressed because it is too large. Load diff

After

Width:  |  Height:  |  Size: 6.9 MiB

File diff suppressed because it is too large. Load diff

After

Width:  |  Height:  |  Size: 6.9 MiB

File diff suppressed because it is too large. Load diff

After

Width:  |  Height:  |  Size: 6.8 MiB

File diff suppressed because it is too large. Load diff

After

Width:  |  Height:  |  Size: 1.5 MiB

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Do not edit this file with editors other than draw.io -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="1571px" height="733px" viewBox="-0.5 -0.5 1571 733" content="&lt;mxfile host=&quot;app.diagrams.net&quot; agent=&quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0&quot; version=&quot;25.0.3&quot; scale=&quot;1&quot; border=&quot;0&quot;&gt;&#xA; &lt;diagram name=&quot;Page-1&quot; id=&quot;EzXMAEqKDDRs-_LGy8zr&quot;&gt;&#xA; &lt;mxGraphModel dx=&quot;1687&quot; dy=&quot;920&quot; grid=&quot;1&quot; gridSize=&quot;10&quot; guides=&quot;1&quot; tooltips=&quot;1&quot; connect=&quot;1&quot; arrows=&quot;1&quot; fold=&quot;1&quot; page=&quot;1&quot; pageScale=&quot;1&quot; pageWidth=&quot;827&quot; pageHeight=&quot;1169&quot; math=&quot;0&quot; shadow=&quot;0&quot;&gt;&#xA; &lt;root&gt;&#xA; &lt;mxCell id=&quot;0&quot; /&gt;&#xA; &lt;mxCell id=&quot;1&quot; parent=&quot;0&quot; /&gt;&#xA; &lt;mxCell id=&quot;4ED7IVWrFvjwATd2QOsb-28&quot; value=&quot;Speed Helper&quot; style=&quot;rounded=0;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=18;fontColor=#ffffff;fillColor=#647687;strokeColor=#314354;&quot; vertex=&quot;1&quot; parent=&quot;1&quot;&gt;&#xA; &lt;mxGeometry x=&quot;265&quot; y=&quot;150&quot; width=&quot;150&quot; height=&quot;70&quot; as=&quot;geometry&quot; /&gt;&#xA; &lt;/mxCell&gt;&#xA; &lt;mxCell id=&quot;4ED7IVWrFvjwATd2QOsb-29&quot; value=&quot;&quot; style=&quot;edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;startArrow=none;&quot; edge=&quot;1&quot; parent=&quot;1&quot; target=&quot;4ED7IVWrFvjwATd2QOsb-31&quot;&gt;&#xA; &lt;mxGeometry relative=&quot;1&quot; as=&quot;geometry&quot;&gt;&#xA; &lt;mxPoint x=&quot;920&quot; y=&quot;420&quot; as=&quot;sourcePoint&quot; /&gt;&#xA; &lt;/mxGeometry&gt;&#xA; &lt;/mxCell&gt;&#xA; &lt;mxCell id=&quot;4ED7IVWrFvjwATd2QOsb-30&quot; value=&quot;&amp;lt;div&amp;gt;&amp;lt;b&amp;gt;Motor Controller&amp;lt;/b&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;div&amp;gt;&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;div&amp;gt;PID MODE&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;div&amp;gt;&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;div&amp;gt;or&amp;lt;/div&amp;gt;&amp;lt;div&amp;gt;&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;div&amp;gt;STARTUP MODE&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;&quot; style=&quot;rounded=0;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=18;fontColor=#ffffff;fillColor=#647687;strokeColor=#314354;&quot; vertex=&quot;1&quot; parent=&quot;1&quot;&gt;&#xA; &lt;mxGeometry x=&quot;610&quot; y=&quot;340&quot; width=&quot;340&quot; height=&quot;160&quot; as=&quot;geometry&quot; /&gt;&#xA; &lt;/mxCell&gt;&#xA; &lt;mxCell id=&quot;4ED7IVWrFvjwATd2QOsb-31&quot; value=&quot;Motor Driver&quot; style=&quot;rounded=0;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=18;fontColor=#ffffff;fillColor=#647687;strokeColor=#314354;&quot; vertex=&quot;1&quot; parent=&quot;1&quot;&gt;&#xA; &lt;mxGeometry x=&quot;1070&quot; y=&quot;385&quot; width=&quot;150&quot; height=&quot;70&quot; as=&quot;geometry&quot; /&gt;&#xA; &lt;/mxCell&gt;&#xA; &lt;mxCell id=&quot;4ED7IVWrFvjwATd2QOsb-32&quot; value=&quot;ADC&quot; style=&quot;rounded=0;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=18;fontColor=#ffffff;fillColor=#647687;strokeColor=#314354;&quot; vertex=&quot;1&quot; parent=&quot;1&quot;&gt;&#xA; &lt;mxGeometry x=&quot;610&quot; y=&quot;715&quot; width=&quot;150&quot; height=&quot;70&quot; as=&quot;geometry&quot; /&gt;&#xA; &lt;/mxCell&gt;&#xA; &lt;mxCell id=&quot;4ED7IVWrFvjwATd2QOsb-33&quot; value=&quot;Motor&quot; style=&quot;rounded=0;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=18;fontColor=#ffffff;fillColor=#647687;strokeColor=#314354;&quot; vertex=&quot;1&quot; parent=&quot;1&quot;&gt;&#xA; &lt;mxGeometry x=&quot;1325&quot; y=&quot;385&quot; width=&quot;150&quot; height=&quot;70&quot; as=&quot;geometry&quot; /&gt;&#xA; &lt;/mxCell&gt;&#xA; &lt;mxCell id=&quot;4ED7IVWrFvjwATd2QOsb-34&quot; value=&quot;&quot; style=&quot;endArrow=classic;html=1;rounded=0;strokeColor=#647687;exitX=0.5;exitY=1;exitDx=0;exitDy=0;shape=flexArrow;strokeWidth=2;fillColor=default;gradientColor=none;width=32;endSize=11.67;entryX=0.5;entryY=0;entryDx=0;entryDy=0;horizontal=0;&quot; edge=&quot;1&quot; parent=&quot;1&quot; source=&quot;4ED7IVWrFvjwATd2QOsb-28&quot; target=&quot;4ED7IVWrFvjwATd2QOsb-43&quot;&gt;&#xA; &lt;mxGeometry width=&quot;50&quot; height=&quot;50&quot; relative=&quot;1&quot; as=&quot;geometry&quot;&gt;&#xA; &lt;mxPoint x=&quot;330&quot; y=&quot;280&quot; as=&quot;sourcePoint&quot; /&gt;&#xA; &lt;mxPoint x=&quot;210&quot; y=&quot;320&quot; as=&quot;targetPoint&quot; /&gt;&#xA; &lt;Array as=&quot;points&quot; /&gt;&#xA; &lt;/mxGeometry&gt;&#xA; &lt;/mxCeLine truncated

After

Width:  |  Height:  |  Size: 203 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 64 KiB

After

Width:  |  Height:  |  Size: 64 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 43 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

+85
View File
@@ -0,0 +1,85 @@
##############################
# #
# #
# -----p2 #
# | | #
# | | <- Crop Window # <- Whole PDF Window
# | | #
# p1----| #
# #
##############################
# Coordinate origin is at bottom left of PDF window
#
# y
# î
# |
# |
# +-----> x
import argparse
from PyPDF2 import PdfReader, PdfWriter
def crop_pdf(input_path, output_path, p1, p2):
"""
Crop a PDF file based on the given bottom-left (p1) and top-right (p2) coordinates.
Parameters:
- input_path (str): Path to the input PDF file.
- output_path (str): Path to save the cropped PDF file.
- p1 (tuple): Bottom-left corner of the crop window (x, y).
- p2 (tuple): Top-right corner of the crop window (x, y).
"""
# Validate coordinates
if p1[0] >= p2[0]:
raise ValueError("Invalid x dimensions: p1[0] must be less than p2[0]")
if p1[1] >= p2[1]:
raise ValueError("Invalid y dimensions: p1[1] must be less than p2[1]")
# Open the input PDF
with open(input_path, "rb") as in_f:
input_pdf = PdfReader(in_f)
output_pdf = PdfWriter()
num_pages = len(input_pdf.pages)
print(f"Document has {num_pages} pages.")
# Loop through all pages
for i in range(num_pages):
page = input_pdf.pages[i]
# Set the cropbox properties for the page
page.cropbox.lower_left = p1 # Bottom-left corner
page.cropbox.upper_right = p2 # Top-right corner
# Debug information about the crop box
print(f"Page {i + 1}:")
print(f" - Cropbox Lower Left: {page.cropbox.lower_left}")
print(f" - Cropbox Upper Right: {page.cropbox.upper_right}")
# Add the modified page to the writer
output_pdf.add_page(page)
# Write the final output
with open(output_path, "wb") as out_f:
output_pdf.write(out_f)
print(f"Cropped PDF saved as {output_path}")
# Add argument parsing to handle command-line inputs
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Crop a PDF file based on coordinates.")
parser.add_argument("input_path", type=str, help="Path to the input PDF file.")
parser.add_argument("output_path", type=str, help="Path to save the cropped PDF file.")
parser.add_argument("p1", type=float, nargs=2, help="Bottom-left corner of the crop window (x, y).")
parser.add_argument("p2", type=float, nargs=2, help="Top-right corner of the crop window (x, y).")
args = parser.parse_args()
# Convert command-line inputs for coordinates
bottom_left = tuple(args.p1)
top_right = tuple(args.p2)
# Call the crop function
try:
crop_pdf(args.input_path, args.output_path, bottom_left, top_right)
except ValueError as e:
print(f"Error: {e}")
+139
View File
@@ -0,0 +1,139 @@
"""
Script for automatically generating .svg files for documentation
How to use:
1. Install Inkscape and add to PATH
2. Install KiCad and add to PATH
3. Install PyPDF2
4. Copy the schematic_theme.json file into the following directory:
Linux: ~.config/kicad/<version>/colors
Windows: %appdata%/kicad/<version>/colors
"""
import subprocess
import os
# Output directory path
svg_dir = "../docs/svg/"
# Temp directory path
temp_dir = "temp/"
# .kicad_sch path/filename
kicad_sch_filename = "../KiCad/RP2040-Decoder.kicad_sch"
# Define crop areas with p1 (bottom-left) and p2 (top-right) points and custom pdf_name
crop_areas = {
"Input Stage": {
"p1": (60, 440), # Bottom-left corner (x1, y1)
"p2": (430, 560), # Top-right corner (x2, y2)
"name": "Input_Stage"
},
"Motor Driver": {
"p1": (600, 125),
"p2": (810, 315),
"name": "Motor_Driver"
},
"Auxillary Outputs": {
"p1": (620, 395),
"p2": (810, 555),
"name": "Aux_Outputs"
},
"Microcontroller": {
"p1": (40, 20),
"p2": (600, 420),
"name": "Microcontroller"
}
}
# 1. Create temp directory
try:
os.mkdir(temp_dir)
print(f"Directory '{temp_dir}' created successfully.")
except FileExistsError:
print(f"Directory '{temp_dir}' already exists.")
except PermissionError:
print(f"Permission denied: Unable to create '{temp_dir}'.")
except Exception as e:
print(f"An error occurred: {e}")
# 2. Export from KiCad with and without drawing sheet
subprocess.run(
["kicad-cli", "sch", "export", "pdf", "--no-background-color", "--exclude-drawing-sheet", "--theme", "schematic_theme",
"--output", temp_dir + "RP2040-Decoder_temp.pdf", kicad_sch_filename],
check=True
)
subprocess.run(
["kicad-cli", "sch", "export", "svg", "--no-background-color", "--theme", "schematic_theme",
"--output", svg_dir, kicad_sch_filename],
check=True
)
# 3. Crop the PDF for each specified crop area
for crop_key, crop_data in crop_areas.items():
p1 = crop_data["p1"] # (x1, y1)
p2 = crop_data["p2"] # (x2, y2)
pdf_path = temp_dir + crop_data["name"] + ".pdf" # Name of the output cropped PDF
subprocess.run(
["python", "crop_pdf.py", temp_dir + "RP2040-Decoder_temp.pdf", pdf_path, str(p1[0]), str(p1[1]), str(p2[0]), str(p2[1])],
check=True
)
print(f"Cropped part {crop_key} saved as {pdf_path}")
# 4. Convert each cropped PDF to SVG using Inkscape
for crop_key, crop_data in crop_areas.items():
svg_path = svg_dir + crop_data["name"] + ".svg"
pdf_path = temp_dir + crop_data["name"] + ".pdf"
subprocess.run(
["inkscape", "--export-type=svg", "--export-filename=" + svg_path, pdf_path],
check=True
)
print(f"Converted {pdf_path} to {svg_path}")
# 5. Set transparency for each SVG
for crop_key, crop_data in crop_areas.items():
svg_path = svg_dir + crop_data["name"] + ".svg"
subprocess.run(
["python", "set_opacity.py", svg_path, svg_path],
check=True
)
print(f"Set transparency for {svg_path}")
# 6. Clean up the temporary PDF files and attempt to delete temp directory
for crop_key, crop_data in crop_areas.items():
pdf_path = temp_dir + crop_data["name"] + ".pdf"
try:
os.remove(pdf_path) # Attempt to delete the cropped PDF
print(f"Deleted temporary file: {pdf_path}")
except FileNotFoundError:
print(f"File not found: {pdf_path}")
except PermissionError:
print(f"Permission denied: Unable to delete '{pdf_path}'.")
except Exception as e:
print(f"An error occurred while deleting '{pdf_path}': {e}")
temp_file = temp_dir + "RP2040-Decoder_temp.pdf"
try:
os.remove(temp_file) # Attempt to delete the final temporary file
print(f"Deleted temporary file: {temp_file}")
except FileNotFoundError:
print(f"File not found: {temp_file}")
except PermissionError:
print(f"Permission denied: Unable to delete '{temp_file}'.")
except Exception as e:
print(f"An error occurred while deleting '{temp_file}': {e}")
try:
os.rmdir(temp_dir)
print(f"Directory '{temp_dir}' deleted successfully.")
except FileNotFoundError:
print(f"Directory '{temp_dir}' does not exist.")
except OSError:
print(f"Directory '{temp_dir}' is not empty or cannot be removed.")
except PermissionError:
print(f"Permission denied: Unable to delete '{temp_dir}'.")
except Exception as e:
print(f"An error occurred: {e}")
+48
View File
@@ -0,0 +1,48 @@
def print_speed_steps():
"""
This script generates and prints speed step definitions for both reverse and forward directions.
Functions:
print_speed_steps(): Generates and prints speed step definitions in hexadecimal and binary formats used in shared.h.
- Reverse speed steps range from 0x00 to 0x7F.
- Forward speed steps range from 0x80 to 0xFF.
* in NMRA Standard 9.2.1 section 2.3.2.1 or RCN-212 section 2.2.2.
*
* The following speed steps are defined:
*
* | DEC | BIN | DIRECTION | DEFINITION |
* |-----|-----------|-----------|----------------------|
* | 000 | 0000 0000 | Reverse | STOP |
* | 001 | 0000 0001 | Reverse | EMERGENCY STOP |
* | 002 | 0000 0010 | Reverse | Speed step 001 |
* | 003 | 0000 0011 | Reverse | Speed step 002 |
* | 004 | 0000 0100 | Reverse | Speed step 003 |
* | ... | .... .... | Reverse | ... |
* | 126 | 0111 1110 | Reverse | Speed step 125 |
* | 127 | 0111 1111 | Reverse | Speed step 126 |
* | 128 | 1000 0000 | Forward | STOP |
* | 129 | 1000 0001 | Forward | EMERGENCY STOP |
* | 130 | 1000 0010 | Forward | Speed step 001 |
* | 131 | 1000 0011 | Forward | Speed step 002 |
* | 132 | 1000 0100 | Forward | Speed step 003 |
* | ... | .... .... | Forward | ... |
* | 254 | 1111 1110 | Forward | Speed step 125 |
* | 255 | 1111 1111 | Forward | Speed step 126 |
"""
# Reverse speed steps
print(f"SPEED_STEP_REVERSE_STOP = 0x{0:02X}, // {0:08b}bin {0:03d}dec")
print(f"SPEED_STEP_REVERSE_EMERGENCY_STOP = 0x{1:02X}, // {1:08b}bin {1:03d}dec")
for i in range(1, 127):
print(f"SPEED_STEP_REVERSE_{i:03d} = 0x{i+1:02X}, // {i+1:08b}bin {i+1:03d}dec")
print("\n\n")
# Forward speed steps
print(f"SPEED_STEP_FORWARD_STOP = 0x{128:02X}, // {128:08b}bin {128:03d}dec")
print(f"SPEED_STEP_FORWARD_EMERGENCY_STOP = 0x{129:02X}, // {129:08b}bin {129:03d}dec")
for i in range(1, 127):
print(f"SPEED_STEP_FORWARD_{i:03d} = 0x{i+129:02X}, // {i+129:08b}bin {i+129:03d}dec")
# Call the function
print_speed_steps()
+220
View File
@@ -0,0 +1,220 @@
{
"3d_viewer": {
"background_bottom": "rgb(102, 102, 128)",
"background_top": "rgb(204, 204, 230)",
"board": "rgba(51, 43, 23, 0.902)",
"copper": "rgb(179, 156, 0)",
"silkscreen_bottom": "rgb(230, 230, 230)",
"silkscreen_top": "rgb(230, 230, 230)",
"soldermask_bottom": "rgba(20, 51, 36, 0.831)",
"soldermask_top": "rgba(20, 51, 36, 0.831)",
"solderpaste": "rgb(128, 128, 128)"
},
"board": {
"anchor": "rgb(255, 38, 226)",
"aux_items": "rgb(255, 255, 255)",
"b_adhes": "rgb(0, 0, 132)",
"b_crtyd": "rgb(38, 233, 255)",
"b_fab": "rgb(88, 93, 132)",
"b_mask": "rgba(2, 255, 238, 0.400)",
"b_paste": "rgba(0, 194, 194, 0.902)",
"b_silks": "rgb(232, 178, 167)",
"background": "rgb(0, 16, 35)",
"cmts_user": "rgb(89, 148, 220)",
"conflicts_shadow": "rgba(255, 0, 5, 0.502)",
"copper": {
"b": "rgb(77, 127, 196)",
"f": "rgb(200, 52, 52)",
"in1": "rgb(127, 200, 127)",
"in10": "rgb(237, 124, 51)",
"in11": "rgb(91, 195, 235)",
"in12": "rgb(247, 111, 142)",
"in13": "rgb(167, 165, 198)",
"in14": "rgb(40, 204, 217)",
"in15": "rgb(232, 178, 167)",
"in16": "rgb(242, 237, 161)",
"in17": "rgb(237, 124, 51)",
"in18": "rgb(91, 195, 235)",
"in19": "rgb(247, 111, 142)",
"in2": "rgb(206, 125, 44)",
"in20": "rgb(167, 165, 198)",
"in21": "rgb(40, 204, 217)",
"in22": "rgb(232, 178, 167)",
"in23": "rgb(242, 237, 161)",
"in24": "rgb(237, 124, 51)",
"in25": "rgb(91, 195, 235)",
"in26": "rgb(247, 111, 142)",
"in27": "rgb(167, 165, 198)",
"in28": "rgb(40, 204, 217)",
"in29": "rgb(232, 178, 167)",
"in3": "rgb(79, 203, 203)",
"in30": "rgb(242, 237, 161)",
"in4": "rgb(219, 98, 139)",
"in5": "rgb(167, 165, 198)",
"in6": "rgb(40, 204, 217)",
"in7": "rgb(232, 178, 167)",
"in8": "rgb(242, 237, 161)",
"in9": "rgb(141, 203, 129)"
},
"cursor": "rgb(255, 255, 255)",
"drc_error": "rgba(215, 91, 107, 0.800)",
"drc_exclusion": "rgba(255, 255, 255, 0.800)",
"drc_warning": "rgba(255, 208, 66, 0.800)",
"dwgs_user": "rgb(194, 194, 194)",
"eco1_user": "rgb(180, 219, 210)",
"eco2_user": "rgb(216, 200, 82)",
"edge_cuts": "rgb(208, 210, 205)",
"f_adhes": "rgb(132, 0, 132)",
"f_crtyd": "rgb(255, 38, 226)",
"f_fab": "rgb(175, 175, 175)",
"f_mask": "rgba(216, 100, 255, 0.400)",
"f_paste": "rgba(180, 160, 154, 0.902)",
"f_silks": "rgb(242, 237, 161)",
"footprint_text_invisible": "rgb(132, 132, 132)",
"grid": "rgb(132, 132, 132)",
"grid_axes": "rgb(194, 194, 194)",
"locked_shadow": "rgba(255, 38, 226, 0.502)",
"margin": "rgb(255, 38, 226)",
"pad_plated_hole": "rgb(194, 194, 0)",
"pad_through_hole": "rgb(227, 183, 46)",
"page_limits": "rgb(132, 132, 132)",
"plated_hole": "rgb(26, 196, 210)",
"ratsnest": "rgba(0, 248, 255, 0.349)",
"user_1": "rgb(194, 194, 194)",
"user_2": "rgb(89, 148, 220)",
"user_3": "rgb(180, 219, 210)",
"user_4": "rgb(216, 200, 82)",
"user_5": "rgb(194, 194, 194)",
"user_6": "rgb(89, 148, 220)",
"user_7": "rgb(180, 219, 210)",
"user_8": "rgb(216, 200, 82)",
"user_9": "rgb(232, 178, 167)",
"via_blind_buried": "rgb(187, 151, 38)",
"via_hole": "rgb(227, 183, 46)",
"via_micro": "rgb(0, 132, 132)",
"via_through": "rgb(236, 236, 236)",
"worksheet": "rgb(200, 114, 171)"
},
"gerbview": {
"axes": "rgb(0, 0, 132)",
"background": "rgb(0, 0, 0)",
"dcodes": "rgb(255, 255, 255)",
"grid": "rgb(132, 132, 132)",
"layers": [
"rgb(200, 52, 52)",
"rgb(127, 200, 127)",
"rgb(206, 125, 44)",
"rgb(79, 203, 203)",
"rgb(219, 98, 139)",
"rgb(167, 165, 198)",
"rgb(40, 204, 217)",
"rgb(232, 178, 167)",
"rgb(242, 237, 161)",
"rgb(141, 203, 129)",
"rgb(237, 124, 51)",
"rgb(91, 195, 235)",
"rgb(247, 111, 142)",
"rgb(77, 127, 196)",
"rgb(200, 52, 52)",
"rgb(127, 200, 127)",
"rgb(206, 125, 44)",
"rgb(79, 203, 203)",
"rgb(219, 98, 139)",
"rgb(167, 165, 198)",
"rgb(40, 204, 217)",
"rgb(232, 178, 167)",
"rgb(242, 237, 161)",
"rgb(141, 203, 129)",
"rgb(237, 124, 51)",
"rgb(91, 195, 235)",
"rgb(247, 111, 142)",
"rgb(77, 127, 196)",
"rgb(200, 52, 52)",
"rgb(127, 200, 127)",
"rgb(206, 125, 44)",
"rgb(79, 203, 203)",
"rgb(219, 98, 139)",
"rgb(167, 165, 198)",
"rgb(40, 204, 217)",
"rgb(232, 178, 167)",
"rgb(242, 237, 161)",
"rgb(141, 203, 129)",
"rgb(237, 124, 51)",
"rgb(91, 195, 235)",
"rgb(247, 111, 142)",
"rgb(77, 127, 196)",
"rgb(200, 52, 52)",
"rgb(127, 200, 127)",
"rgb(206, 125, 44)",
"rgb(79, 203, 203)",
"rgb(219, 98, 139)",
"rgb(167, 165, 198)",
"rgb(40, 204, 217)",
"rgb(232, 178, 167)",
"rgb(242, 237, 161)",
"rgb(141, 203, 129)",
"rgb(237, 124, 51)",
"rgb(91, 195, 235)",
"rgb(247, 111, 142)",
"rgb(77, 127, 196)",
"rgb(200, 52, 52)",
"rgb(127, 200, 127)",
"rgb(206, 125, 44)",
"rgb(79, 203, 203)"
],
"negative_objects": "rgb(132, 132, 132)",
"page_limits": "rgb(132, 132, 132)",
"worksheet": "rgb(0, 0, 132)"
},
"meta": {
"name": "schematic_theme",
"version": 5
},
"schematic": {
"anchor": "rgb(0, 0, 255)",
"aux_items": "rgb(0, 0, 0)",
"background": "rgb(245, 244, 239)",
"brightened": "rgb(255, 0, 255)",
"bus": "rgb(0, 0, 132)",
"bus_junction": "rgb(0, 0, 132)",
"component_body": "rgb(255, 255, 194)",
"component_outline": "rgb(132, 0, 0)",
"cursor": "rgb(15, 15, 15)",
"dnp_marker": "rgba(220, 9, 13, 0.702)",
"erc_error": "rgba(230, 9, 13, 0.800)",
"erc_exclusion": "rgba(94, 194, 194, 0.800)",
"erc_warning": "rgba(209, 146, 0, 0.800)",
"fields": "rgb(132, 0, 132)",
"grid": "rgb(181, 181, 181)",
"grid_axes": "rgb(0, 0, 132)",
"hidden": "rgb(94, 194, 194)",
"hovered": "rgb(0, 0, 255)",
"junction": "rgb(0, 150, 0)",
"label_global": "rgb(132, 0, 0)",
"label_hier": "rgb(114, 86, 0)",
"label_local": "rgb(0, 107, 255)",
"netclass_flag": "rgb(72, 72, 72)",
"no_connect": "rgb(0, 0, 132)",
"note": "rgb(205, 0, 21)",
"note_background": "rgba(0, 0, 0, 0.000)",
"op_currents": "rgb(224, 0, 12)",
"op_voltages": "rgb(132, 0, 50)",
"override_item_colors": false,
"page_limits": "rgb(181, 181, 181)",
"pin": "rgb(132, 0, 0)",
"pin_name": "rgb(0, 100, 100)",
"pin_number": "rgb(169, 0, 0)",
"private_note": "rgb(72, 72, 255)",
"reference": "rgb(0, 100, 100)",
"shadow": "rgba(102, 179, 255, 0.800)",
"sheet": "rgb(132, 0, 0)",
"sheet_background": "rgba(255, 255, 255, 0.000)",
"sheet_fields": "rgb(132, 0, 132)",
"sheet_filename": "rgb(114, 86, 0)",
"sheet_label": "rgb(0, 100, 100)",
"sheet_name": "rgb(0, 100, 100)",
"value": "rgb(0, 100, 100)",
"wire": "rgb(0, 150, 0)",
"worksheet": "rgb(132, 0, 0)"
}
}
+46
View File
@@ -0,0 +1,46 @@
import re
import argparse
def set_opacity(input_file, output_file):
"""
Replace all occurrences of 'fill-opacity:1' with 'fill-opacity:0',
except when preceded by 'fill:#ffffc2'.
:param input_file: Path to the input SVG file.
:param output_file: Path to save the modified SVG file.
"""
try:
# Read the content of the input SVG file
with open(input_file, 'r') as file:
svg_content = file.read()
# Regex to match 'fill-opacity:1' and not preceded by 'fill:#ffffc2'
pattern = r'(?<!fill:#ffffc2;)fill-opacity:1'
modified_content = re.sub(pattern, 'fill-opacity:0', svg_content)
# Save the modified content to the output file
with open(output_file, 'w') as file:
file.write(modified_content)
print(f"Modified SVG saved as: {output_file}")
except Exception as e:
print(f"An error occurred: {e}")
def main():
# Set up the argument parser
parser = argparse.ArgumentParser(
description="Modify SVG files by replacing 'fill-opacity:1' with 'fill-opacity:0', "
"except when preceded by 'fill:#ffffc2'."
)
parser.add_argument('input_file', type=str, help="Path to the input SVG file.")
parser.add_argument('output_file', type=str, help="Path to save the modified SVG file.")
# Parse the arguments
args = parser.parse_args()
# Call the function with the provided file paths
set_opacity(args.input_file, args.output_file)
if __name__ == "__main__":
main()
-63
View File
@@ -1,63 +0,0 @@
//////////////////////////
// RP2040-Decoder //
// Gabriel Koppenstein //
// shared.c //
//////////////////////////
#include "shared.h"
// Functions in shared.c can be accessed by both cores
// Measures Back-EMF voltage (proportional to the rotational speed of the motor) on GPIO 28 and GPIO 29 respectively (depending on direction)
float measure(uint8_t total_iterations,
uint8_t measurement_delay_us,
uint8_t l_side_arr_cutoff,
uint8_t r_side_arr_cutoff,
bool direction){
uint32_t sum = 0;
uint16_t adc_val[total_iterations];
int32_t j = 0;
uint16_t key;
pwm_set_gpio_level(MOTOR_FWD_PIN, 0);
pwm_set_gpio_level(MOTOR_REV_PIN, 0);
adc_select_input((!direction)+2);
busy_wait_us(measurement_delay_us);
adc_run(true);
for (int32_t i = 0; i < total_iterations; ++i) {
//Take adc value out of fifo when available, then do one step of insertion sort.
adc_val[i] = adc_fifo_get_blocking();
key = adc_val[i];
j = i - 1;
while (j >= 0 && adc_val[j] > key) {
adc_val[j + 1] = adc_val[j];
j--;
}
adc_val[j + 1] = key;
}
adc_run(false);
//discard x entries beginning from the lowest entry of the array (counting up); x = msr.l_side_arr_cutoff
//discard y entries beginning from the highest index of the array (counting down); y = msr.r_side_arr_cutoff
for (int32_t i = l_side_arr_cutoff; i < total_iterations - r_side_arr_cutoff ; ++i) {
sum += adc_val[i];
}
float res = (float)sum / (float)( total_iterations - (l_side_arr_cutoff + r_side_arr_cutoff) );
// return true to keep the repeating timer active
return res;
}
// retrieve 4Bytes from CV_ARRAY_FLASH at once and return 32-Bit value
uint32_t get_32bit_CV (uint16_t CV_start_index){
uint8_t byte_3 = CV_ARRAY_FLASH[CV_start_index];
uint8_t byte_2 = CV_ARRAY_FLASH[CV_start_index+1];
uint8_t byte_1 = CV_ARRAY_FLASH[CV_start_index+2];
uint8_t byte_0 = CV_ARRAY_FLASH[CV_start_index+3];
return (byte_0) + (byte_1<<8) + (byte_2<<16) + (byte_3<<24);
}
// retrieve 2Bytes from CV_ARRAY_FLASH at once and return 16-Bit value
uint16_t get_16bit_CV (uint16_t CV_start_index){
uint8_t byte_1 = CV_ARRAY_FLASH[CV_start_index];
uint8_t byte_0 = CV_ARRAY_FLASH[CV_start_index+1];
return (byte_0) + (byte_1<<8);
}
-49
View File
@@ -1,49 +0,0 @@
//////////////////////////
// RP2040-Decoder //
// Gabriel Koppenstein //
// shared.h //
//////////////////////////
#pragma once
#include "string.h"
#include "pico/float.h"
#include "pico/stdlib.h"
#include "pico/multicore.h"
#include "pico/printf.h"
#include "hardware/pwm.h"
#include "hardware/adc.h"
#include "hardware/flash.h"
#include "hardware/irq.h"
// Constant Value of 125 x 10⁶
#define _125M 125000000
// GPIO used for DCC-Signal, Motor PWM or ADC
#define DCC_INPUT_PIN 21u
#define MOTOR_FWD_PIN 23u
#define MOTOR_REV_PIN 22u
#define FWD_V_EMF_ADC_PIN 28u
#define REV_V_EMF_ADC_PIN 29u
// GPIO used directly (GPIO 0-5 incl.) as outputs or to switch auxiliary output transistors (GPIO 24-27 incl.)
#define GPIO_OUTPUT_PIN_MASK (1u<<24) | (1u<<25) | (1u<<26) | (1u<<27) | (1u<<5) | (1u<<4) | (1u<<3) | (1u<<2) | (1u<<1) | (1u<<0)
// GPIO pin mask to prevent setting illegal GPIOs (ADC, Motor, DCC Input Pin)
#define GPIO_ILLEGAL_MASK (1u<<DCC_INPUT_PIN) | (1u<<MOTOR_FWD_PIN) | (1u<<MOTOR_REV_PIN) | (1u<<FWD_V_EMF_ADC_PIN) | (1u<<REV_V_EMF_ADC_PIN)
// GPIO pin mask with allowed outputs (AUX & GPIO (configured as outputs))
#define GPIO_ALLOWED_OUTPUTS (GPIO_OUTPUT_PIN_MASK) & ~(GPIO_ILLEGAL_MASK)
// Offset from base address used for saving CV_ARRAY_FLASH
#define FLASH_TARGET_OFFSET (PICO_FLASH_SIZE_BYTES-FLASH_SECTOR_SIZE)
extern repeating_timer_t pid_control_timer;
extern repeating_timer_t speed_helper_timer;
extern const uint8_t *CV_ARRAY_FLASH;
void core1_entry();
float measure(uint8_t total_iterations,
uint8_t measurement_delay_us,
uint8_t l_side_arr_cutoff,
uint8_t r_side_arr_cutoff,
bool direction);
uint32_t get_32bit_CV (uint16_t CV_start_index);
uint16_t get_16bit_CV (uint16_t CV_start_index);