Jump to content
  • 0

AnalogIn_Record indexing?


Chazzo

Question

I am having good success with building a GUI that is built around the analogIn_Record.py example. Thanks to those that have helped me get this far. 

I'm looking to have the data aligned so that there are no duplicates from the buffer(the buffer as I understand is where the recently recorded data is kept in a serial fashion). I think I have correctly determined that I need to use the FDwfAnalogInStatusData2 function to do this. I have found the documentation to be a little limited, but I also have found this forum post as well -> https://forum.digilentinc.com/topic/9747-analogin-record-problem/

Despite the explanations I'm still having difficulty with understanding how to implement the function. I have also had a look at AnalogIn_record_Trigger.py as well. The circular buffer is interesting and it sounds like what I might need for my project but its not trivial with what it's doing so I will need to spend more time with it. Maybe its not what I need?

Basically I am having trouble with knowing where to being. I've tried to poke at it and understand its behavior but I'm not getting anywhere to fast. Despite what I enter for a variable index it seems to still return the full buffer?

I know I've kind of provided limited information. I don't want anyone to feel obligated "do the work for me" it for me but I think I could benefit from a push. Let me know what I can do help to provide understanding on my question. I'll provide updates on any other questions I may have.

TLDR; In short I need a layman explanation of what the FDwfAnalogInStatusData2 does based on what index number is provided, and how i is used to align the data.

 

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Hi @Chazzo

The record should be used to capture more samples than the device buffer size using streaming data from device. Due to this it has a rate limitation depending on device or protocol (like 4-8MHz on 2 channels for AD2 and 125MHz on 1 channel for ADP3X50 which uses DDR buffering).
If you want to capture up to device buffer samples (8-128Ki depending on device/configuration) you can use the normal (single) mode up to max rate 100/125MHz on all channels. If you capture up to device buffer with record this can also go up to max rate.

When recording the device doesn't know when the trigger will occur but it will collect at least the specified number of samples before looking for trigger and it will stop when the specified after-trigger samples are collected. If the trigger position is zero the streaming will start only on trigger.

With record we are getting data chunks from the device in a loop:
while True:
Fetching device status and data:
    dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts))
This will tell how many new samples are available and if device buffer overflow occurred:
    dwf.FDwfAnalogInStatusRecord(hdwf, byref(cAvailable), byref(cLost), byref(cCorrupted))

With this we are getting the data samples in our buffers and making sure to not overflow it when it gets to the end:
    while cAvailable.value>0:
        cSamples = cAvailable.value
        if iSample+cAvailable.value > nSamples:
            cSamples = nSamples-iSample
        dwf.FDwfAnalogInStatusData2(hdwf, c_int(0), byref(rgdSamples1, sizeof(c_double)*iSample), c_int(iBuffer), c_int(cSamples)) # get channel 1 data

        dwf.FDwfAnalogInStatusData2(hdwf, c_int(1), byref(rgdSamples2, sizeof(c_double)*iSample), c_int(iBuffer), c_int(cSamples)) # get channel 2 data
        iBuffer += cSamples
        cAvailable.value -= cSamples
        iSample += cSamples
        iSample %= nSamples

Like we have an 10M buffer earlier filled up to 9999K and we get 3K new samples:
First get 1K to full it up to 10M:
        FDwfAnalogInStatusData2(hdwf, ch#, &Buffer10M[9999K], 0, 1K)
Then get the remaining 2K to our buffer start:
        FDwfAnalogInStatusData2(hdwf, ch#, &Buffer10M[0], 1K, 2K)

Exit loop when done:
    if sts.value == DwfStateDone : # done
        break

Then align the data in our buffer so the last captured sample to be the at the end:
    rgdSamples1 = rgdSamples1[iSample:]+rgdSamples1[:iSample]
    Buffer10M = Buffer10M[last+1....end] | Buffer10M[0...last]

 

Link to comment
Share on other sites

  • 0

Thanks for your response @attila. Your response has given me a bit to think about.

I was doing some more reading in the sdk and was reminded of acquisition mode 2 for FDwfAnalogInAcquisitionModeSet. The "Heart Scanner" mode. In the description it says: "The IndexWrite shows the buffer write position." I'm assuming there is a property or some method to retrieve this. I haven't been able to find an example using it. My hope is that it is a simpler way to align data. Maybe the circular buffer is doing a bit more than I need? I don't need any kind of triggering functionality, I just need to be able to take the new updated data from the buffer and append it the data being saved.

Many thanks.

Link to comment
Share on other sites

  • 0

Hi @Chazzo

The scan Screen/Shift modes should be used at low rates, see WF SDK/ samples/ py/ AnalogIn_ShiftScreen.py
The scan is similar to unlimited and no trigger mode Record but this later one can also be used at higher rates and it provides buffer overflow notification.
I'm thinking on adding a new function to simplify this record process...

Link to comment
Share on other sites

  • 0

Hi @attila, thanks for you suggestions. I am recording slow signals. Some of the tests I am running can take several minutes to run. 

Just to clarify, is there a way to get the buffer write position using "IndexWrite"? In the documentation it states "The IndexWrite shows the buffer write position". Its been suggested that I can get the write position which should make it easy to identify new data and unique data to store. Or is it not what I think it is? I haven't found any examples using this variable or method. 

One thought I have is to compare the last buffer to the newbuffer dump. Simply remove all values that match and are also in a series to the previous buffer. This is assuming that the data is unique and I feel is bad practice. One area this may fail is if of course you are receiving a constant voltage. 

Link to comment
Share on other sites

  • 0

Good news! I was able to figure it out. As you would have probably suggested it is the FDwfAnalogInStatusIndexWrite() function. I'm not the most familiar with ctypes so I messed around with the syntax and looked at some other variables and was able to figure out the pass by reference syntax. This was the functionality I was looking for! 

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...