analogdevicesinc / libsmu

Software abstractions for the analog signal exploration tools.
http://analogdevicesinc.github.io/libsmu/
BSD 3-Clause "New" or "Revised" License
31 stars 31 forks source link

Sample Rate parameter in Session initialize #117

Closed damercer closed 6 years ago

damercer commented 6 years ago

Hello: In Libsmu 1.0 Python bindings there is an optional parameter shown in the source code:

def __init__(self, add_all=True, ignore_dataflow=True, sample_rate=0, queue_size=None):
        """Initialize a session.
        Attributes:
            add_all (bool, optional): Add all attached devices to the session on initialization.
            ignore_dataflow (bool, optional): Ignore sample drops or write timeouts for all
                devices in the session which mainly affects running in continuous mode.
            sample_rate (int, optional): Sample rate to run the session at.
                A sample rate of 0 (the default) causes the session to use the
                default sample rate.
            queue_size (int, optional): Size of input/output sample queues for
                every device (defaults to 10000).
        """

to change the sample rate.

I use the following line to initialize a session: session = Session(ignore_dataflow=True, sample_rate=SAMPLErate, queue_size=MaxSamples) Where SAMPLErate is an integer. This does not seem to actually change/set the sample rate to the value passed. Seems to use default 100 KHz. I tried 75000 and the actual rate remained 100000.

Is this supposed to work or does it also need something different in the firmware to change as well? If not this should be noted in the source code documentation in the mean time.

Thanks Doug

claudiupop commented 6 years ago

Hi, It should work. I made a python program which changes the sample rate, then reads data for a second and then prints the number of samples read. It works as expected.

I attached the program here.

sampleRate.zip

Thanks

damercer commented 6 years ago

I must be doing something wrong then. When I connect an external sine wave source (M2k and Scopy) at 500 Hz I get too many samples per cycle of the sine wave. If I set the sample rate to 50,000 I should get 100 samples between peaks of the sine wave. In the raw data I'm getting 200 samples between peaks which says to me that the sample rate is actually still 100 KSPS?

Here is a csv file of the raw samples. Channel A V contains the 500 Hz signal from M2k/Scopy.

Thanks for checking this out.

Doug

50KSPS-500hz.zip

damercer commented 6 years ago

Here is some other results of testing: Subroutine I use to create session:

#
def ConnectDevice():
    global devx, dev0, dev1, dev2, session, BrdSel, CHA, CHB, DevID, MaxSamples, AWGSAMPLErate
    global bcon, FWRevOne, HWRevOne, FWRevTwo, HWRevTwo, WRevThree, HWRevThree, SAMPLErate

    if DevID == "No Device" or DevID == "m1k":
        SAMPLErate = AWGSAMPLErate # Scope sample rate
        print("Request sample rate: " + str(SAMPLErate))
        session = Session(ignore_dataflow=True, sample_rate=SAMPLErate, queue_size=MaxSamples)
        # session.add_all()
        if not session.devices:
            print 'No Device plugged IN!'
            DevID = "No Device"
            bcon.configure(text="Recon", style="RConn.TButton") #, bg="red")
            return
        session.configure()
        print("Session sample rate: " + str(session.sample_rate))
        MakeBoardScreen()
        SelectBoard()
        bcon.configure(text="Conn", style="GConn.TButton")
#

This is what gets printed in the console screen:

Request sample rate: 50000 Session sample rate: 100000

session still seems to be at 100KSPS???

Doug

claudiupop commented 6 years ago

The problem is that after you create the session, the sample rate is set to 50000 and after that you call session.configure() (configure method is used to set the session sample rate) and the implicit value of that parameter is 0 (which means use the default sample rate 100kSps). If you remove the line with session.configure() it should work.

damercer commented 6 years ago

OK This is what's happening. When I run the session.configure() it resets the sample rate to 100KSPS. If I comment out this line it stays as set in the session initialization. Do I need to pass something to the session.configure() call? Things seem to work without this but I will need to completely retest all the operations of the program again to be sure.

Doug

claudiupop commented 6 years ago

Session.configure() sets the session sample rate, and it takes one parameter, the sample rate that you want for the session. If you don't pass any parameter the session will be configured to run at 100KSPS.