Jump to content
  • 0

Receiving ASCII bits from a UART Controller by using Logic Analyzer APIs


Lesiastas

Question

Greetings! I'm working on a project involving the use of the Analog Discovery 2's Logic Analyzer feature and I've been tasked to recreate its function through the use of a VB6 Wrapper. I'm having a hard time finding the correct APIs to use. The Python sample codes in the WaveForms SDK folder isn't working when I tried to use it in receiving ASCII bits from a UART controller. For people like me that aren't good in coding, it would be great if it would at least contain more examples showing the different uses of the settings present in the Logic Analyzer GUI. So I just set some additional APIs that could help my code and here's the code that I've made so far:

image.png.f97c985f5fe1a1018080fb3df8063bdb.png

The main showstopper that I've encountered right now is the highlighted API in the picture above. It's suppose to retrieve the acquired data samples from the instrument, but it still cannot receive the bits of the ASCII character that I'm sending. This is the result that I'm trying to replicate using the Logic Analyzer APIs:

image.png.97656181c031c4f5c0373793fdd40106.png

I used a UART Controller as the Tx to the VB6 Wrapper while I was doing breakpoint debug in it to see the received bits. These are the results that I got:

image.thumb.png.82af994684f5d703def490e6a5bc4d92.png

It received a "1" and "0" bits unlike the one in the Logic Analyzer GUI. I could be wrong, but I think the problem is I still haven't set the Trigger and Trigger Detector APIs for the Logic Analyzer properly.

Any advice guys?

Link to comment
Share on other sites

16 answers to this question

Recommended Posts

Hi @Lesiastas

For FDwfDigitalUart functions you don't have to configure the digital-in or -out. The uart functions will do this.

1. For repeated capture use FDwfDigitalInAcquisitionModeSet acqmodeSingle 0 . The other options depend on your reqirements.

2. Please take a look at the manual and examples in WF SDK

image.png

image.png.20e36a37e47784204e83be386b3a4918.png

DigitalIn_Trigger.py:
dwf.FDwfDigitalInTriggerSet(hdwf, c_int(0), c_int(0), c_int(0), c_int(1<<7)) # DIO7 falling edge

Link to comment
Share on other sites

Hi @Lesiastas

In the SDK the digital-in functions provides raw data, this needs to be interpreted in the custom application or script.
See the SDK/ samples/ py/ DigitalIn_Spi_Spy.py
An example UART interpreter can be found in the WF application/ Logic Analyzer/ Custom

 

Link to comment
Share on other sites

Hi @attila

Thanks to all of your advice regarding the Signal Function of the Logic Analyzer GUI. Its working already and we decided to move forward to what our project really wants to use for the Parallel Tx and Rx using the Analog Discovery 2.

Question: What is the API equivalent of the "Add UART" setting in the WaveForms Logic Analyzer GUI? And is it possible to be used for 2 or more Rx Channels?

image.png

These are the results that we want to replicate through the use of the Logic Analyzer APIs:
image.png.5c96cdce02f4414b37fae1a20f8c7e47.png

Regards,

Lesiastas

 

Link to comment
Share on other sites

Hi @Lesiastas

The samples mean the DIO values collected at the same time. The bits in each sample correspond to DIOs.
Like with FDwfDigitalInSampleFormatSet(hdwf, 16) you will get UInt16 samples, where bits from 0 to 15 correspond to DIO 0 to 15.

Such UInt16 sample array can be converted to BitArrays like this:

Dim bitarray(15) As BitArray
For b As Integer = 0 To 15
    bitarray(b) = New BitArray(cSamples)
    For i As Integer = 0 To cSamples - 1
        bitarray(b)(i) = System.Convert.ToBoolean((rgwData(i) >> b) And 1)
    Next
Next

 

Link to comment
Share on other sites

Hi @attila

Regarding your advice on the FDwfDigitalInTriggerSet API, we want to use all of the 16 DIO channels for the Rx Side.
So the change that I did in line with your suggestion is FDwfDigitalInTriggerSet(handle, 0, 0, 0, (sample >> &HFFFF) & 1) to enable all of the channels.

We want to receive values that are only 0s and 1s since this is the result we are trying to replicate base from the WaveForms Logic Analyzer GUI.
Is it possible to have all of the 16 DIO channels' value as 0/1?
 

Thank you for your guidance,
Lesiastas

Link to comment
Share on other sites

Hi @attila

Thanks for the advice regarding the FDwfDigitalInTriggerSet API.

13 hours ago, attila said:

To have DIO7 value as 0/1 from a sample use: (sample>>7)&1

Sorry but, can you please explain what do you mean by "sample"? Is it the format bit in FDwfDigitalInSampleFormatSet or the size of the sample in FDwfDigitalInBufferSizeSet?

Sincerely yours, 
Lesiastas

Link to comment
Share on other sites

Hi @Lesiastas

The FDwfDigitalUart can handle only one RX at a time.

The captured samples with FDwfDigitalInStatusData represent DIO values as bits, in a 16 bit integer from LSbit DIO-0 to MSbit DIO-15
Like in 128, or hex0080, or binary0000000010000000 the DIO7 is 1
To have DIO7 value as 0/1 from a sample use: (sample>>7)&1

 

Link to comment
Share on other sites

Hi @attila

A follow-up question: Does the FDwfDigitalUart Function support 2 Tx and 2 Rx? 
Because that's what we want to do for this project and the APIs of the Pattern Generator and Logic Analyzer is seen to be configurable to do this.

Sincerely yours, 
Lesiastas

Link to comment
Share on other sites

Hi @attila

Thanks for bearing with my tedious questions and sorry if I may be a bother.
I got the bits of the ASCII character that I'm sending using the UART Controller with 9600 baud rate.

What I did was set the divisor to the internal frequency of AD2 to 9600 and used that in FDwfDigitalOutDividerSet and FDwfDigitalInDividerSet so that the devices' baud rate can match up with each other. Here's the changes I did:

Dim phzFreq As Double
Dim hzDI As Double 
Dim hzData As Double : hzData = 9600 'Divisor to AD2's Internal Clock


'DigitalOut API
FDwfDigitalOutDividerSet(handle, idxChannel, (phzFreq / hzData))

'DigitalIn API
FDwfDigitalInDividerSet(handle, (hzDI / hzData))

I thank you as well regarding the FDwfDigitalInTriggerSet API, I changed the 0xFFFF to (1<<7) to try what it does. I observed that the bits that was supposed to be "1" became a different value depending on the channel that I used.

Trial done: Sending ASCII "a" using UART Controller

- DIO #0, #7, #1, and #2 were used to characterize results.
- FDwfDigitalInTriggerSet(handle, 0, 0, 0, (1 << 0))
- FDwfDigitalInTriggerSet(handle, 0, 0, 0, (1 << 7))
- FDwfDigitalInTriggerSet(handle, 0, 0, 0, (1 << 1))
- FDwfDigitalInTriggerSet(handle, 0, 0, 0, (1 << 2))

Expected and wanted result using ASCII "a" = 1000 0110

Actual result using DIO #0 = (1)000 0(1)(1)0
image.png.4cfab07fda6ef5dd34d849d665a6160d.png
Actual result using DIO #7 = (128)000 0(128)(128)0 

image.png.53e07b451da5667941e479ae936cd322.png

Actual result using DIO #1 = (2)000 0(2)(2)0 

image.png.28693bd92a09e42008fce0d5ef5d1570.png

Actual result using DIO #2 = (4)000 0(4)(4)0 

image.png.6b6e2d30bb5947e41668c05d0361ed6f.png

I suspect that this is because with the order of significant bits.
Is there a way to replicate the results on DIO #0 to all of the other channels or is this how it really works?

Regards, 

Lesiastas

Link to comment
Share on other sites

Hi @attila

Thanks for the advice ? I'll try just that.
Sorry for more questions but:


1. What values should I set to the FDwfDigitalInAcquisitionModeSet, FDwfDigitalInDividerSet, FDwfDigitalInSampleModeSet, FDwfDigitalInTriggerPositionSet, and FDwfDigitalInTriggerSet for Repeated Acquisition Mode in Analog Discovery 2? 

2. And lastly, what values should I set to the FDwfDigitalInTriggerSet in order for it to trigger on Falling Edges using DIO Channel 0?

Yours truly,
Lesiastas

Link to comment
Share on other sites

Hi @attila

I found a thread which seems very similar to what I'm working on.

The main difference is I want to use a UART Controller to send an ASCII character and have the FDwfDigitalInStatusData API display the bits of the ASCII character.
Here's the VB6 code that I've come up with the help of the thread that I read.

Imports UART_Single_Acquisition.ComClass1
Imports System.Windows.Forms
Imports System.Text
Imports System.Text.RegularExpressions
Public Class Form1
    Private Sub UartButton1(ByVal sender As System.Object, ByVal e As EventArgs) Handles Button1.Click

        Dim UART As New UART_Single_Acquisition.ComClass1
        Dim handle As Integer
        Dim sts As Byte
        Dim phzFreq As Double
        Dim hzDI As Double
        Dim hzData As Double : hzData = 9600
        Dim idxChannel As Integer : idxChannel = 0
        Dim cSamples As Integer : cSamples = 2 * 8
        Dim rgwData(cSamples) As UInt16
        'Dim pfAuto As Integer

        'Opening Device
        Call AD2_FDwfDeviceOpen(-1, handle)
        Call AD2_FDwfDigitalOutReset(handle)
        Call AD2_FDwfDigitalInReset(handle)
        'DigitalOut APIs
        Call AD2_FDwfDigitalOutInternalClockInfo(handle, phzFreq)
        Call AD2_FDwfDigitalOutEnableSet(handle, idxChannel, 1)
        Call AD2_FDwfDigitalOutIdleSet(handle, idxChannel, 2) 'DwfDigitalOutIdleHigh As Byte = 2
        Call AD2_FDwfDigitalOutDividerSet(handle, idxChannel, (phzFreq / hzData))
        'Call AD2_FDwfDigitalOutCounterSet(handle, idxChannel, 1, 1)
        Call AD2_FDwfDigitalOutRunSet(handle, (cSamples / phzFreq))
        Call AD2_FDwfDigitalOutRepeatSet(handle, 1)
        
        'DigitalIn Parameters
        Call AD2_FDwfDigitalInInternalClockInfo(handle, hzDI)
        Call AD2_FDwfDigitalInTriggerSourceSet(handle, 3) 'trigsrcDetectorDigitalIn As Byte = 3
        Call AD2_FDwfDigitalInTriggerAutoTimeoutSet(handle, 10.0)
        Call AD2_FDwfDigitalInSampleModeSet(handle, 1) 'DwfDigitalInSampleModeSimple As Byte = 0
        Call AD2_FDwfDigitalInDividerSet(handle, (hzDI / hzData))
        'Use 8 for 8bit, 16 for 16bit and 32 for 32bit samples
        Call AD2_FDwfDigitalInSampleFormatSet(handle, (16))
        Call AD2_FDwfDigitalInBufferSizeSet(handle, cSamples)
        Call AD2_FDwfDigitalInTriggerPositionSet(handle, (cSamples - 1))
        Call AD2_FDwfDigitalInTriggerSlopeSet(handle, 1) 'DwfTriggerSlopeFall As Byte = 1
        'Call AD2_FDwfDigitalInTriggerSet(handle,0,0,&HFFFF,&HFFFF)

        'DigitalIn Enable
        Call AD2_FDwfDigitalInConfigure(handle, 0, 1)
        'DigitalOut Enable
        Call AD2_FDwfDigitalOutConfigure(handle, 1)

        'Acquisition State
        Call AD2_FDwfDigitalInStatus(handle, 1, sts)
        '1* for 8bit, 2* for 16bit, 4* for 32bit samples
        Call AD2_FDwfDigitalInStatusData(handle, rgwData, (2 * cSamples))

        'Done
        Call AD2_FDwfDeviceClose(handle)

    End Sub
End Class

Sincerely yours,
Lesiastas

Link to comment
Share on other sites

Hi @Lesiastas

WaveForms application trigger options are similar to the following SDK settings:
None     = FDwfDigitalInTriggerSourceSet(hdwf, trigsrcNone)
Auto      = FDwfDigitalInTriggerSourceSet(hdwf, other than trigsrcNone) FDwfDigitalInTriggerAutoTimeoutSet(hdwf, not zero
Normal = FDwfDigitalInTriggerSourceSet(hdwf, other than trigsrcNone) FDwfDigitalInTriggerAutoTimeoutSet(hdwf, zero

Link to comment
Share on other sites

Hi @attila

A follow-up question: What is the API function to set the Trigger Mode settings? (The highlighted settings in the picture below)
I've checked the APIs available in the reference manual but there is no TriggerMode API in there.
image.png.f416ba902f528d12eb4ed3c6647a846c.png
 

Sincerely yours,

Lesiastas

 


 

Link to comment
Share on other sites

Hi @attila 

Is it not possible to replicate the function of the Logic Analyzer GUI without using the FDwfDigitalUart functions? Because I was advised to see if I can get the Signal Bus functions of the Logic Analyzer GUI to work in the API first. Only then we'll proceed with using the UART Bus present in the Logic Analyzer GUI. Sorry if its a bit confusing, but I'll also try your advice :) 

 


 

image.png

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...