diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f08da47 --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +The person or persons who have associated work with this document (the "Dedicator" or "Certifier") hereby either (a) certifies that, to the best of his knowledge, the work of authorship identified is in the public domain of the country from which the work is published, or (b) hereby dedicates whatever copyright the dedicators holds in the work of authorship identified below (the "Work") to the public domain. A certifier, moreover, dedicates any copyright interest he may have in the associated work, and for these purposes, is described as a "dedicator" below. + +A certifier has taken reasonable steps to verify the copyright status of this work. Certifier recognizes that his good faith efforts may not shield him from liability if in fact the work certified is not in the public domain. + +Dedicator makes this dedication for the benefit of the public at large and to the detriment of the Dedicator's heirs and successors. Dedicator intends this dedication to be an overt act of relinquishment in perpetuity of all present and future rights under copyright law, whether vested or contingent, in the Work. Dedicator understands that such relinquishment of all rights includes the relinquishment of all rights to enforce (by lawsuit or otherwise) those copyrights in the Work. + +Dedicator recognizes that, once placed in the public domain, the Work may be freely reproduced, distributed, transmitted, used, modified, built upon, or otherwise exploited by anyone for any purpose, commercial or non-commercial, and in any way, including by methods that have not yet been invented or conceived. diff --git a/README.md b/README.md new file mode 100644 index 0000000..b52a4af --- /dev/null +++ b/README.md @@ -0,0 +1,59 @@ +# Pico PIO ADC + +Sigma-delta ADC demo for Raspberry Pi Pico using PIO. + + +## Building + +1. You need to have `PICO_SDK_PATH` set. +2. Just run `cmake -B build src` to configure the project. +3. And then `cmake --build build` to build it. +4. Flash the firmware via `picotool load -f build/pico-pio-adc.uf2`. + + +## GNU Radio Companion + +The GNU Radio Companion examples work with a FIFO that receives the stream from the serial. +Build creates a simple tool to move the bytes around, so you can do this: + +``` +mkfifo samples.fifo +build/tools/serial /dev/ttyACM1 >samples.fifo +``` + +Then GRC can grab the samples. + +If you tire of having to start the serial tool manually, you can do this: + +``` +watch -n1 'build/tools/serial /dev/ttyACM1 >samples.fifo' +``` + +This restarts it in a second once it quits. + + +## Circuit + + + Circuit Schema + + +Click the image to open interactive version in Paul Falstad's excellent online simulator. + + +## Screenshots + +
+ Noise Floor + +
+ +
+ IR Blast, full rate + +
+ +
+ IR Blast, tuned at 38 kHz + +
diff --git a/grc/base.grc b/grc/base.grc index 116ff2c..36278f5 100644 --- a/grc/base.grc +++ b/grc/base.grc @@ -69,7 +69,7 @@ blocks: alias: '' begin_tag: pmt.PMT_NIL comment: '' - file: /home/mordae/work/smart/pico-pdm/samples.fifo + file: ../samples.fifo length: '0' maxoutbuf: '0' minoutbuf: '0' diff --git a/grc/ir38.grc b/grc/ir38.grc index cb0f073..5054dff 100644 --- a/grc/ir38.grc +++ b/grc/ir38.grc @@ -109,7 +109,7 @@ blocks: alias: '' begin_tag: pmt.PMT_NIL comment: '' - file: /home/mordae/work/smart/pico-pdm/samples.fifo + file: ../samples.fifo length: '0' maxoutbuf: '0' minoutbuf: '0' @@ -567,6 +567,7 @@ blocks: connections: - [blocks_char_to_float_0, '0', blocks_float_to_complex_0, '0'] +- [blocks_char_to_float_0, '0', blocks_float_to_complex_0, '1'] - [blocks_complex_to_mag_squared_0, '0', qtgui_time_sink_x_0_0, '0'] - [blocks_file_source_0, '0', blocks_char_to_float_0, '0'] - [blocks_float_to_complex_0, '0', blocks_freqshift_cc_0, '0'] diff --git a/images/circuitjs.png b/images/circuitjs.png new file mode 100644 index 0000000..0cbed96 Binary files /dev/null and b/images/circuitjs.png differ diff --git a/images/ir-blast-full.png b/images/ir-blast-full.png new file mode 100644 index 0000000..803b8da Binary files /dev/null and b/images/ir-blast-full.png differ diff --git a/images/ir-blast-narrow.png b/images/ir-blast-narrow.png new file mode 100644 index 0000000..41c4769 Binary files /dev/null and b/images/ir-blast-narrow.png differ diff --git a/images/noise-floor.png b/images/noise-floor.png new file mode 100644 index 0000000..26b1361 Binary files /dev/null and b/images/noise-floor.png differ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b537733..f708df3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,17 +1,27 @@ cmake_minimum_required(VERSION 3.21) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +include(ExternalProject) + +ExternalProject_Add(tools + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tools + BINARY_DIR ${CMAKE_BINARY_DIR}/tools + CMAKE_ARGS -DCMAKE_C_COMPILER=cc + -DCMAKE_CXX_COMPILER=c++ + INSTALL_COMMAND "" +) + include($ENV{PICO_SDK_PATH}/pico_sdk_init.cmake) -project(pdmtest) +project(pico-pio-adc) pico_sdk_init() -add_executable(pdmtest main.c) +add_executable(pico-pio-adc main.c) add_subdirectory(vendor/pico-stdio-usb-simple) target_link_libraries( - pdmtest + pico-pio-adc pico_stdio_usb_simple pico_divider @@ -27,7 +37,7 @@ target_link_libraries( hardware_vreg ) -target_compile_definitions(pdmtest PRIVATE +target_compile_definitions(pico-pio-adc PRIVATE PLL_SYS_REFDIV=1 PLL_SYS_VCO_FREQ_HZ=1584000000 PLL_SYS_POSTDIV1=6 @@ -35,16 +45,16 @@ target_compile_definitions(pdmtest PRIVATE SYS_CLK_HZ=132000000 ) -pico_add_extra_outputs(pdmtest) +pico_add_extra_outputs(pico-pio-adc) -set_property(TARGET pdmtest PROPERTY C_STANDARD 23) -target_compile_options(pdmtest PRIVATE -Wall -Wextra -Wnull-dereference) -target_compile_definitions(pdmtest PUBLIC PICO_MAX_SHARED_IRQ_HANDLERS=8u) -target_compile_definitions(pdmtest PUBLIC PICO_STDIO_ENABLE_CRLF_SUPPORT=1) -target_compile_definitions(pdmtest PUBLIC PICO_STDIO_DEFAULT_CRLF=1) -target_compile_definitions(pdmtest PUBLIC PICO_STDIO_AUX=1) +set_property(TARGET pico-pio-adc PROPERTY C_STANDARD 23) +target_compile_options(pico-pio-adc PRIVATE -Wall -Wextra -Wnull-dereference) +target_compile_definitions(pico-pio-adc PUBLIC PICO_MAX_SHARED_IRQ_HANDLERS=8u) +target_compile_definitions(pico-pio-adc PUBLIC PICO_STDIO_ENABLE_CRLF_SUPPORT=1) +target_compile_definitions(pico-pio-adc PUBLIC PICO_STDIO_DEFAULT_CRLF=1) +target_compile_definitions(pico-pio-adc PUBLIC PICO_STDIO_AUX=1) -target_include_directories(pdmtest PRIVATE include) +target_include_directories(pico-pio-adc PRIVATE include) -#pico_set_binary_type(pdmtest no_flash) -#pico_set_binary_type(pdmtest copy_to_ram) +#pico_set_binary_type(pico-pio-adc no_flash) +#pico_set_binary_type(pico-pio-adc copy_to_ram) diff --git a/src/tools/.clangd b/src/tools/.clangd new file mode 100644 index 0000000..712f2e1 --- /dev/null +++ b/src/tools/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + CompilationDatabase: ../../build/tools diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt new file mode 100644 index 0000000..49c0aab --- /dev/null +++ b/src/tools/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.21) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +project(tools) + +add_executable(serial serial.c) diff --git a/src/tools/serial.c b/src/tools/serial.c new file mode 100644 index 0000000..44c6434 --- /dev/null +++ b/src/tools/serial.c @@ -0,0 +1,36 @@ +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + const char *path = "/dev/ttyACM1"; + + if (argc >= 2) + path = argv[1]; + + int fd = open(path, O_RDONLY | O_NOCTTY); + if (fd < 0) + return 1; + + struct termios tty; + tcgetattr(fd, &tty); + cfmakeraw(&tty); + tty.c_cflag |= CLOCAL; + tty.c_cflag &= ~(HUPCL | CRTSCTS); + tcsetattr(fd, TCSANOW, &tty); + + uint8_t buf[4]; + int sofar = 0; + + while (1) { + int n = read(fd, buf, sizeof(buf)); + if (n > 0) { + fwrite(buf, n, 1, stdout); + } else { + return n < 0; + } + } +}