Jump to content
  • 0

Analog Discovery 3 Custom Waveform and Continuous Clock


Empower

Question

How do I set up the digital output such that I have a continuous clock and then periodically send a custom waveform?  I'm using Python pydwg.  The closest I've been able to get is to set up the DigitalOutput Counter to create the clock and setup DigitalOutput Custom for the pattern.  However, when the pattern ends, so does the counter.  The image shows an example my intended behavior.

image.png.bb0268643f90ae7598b439a599321eef.png

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

@Fausto This code generates the embedded captured waveform.  In this example, I would like channel 0 to run continuously.
 

import pydwf
from pydwf.utilities import openDwfDevice

# Define "Custom" waveform
pattern = '1' * 100 + ('0' * 5 + '1' * 5 + '0' * 5 ) * 100 + '1' * 100

clock = 80e6 # MHz

# Initialize DigitalWaveForm device
dwf = pydwf.DwfLibrary()
device = openDwfDevice(dwf)
device.paramSet(pydwf.DwfDeviceParameter.Frequency, int(clock))
digital_out = device.digitalOut

# Initialize DigitalOut channels
for channel in [0, 1]:
    digital_out.enableSet(channel, True)
    digital_out.outputSet(channel, pydwf.DwfDigitalOutOutput.PushPull)
    digital_out.idleSet(channel, pydwf.DwfDigitalOutIdle.High)

# Configure channel 0 as a "Pulse" for a clock
digital_out.typeSet(0, pydwf.DwfDigitalOutType.Pulse)
digital_out.dividerSet(0, 32)
digital_out.counterSet(0, 1, 1)

# Configure channel 1 as a "Custom" waveform
digital_out.typeSet(1, pydwf.DwfDigitalOutType.Custom)
duration = 1 / clock * len(pattern) # max 3518437.2088832
# Set duration.  If this is longer the pattern loops
digital_out.runSet(duration)
digital_out.dataSet(1, pattern)

# Start the waveform
digital_out.configure(start=True)

image.thumb.png.2bab839a58cd4ec0f6cd2a64b376231b.png

Link to comment
Share on other sites

  • 0

Hi @Fausto


I made pydwf. I haven't played a lot with custom digital pattern generation other than checking that the basic functionality works; so I can't give an answer from the top of my head. But I can see tomorrow if I can reproduce what you're seeing and hopefully figure out a solution.

Cheers, Sidney
 

Link to comment
Share on other sites

  • 0

Hi @Fausto

I looked into it and I think I found a solution. As usual, the behavior is not fully documented in the SDK documentation, so experimentation is necessary to figure out what's going on.

When you put a digital channel in "Custom" mode, (using digitalOut.typeSet() in pydwf), the behavior is as follows:

  • The call to digitalOut.dataSet() that passes the arbitrary pulse shape data implicitly sets the high/low "counter" values to the number of samples passed. This is the most usual setting, in case the arbitrary data needs to be played back-to-back.
  • It is possible to update the counter lo/hi values afterward, using the pydwf method digitalOut.counterSet(), to change the period of your custom output to something bigger than the length of your custom waveform. However, there are some caveats, as outlined below.

First, only the second argument to digitalOut.counterSet(low, high) is used. A successive call to digitalOut.counterGet() will show (high, high).

Second, the value you can pass (which will determine the period of the waveform) is limited to the digitalOut buffer length (i.e., the number you get when calling digitalOut.dataInfo()).

Third, the value of the bits not specified is fixed to 0 (low voltage).

All this is highly suggestive of how the "digitalOut" mode really works internally. The per-channel DigitalOut buffer is a fixed size, and you can configure an output periodicity that is less than or equal to this buffer size, but not more. That seems to be the rule, which is unfortunately not documented.

For your use case, the best you can do is the following.

First, your device supports multiple configurations. The AD3's default configuration has digital output buffers of 2048 samples. However, by picking another configuration, you can increase this number to 32768 (at the cost of smaller analog buffers).

Second, the most natural thing to do for your custom output channel is to just prepare a custom digital pattern that includes the inter-pattern idle period.

I have tested/prototyped this in the attached script. Here, channel 0 produces a 1 kHz clock, while channel 1 periodically (every 10 ms) emits a short active burst of 46 bits with bit lengths of 1 us, followed by an "idle" time of 9954 bit periods.

Notice especially the way I use openDwfDevice, which selects a device configuration that maximizes the size of the DigitalOut instrument buffer.


I hope this helps to get the device to do what you need.

Cheers Sidney

digital_out_test.py

Link to comment
Share on other sites

  • 0

Hi @Empower

Pad the custom pattern with 1s, like it is done here in the app:

image.png

 

If the 2048 samples provided by the default (1st) configuration are not sufficient use the 5th (index 4) device configuration.
If you want to keep the custom pattern in phase with the clock, make sure to configure multiple of periods:
custom samples / custom frequency = N / clock frequency, like 2000/100MHz = 20/500kHz

image.png

 

You can use the following parameter to keep the device running after software close, application exit:
dwf.FDwfParamSet(DwfParamOnClose, c_int(0)) # 0 = run, 1 = stop, 2 = shutdown

Link to comment
Share on other sites

  • 0

@reddish and @attila thanks for your timely responses.  Both of you show a repeating "Custom" pattern, so while I cannot run a continuous "clock" while only running a single Custom pattern.  However in my use case, extending the buffer to 32k, will get me to a solution.  

@attila How do I run dwf.FDwfParamSet(DwfParamOnClose, c_int(0)) # 0 = run, 1 = stop, 2 = shutdown using pydwf?   I can't find FDwfParamSet.

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