From 0c8be8bb27ea262e9d87676b6ecdda0cc40aa5ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?BENEDEK=20L=C3=A1szl=C3=B3?= Date: Fri, 28 Mar 2025 15:57:57 +0100 Subject: [PATCH] basic signal generator control --- CMakeLists.txt | 1 + src/awg/CMakeLists.txt | 7 +++++++ src/awg/main.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 src/awg/CMakeLists.txt create mode 100644 src/awg/main.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 74aae13..7e22118 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,3 +13,4 @@ link_directories(/opt/picoscope/lib) add_subdirectory(src/recorder) add_subdirectory(src/filter) +add_subdirectory(src/awg) diff --git a/src/awg/CMakeLists.txt b/src/awg/CMakeLists.txt new file mode 100644 index 0000000..d5914b0 --- /dev/null +++ b/src/awg/CMakeLists.txt @@ -0,0 +1,7 @@ +file(GLOB_RECURSE SOURCES "./*.c") +add_executable(awg ${SOURCES}) +target_compile_options(awg PRIVATE -Wall -Wextra) +target_link_libraries(awg ps2000) +set_target_properties(awg PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" +) \ No newline at end of file diff --git a/src/awg/main.c b/src/awg/main.c new file mode 100644 index 0000000..bd37220 --- /dev/null +++ b/src/awg/main.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include + +int main(void) { + int16_t unit = ps2000_open_unit(); + if (unit == -1) { + fprintf(stderr, "failed to open a unit!\n"); + return -1; + } else if (unit == 0) { + fprintf(stderr, "no units to open!\n"); + return -1; + } + + for (int32_t i = 0; i < 2000; i++) { + int16_t err = ps2000_set_sig_gen_built_in(unit, i * 1000, 0, PS2000_DC_VOLTAGE, 0, 0, 0, 0, PS2000_UPDOWN, 0); + + if (err == 0) { + printf("failed to set voltage\n"); + return 1; + } else { + fprintf(stderr, "%d\n", i); + } + + usleep(1000); + } + + ps2000_stop(unit); + ps2000_close_unit(unit); + + return 0; +} \ No newline at end of file