Jump to content
  • 0

Analog discovery 2 + parallel recording and playing


Moj

Question

Hello everyone,

I want to connect an analog discovery 2 to a CORE i7 laptop.

Then, I want to play a signal using one core, and record this signal using another core. 

But I get this error:  "Devices are busy, used by other applications". 

I would be thankful if you help me to solve this problem.

If you need more information, I use the the attached python code. This code is a combination of "Admittance_player.py" and "AnalogIn_Record.py" exisiting in sample/py.


Thank you!

 


 

one.py

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 1

Hi @Moj

What is your analog-in sampling rate ? This should be at least 4x the signal rate to capture it correctly.
By default averaged samples are stored (FDwfAnalogInChannelFilterSet filterAverage) so at lower sample/signal rate the amplitude will be attenuated.

Sweep 160-200kHz 1sec

image.png

image.png

image.png

image.png

Link to comment
Share on other sites

  • 0

Hi @Moj

As Atilla said, a DWF device can only be opened from a single process. It /is/ possible to use multiple threads in that process to access the device (seemingly) simultaneously, but the interactions with the device will not overlap.

If you're going to use Python, perhaps it is worth it to check out the pydwf package that takes care of a lot of the ctypes drudgery, provides proper error handling, and has decent documentation and examples as well.

 

Link to comment
Share on other sites

  • 0
On 12/30/2022 at 2:37 PM, reddish said:

Hi @Moj

As Atilla said, a DWF device can only be opened from a single process. It /is/ possible to use multiple threads in that process to access the device (seemingly) simultaneously, but the interactions with the device will not overlap.

If you're going to use Python, perhaps it is worth it to check out the pydwf package that takes care of a lot of the ctypes drudgery, provides proper error handling, and has decent documentation and examples as well.

 

Hello @attila @reddish

Thank you for your replies and "Happy New Year"!

I wanted to use two threads to solve a problem. But you mentioned that my solution is not practical. So I explain the main problem.

My goal is to generate a signal and read it simultaneously using Analog discovery 2 + Python.

For this, I selected the trigger source of AnalogIn as follows:

dwf.FDwfAnalogInTriggerSourceSet(hdwf, c_int(7)) # trigsrcAnalogOut1 
dwf.FDwfAnalogInTriggerConditionSet(hdwf, c_int(2))

The sampling frequency for AnalogIn and AnalogOut is 800e3.

The number of samples of this signal is 4000, Figure-left. 

I selected 4000 because I know that the buffer size of analog discovery 2 is more than 4000.

when I run the code, I see a delay in the measured signal, Figure-right.

The amount of delay is not fixed. I mean that it fluctuates. 

The python code has been attached.

Please let me know how I can remove this delay.


I appriciate your time in advance!

 

Delay.png

Python_code.py

Link to comment
Share on other sites

  • 0

Hi @Moj

I am not going to try to understand your code fully because with all the ctypes stuff I consider it too much of a chore.

One thing you should know (and that is not clearly documented) is that the analog-in record functions tend to give you too much data, and you need to keep the LAST samples read, to make sure repeated recordings are properly aligned relative to the trigger.

If I were you I would try to simplify the code first with reading only, and use a separate function generator to verify that you get the triggering right (if you have it).

Also, I would again urge you to consider using pydwf -- it will clean up your code tremendously. Here's an AnalogIOut -> AnalogIn example in pydwf that properly aligns recorded samples (see lines 203--209 and the docstring at the top of the file):

https://github.com/sidneycadot/pydwf/blob/master/source/pydwf-examples/AnalogInRecordMode.py


What you are doing is more complicated, due to the fact that you need to interleave data output and data input. I haven't tried that myself and I am not certain it is possible, even at a modest 800 kHz input/output rate. You might consider if the analog-out frequency modulation offered by DWF could be sufficient for your application of generating a sinusoid chirp, as it relieves you from the hassle of interleaving analog input and output.

Edited by reddish
Link to comment
Share on other sites

  • 0

Hi @Moj

If the generated and captured samples fit in the device buffer the simple (single capture and custom signal) can be used like this: 
Python_code_single.py

image.png

 

For longer capture and generate, the record and play can be used at limited rate:
Python_code_playrec.py

image.png

 

The available device buffer sizes are the following but it can be obtained by FDwfAnalogInBufferSizeInfo and FDwfAnalogOutNodeDataInfo.

image.png

Link to comment
Share on other sites

  • 0

Dear @attila

I appreciate your time in preparing those two useful python codes for me.

I only have one question for you. 

when I want to play and record a chirp between 160 kHz and 200 kHz, i.e., f1=160e3 and f2=200e3, I get different voltage amplitude. 

To explain more, the peak-to-peak amplitude of this chirp in theory should be 2 volts, but during the measurement, it drops down. 

The amount of this reduction is not always constant. for example in Figure 1, the peak-to-peak amplitude is 1.1 volt while in another try it is 1.6 v. 

Is it possible to solve this problem? 

Just so you know, I connect the analog discovery 2 to my laptop through the USB cable that you provided in the box. 

For your information, the delay problem is not as severe as in the past, but there is still a little delay (please see Figure 1 in the box - There is approximately 1000 sample delay).

Thank you very much.

 

 

a.JPG

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...