Jump to content
  • 0

Digital In Sample Frequency Is Slow


Empower

Question

Hi, using the GUI I'm able to sample at 100 MHz.  I'd like to replicate this is software using pydwf or the SDK.
image.png.6d236cb01607f3b3b700f1b94c3687f1.png

Here is my example using pydwf.  I have two questions when running this code.

1. This is sampling at 2 MHz, but I expect 50 MHz or 100 MHz.  How to I sample at 100 MHz?  I'm not setting the divider, so I thought this would sample as fast as possible.

2. This is driving out at 1 MHz (measured externally).  I expect this should be 25 MHz.  How is the 1 MHz determined?

# %% Digilent Waveform Digital In

import pydwf
from time import sleep
import matplotlib.pyplot as plt
from pydwf import DwfState, DwfTriggerSource
from pydwf.utilities import openDwfDevice

CH = {'out': 0, 'in': 0}

def main():

    device = openDwfDevice(pydwf.DwfLibrary())
    device.paramSet(pydwf.DwfDeviceParameter.Frequency, int(100e6))

    digital_out = device.digitalOut
    digital_in = device.digitalIn

    # Configure for 1 MHz out
    digital_out.enableSet(CH['out'], True)
    digital_out.dividerSet(CH['out'], 1)
    digital_out.counterSet(CH['out'], low_count=2, high_count=2)

    digital_in.inputOrderSet(dio_first=True)

    clock_frequency = digital_in.internalClockInfo()
    divider_count = digital_in.dividerGet()
    digital_in.sampleFormatSet(num_bits=1) # 1 bit per sample format
    number_samples = 64
    digital_in.bufferSizeSet(number_samples)
    digital_in.triggerSourceSet(DwfTriggerSource.DetectorDigitalIn)
    digital_in.triggerPositionSet(0)
    digital_in.triggerSet(level_low=0, level_high=0, edge_rise=1<<CH['in'],
                        edge_fall=0)
    print(f'clock frequency: {clock_frequency/1e6} MHz')
    print(f'sample frequency: {clock_frequency/divider_count/1e6} MHz')

    digital_in.configure(reconfigure=False, start=True)

    digital_out.configure(start=True)

    while True:
        status = digital_in.status(read_data_flag=True)
        print(f'status: {status}')
        if status == DwfState.Done:
            print("done")
            break
        sleep(0.1)

    data = digital_in.statusData(number_samples)
    device.close()

    plt.plot(data, marker='.')
    plt.show()

# %% Main
if __name__ == '__main__':
    main()

 

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

I added this line to the setup.  The sample rate is still slow (2 MHz).  Is this expected?

digital_in.dividerSet(int(clock_frequency/100e6))

Another odd behavior, if I change the internal clock, the first run of the script shows the correctly-changed internal clock value and the second run of the same, unmodified script shows the internal clock is 1/2 of what it is set to.  

Here I set the internal from 80 MHz to 100 MHz and the script correctly reports 100 MHz.  The script output is shown below.

image.png.25bff39aa5f293a35158efae73f10141.png

Then, on my second run of the same script, the device unexpectedly reports 50 MHz.  The output of second run of the same script is shown below.

image.png.51b4cdf197e0f22f975e50f560af0617.png

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