• 0

Digital input pin as interrupt in WaveForms SDK with Analog Discovery 2 or Digital Discovery?


Go to solution Solved by attila,

Question

Is there any way to program an interrupt when a digital input pin goes high in WaveForms SDK with Analog Discovery 2 or Digital Discovery?

I want to write a code (using WaveForms SDK), with which I wait for a digital input pin to go high. After the pin goes high, I want to continue with the program. Something like the following code:

# Some code

while (not digitalInputPinIsHigh()):
  continue

# Continue with the program


The problem is that the pin's output is a pulse that is only high for 30 μs, so if I continuously check the digital input pin until it goes high, I think I can miss the pulse. Is there a way to program an interrupt (some code/function that is executed when the pin goes high)? Something like the following code:

def ISR():
  digitalInputPulseArrived = True

# Some code

digitalInputPulseArrived = False
while (not digitalInputPulseArrived):
  continue

# Continue with the program

 

Edited by Nicolas Gammarano
Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 1
  • Solution

Hi @Nicolas Gammarano

The rate/latency of the communication is higher then 30us, 0.125ms-10ms... depending on USB and system load.

Since you are using the digital-in/out for other tasks, you could connect the 'interrupt' signal to a trigger IO.
Configure the analog-in to trigger on this and you can check for acquisition done, like:

dwf.FDwfAnalogInFrequencySet(hdwf, c_double(1e8)) # short capture is suffice
dwf.FDwfAnalogInTriggerSourceSet(hdwf, trigsrcExternal1) # T1
dwf.FDwfAnalogInConfigure(hdwf, c_bool(True), c_bool(True))

while ...
    while True:
        sts = c_byte()
        dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts))
        if sts.value == DwfStateDone.value :
            break # T1 triggered, capture done, analog-in is automatically rearmed, waiting for next trigger


Edit: You could also use a analog-out channel for similar purpose, checking the remaining repeat count with FDwfAnalogOutRepeatStatus

Edited by attila
Link to post
Share on other sites
  • 0

Thank you @attila

The AnalogIn functions (FDwfAnalogInFrequencySet, FDwfAnalogInTriggerSourceSet, FDwfAnalogInConfigure, FDwfAnalogInStatus) are available in the Analog Discovery 2, but not in the Digital Discovery. Am I right?

Edited by Nicolas Gammarano
Link to post
Share on other sites
  • 0

Thank you @attila.

I have 2 more questions though. 😅

1) How can I configure the pin that will act as a trigger?

Where in the code (if I use FDwfAnalogInTriggerSourceSet or FDwfDigitalInTriggerSourceSet) do you configure which pin is the source of the trigger?

I see the trigsrc constant values in the file dwfconstants.py:

# trigger source
trigsrcNone                 = c_ubyte(0)
trigsrcPC                   = c_ubyte(1)
trigsrcDetectorAnalogIn     = c_ubyte(2)
trigsrcDetectorDigitalIn    = c_ubyte(3)
trigsrcAnalogIn             = c_ubyte(4)
trigsrcDigitalIn            = c_ubyte(5)
trigsrcDigitalOut           = c_ubyte(6)
trigsrcAnalogOut1           = c_ubyte(7)
trigsrcAnalogOut2           = c_ubyte(8)
trigsrcAnalogOut3           = c_ubyte(9)
trigsrcAnalogOut4           = c_ubyte(10)
trigsrcExternal1            = c_ubyte(11)
trigsrcExternal2            = c_ubyte(12)
trigsrcExternal3            = c_ubyte(13)
trigsrcExternal4            = c_ubyte(14)
trigsrcHigh                 = c_ubyte(15)
trigsrcLow                  = c_ubyte(16)

You put trigsrcExternal1 in the code. Does this correspond to pin T1 in the Analog Discovery 2? To which pin does this correspond in the Digital Discovert?
Where can I find the correspondence between each constant (trigsrcExternal1, trigsrcExternal2, trigsrcExternal3, trigsrcExternal4, trigsrcAnalogIn, etc.) and the pin that acts as trigger for each device (in particular for the Analog Discovery 2 and for the Digital Discovery)?

2) How can I configure 2 different triggers?

Now I want to write a code (using WaveForms SDK), where I wait for 2 digital input pins to go high. Something like the following code:

# Some code

# Repeat the while loop until a rising edge in Pin1 is detected
while (not digitalInputPin1IsHigh()):
  
  # Some more code
  
  # Get stuck waiting until a rising edge in Pin2 is detected
  while (not digitalInputPin2IsHigh()):
    continue
  
  # Some more code

# Continue with the program

As I said earlier, both pin outputs are pulses that are high for 30 μs.
Is there a way I can do this with the triggers?

Link to post
Share on other sites
  • 0

Hi @Nicolas Gammarano

See the manual and examples in the WF SDK/ samples/ py like the DigitalIn_Trigger.py

# for Digital Discovery bit order with 32 bit sampling [DIO24:39 + DIN0:15]
dwf.FDwfDigitalInInputOrderSet(hdwf, c_int(1))
....
dwf.FDwfDigitalInTriggerSourceSet(hdwf, c_ubyte(3)) # trigsrcDetectorDigitalIn
dwf.FDwfDigitalInTriggerSet(hdwf, c_int(0), c_int(1<<0), c_int(0), c_int((1<<1)|(1<<2))) # DIO-0 high and (DIO-1 rise or DIO-2 rise)

On DD the DIO-0 represents 24, 1 -> 25, 2 -> 26, ...

image.thumb.png.fd1a20de82dd763cb286a8ac49249eb4.png

Link to post
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