• 0
Lesiastas

Intelligent Record Mode for the Logic Analyzer

Question

Greetings!

i'm working on a project involving the use of the Logic Analyzer function of the Analog Discovery 2. I have observed that its Record Mode can be used to capture huge samples of data. The only problem that I'm having is it takes too long for the Record Mode to fill its memory before returning results even when the sample size used is 20k. 

I would like to know if it is possible to make the Record Mode of the Logic Analyzer intelligent in a way by making it stop filling its memory when the data to be transmitted has already been received. Because the application that I'm using Record Mode for should do so in order to return results faster.

Any advice would help a lot.

Best regards,
Lesiastas

Share this post


Link to post
Share on other sites

13 answers to this question

Recommended Posts

  • 0

Hi @attila

Thanks for pointing that out. I've tried it in the WaveForms GUI Application and the way I see it, the record mode fills the sample size set before returning results. This will take some additional test time in the application that I'm using it for. 

I've created a custom script for both the Pattern Generator and Logic Analyzer using VB6.(AD2_Time_Testing.rar)
The setup that I am working on is this:

1). I'm using the Pattern Generator to transmit 256 characters. DIOs #0 and #1 are used as the Transmitter pins.

2). I'm using the Record Mode of the Logic Analyzer to receive a minimum of 9k characters. DIOs #2 and #3 are used as the Receiver pins.

The Tx side is already working well, the only thing that concerns me is the way Record Mode behaves. I need it to stop recording once all of the 256 characters has been received. What I'm getting is it continues recording even though all of the 256 characters has been received already. 

To put it simply, I would like the record mode to behave like 'Single' mode in the WF Logic Analyzer app as well as receive a minimum of 9k characters.

image.png.ce1337e6869236a8b3c566ac53fe5e95.png

Is it possible to set the record mode in this manner? Please check the custom script that I've attached in this post. I'm open to any changes in order to improve it. 

Best regards,
Lesiastas

Share this post


Link to post
Share on other sites
  • 0

Hi @attila 

On 10/24/2019 at 10:50 PM, attila said:

In case you don't need prefill/pretrigger, in the 'Config' set the trigger position to zero.

Does this mean I have to set FDwfDigitalInTriggerPrefillSet(hdwf, 0) to this values?

Best regards,
Lesiastas

 

Share this post


Link to post
Share on other sites
  • 0

Hi @Lesiastas

Is the copying from rgTemp to rgData takes long?
You may try to optimize this with copy or concat VB methods.

In case you are decoding only the DIO-2/3, you can use FallingEdge = &H000C to trigger only on these DIOs.
This way you may need to capture less samples, shortening the record length.

Adding your earlier posts to be easier to put the question in context...

 

Share this post


Link to post
Share on other sites
  • 0

Hi @attila

Thanks for reminding me about some information about my previous posts. 
I've determined why my VB Script is taking too long. It's not because of the Logic Analyzer's Record Mode, it's because of the Analog Discovery 2's FDwfDeviceConfigOpen.

I've done 10 trials in measuring the Logic Analyzer Record Mode in the VB Script I'm working on: AD2_Time_Testing.rar

image.png.48473af56e0531f662ee3f65a31fb5ff.png

The AD2_RecordStart first enables the trigger for the Logic Analyzer and then starts the transmission of the Pattern Generator. This ensures that data is received. It's average test time is 0.03 seconds, which is acceptable.

The thing that I observed is regarding the FDwfDeviceConfigOpen's test time. I've done 10 trials to measure it and these are the results:

image.png.88e9c1b70151e136090757ca4f61f814.png

I've measured all the other functions in the VB Script that I'm working on.
The DeviceConfigOpen produces the longest time before opening. It takes about 325 milliseconds for the Analog Discovery 2 to open, which is too long.
Can the time it takes for FDwfDeviceConfigOpen to finish be lessened or does it really take this long?

Best regards,
Lesiastas

 

Share this post


Link to post
Share on other sites
  • 0

Hi @Lesiastas

As initialization when you application starts, before calling open set the following option to 0/Run:
dwf.FDwfParamSet(DwfParamOnClose, c_int(0)) # 0 = run, 1 = stop, 2 = shutdown

2 - open always takes 'long' time (~300ms) since the device is powered down on close and reprogrammed on each opening
1 - device remains powered but the outputs are stopped on close, this takes a few ms on open/close *
0 - device continues the output after close (waveform, pattern generation, supplies), the open/close are fast *
*The first open after power up will take 'long' time since the device needs to be programmed.

image.png.3ca3033097afdadfef235e425a0897f5.png

Share this post


Link to post
Share on other sites
  • 0

Hi @attila

Thank you for clearing that one. I'll apply that concept to the code I'm working on.

On 10/24/2019 at 10:50 PM, attila said:

In case you don't need prefill/pretrigger, in the 'Config' set the trigger position to zero.

Does this mean I have to set the following APIs to these parameters:
 


Dim cSamplesAfterTrigger As Long : cSamplesAfterTrigger = 18000
Dim cSamples As Long : cSamplesAfterTrigger = 18000

'Logic Parameters
FDwfDigitalInTriggerSourceSet(phdwf, trigsrcDetectorDigitalIn)
FDwfDigitalInTriggerSet(phdwf, 0, 0, 0, &HFFFF)
FDwfDigitalInDividerSet(phdwf, (100000000.0 / 230400))
FDwfDigitalInSampleFormatSet(phdwf, 8)
FDwfDigitalInBufferSizeInfo(phdwf, BufferSize)

If cSamples > BufferSize Then
FDwfDigitalInAcquisitionModeSet(phdwf, acqmodeRecord)
FDwfDigitalInTriggerPrefillSet(phdwf, 0)
FDwfDigitalInTriggerPositionSet(phdwf, cSamplesAfterTrigger)
FDwfDigitalInSampleSensibleSet(phdwf, &HFFFF)
Else
FDwfDigitalInBufferSizeSet(phdwf, cSamples)
FDwfDigitalInTriggerPositionSet(phdwf, cSamples - 10)
End If

Best regards,
Lesiastas

Share this post


Link to post
Share on other sites
  • 0

Hi @Lesiastas

No. You should leave it as it is.
From your question I thought you are using the WF application.

To reduce the device connection/opening latency use the on-close param.

To 'intelligently' stop the recording process you could analyzer the received data chunks (samples) and when there is no UART activity on the lines for X time (N samples). This depends on you project...

Share this post


Link to post
Share on other sites
  • 0

Hi @attila

I'm really sorry for the confusion that I've caused you. What I'm doing is I'm observing the behavior of the AD2 in the WF application and I integrate those into the VB Script I'm working on. Then if I encounter a really hard showstopper, that's when I go and ask the forums for more details.

16 hours ago, attila said:

To reduce the device connection/opening latency use the on-close param.

Thanks for this advice! I'll try exploring the different settings of DwfParamOnClose :) 

16 hours ago, attila said:

To 'intelligently' stop the recording process you could analyzer the received data chunks (samples) and when there is no UART activity on the lines for X time (N samples).

I'm sorry to be a bother but can you please explain this quote further? Thank you in advance!

Best regards, 
Lesiastas

Share this post


Link to post
Share on other sites
  • 0

Hi @Lesiastas

For variable length of transfers you could detect the end of transmission by looking for long idle on UART lines during data reception.
This depends on your project...

Dim cIdle as Integer = 0
Dim nIdle as Integer = cSamplePerBit*100 ''''' 100 bit long idle
...
    For i = 0 To cAvailable - 1
        If (rgTemp(i) & 3) = 3
            cIdle += 1
        Else
            cIdle = 0
        End If
        ...
    Next
    ...
    ''''' UART lines are idle for long time it is probably end of transmission
    If cIdle > nIdle 
        Exit While
    End If

 

Share this post


Link to post
Share on other sites
  • 0

Hi @attila

I'm having a hard time figuring out where to insert the snippet of code you've provided. I'd like to ask where should I place it in this VB Script I'm working on.

Public Shared Function AD2_RecordStart(ByVal hdwf As Integer, ByVal fReconfigure As Integer, ByVal fStart As Integer, ByVal fReadData As Integer, ByRef sts As Byte, ByVal cSamples As Integer, ByVal cBuffer As Integer, ByRef cAvailable As Integer, ByRef cLost As Integer, ByRef cCorrupted As Integer, ByRef rgData() As Byte) As Integer

        'Record Parameters
        ReDim rgData(cSamples)
        Dim fOverflow As Boolean : fOverflow = False
        Dim iSample As Integer : iSample = 0

        If cSamples > cBuffer Then ' record
            While iSample < cSamples
                If FDwfDigitalInStatus(hdwf, fReadData, sts) = 0 Then
                    Return 0
                End If
                If sts = DwfStateDone Or sts = DwfStateTriggered Then
                    FDwfDigitalInStatusRecord(hdwf, cAvailable, cLost, cCorrupted)
                    If cLost <> 0 Or cCorrupted <> 0 Then
                        fOverflow = True
                    End If
                    cAvailable = Math.Min(cAvailable, cSamples - iSample)
                    Dim rgTemp(cAvailable) As Byte
                    ' in other programming languages use pass pointer to rgData[iSample]
                    FDwfDigitalInStatusData(hdwf, rgTemp, 1 * cAvailable)
                    For i = 0 To cAvailable - 1
                        rgData(iSample) = rgTemp(i)
                        iSample = iSample + 1
                    Next
                End If
                If sts = DwfStateDone Then
                    Exit While
                End If
            End While
        Else
            While True
                If FDwfDigitalInStatus(hdwf, 1, sts) = 0 Then
                    Return 0
                End If
                If sts = DwfStateDone Then
                    Exit While
                End If
            End While
            iSample = rgData.Length
            FDwfDigitalInStatusData(hdwf, rgData, 1 * rgData.Length)
        End If

    End Function

Best regards, 
Lesiastas

Share this post


Link to post
Share on other sites
  • 0

Hi @Lesiastas

Public Shared Function AD2_RecordStart(ByVal hdwf As Integer, ByVal fReconfigure As Integer, ByVal fStart As Integer, ByVal fReadData As Integer, ByRef sts As Byte, ByVal cSamples As Integer, ByVal cBuffer As Integer, ByRef cAvailable As Integer, ByRef cLost As Integer, ByRef cCorrupted As Integer, ByRef rgData() As Byte) As Integer

        'Record Parameters
        ReDim rgData(cSamples)
        Dim fOverflow As Boolean : fOverflow = False
        Dim iSample As Integer : iSample = 0
        Dim cIdle as Integer = 0
        Dim nIdle as Integer = 3*100 ''''' 100 bit long idle

        If cSamples > cBuffer Then ' record
            While iSample < cSamples
                If FDwfDigitalInStatus(hdwf, fReadData, sts) = 0 Then
                    Return 0
                End If
                If sts = DwfStateDone Or sts = DwfStateTriggered Then
                    FDwfDigitalInStatusRecord(hdwf, cAvailable, cLost, cCorrupted)
                    If cLost <> 0 Or cCorrupted <> 0 Then
                        fOverflow = True
                    End If
                    cAvailable = Math.Min(cAvailable, cSamples - iSample)
                    Dim rgTemp(cAvailable) As Byte
                    ' in other programming languages use pass pointer to rgData[iSample]
                    FDwfDigitalInStatusData(hdwf, rgTemp, 1 * cAvailable)
                    For i = 0 To cAvailable - 1
                        rgData(iSample) = rgTemp(i)
                        iSample = iSample + 1
                        If (rgTemp(i) & 3) = 3
                            cIdle += 1
                        Else
                            cIdle = 0
                        End If
                    Next
                    If cIdle > nIdle 
                        Exit While
                    End If
                End If
                If sts = DwfStateDone Then
                    Exit While
                End If
            End While
        Else
            While True
                If FDwfDigitalInStatus(hdwf, 1, sts) = 0 Then
                    Return 0
                End If
                If sts = DwfStateDone Then
                    Exit While
                End If
            End While
            iSample = rgData.Length
            FDwfDigitalInStatusData(hdwf, rgData, 1 * rgData.Length)
        End If

    End Function

 

Share this post


Link to post
Share on other sites
  • 0

Hi @attila

Thank you for your support regarding the code I'm working on.
I'm still getting a big execution time from this group of codes:

Public Function AD2_RecordStart(ByVal hdwf As Integer, ByVal fReconfigure As Integer, ByVal fStart As Integer, ByVal fReadData As Integer, ByRef sts As Byte, ByVal cSamples As Integer, ByVal cBuffer As Integer, ByRef cAvailable As Integer, ByRef cLost As Integer, ByRef cCorrupted As Integer, ByRef rgData() As Byte) As Integer

        'Record Parameters
        ReDim rgData(cSamples)
        Dim fOverflow As Boolean : fOverflow = False
        Dim iSample As Integer : iSample = 0
        Dim cIdle As Integer = 0
        Dim nIdle As Integer = 3 * 100 ''''' 100 bit long idle

        If cSamples > cBuffer Then ' record
            While iSample < cSamples
                If FDwfDigitalInStatus(hdwf, fReadData, sts) = 0 Then
                    Return 0
                End If
                If sts = DwfStateDone Or sts = DwfStateTriggered Then
                    FDwfDigitalInStatusRecord(hdwf, cAvailable, cLost, cCorrupted)
                    If cLost <> 0 Or cCorrupted <> 0 Then
                        fOverflow = True
                    End If
                    cAvailable = Math.Min(cAvailable, cSamples - iSample)
                    Dim rgTemp(cAvailable) As Byte
                    ' in other programming languages use pass pointer to rgData[iSample]
                    FDwfDigitalInStatusData(hdwf, rgTemp, 1 * cAvailable)
                    For i = 0 To cAvailable - 1
                        rgData(iSample) = rgTemp(i)
                        iSample = iSample + 1
                        If (rgTemp(i) & 3) = 3 Then
                            cIdle += 1
                        Else
                            cIdle = 0
                        End If
                    Next
                    If cIdle > nIdle Then
                        Exit While
                    End If
                End If
                If sts = DwfStateDone Then
                    Exit While
                End If
            End While
        Else
            While True
                If FDwfDigitalInStatus(hdwf, 1, sts) = 0 Then
                    Return 0
                End If
                If sts = DwfStateDone Then
                    Exit While
                End If
            End While
            iSample = rgData.Length
            FDwfDigitalInStatusData(hdwf, rgData, 1 * rgData.Length)
        End If

    End Function

I transmitted 256 characters and it was done after 12 seconds. I also transmitted 510 characters but it took even longer to finish it. It took about 20.5 seconds before it could finish and the big contributor to this execution time is the snippet of code above.

I think the code could be simplified but I'm having a hard time to determine which to change.
Is there any way to work around this issue? Any advice would really help.
Thanks in advance.

Best regards,
Lesiastas

 

 

Share this post


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