From 7077b8d448a847f593402381be5244f86eae75e8 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 25 Aug 2020 21:01:08 -0400 Subject: [PATCH] stable signal handling towards 100kHz --- gui/wxmain.hpp | 14 ++++++++------ source/adc.cpp | 8 ++++---- source/dac.cpp | 4 ++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/gui/wxmain.hpp b/gui/wxmain.hpp index 05faf70..d694734 100644 --- a/gui/wxmain.hpp +++ b/gui/wxmain.hpp @@ -100,7 +100,8 @@ public: auto button = dynamic_cast(ce.GetEventObject()); if (!m_render_timer->IsRunning()) { - m_device = new stmdsp::device(m_device_combo->GetStringSelection().ToStdString()); + if (m_device == nullptr) + m_device = new stmdsp::device(m_device_combo->GetStringSelection().ToStdString()); if (m_device->connected()) { m_device->continuous_start(); m_device_samples_future = std::async(std::launch::async, @@ -116,8 +117,8 @@ public: m_device->continuous_stop(); button->SetLabel("Single"); - delete m_device; - m_device = nullptr; + //delete m_device; + //m_device = nullptr; } } @@ -129,10 +130,11 @@ public: if (wxFileInputStream file_stream (/*dialog.GetPath()*/file); file_stream.IsOk()) { auto size = file_stream.GetSize(); auto buffer = new unsigned char[size]; - auto device = new stmdsp::device(m_device_combo->GetStringSelection().ToStdString()); - if (device->connected()) { + if (m_device == nullptr) + m_device = new stmdsp::device(m_device_combo->GetStringSelection().ToStdString()); + if (m_device->connected()) { file_stream.ReadAll(buffer, size); - device->upload_filter(buffer, size); + m_device->upload_filter(buffer, size); } } } diff --git a/source/adc.cpp b/source/adc.cpp index 1f65e68..c912a7e 100644 --- a/source/adc.cpp +++ b/source/adc.cpp @@ -29,7 +29,7 @@ static void adc_read_callback(ADCDriver *); .cfgr2 = 0, .tr1 = ADC_TR(0, 4095), .smpr = { - ADC_SMPR1_SMP_AN5(ADC_SMPR_SMP_247P5), 0 + ADC_SMPR1_SMP_AN5(ADC_SMPR_SMP_2P5), 0 }, .sqr = { ADC_SQR1_SQ1_N(ADC_CHANNEL_IN5), @@ -38,7 +38,7 @@ static void adc_read_callback(ADCDriver *); }; constexpr static const GPTConfig gpt_config = { - .frequency = 1000000, + .frequency = 4000000, .callback = nullptr, .cr2 = TIM_CR2_MMS_1, /* TRGO */ .dier = 0 @@ -65,7 +65,7 @@ namespace adc adc_is_read_finished = false; adc_group_config.circular = false; adcStartConversion(adcd, &adc_group_config, buffer, count); - gptStartContinuous(gptd, 100); // 10kHz + gptStartContinuous(gptd, 2); while (!adc_is_read_finished); return buffer; } @@ -77,7 +77,7 @@ namespace adc adc_operation_func = operation_func; adc_group_config.circular = true; adcStartConversion(adcd, &adc_group_config, buffer, count); - gptStartContinuous(gptd, 100); // 10kHz + gptStartContinuous(gptd, 2); } void read_stop() diff --git a/source/dac.cpp b/source/dac.cpp index 644689e..6d5950e 100644 --- a/source/dac.cpp +++ b/source/dac.cpp @@ -28,7 +28,7 @@ constexpr static const DACConversionGroup dac_group_config = { }; constexpr static const GPTConfig gpt_config = { - .frequency = 1000000, + .frequency = 4000000, .callback = nullptr, .cr2 = TIM_CR2_MMS_1, /* TRGO */ .dier = 0 @@ -48,7 +48,7 @@ namespace dac void write_start(dacsample_t *buffer, size_t count) { dacStartConversion(dacd, &dac_group_config, buffer, count); - gptStartContinuous(gptd, 100); + gptStartContinuous(gptd, 2); } void write_stop()