Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
91e10e16b6 | ||
|
|
332275ec07 | ||
|
|
a2b1233c4e | ||
|
|
93455218e8 | ||
|
|
cc48cca779 | ||
|
|
185c703bc0 | ||
|
|
5a00f5af2c | ||
|
|
a2f30d0654 | ||
|
|
87e4aff24f | ||
|
|
8c34f55877 | ||
|
|
e215212025 | ||
|
|
86df810a49 | ||
|
|
0d0c182ba4 | ||
|
|
1c7b833c63 | ||
|
|
2442853c45 | ||
|
|
0b71d556f8 | ||
|
|
a3d63f2d53 | ||
|
|
73e88a86bb | ||
|
|
de77d8465f | ||
|
|
e4d352fe0e | ||
|
|
20736ad7f0 | ||
|
|
8fdce91e64 | ||
|
|
7ab22c439d | ||
|
|
501d9470f3 | ||
|
|
509466c61a | ||
|
|
7befd2cdaf | ||
|
|
0ceb24a79f | ||
|
|
56c7b394dd | ||
|
|
454889162b | ||
|
|
ed98553e49 | ||
|
|
11b9a62142 | ||
|
|
5752f277e2 | ||
|
|
5e72e8538b | ||
|
|
d333dffdb4 | ||
|
|
82ce5e24aa | ||
|
|
f2b944b6c9 | ||
|
|
390dd32671 | ||
|
|
1d08f5a88f | ||
|
|
4096171fb4 | ||
|
|
a93617de60 | ||
|
|
738575263f | ||
|
|
50290e059d | ||
|
|
d0e7406627 | ||
|
|
be49c1b43f | ||
|
|
21bee73f01 | ||
|
|
ad888dd4a0 | ||
|
|
17c67b5ba8 | ||
|
|
a573e36d2f | ||
|
|
7ab3f74cba | ||
|
|
a7531be0e6 | ||
|
|
91eb160833 | ||
|
|
d17660f018 | ||
|
|
e648e5dfa2 | ||
|
|
0368a22ce7 | ||
|
|
7e1c079e10 | ||
|
|
f1961fa5bd | ||
|
|
521c8e6b7b | ||
|
|
0462d3f6b7 | ||
|
|
97b92fd9d8 | ||
|
|
d970170795 | ||
|
|
acdbf3cffe | ||
|
|
7d2c80574a | ||
|
|
f8b99de801 | ||
|
|
7b1d5ed152 | ||
|
|
e8a8ac6d98 | ||
|
|
bce1405a60 | ||
|
|
fa3791c781 | ||
|
|
a0d775f081 | ||
|
|
ab2a7e17ea | ||
|
|
5b25cd2f7a | ||
|
|
6863502e22 | ||
|
|
01bac1ba00 | ||
|
|
5ca892610e | ||
|
|
fb165f6e08 | ||
|
|
251d71e73f | ||
|
|
c0f61511ce | ||
|
|
72bd29ddbc | ||
|
|
fad8b68e01 | ||
|
|
12b45b9da3 | ||
|
|
3f7f092b2c | ||
|
|
cf79990b51 | ||
|
|
70846f5336 | ||
|
|
babe18c758 | ||
|
|
d05bd6ef33 | ||
|
|
b7a5aa8960 | ||
|
|
5c3525c82e | ||
|
|
304e7f3faa | ||
|
|
8b37c6ead4 | ||
|
|
a099ef67ed | ||
|
|
0c225ee7f0 | ||
|
|
f8fcd77449 | ||
|
|
cb6669992f | ||
|
|
c65afef54f | ||
|
|
d862355199 | ||
|
|
7779207858 | ||
|
|
0736054a49 | ||
|
|
b765f80048 | ||
|
|
cc81e4ed4c | ||
|
|
5d82d0c3f7 | ||
|
|
42d6fe3ef6 | ||
|
|
6d04cfb8b3 | ||
|
|
a83f53d3d8 | ||
|
|
fc8653ad74 | ||
|
|
c6ee7b2564 | ||
|
|
0380b398fc | ||
|
|
201d521be8 | ||
|
|
dc53d98fda | ||
|
|
a9c3c60b81 | ||
|
|
78187ec19f | ||
|
|
9240e5b1a7 | ||
|
|
d417235df5 | ||
|
|
c1564feb4b | ||
|
|
f3ffb73b62 | ||
|
|
577bc5dd5c | ||
|
|
9b8906f476 | ||
|
|
baf9ea6081 | ||
|
|
1810541e48 | ||
|
|
b5b5de89dd | ||
|
|
3ef7fb99c7 | ||
|
|
461f65c88d | ||
|
|
7f870bcf71 | ||
|
|
38ec9bf60d | ||
|
|
f529859eff | ||
|
|
e0c0424f87 | ||
|
|
8fb10e212e | ||
|
|
9ee13b67e7 | ||
|
|
df9b0ba633 | ||
|
|
df009a5430 | ||
|
|
0ca6f2ca13 | ||
|
|
3f27046838 | ||
|
|
5f0b51b043 | ||
|
|
02e1fdf156 | ||
|
|
5ae65b301d | ||
|
|
78123663ce | ||
|
|
d7f4621b96 | ||
|
|
3364793a6f | ||
|
|
6df051019d | ||
|
|
9cf7301af7 | ||
|
|
5ec8f953b4 | ||
|
|
52ec79105d | ||
|
|
4b125c3488 | ||
|
|
12e54994a8 | ||
|
|
c8b75ee71f | ||
|
|
27d68d3d24 | ||
|
|
626e20fa5f | ||
|
|
992d6ae800 | ||
|
|
721e5d5a65 | ||
|
|
f28e594051 | ||
|
|
4c1be24278 | ||
|
|
1ce384943e | ||
|
|
07b792ac13 | ||
|
|
f0a23c208e |
No files matched your search
@@ -0,0 +1,42 @@
|
||||
name: Build Software
|
||||
|
||||
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:
|
||||
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
|
||||
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
|
||||
run: cmake --build ${{github.workspace}}/Software/build-Rev-0_3 --config ${{env.BUILD_TYPE}}
|
||||
|
||||
- name: Configure and run CMake for Hardware Rev 1.0
|
||||
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
|
||||
run: cmake --build ${{github.workspace}}/Software/build-Rev-1_0 --config ${{env.BUILD_TYPE}}
|
||||
@@ -0,0 +1,77 @@
|
||||
name: Generate documentation doxygen/breathe/sphinx and deploy on gh-pages/gh-pages-dev
|
||||
|
||||
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
|
||||
@@ -0,0 +1,111 @@
|
||||
name: Render PCB images and rotating mp4
|
||||
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-images:
|
||||
name: render-images
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out the repo
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Render PCB image and .mp4 (Rev 1.0)
|
||||
uses: linalinn/kicad-render@main
|
||||
with:
|
||||
pcb_file: KiCad/Rev_1_0/RP2040-Decoder.kicad_pcb
|
||||
output_path: ${{ github.workspace }}/images_rev_1_0
|
||||
animation: mp4
|
||||
|
||||
- name: Render PCB image and .mp4 (Rev 0.3)
|
||||
uses: linalinn/kicad-render@main
|
||||
with:
|
||||
pcb_file: KiCad/Rev_0_3/RP2040-Decoder.kicad_pcb
|
||||
output_path: ${{ github.workspace }}/images_rev_0_3
|
||||
animation: mp4
|
||||
|
||||
- name: Upload images and mp4 as artifact (Rev 1.0)
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: pcb-images_rev_1_0
|
||||
path: images_rev_1_0/
|
||||
|
||||
- name: Upload images and mp4 as artifact (Rev 0.3)
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: pcb-images_rev_0_3
|
||||
path: images_rev_0_3/
|
||||
|
||||
deploy-pages-main:
|
||||
if: github.ref == 'refs/heads/main' # Only deploy on 'main' branch
|
||||
runs-on: ubuntu-latest
|
||||
needs: render-images
|
||||
|
||||
steps:
|
||||
- name: Download pcb-images_rev_1_0 artifact
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: pcb-images_rev_1_0
|
||||
path: images_rev_1_0/
|
||||
|
||||
- name: Download pcb-images_rev_0_3 artifact
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: pcb-images_rev_0_3
|
||||
path: images_rev_0_3/
|
||||
|
||||
- name: Deploy
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: ./images_rev_1_0
|
||||
publish_branch: gh-pages # Specify the target branch (gh-pages in this case)
|
||||
destination_dir: img_rev_1_0
|
||||
|
||||
- name: Deploy
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: ./images_rev_0_3
|
||||
publish_branch: gh-pages # Specify the target branch (gh-pages in this case)
|
||||
destination_dir: img_rev_0_3
|
||||
|
||||
deploy-pages-dev:
|
||||
if: github.ref == 'refs/heads/dev' # Only deploy on 'dev' branch
|
||||
runs-on: ubuntu-latest
|
||||
needs: render-images
|
||||
|
||||
steps:
|
||||
- name: Download pcb-images_rev_1_0 artifact
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: pcb-images_rev_1_0
|
||||
path: images_rev_1_0/
|
||||
|
||||
- name: Download pcb-images_rev_0_3 artifact
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: pcb-images_rev_0_3
|
||||
path: images_rev_0_3/
|
||||
|
||||
- name: Deploy Rev 1.0
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: ./images_rev_1_0
|
||||
publish_branch: gh-pages-dev # Specify the target branch (gh-pages-dev in this case)
|
||||
destination_dir: img_rev_1_0
|
||||
|
||||
- name: Deploy Rev 0.3
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: ./images_rev_0_3
|
||||
publish_branch: gh-pages-dev # Specify the target branch (gh-pages-dev in this case)
|
||||
destination_dir: img_rev_0_3
|
||||
@@ -0,0 +1,131 @@
|
||||
name: Build Software and create prerelease 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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -1,53 +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
|
||||
)
|
||||
|
||||
# disable usb stack
|
||||
pico_enable_stdio_usb(RP2040-Decoder 0)
|
||||
|
||||
# disable uart output (to enable put a 1 instead of the 0)
|
||||
pico_enable_stdio_uart(RP2040-Decoder 0)
|
||||
|
||||
# create map/bin/hex file etc.
|
||||
#pico_add_extra_outputs(RP2040-Decoder)
|
||||
@@ -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
|
||||
},
|
||||
@@ -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))
|
||||
)
|
||||
)
|
||||
@@ -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": {}
|
||||
}
|
||||
@@ -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)
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,3 @@
|
||||
(fp_lib_table
|
||||
(lib (name "RP2040-Decoder_Additional_Footprints")(type "KiCad")(uri "${KIPRJMOD}")(options "")(descr ""))
|
||||
)
|
||||
@@ -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 ""))
|
||||
)
|
||||
@@ -8,11 +8,13 @@ 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
|
||||
------------
|
||||
@@ -25,18 +27,19 @@ 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>
|
||||
<div style="display: flex; justify-content: space-between; align-items: center;">
|
||||
<img src="https://raw.githubusercontent.com/gab-k/RP2040-Decoder/refs/heads/gh-pages-dev/img/top.png" alt="Image 1" style="width: 50%;"/>
|
||||
<img src="https://raw.githubusercontent.com/gab-k/RP2040-Decoder/refs/heads/gh-pages-dev/img/bottom.png" alt="Image 2" style="width: 50%;"/>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
build
|
||||
@@ -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 0)
|
||||
# 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 0)
|
||||
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
|
||||
)
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -0,0 +1,818 @@
|
||||
//////////////////////////
|
||||
// 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();
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,426 @@
|
||||
/*!
|
||||
*
|
||||
* \file core0.h
|
||||
* Used exclusively by core0
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "shared.h"
|
||||
#include "CV.h"
|
||||
|
||||
/**
|
||||
* @def MESSAGE_3_BYTES
|
||||
* @brief Comparison bitmask for detecting 3 byte long DCC messages/packets
|
||||
*/
|
||||
#define MESSAGE_3_BYTES 0b11111111110000000000000000000000000001
|
||||
/**
|
||||
* @def MESSAGE_MASK_3_BYTES
|
||||
* @brief Bitmask for detecting 3 byte long DCC messages/packets, input_bit_buffer is bitwise ANDed with the mask
|
||||
*/
|
||||
#define MESSAGE_MASK_3_BYTES 0b11111111111000000001000000001000000001
|
||||
/**
|
||||
* @def MESSAGE_4_BYTES
|
||||
* @brief Comparison bitmask for detecting 4 byte long DCC messages/packets
|
||||
*/
|
||||
#define MESSAGE_4_BYTES 0b11111111110000000000000000000000000000000000001
|
||||
/**
|
||||
* @def MESSAGE_MASK_4_BYTES
|
||||
* @brief Bitmask for detecting 4 byte long DCC messages/packets, input_bit_buffer is bitwise ANDed with the mask
|
||||
*/
|
||||
#define MESSAGE_MASK_4_BYTES 0b11111111111000000001000000001000000001000000001
|
||||
/**
|
||||
* @def MESSAGE_5_BYTES
|
||||
* @brief Comparison bitmask for detecting 5 byte long DCC messages/packets
|
||||
*/
|
||||
#define MESSAGE_5_BYTES 0b11111111110000000000000000000000000000000000000000000001
|
||||
/**
|
||||
* @def MESSAGE_MASK_5_BYTES
|
||||
* @brief Bitmask for detecting 5 byte long DCC messages/packets, input_bit_buffer is bitwise ANDed with the mask
|
||||
*/
|
||||
#define MESSAGE_MASK_5_BYTES 0b11111111111000000001000000001000000001000000001000000001
|
||||
|
||||
/**
|
||||
* @def INVALID_PACKAGE
|
||||
* @brief Return value of detect_dcc_packet() when the packet is invalid, meaning no packet was detected
|
||||
*/
|
||||
#define INVALID_PACKAGE SIZE_MAX
|
||||
|
||||
/**
|
||||
* @def RING_BUFFER_PACKETS
|
||||
* @brief First dimension of dcc ring buffer array - meaning RING_BUFFER_PACKETS can be retained inside the buffer
|
||||
*/
|
||||
#define RING_BUFFER_PACKETS 8
|
||||
/**
|
||||
* @def RING_BUFFER_BYTES
|
||||
* @brief Secoond dimension of dcc ring buffer array - meaning each packet can have a maximum size of RING_BUFFER_BYTES
|
||||
*/
|
||||
#define RING_BUFFER_BYTES 5
|
||||
|
||||
/**
|
||||
* @def FLASH_CMD_READ_JEDEC_ID
|
||||
* @brief Constant value of 0x9F used as a JEDEC ID read command for reading the JEDEC ID of a winbond flash memory chip
|
||||
*/
|
||||
#define FLASH_CMD_READ_JEDEC_ID 0x9F
|
||||
/**
|
||||
* @def FLASH_TIMEOUT_IN_MS
|
||||
* @brief Timeout value for flash access
|
||||
*/
|
||||
#define FLASH_TIMEOUT_IN_MS 500
|
||||
|
||||
/**
|
||||
* @def ADC_CALIBRATION_ITERATIONS
|
||||
* @brief Iterations for measuring adc offset
|
||||
*/
|
||||
#define ADC_CALIBRATION_ITERATIONS 8192
|
||||
/**
|
||||
* @def WATCHDOG_TIMER_IN_MS
|
||||
* @brief Watchdog timer setting, watchdog update needs to be called every WATCHDOG_TIMER_IN_MS milliseconds, otherwise decoder resets itself.
|
||||
*/
|
||||
#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.
|
||||
*
|
||||
* @typedef dcc_packet_t
|
||||
* @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.
|
||||
*
|
||||
* @typedef dcc_ring_buffer_t
|
||||
* @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();
|
||||
@@ -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 < BASE_PWM_ARR_LEN) {
|
||||
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)%BASE_PWM_ARR_LEN;
|
||||
// Set ramp_up_mode flag to true
|
||||
ctrl_par->mode = PID_MODE;
|
||||
// Multiply with k_ff constant and set as current feed forward value
|
||||
ctrl_par->feed_fwd = ctrl_par->startup.k_ff * (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)
|
||||
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->measurement = 0.0f;
|
||||
ctrl_par->measurement_prev = 0.0f;
|
||||
ctrl_par->measurement_corrected = 0.0f;
|
||||
ctrl_par->setpoint = 0;
|
||||
ctrl_par->feed_fwd = 0;
|
||||
|
||||
// Startup controller variables
|
||||
ctrl_par->startup.level = 0;
|
||||
ctrl_par->startup.base_pwm_arr_i = 0;
|
||||
ctrl_par->startup.k_ff = (float) CV_ARRAY_FLASH[46]/255;
|
||||
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;
|
||||
|
||||
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);
|
||||
panic("Error calling flash_safe_execute_core_init() on core1!");
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
/*!
|
||||
*
|
||||
* \file core1.h
|
||||
* Used exclusively by core1
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared.h"
|
||||
|
||||
|
||||
/**
|
||||
* @def BASE_PWM_ARR_LEN
|
||||
* @brief The length of the base PWM array.
|
||||
*
|
||||
* This macro defines the length of the base PWM ring buffer array.
|
||||
*/
|
||||
#define BASE_PWM_ARR_LEN 16
|
||||
|
||||
/**
|
||||
* @brief Enumeration for controller operating modes.
|
||||
*
|
||||
* Defines the two controller operating modes.
|
||||
*
|
||||
* @enum controller_mode_t
|
||||
*/
|
||||
typedef enum {
|
||||
STARTUP_MODE, /**< Controller startup mode state */
|
||||
PID_MODE, /**< Controller pid mode state */
|
||||
} controller_mode_t;
|
||||
|
||||
/**
|
||||
* @brief Structure for startup controller parameters and variables.
|
||||
*
|
||||
* This structure defines the parameters and variables used in the startup
|
||||
* controller, including the latest PWM level, base pwm level ring buffer array and the respective ring buffer index.
|
||||
*
|
||||
* @typedef startup_parameters_t
|
||||
* @struct startup_parameters_t
|
||||
*/
|
||||
typedef struct startup_parameters_t {
|
||||
uint16_t level; /**< Latest level */
|
||||
uint16_t base_pwm_arr[BASE_PWM_ARR_LEN]; /**< base pwm ring buffer array */
|
||||
uint16_t base_pwm_arr_i; /**< base pwm ring buffer array index */
|
||||
float k_ff; /**< Feed forward factor */
|
||||
}startup_parameters_t;
|
||||
|
||||
/**
|
||||
* @brief Structure for PID controller parameters and variables.
|
||||
*
|
||||
* This structure defines the parameters and variables used in the PID
|
||||
* controller, including gains, error tracking, integrator limits, ...
|
||||
*
|
||||
* @typedef pid_parameters_t
|
||||
* @struct pid_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 - See gain scheduling documentation for more details
|
||||
float k_p_x_1_shift; /**< Effectively defines where x1 is shifted from 0% of max setpoint to 100% of max setpoint */
|
||||
float k_p_x_1; /**< x1 */
|
||||
float k_p_x_2; /**< x2 */
|
||||
float k_p_y_0; /**< y0 = KP @ x0 */
|
||||
float k_p_y_1; /**< y1 = KP @ x1 */
|
||||
float k_p_y_2; /**< y2 = KP @ x2 */
|
||||
float k_p_m_1; /**< slope from (x0, y0) to (x1, y1) */
|
||||
float k_p_m_2; /**< slope from (x1, y1) to (x2, y2) */
|
||||
} pid_parameters_t;
|
||||
|
||||
/**
|
||||
* @brief Structure for various controller parameters.
|
||||
*
|
||||
* This structure defines the highest level general controller parameters, including
|
||||
* General settings (setpoint, mode), startup controller settings struct, PID controller struct, and measurement data.
|
||||
*
|
||||
* @typedef controller_parameter_t
|
||||
* @struct controller_parameter_t
|
||||
*/
|
||||
typedef struct controller_parameter_t{
|
||||
// General controller parameters
|
||||
controller_mode_t mode; /**< Current controller mode */
|
||||
float feed_fwd; /**< Current feed forward value set by startup controller */
|
||||
uint32_t setpoint; /**< Current setpoint */
|
||||
uint16_t speed_table[127]; /**< Array with setpoint values corresponding to every speed step */
|
||||
// Startup controller parameters
|
||||
startup_parameters_t startup; /**< Struct for startup controller specific variables */
|
||||
// PID controller parameters
|
||||
pid_parameters_t pid; /**< Struct for PID controller specific variables */
|
||||
// Measurement variables
|
||||
float measurement; /**< Latest measurement value */
|
||||
float measurement_prev; /**< Previous measurement value */
|
||||
float measurement_corrected; /**< Corrected measurement value (measurement - adc_offset = measurement_corrected) */
|
||||
float adc_offset; /**< ADC offset value */
|
||||
uint8_t msr_delay_in_us; /**< Delay before V_EMF is measured */
|
||||
uint8_t msr_total_iterations; /**< Amount of samples */
|
||||
uint8_t l_side_arr_cutoff; /**< Discarded outlier samples (left side) */
|
||||
uint8_t r_side_arr_cutoff; /**< Discarded outlier 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)
|
||||
@@ -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()
|
||||
@@ -0,0 +1,66 @@
|
||||
//////////////////////////
|
||||
// RP2040-Decoder //
|
||||
// Gabriel Koppenstein //
|
||||
// shared.c //
|
||||
//////////////////////////
|
||||
|
||||
#include "shared.h"
|
||||
|
||||
// TODO: Implement getter and setter functions for speed steps, 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;
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,480 @@
|
||||
/*!
|
||||
*
|
||||
* \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"
|
||||
|
||||
/**
|
||||
* @brief Logs a message with a specified log level.
|
||||
*
|
||||
* This macro logs a message if the specified log level is less than or equal to the global LOGLEVEL.
|
||||
* The log message includes the core number and the time since boot in milliseconds.
|
||||
*
|
||||
* @param level The log level of the message.
|
||||
* @param ... The format string and arguments for the log message.
|
||||
*/
|
||||
#define LOG(level, ...) { \
|
||||
if (level <= LOGLEVEL) { \
|
||||
printf("[core%u @ %u ms] ", get_core_num(), to_ms_since_boot(get_absolute_time())); \
|
||||
printf(__VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
|
||||
/**
|
||||
* @def _125M
|
||||
* @brief Constant value representing 125 million (125 x 10^6).
|
||||
*/
|
||||
#define _125M 125000000
|
||||
|
||||
/**
|
||||
* @enum error_t
|
||||
* @brief Enumeration of error codes used in the system.
|
||||
*
|
||||
* This enumeration defines various error codes that can be encountered
|
||||
* during the execution of the program. Each error code is represented
|
||||
* as a bit flag, allowing multiple errors to be combined using bitwise
|
||||
* operations.
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
FLASH_SAFE_EXECUTE_CORE_INIT_FAILURE = (1<<0), /**< Indicates a failure during the initialization of the flash safe execute mode. */
|
||||
FLASH_SAFE_EXECUTE_ERASE_FAILURE = (1<<1), /**< Indicates a failure during the erase operation in flash safe execute mode. */
|
||||
FLASH_SAFE_EXECUTE_PROGRAM_FAILURE = (1<<2), /**< Indicates a failure during the program operation in flash safe execute mode. */
|
||||
FLASH_SIZE_READBACK_FAILURE = (1<<3), /**< Indicates a failure in reading back the flash size. */
|
||||
STDIO_INIT_FAILURE = (1<<4), /**< Indicates a failure during the initialization of stdio. */
|
||||
REBOOT_BY_WATCHDOG = (1<<5), /**< Indicates that the system rebooted due to the watchdog timer. */
|
||||
INVALID_DIRECTION = (1<<6), /**< Indicates an invalid direction was specified. */
|
||||
} error_t;
|
||||
|
||||
|
||||
/**
|
||||
* @enum direction_t
|
||||
* @brief Enumeration for motor direction.
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
DIRECTION_FORWARD = 1, /**< Represents the forward direction */
|
||||
DIRECTION_REVERSE = 0, /**< Represents the reverse direction. */
|
||||
} direction_t;
|
||||
|
||||
/**
|
||||
* @brief Enum to define all speed steps.
|
||||
*
|
||||
*/
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Pointer to the uint8_t array in flash which stores the CVs.
|
||||
*/
|
||||
extern const uint8_t *CV_ARRAY_FLASH;
|
||||
|
||||
/**
|
||||
* @brief Target speed step for the decoder.
|
||||
*
|
||||
* This external variable represents the desired speed step that the decoder
|
||||
* should aim to achieve.
|
||||
*/
|
||||
extern speed_step_t speed_step_target;
|
||||
|
||||
/**
|
||||
* @brief Previous target speed step.
|
||||
*
|
||||
* This variable holds the previous target speed step value for the decoder.
|
||||
* It is used to keep track of the last speed step that was set.
|
||||
*/
|
||||
extern speed_step_t speed_step_target_prev;
|
||||
|
||||
/**
|
||||
* @brief Indicates whether the CV setup check has been completed.
|
||||
*
|
||||
* This flag is used to track the status of the CV setup check.
|
||||
* When the check is done, this variable should is set to true by core 0.
|
||||
*/
|
||||
extern bool cv_setup_check_done;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Indicates whether the core initialization for safe flash execution is complete.
|
||||
*
|
||||
* This flag is used to signal the completion of the flash safe execute core initialization.
|
||||
* When the initialization is done this variable is set to true by core 1.
|
||||
*/
|
||||
extern bool flash_safe_execute_core_init_done;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Global variable to hold the current error state.
|
||||
*
|
||||
* This variable is used to track the error state.
|
||||
*/
|
||||
extern error_t error_state;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Entry point for the second core (core 1).
|
||||
*
|
||||
* This function is the entry point for the second core, basically the main() of core1.
|
||||
*/
|
||||
void core1_entry();
|
||||
|
||||
/**
|
||||
* @brief Retrieves a 32-bit Configuration Variable (CV) starting from the specified index.
|
||||
*
|
||||
* This function reads and returns a 32-bit CV value from the given starting index.
|
||||
*
|
||||
* @param CV_start_index The starting index of the 32-bit CV to be retrieved.
|
||||
* @return The 32-bit CV value.
|
||||
*/
|
||||
uint32_t get_32bit_CV (uint16_t CV_start_index);
|
||||
|
||||
/**
|
||||
* @brief Retrieves a 16-bit Configuration Variable (CV) value starting from the specified index.
|
||||
*
|
||||
* This function reads and returns a 16-bit CV value from the given starting index.
|
||||
*
|
||||
* @param CV_start_index The starting index of the 16-bit CV to be retrieved.
|
||||
* @return The 16-bit CV value starting from the specified 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 |
|
||||
*
|
||||
* also see @ref speed_step_t for available steps.
|
||||
*
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* @brief Sets a specific error.
|
||||
*
|
||||
* This function sets a specific error to the error_state variable.
|
||||
*
|
||||
* @param err The error code to set.
|
||||
*/
|
||||
void set_error(error_t err);
|
||||
|
||||
/**
|
||||
* @brief Clears the specified error.
|
||||
*
|
||||
* This function resets the error state for the given error code.
|
||||
*
|
||||
* @param err The error code to be cleared.
|
||||
*/
|
||||
void clear_error(error_t err);
|
||||
|
||||
/**
|
||||
* @brief Clears all error flags or statuses in the system.
|
||||
*
|
||||
* Clears error_state variable
|
||||
*/
|
||||
void clear_all_errors();
|
||||
|
||||
/**
|
||||
* @brief Retrieves the current error state.
|
||||
*
|
||||
* This function returns the current error state of the system.
|
||||
*
|
||||
* @return error_t The current error state.
|
||||
*/
|
||||
error_t get_error_state();
|
||||
@@ -1,678 +0,0 @@
|
||||
//////////////////////////
|
||||
// RP2040-Decoder //
|
||||
// Gabriel Koppenstein //
|
||||
// core0.c //
|
||||
//////////////////////////
|
||||
|
||||
#include "core0.h"
|
||||
// XIP_BASE + FLASH_TARGET_OFFSET = "0x101FF000" <- This address need to be smaller than __flash_binary_end stored in RP2040-Decoder.elf.map
|
||||
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){
|
||||
LOG(1, "adc_offset_adjustment\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);
|
||||
|
||||
LOG(1, "new adc offset CV[171] (%f): (uint8_t)%d\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] = 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;
|
||||
else
|
||||
regular_cv_write(cv_index,cv_data);
|
||||
break;
|
||||
case 6: //CV_7
|
||||
// Read only (CV_7 - Version no.)
|
||||
// ADC offset Adjustment (CV_7; Value = 7);
|
||||
if (cv_data == 7) {
|
||||
LOG(1, "trigger adc offset adjustment via cv7 => 7\n");
|
||||
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){
|
||||
LOG(1, "reset of flash triggered via cv8 => 8\n");
|
||||
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];
|
||||
// LOG(1, "new speed %d", speed_step);
|
||||
multicore_fifo_push_blocking(speed_step);
|
||||
// LOG(1, " submitted to list\n");
|
||||
// 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;
|
||||
LOG(3, "iteration %d: maxlevel %d level %d\n", i, max_level, level);
|
||||
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);
|
||||
LOG(3, "level %d measurement %f loop-cond: %f\n", level, measurement, measurement-(float)CV_ARRAY_FLASH[171]);
|
||||
if (level > max_level) {
|
||||
// Abort measurement and write default value of 0 to flash
|
||||
LOG(1, "measure_base_pwm: abort measurement and return 0\n");
|
||||
return 0;
|
||||
}
|
||||
} while((measurement - (float)CV_ARRAY_FLASH[171]) < 5.0f);
|
||||
LOG(3, "level_arr[%d] = %f\n", i, level);
|
||||
level_arr[i] = (float)level;
|
||||
busy_wait_ms(100);
|
||||
}
|
||||
// Find and return overall average discarding outliers in measurement - multiply with 0.9
|
||||
float retVal = 0.9f*two_std_dev(level_arr,5);
|
||||
LOG(1, "measure_base_pwm: %d(%f)\n", (uint16_t)retVal, retVal);
|
||||
return (uint16_t)(retVal);
|
||||
}
|
||||
|
||||
|
||||
// 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 ){
|
||||
LOG(1, "found cv[64] equals to 0xff, reseting CVs (and CV[8] = 8)\n");
|
||||
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 ){
|
||||
LOG(1, "found cv[171] equals to 0xff, adc offset adjstments (and cr[7] = 7)\n");
|
||||
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){
|
||||
LOG(1, "found cv[175] equals to 0, forward direction\n");
|
||||
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){
|
||||
LOG(1, "found cv[177] equals to 0, reverse direction\n");
|
||||
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);
|
||||
}
|
||||
LOG(1, "int_lim_max %d\n", CV_ARRAY_FLASH[51]);
|
||||
LOG(1, "int_lim_min %d\n", CV_ARRAY_FLASH[52]);
|
||||
}
|
||||
|
||||
|
||||
// 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);
|
||||
|
||||
LOG(2, "init motor(%d): wrapCounter %d clkdiv %d\n", gpio, wrap_counter, CV_ARRAY_FLASH[173]);
|
||||
}
|
||||
|
||||
|
||||
// Main initialization - GPIO Config / ADC Config
|
||||
void init_gpio_adc(){
|
||||
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();
|
||||
LOG(1, "\n\n======\ncore0 init\n");
|
||||
init_gpio_adc();
|
||||
LOG(1, "init motor pwms\n");
|
||||
init_motor_pwm(MOTOR_FWD_PIN);
|
||||
init_motor_pwm(MOTOR_REV_PIN);
|
||||
LOG(1, "check cvs\n");
|
||||
cv_setup_check();
|
||||
LOG(1, "init outputs\n");
|
||||
init_outputs();
|
||||
LOG(1, "init gpios\n");
|
||||
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);
|
||||
LOG(1, "core0 done\n");
|
||||
while (1);
|
||||
}
|
||||
@@ -1,58 +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);
|
||||
|
||||
|
||||
#define ProgramInstrVerifyBit 0b10
|
||||
#define ProgramInstrVerifyByte 0b01
|
||||
#define ProgramInstrWriteByte 0b11
|
||||
#define ProgramCmd(instr, adrmsbits) ((instr<<2) | (adrmsbits))
|
||||
|
||||
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_gpio_adc();
|
||||
@@ -1,337 +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_delay_in_us,
|
||||
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;
|
||||
|
||||
if(LOGLEVEL >= 1) {
|
||||
static int counter = 0;
|
||||
counter++;
|
||||
if(counter > 100) {
|
||||
LOG(1, "pid error(%f) output(%f)\n", e, output);
|
||||
counter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
LOG(1, "speedtable min(%f) mid(%f) max(%f)\n", v_min, v_mid, v_max);
|
||||
|
||||
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() {
|
||||
LOG(1, "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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
@@ -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)
|
||||
@@ -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
|
||||
@@ -0,0 +1,2 @@
|
||||
sphinx-rtd-theme>=3.0.2
|
||||
breathe>=4.35.0
|
||||
@@ -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"
|
||||
@@ -0,0 +1,77 @@
|
||||
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?
|
||||
----------------------------------
|
||||
The latest release includes the production files for JLCPCB, which includes the Gerber files, BOM, and Pick and Place files. You can find the latest release `here <https://github.com/gab-k/RP2040-Decoder/releases>`_.
|
||||
|
||||
In order to manually 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 in the latest `release <https://github.com/gab-k/RP2040-Decoder/releases>`_ and skip to :ref:`flashing_the_software`.
|
||||
|
||||
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 <https://marketplace.visualstudio.com/items?itemName=raspberry-pi.raspberry-pi-pico>`_.
|
||||
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::
|
||||
- Make sure to choose the correct board definition file in your CMakeLists.txt file for example ``RP2040-Decoder-board-Rev-1_0`` for Hardware Rev 1.0.
|
||||
- In VSCode open the "Software" subdirectory for the extension to detect you project automatically.
|
||||
|
||||
.. _flashing_the_software:
|
||||
|
||||
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 flashing process, hold the button SW1 while re-plugging the decoder into your computer. The decoder should now show as a Mass Storage Device again.
|
||||
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>`_
|
||||
|
||||
.. _flashing_the_software_swd:
|
||||
|
||||
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:`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>`_.
|
||||
The most relevant sections 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.
|
||||
@@ -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,128 @@
|
||||
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
|
||||
|
||||
|
||||
.. _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,130 @@
|
||||
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
|
||||
|
||||
|
||||
.. _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.
|
||||
@@ -0,0 +1,16 @@
|
||||
.. 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:
|
||||
|
||||
gs/getting_started
|
||||
hardware/index
|
||||
software/index
|
||||
other/index
|
||||
@@ -0,0 +1,126 @@
|
||||
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.
|
||||
|
||||
- Index 0 in the CV array corresponds with ``CV_1``, index 1 corresponds with ``CV_2`` and so forth.
|
||||
|
||||
Reset all CVs
|
||||
------------------------
|
||||
|
||||
To reset all CVs to default, a value of ``8`` can be written to ``CV8``. Alternatively write a value of ``255`` to ``CV_65`` this will also reset all CVs to default, but only after power cycling the decoder.
|
||||
|
||||
Speed step configuration
|
||||
------------------------
|
||||
|
||||
.. figure:: ../../../svg/sw/speed_table.svg
|
||||
:alt: Speed Table
|
||||
:align: center
|
||||
|
||||
Speed Table
|
||||
|
||||
* :math:`v_{min} = CV_{2}`
|
||||
* :math:`v_{mid} = 16 \cdot CV_{6}`
|
||||
* :math:`v_{max} = 16 \cdot CV_{5}`
|
||||
|
||||
The figure above shows how the speed steps can be configured using the corresponding CVs. The red * represents :math:`v_{min}` which is always at speed step 1, the green * shows :math:`v_{mid}` at speed step 63, and the blue * shows :math:`v_{max}` at speed step 126.
|
||||
|
||||
CV List
|
||||
-------
|
||||
|
||||
:math:`CV_{1}` - Basic address
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Short DCC address
|
||||
|
||||
:math:`CV_{2}` - :math:`v_{min}`
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Min motor voltage/speed is: :math:`v_{min} = CV_{2}`
|
||||
|
||||
:math:`CV_{3}` - Acceleration rate
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
The time for one discrete acceleration time step can be calculated as :math:`CV_{3} \cdot CV_{175}`.
|
||||
|
||||
.. note:: Base speed steps are always 128/126 steps.
|
||||
|
||||
:math:`CV_{4}` - Deceleration rate
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
The time for one discrete deceleration time step can be calculated as :math:`CV_{4} \cdot CV_{175}`.
|
||||
|
||||
.. note:: Base speed steps are always 128/126 steps.
|
||||
|
||||
:math:`CV_{5}` - :math:`v_{max}`
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Max motor voltage/speed is calculated as: :math:`v_{max} = 16 \cdot CV_{5}`
|
||||
|
||||
:math:`CV_{6}` - :math:`v_{mid}`
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Mid motor voltage/speed is calculated as: :math:`v_{mid} = 16 \cdot CV_{6}`
|
||||
|
||||
:math:`CV_{7}` - Version No. (Read-Only)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Writing a value of ``7`` triggers an ADC offset adjustment.
|
||||
|
||||
:math:`CV_{8}` - Manufacturer (Read-Only)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Default = ``13`` = Public Domain & Do-It-Yourself Decoders
|
||||
|
||||
Even though :math:`CV_{8}` is defined as a Read-only CV, writing a value of ``8`` resets all CV values to the default values in ``CV.h``.
|
||||
|
||||
:math:`CV_{9}` - Motor PWM Frequency
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
:math:`f_{PWM_{MOTOR}} = (CV_9 \cdot 100 + 10000) \, Hz`
|
||||
|
||||
:math:`CV_{11}` - Packet timeout
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
If no package is received for :math:`x = CV_{11}` seconds the decoder will automatically stop the motor (Emergency Stop).
|
||||
|
||||
:math:`CV_{12}` - Permitted operating modes
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Currently, DCC Digital mode is the only supported mode.
|
||||
|
||||
:math:`CV_{17}` & :math:`CV_{18}` - 14-Bit extended/long address
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Address is only used if bit5 of :math:`CV_{29}` has a value of ``1``.
|
||||
|
||||
.. image:: ../../../svg/sw/Long_address.svg
|
||||
:alt: Long Address
|
||||
:align: center
|
||||
|
||||
Bit15 and bit14 which correspond to bit7 and bit6 of :math:`CV_{17}` are always ``1``. :math:`CV_{17} = 192` & :math:`CV_{18} = 0` is also not a valid address.
|
||||
Otherwise, the valid value range of :math:`CV_{17}` ranges from ``192`` to ``231`` and ``0`` to ``255`` for :math:`CV_{18}` respectively.
|
||||
|
||||
:math:`CV_{29}` - Decoder Configuration
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Bit0 is can be used to reverse motor 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.
|
||||
|
||||
:math:`CV_{31}` & :math:`CV_{32}` - Extended CV pointer (Read-Only)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Not in use.
|
||||
|
||||
|
||||
:math:`CV_{116}` to :math:`CV_{171}` - PWM Slice configuration
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
.. image:: ../../../svg/sw/GPIO_slices.svg
|
||||
:alt: GPIO Slices
|
||||
:align: center
|
||||
|
||||
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: :math:`f_{PWM} = \frac{125 \, \text{MHz}}{(CV_{\text{clk_div}} + 1) \cdot (CV_{\text{wrap}} + 1)}`
|
||||
|
||||
The duty-cycle can be calculated as follows: :math:`D = \frac{CV_{\text{Level}}}{CV_{\text{wrap}} + 1}`
|
||||
|
||||
|
||||
A more detailed explanation regarding PWM can be found in the `RP2040-Datasheet - Chapter 4.5 <https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf>`_.
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
Debugging and Logging
|
||||
==================================
|
||||
|
||||
For logging and debugging you have to build the software yourself. This is explained here: :ref:`building_the_software`
|
||||
|
||||
.. _debugging_via_swd:
|
||||
|
||||
Debugging via SWD
|
||||
----------------------------------
|
||||
Please refer to :ref:`flashing_the_software_swd`.
|
||||
|
||||
|
||||
.. _logging:
|
||||
|
||||
Logging
|
||||
----------------------------------
|
||||
|
||||
Logging can be enabled in ``CMakeLists.txt``, and is available with two interfaces:
|
||||
|
||||
- Logging via UART RX/TX pins (GPIO0/GPIO1 by default)
|
||||
- Logging via USB CDC/ACM
|
||||
|
||||
Additionally you can make the decoder wait for input via serial port by setting LOG_WAIT to 1. For more details please see comments inside ``CMakeLists.txt``.
|
||||
@@ -0,0 +1,10 @@
|
||||
Other
|
||||
======================
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
:caption: Contents:
|
||||
|
||||
troubleshooting
|
||||
debug_logging
|
||||
CV_list
|
||||
@@ -0,0 +1,27 @@
|
||||
Troubleshooting
|
||||
================
|
||||
|
||||
To narrow down the issue when your decoder is not working as expected, you can do the following (in no particular order):
|
||||
|
||||
Enable logging and or debug via SWD
|
||||
------------------------------------
|
||||
Log messages can be enabled and output via either UART or USB please see :ref:`logging` for details.
|
||||
For more advanced users it might also be beneficial to :ref:`debug with SWD <debugging_via_swd>`
|
||||
|
||||
Checking the power supply:
|
||||
--------------------------------------
|
||||
|
||||
* **+3V3 to GND** should be 3.3V ± 1%
|
||||
* **VDC/+V to GND** should be somewhere in the range of at least 6V to 23V depending on your track voltage.
|
||||
|
||||
If you don't measure the correct voltages, try to `measure your track voltage <https://dccwiki.com/Measuring_Track_Voltage>`_
|
||||
|
||||
Check your motor:
|
||||
-----------------
|
||||
|
||||
Desolder your motor and try the motor with an appropriate power supply and DC voltage, to check if the motor is working or not.
|
||||
|
||||
CV 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
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
Software
|
||||
=================
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 3
|
||||
:caption: Contents:
|
||||
|
||||
sw_description
|
||||
header_files
|
||||
@@ -0,0 +1,190 @@
|
||||
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 (simplified) 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.
|
||||
|
||||
|
||||
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.
|
||||
At all times either the startup controller or the PID controller is active.
|
||||
|
||||
The startup controller handles overcoming friction of the motor, and finding a base PWM level for overcoming friction.
|
||||
The base PWM level is equivalent to a certain PWM duty cycle.
|
||||
The base level gets saved and added to the output of the PID controller which handles motor control when the motor is in motion.
|
||||
This means the actual output of the PID controller is the sum of the PID output and the base PWM level. This is referred to as the :ref:`feed forward <feed_forward>` block.
|
||||
The benefit of doing this is that the PID controller does not have to work in the non linear friction region of the motor, improving control performance.
|
||||
|
||||
|
||||
Startup Controller
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Used on startup, meaning when the motor is not moving. First the startup controller retrieves the last `BASE_PWM_ARR_LEN` base PWM levels.
|
||||
The base pwm levels are not retained on a power cycle. That means when there is no previous base PWM level saved, the startup controller will start ramping up from 0.
|
||||
When there is less than `BASE_PWM_ARR_LEN` base PWM levels saved, the startup controller will ramp up from the average of the saved base PWM levels.
|
||||
|
||||
After the startup controller retrieved the average of the last base pwm levels :math:`\bar{b}` it sets a PWM duty cycle level of :math:`\frac{2}{3} \cdot \bar{b}` and then ramps up the duty cycle/PWM level until the motor starts moving.
|
||||
When no previous startup PWM levels are saved the startup controller begins ramping up from 0.
|
||||
The actual value at which the motor started moving is multiplied by `K_FF` and used as a reference for the :ref:`feed forward <feed_forward>` block.
|
||||
|
||||
|
||||
|
||||
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
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
|
||||
As previously mentioned, to achieve better control, `Feed-forward <https://en.wikipedia.org/wiki/Feed_forward_(control)>`_ is used.
|
||||
In essence this means that the output of the PID controller is not only the sum of the proportional, integral, and derivative parts, but also the base PWM level.
|
||||
The base PWM level is set by the startup controller and is the PWM level at which the motor starts moving.
|
||||
|
||||
|
||||
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>`_.
|
||||
@@ -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 |
|
Before Width: | Height: | Size: 630 KiB After Width: | Height: | Size: 630 KiB |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 521 KiB After Width: | Height: | Size: 521 KiB |
|
Before Width: | Height: | Size: 630 KiB After Width: | Height: | Size: 630 KiB |
|
Before Width: | Height: | Size: 609 KiB After Width: | Height: | Size: 609 KiB |
|
Before Width: | Height: | Size: 630 KiB After Width: | Height: | Size: 630 KiB |
|
Before Width: | Height: | Size: 518 KiB After Width: | Height: | Size: 518 KiB |
|
Before Width: | Height: | Size: 524 KiB After Width: | Height: | Size: 524 KiB |
|
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="<mxfile host="app.diagrams.net" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0" version="24.9.0" scale="1" border="0">
 <diagram id="4yrCjKYynwCaxiwjl_Zd" name="Page-1">
 <mxGraphModel dx="1434" dy="734" grid="0" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1169" pageHeight="827" background="none" math="0" shadow="0">
 <root>
 <mxCell id="0" />
 <mxCell id="1" parent="0" />
 <mxCell id="C1jbzQCqpV-uhOoT1oVn-1" value="&lt;div style=&quot;font-size: 20px&quot;&gt;&lt;font style=&quot;font-size: 20px&quot;&gt;RP2040&lt;/font&gt;&lt;/div&gt;&lt;div style=&quot;font-size: 20px&quot;&gt;&lt;font style=&quot;font-size: 20px&quot;&gt;Microcontroller&lt;br&gt;&lt;/font&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#647687;fontColor=#ffffff;strokeColor=#314354;" parent="1" vertex="1">
 <mxGeometry x="560" y="340" width="200" height="200" as="geometry" />
 </mxCell>
 <mxCell id="C1jbzQCqpV-uhOoT1oVn-4" value="" style="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;" parent="1" source="C1jbzQCqpV-uhOoT1oVn-1" target="C1jbzQCqpV-uhOoT1oVn-5" edge="1">
 <mxGeometry width="50" height="50" relative="1" as="geometry">
 <mxPoint x="595" y="450" as="sourcePoint" />
 <mxPoint x="485" y="440" as="targetPoint" />
 </mxGeometry>
 </mxCell>
 <mxCell id="C1jbzQCqpV-uhOoT1oVn-5" value="GPIO" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=18;fontColor=#ffffff;fillColor=#647687;strokeColor=#314354;" parent="1" vertex="1">
 <mxGeometry x="680" y="600" width="120" height="60" as="geometry" />
 </mxCell>
 <mxCell id="UgZSE7u6rpuSXDGsVSFL-2" value="&lt;div&gt;Auxillary outputs&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=18;fontColor=#ffffff;fillColor=#647687;strokeColor=#314354;" parent="1" vertex="1">
 <mxGeometry x="520" y="600" width="120" height="60" as="geometry" />
 </mxCell>
 <mxCell id="UgZSE7u6rpuSXDGsVSFL-5" value="" style="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;" parent="1" source="C1jbzQCqpV-uhOoT1oVn-1" target="UgZSE7u6rpuSXDGsVSFL-2" edge="1">
 <mxGeometry width="50" height="50" relative="1" as="geometry">
 <mxPoint x="645" y="440" as="sourcePoint" />
 <mxPoint x="695" y="390" as="targetPoint" />
 </mxGeometry>
 </mxCell>
 <mxCell id="UgZSE7u6rpuSXDGsVSFL-7" value="Motor Driver" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=18;fontColor=#ffffff;fillColor=#647687;strokeColor=#314354;" parent="1" vertex="1">
 <mxGeometry x="960" y="360" width="120" height="60" as="geometry" />
 </mxCell>
 <mxCell id="UgZSE7u6rpuSXDGsVSFL-9" value="" style="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 |
|
After Width: | Height: | Size: 6.9 MiB |
|
After Width: | Height: | Size: 6.9 MiB |
|
After Width: | Height: | Size: 6.8 MiB |
|
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" style="background: transparent; background-color: transparent; color-scheme: light;" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="1930px" height="2823px" viewBox="-0.5 -0.5 1930 2823" content="<mxfile host="app.diagrams.net" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0" version="26.0.3" scale="1" border="0">
 <diagram id="fYnpBcbPwy3h1yrhEr7x" name="Page-1">
 <mxGraphModel dx="6320" dy="5010" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" background="none" math="0" shadow="0">
 <root>
 <mxCell id="0" />
 <mxCell id="1" parent="0" />
 <mxCell id="K4uLP4tBgHA3zsCXKBI8-35" value="" style="line;strokeWidth=15;html=1;rounded=0;fontFamily=Helvetica;fontSize=100;fontColor=default;fillColor=none;gradientColor=none;direction=west;strokeColor=#0000FF;" parent="1" vertex="1">
 <mxGeometry x="1180" y="1337.75" width="100" height="15" as="geometry" />
 </mxCell>
 <mxCell id="No6-LZMIRZosWDj3bi_c-3" value="" style="line;strokeWidth=15;html=1;rounded=0;fontFamily=Helvetica;fontSize=100;fontColor=default;fillColor=none;gradientColor=none;direction=west;" vertex="1" parent="1">
 <mxGeometry x="1565" y="1335" width="435" height="15" as="geometry" />
 </mxCell>
 <mxCell id="No6-LZMIRZosWDj3bi_c-1" value="" style="shape=image;verticalLabelPosition=bottom;labelBackgroundColor=default;verticalAlign=top;aspect=fixed;imageAspect=0;image=data:image/png,iVBORw0KGgoAAAANSUhEUgAABiAAAANoCAYAAABJLCIrAAAABHNCSVQICAgIfAhkiAAAIABJREFUeJzs3Xt8HHW9P/7XJGmTFNIbm6Q0KZBSFOktbaGAFNFzTil45CIgogIe/Qm0pRRF5RwVFTyg54Ci0Ja2+P3JEQRBSwU9Uijn9z0gt0JL26QXQEovNGmSZuktzbVJ5vfH7uzO7Hxm5jOzM7szm9fzwZLduXw+n5mdbrKf93zeH+Wtt5pUEBERERERERERERER+ago3w0gIiIiIiIiIiIiIqLCwwAEERERERERERERERH5jgEIIiIiIiIiIiIiIiLyXQnAKSCIiIiIiIiIiIiIiMhfHAFBRERERERERERERES+YwCCiIiIiIiIiIiIiIh8xwAEERERERERERERERH5jgEIIiIiIiIiIiIiIiLyHQMQRERERERERERERETkOwYgiIiIiIiIiIiIiIjIdyWqmu8mEBERERERERERERFRoeEICCIiIiIiIiIiIiIi8h0DEERERERERERERERE5DsGIIiIiIiIiIiIiIiIyHcMQBARERERERERERERke9KAM5CTURERERERERERERE/uIICCIiIiIiIiIiIiIi8h0DEERERERERERERERE5DsGIIiIiIiIiIiIiIiIyHcMQBARERERERERERERke8YgCAiIiIiIiIiIiIiIt8xAEFERERERERERERERL4rUdV8N4GIiIiIiIiIiIiIiAoNR0AQEREREREREREREZHvGIAgIiIiIiIiIiIiIiLfMQBBRERERERERERERES+YwCCiIiIiIiIiIiIiIh8VwJwFmoiIiIiIiIiIiIiIvIXR0AQEREREREREREREZHvGIAgIiIiIiIiIiIiIiLfMQBBRERERERERERERES+YwCCiIiIiIiIiIiIiIh8xwAEERERERERERERERH5jgEIIiIiIiIiIiIiIiLyHQMQRERERERERERERETkuxJVzXcTiIiIiIiIiIiIiIio0HAEBBERERERERERERER+Y4BCCIiIiIiIiIiIiIi8h0DEERERERERERERERE5LsSgJNAEBERERERERERERGRvzgCgoiIiIiIiIiIiIiIfMcABBEREUXajh2NwuW9vUdx8OCe1OujR5vR1dliW5aq9kIdPGBYVqQclmpHWekR3fNOlJV2Su13/AjxdiPKu4WvM39qSor7U8syyxxR3m3aPpN+f+2nfpm+HKeynI5FtE60jeyyzPXa8Vtt67b9ovcodY5K+i3fQ6t99NuL3mc37ZPZVquvpKRfeH7cng9R/ceP6HQ87/p93Lw3+nOsP3fa8QRp2LCjvpZ39Gizr+UREREREYWd8sYbu5mDiYiIiCLrqaf+E6XDS1FeXobjjjsOpaWlKC0djuHDh2PYsBKUlAxDSUkxiouNj6KiIhQVFaG4qAhKURGKipTEMqUISpGS+qkoCooUJfVcURQoUADtuQIoSDxH4r/EOq2ByfWpl8l9hqIhetiUZyoAVU08U1Xjcm1BYhsVUAEVKlQ1ua2q6l6rUAdVDKrp14ODg6mfg4MqVHUw+XwwtWxgYMDw6O8fwMBAP/r6juHYsWPo7e1DX18vOjqOore3F729vbjyqu/k+jQREREREQWCIyCIiIgo+pRkZ2IiLmBc4TDflfVa+/1M1ZCJkvEgyotsb7eS3N98jYuvev1nlArVFJDk3WFEREREVEgYgCAiIqLIs+/gVgx3PQeH3YYAAw5UgGQvZsntVDU18AIKlNRoC0VJ/Muprp7opZVERERERKHEAAQREREVDn16lUT+FEBwh7HPVSUN3S53Bh0o1HJ1YRo+FGxCorqRWmoyEjFU07IRERERUeEryXcDiIiIiLKVyt+u68TT7ib23PvIHkFbPDtREYV3qkBGDxkyvqmwTfCmrUrOJWMYpVUgp4OIiIiICABKcpOSgIiIiCg4CrSAg16Wf+SoiEbfbQ7xdORbob4DXo8rD19knKeVcbmxmtpC1X0x43c0IiIiIioUHAFBREREhcPPTrtC7et1iachaDzD3smeu3z05huDD8aJp3WvVW1LRhyIiIiIqDAxAEFERESRJ85eogjW+qeQu40L+dhyj2ezoEh/nBg31I9o0F8R2sitIl2Eom3/Tm9tIyIiIiIKoRImGSUiIqJCku7GE/+N49fUDqIMTVHuao5y2/OPZ48yyeVqUlXVkHopsaerPE9ERERERKHGERBEREQUcVadv4pwfWZudSXzmWRfciF0ORfCMeQWz1gh8dTN72Enu6CnkpyEWnvuNHk1EREREVHUFOW7AURERETZUKDrFjZ19Dl35qmCZ6KX1vtFj+GckQVF8KDIy8Pb6DShtKpmfp7wWiMiIiKiwsEREERERBRpKtR0B5+po8+549hrV1/Uugij1t7c4ZkZUrKNHHrcP3MUhCEooRhHYlVV13mrhIiIiIgohBiAICIiouhTUv8T8Npj6LEtwRQTubrDi2dlKFMU6xEJUtmVvKRgclOkArS1cRJqIiIiIiocTMFEREREEad176mCXOsSk8BmlpMaTSGbusmqPfnDhEEaplEieVJxBamNBNdZ5twz2seNmhjBpSSfQ9UmoSYiIiIiKgwcAUFEREQRp6ZDEB5SMOnLMeRCsZ051k1Xdu46E9ltyTNA3nmalFrIXIpVuYlJqKM9pwwRERERkR2OgCAiIqLIUwEg2ZGXsdQFuyTtogrDYWjf28/RDeSG4Bpxe9lIbS9fqJr8MFF0S6qqOALine truncated
|
||||
|
After Width: | Height: | Size: 1.3 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="<mxfile host="app.diagrams.net" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0" version="25.0.3" scale="1" border="0">
 <diagram name="Page-1" id="EzXMAEqKDDRs-_LGy8zr">
 <mxGraphModel dx="1687" dy="920" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
 <root>
 <mxCell id="0" />
 <mxCell id="1" parent="0" />
 <mxCell id="4ED7IVWrFvjwATd2QOsb-28" value="Speed Helper" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=18;fontColor=#ffffff;fillColor=#647687;strokeColor=#314354;" vertex="1" parent="1">
 <mxGeometry x="265" y="150" width="150" height="70" as="geometry" />
 </mxCell>
 <mxCell id="4ED7IVWrFvjwATd2QOsb-29" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;startArrow=none;" edge="1" parent="1" target="4ED7IVWrFvjwATd2QOsb-31">
 <mxGeometry relative="1" as="geometry">
 <mxPoint x="920" y="420" as="sourcePoint" />
 </mxGeometry>
 </mxCell>
 <mxCell id="4ED7IVWrFvjwATd2QOsb-30" value="&lt;div&gt;&lt;b&gt;Motor Controller&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;PID MODE&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;or&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;STARTUP MODE&lt;br&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=18;fontColor=#ffffff;fillColor=#647687;strokeColor=#314354;" vertex="1" parent="1">
 <mxGeometry x="610" y="340" width="340" height="160" as="geometry" />
 </mxCell>
 <mxCell id="4ED7IVWrFvjwATd2QOsb-31" value="Motor Driver" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=18;fontColor=#ffffff;fillColor=#647687;strokeColor=#314354;" vertex="1" parent="1">
 <mxGeometry x="1070" y="385" width="150" height="70" as="geometry" />
 </mxCell>
 <mxCell id="4ED7IVWrFvjwATd2QOsb-32" value="ADC" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=18;fontColor=#ffffff;fillColor=#647687;strokeColor=#314354;" vertex="1" parent="1">
 <mxGeometry x="610" y="715" width="150" height="70" as="geometry" />
 </mxCell>
 <mxCell id="4ED7IVWrFvjwATd2QOsb-33" value="Motor" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=18;fontColor=#ffffff;fillColor=#647687;strokeColor=#314354;" vertex="1" parent="1">
 <mxGeometry x="1325" y="385" width="150" height="70" as="geometry" />
 </mxCell>
 <mxCell id="4ED7IVWrFvjwATd2QOsb-34" value="" style="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;" edge="1" parent="1" source="4ED7IVWrFvjwATd2QOsb-28" target="4ED7IVWrFvjwATd2QOsb-43">
 <mxGeometry width="50" height="50" relative="1" as="geometry">
 <mxPoint x="330" y="280" as="sourcePoint" />
 <mxPoint x="210" y="320" as="targetPoint" />
 <Array as="points" />
 </mxGeometry>
 </mxCeLine truncated
|
||||
|
After Width: | Height: | Size: 203 KiB |
@@ -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="701px" height="845px" viewBox="-0.5 -0.5 701 845" content="<mxfile host="app.diagrams.net" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0" version="25.0.3" scale="1" border="0">
 <diagram name="Page-1" id="EzXMAEqKDDRs-_LGy8zr">
 <mxGraphModel dx="1687" dy="920" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
 <root>
 <mxCell id="0" />
 <mxCell id="1" parent="0" />
 <mxCell id="4ED7IVWrFvjwATd2QOsb-36" value="" style="endArrow=classic;html=1;rounded=0;strokeColor=#647687;shape=flexArrow;strokeWidth=2;fillColor=default;gradientColor=none;width=32;endSize=11.67;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" target="4ED7IVWrFvjwATd2QOsb-89" source="4ED7IVWrFvjwATd2QOsb-77">
 <mxGeometry width="50" height="50" relative="1" as="geometry">
 <mxPoint x="20" y="70" as="sourcePoint" />
 <mxPoint x="480" y="160" as="targetPoint" />
 <Array as="points">
 <mxPoint x="385" y="135" />
 </Array>
 </mxGeometry>
 </mxCell>
 <mxCell id="4ED7IVWrFvjwATd2QOsb-37" value="STARTUP_MODE" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=20;fontColor=default;rotation=270;" vertex="1" connectable="0" parent="4ED7IVWrFvjwATd2QOsb-36">
 <mxGeometry x="-0.3535" y="-3" relative="1" as="geometry">
 <mxPoint x="-3" y="7" as="offset" />
 </mxGeometry>
 </mxCell>
 <mxCell id="4ED7IVWrFvjwATd2QOsb-64" value="" style="endArrow=classic;html=1;rounded=0;strokeColor=#647687;shape=flexArrow;strokeWidth=2;fillColor=default;gradientColor=none;width=32;endSize=11.67;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="4ED7IVWrFvjwATd2QOsb-89" target="4ED7IVWrFvjwATd2QOsb-102">
 <mxGeometry width="50" height="50" relative="1" as="geometry">
 <mxPoint x="1200" y="490" as="sourcePoint" />
 <mxPoint x="1315" y="490" as="targetPoint" />
 <Array as="points" />
 </mxGeometry>
 </mxCell>
 <mxCell id="4ED7IVWrFvjwATd2QOsb-65" value="K_FF*startup.level" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=20;fontColor=default;rotation=270;" vertex="1" connectable="0" parent="4ED7IVWrFvjwATd2QOsb-64">
 <mxGeometry x="-0.4316" y="7" relative="1" as="geometry">
 <mxPoint x="-7" y="27" as="offset" />
 </mxGeometry>
 </mxCell>
 <mxCell id="4ED7IVWrFvjwATd2QOsb-71" value="" style="endArrow=classic;html=1;rounded=0;strokeColor=#647687;shape=flexArrow;strokeWidth=2;fillColor=default;gradientColor=none;width=32;endSize=11.67;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" target="4ED7IVWrFvjwATd2QOsb-89">
 <mxGeometry width="50" height="50" relative="1" as="geometry">
 <mxPoint x="340" y="20" as="sourcePoint" />
 <mxPoint x="320" y="505" as="targetPoint" />
 <Array as="points">
 <mxPoint x="615" y="20" />
 </Array>
 </mxGeometry>
 </mxCell>
 <mxCell id="4ED7IVWrFvjwATd2QOsb-72" value="MEASUREMENT &Line truncated
|
||||
|
After Width: | Height: | Size: 171 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 64 KiB |
|
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 43 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
@@ -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}")
|
||||
@@ -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}")
|
||||
@@ -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()
|
||||
@@ -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)"
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
@@ -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);
|
||||
}
|
||||
@@ -1,68 +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"
|
||||
|
||||
|
||||
// here you can enable printf debugging (needs extra soldering and you have to enable uart in the cmake configuration)
|
||||
// please note
|
||||
// - if it's disabled it will be compiled completely out
|
||||
// - be careful that printf debugging can change your timing behavior, for example in the pid controller limit the outputs
|
||||
// like already done (only print every 100th iteration for example!)
|
||||
// - also note that with logging enabled GPIO0/1 are DISABLED from decoder functions because they are used for uart to the
|
||||
// outside world (this is configure automatically for you below!)
|
||||
// - IMPORTANT: you have to enable uart in the cmakelists.txt to enable logging!
|
||||
#define LOGLEVEL 0
|
||||
#define LOG(level, ...) { if(level <= LOGLEVEL) {printf(__VA_ARGS__);}}
|
||||
|
||||
// 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
|
||||
|
||||
// if logging is enabled do NOT use gpio0/1 for functions in the decoder
|
||||
#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)
|
||||
#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);
|
||||