Jump to content
  • 0

Strange Behavior when running Multiple Instruments using Python 3 API


cospan

Question

Hi, I'm running into an issue when using Python3 with Analog Discovery 2 on Ubuntu 20.04 LTS box.

Platform: AD2 on Ubuntu 20.04 LTS. Here is a dump for a small 'enumerate' script used to identify the device and software, let me know if you need anything else.

FTDI Version: 0x10408
Devices: 1
  1: SN: b'210321A36017' : b'Digilent USB Device' Flags: 0x2 Type: 0x8 ID: 0x4036014 Loc ID: 0x10c

DMGR Version: b'2.9.3'
Devices: 1
  1: SN: b'SN:210321A36017' : b'Analog Discovery 2' PDID: 0x40300360

DWF Version: b'3.14.3'
Devices: 1
  1: SN: b'SN:210321A36017' : b'Analog Discovery 2'

Goal: I am using the AD2 to interface with an IMU. The IMU has a 'Data Ready' signal. The desired outcome would be that I can initiate a SPI read when the 'Data Ready' signal goes low.

Perhaps this isn't the right way to do this but I configured the logic analyzer tool to tell me when the 'Data Ready' line goes low.

To exercise this I use the pattern generate to toggle a pin and then trigger off of that signal in the logic analyzer, much like the example script does.

Problem: If I perform the steps above (configure and run a pattern generator with a toggling waveform and use the logic analyzer to capture it) everything works fine and I get a status of '2' (Done)

If I then configure the SPI tool, specifically the chip select signal, the logic analyzer doesn't work anymore, I keep getting a status of '1'  (Arm) after the SPI device is running. Here is the output I get

 

>$ ./digital_in_strange_test.py
Opening first device
Waiting for acquisition...
Status: 2
   done
Configuring SPI Device
Waiting for acquisition...
Status: 1
Status: 1
Status: 1
Status: 1
Error

 

I've played around with it for a bit but I haven't figured it out, sometimes instead of showing state '1' (Arm) it shows state '3' (Trig). I'm not sure but I think this might happen when I actually toggle the select signal.

 

Here is the script that will demonstrate the issue:

 

#! /usr/bin/env python3

from ctypes import *
from dwfconstants import *
import math
import sys
import time
import numpy

if sys.platform.startswith("win"):
    dwf = cdll.LoadLibrary("dwf.dll")
elif sys.platform.startswith("darwin"):
    dwf = cdll.LoadLibrary("/Library/Frameworks/dwf.framework/dwf")
else:
    dwf = cdll.LoadLibrary("libdwf.so")

hdwf = c_int()
sts = c_byte()

print("Opening first device")
#dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf))
# device configuration of index 3 (4th) for Analog Discovery has 16kS digital-in/out buffer

TEST_OUT = 7

if __name__ == "__main__":
    #dwf.FDwfDeviceConfigOpen(c_int(-1), c_int(3), byref(hdwf))
    dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf))
    if hdwf.value == 0:
        print("failed to open device")
        szerr = create_string_buffer(512)
        dwf.FDwfGetLastErrorMsg(szerr)
        print(str(szerr.value))
        quit()

    ''' Use the Pattern Generator to toggle pin 7'''
    # generate counter
    dwf.FDwfDigitalOutEnableSet(hdwf, c_int(TEST_OUT), c_int(1))
    dwf.FDwfDigitalOutDividerSet(hdwf, c_int(TEST_OUT), c_int(1<<2))
    dwf.FDwfDigitalOutCounterSet(hdwf, c_int(TEST_OUT), c_int(1), c_int(1))
    dwf.FDwfDigitalOutConfigure(hdwf, c_int(1))


    ''' Configure the Logic Analyzer to capture Pin 7'''
    cSamples = 8
    rgbSamples = (c_ubyte*cSamples)()

    dwf.FDwfDigitalInReset(hdwf)
    dwf.FDwfDigitalInInputOrderSet(hdwf, c_int(1)) # with 8 bits DIO-0:7

    dwf.FDwfDigitalInSampleFormatSet(hdwf, c_int(8))
    # set number of sample to acquire
    dwf.FDwfDigitalInBufferSizeSet(hdwf, c_int(cSamples))
    dwf.FDwfDigitalInTriggerSourceSet(hdwf, c_ubyte(3)) # trigsrcDetectorDigitalIn
    #dwf.FDwfDigitalInTriggerSourceSet(hdwf, trigsrcDetectorDigitalIn)
    #dwf.FDwfDigitalInTriggerPositionSet(hdwf, c_int(int(cSamples/2-1)))
    dwf.FDwfDigitalInTriggerPositionSet(hdwf, c_int(0))
    dwf.FDwfDigitalInTriggerSet(hdwf, c_int(0), c_int(0), c_int(1<<TEST_OUT), c_int(0)) # DIO7 falling edge

    # begin acquisition
    dwf.FDwfDigitalInConfigure(hdwf, c_bool(0), c_bool(1))
    print("Waiting for acquisition...")

    count = 0
    while count < 4:
        dwf.FDwfDigitalInStatus(hdwf, c_int(1), byref(sts))
        print("Status:", str(sts.value))
        if sts.value == 2 : # done
            break
        time.sleep(1)
        count += 1

    if sts.value != 2: print ("Error")
    else: print("   done")


    '''
    Enable SPI Device
    '''
    print ("Configuring SPI Device")
    SPI_FREQ = 1e6
    #SPI_FREQ = 1e3
    SPI_SEL = 1
    SPI_SCLK = 0
    SPI_MOSI = 3
    SPI_MISO = 2

    SPI_MODE = 3
    SPI_MSB_FIRST = 1
    dwf.FDwfDigitalSpiReset(hdwf)
    dwf.FDwfDigitalSpiFrequencySet(hdwf, c_double(SPI_FREQ))
    dwf.FDwfDigitalSpiClockSet(hdwf, c_int(SPI_SCLK))
    dwf.FDwfDigitalSpiDataSet(hdwf, c_int(0), c_int(SPI_MOSI))  # 0 DQ0_MOSI_SISO = DIO-2 (SPI_MOSI)
    dwf.FDwfDigitalSpiDataSet(hdwf, c_int(1), c_int(SPI_MISO))  # 1 DQ1_MISO = DIO-3 (SPI_MISO)
    dwf.FDwfDigitalSpiIdleSet(hdwf, c_int(2), c_int(3))         # 0 DQ0_MOSI_SISO = DwfDigitalOutIdleZet
    dwf.FDwfDigitalSpiIdleSet(hdwf, c_int(3), c_int(3))         # 1 DQ1_MISO = DwfDigitalOutIdleZet
    dwf.FDwfDigitalSpiModeSet(hdwf, c_int(SPI_MODE))
    dwf.FDwfDigitalSpiOrderSet(hdwf, c_int(SPI_MSB_FIRST)) # 1 MSB first
    dwf.FDwfDigitalSpiSelect(hdwf, c_int(SPI_SEL), c_int(1)) # CS DIO-1 high (SPI_SEL)


    # begin acquisition
    dwf.FDwfDigitalInConfigure(hdwf, c_bool(0), c_bool(1))
    print("Waiting for acquisition...")


    count = 0
    while count < 4:
        dwf.FDwfDigitalInStatus(hdwf, c_int(1), byref(sts))
        print("Status:", str(sts.value))
        if sts.value == 2 : # done
            break
        time.sleep(1)
        count += 1

    if sts.value != 2: print ("Error")
    else: print("   done")
    dwf.FDwfDeviceCloseAll()

Perhaps I'm missing something. Thanks for any help.

 

Dave

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

Hi @cospan

The protocols use the digital-out/in resources (Pattern Generator and Logic Analyzer) of the device. The FDwfDigitalSpi can't be used at the same time with the FDwfDigitalOut/In

You could eventually use the FDwfDigitalIO functions to control and to read some additional DIOs.

image.png.744211890b22147bd024fae8ea453eb2.png

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...