Jump to content
  • 0

API for Setting the Clock Frequency and Custom Data Bits of the Pattern Generator of the Analog Discovery 2


Lesiastas

Question

Greetings! I'm working on a Project involving the use of the Analog Discovery 2's Pattern Generator function. I was tasked to create a VB6 Wrapper in MS Visual Studio 2013 that will perform the functions of the Pattern Generator by calling certain APIs from its dwf VB.NET file. I have two concerns on how to do this. First, as I looked at the WaveFormsSDK sample codes and the WaveForms™ SDK Reference Manual, there is no API available for setting the clock frequency of the Pattern Generator, unlike in its WaveForms GUI. 

image.png.efb8ba917ce14acd12d9726a0c7c2831.png

The only API available is  the FDwfDigitalOutInternalClockInfo, which only retrieves the internal clock frequency, not set it to want I need.

image.png.ee4468848f737d06c483bb3d14b777ac.png

Secondly, what I need is to sucessfully transmit an ASCII character using the APIs of the Pattern Generator. I'm a novice at coding, especially with complicated routines, so I'm having trouble with coding for the FDwfDigitalOutDataSet API.

image.png.550a7fe7453209eeb617355cb867b02f.png

What I want to do is to send an ASCII character using a string variable that will be converted into its binary equivalent using the snippet of codes below and store those values to the rgBits variable, which is a byte array to transmit it. 

image.png.8119d743d2f268c17d9927d4dfe52600.png

For example, I'll use ASCII character "U", convert it to its binary form which is Bin(01010101) and put those values in the rgBits variable to be sent to a UART Controller or Logic Analyzer to see if it was transmitted properly. I came up with these codes but I don't think its the correct way of doing it.  Sorry but I'm really, really not that good at coding. It would really help to receive some advice on how to do it.

'Convert String to Binary
        Dim Text As String = TextBox1.Text
        Dim oReturn As New StringBuilder
        'but first, convert String to Byte()
        Dim PatGenTx As String = ("")
        Dim rgBits() As Byte
        ReDim rgBits(0 To Len(PatGenTx))
        For i = 1 To Len(PatGenTx)
            rgBits(i) = Asc(Mid(PatGenTx, i, 1))
            Debug.Print(rgBits(i))
        Next
        'Then store binary values into byte array
        For Each Character As Byte In ASCIIEncoding.ASCII.GetBytes(Text)
            oReturn.Append(Convert.ToString(Character, 2).PadLeft(8, "0"))
            oReturn.Append(PatGenTx)
        Next
        TextBox2.Text = (oReturn.ToString)
        'Take note: bits order is lsb first
        ' for TS output the count of bits its the total number of IO|OE bits, it should be an even number
        ' BYTE:   0                 |1     ...
        ' bit:    0 |1 |2 |3 |...|7 |0 |1 |...
        ' sample: IO|OE|IO|OE|...|OE|IO|OE|...
        Dim countOfBits As UInteger : countOfBits = 8

Thank you and God Bless you guys. :) 

image.png

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

Hi @Lesiastas

The easiest way would be using the FDwfDigitalUart functions.
See the SDK/ samples/ py/ Digital_Uart.py

You can find VB and C# wrappers in SDK/ samples/ vb and cs 
It is working with VB 2017 but I'm not sure about 2013.

In case you want to use the FDwfDigitalOut functions, for custom pattern the frequency is specified with FDwfDigitalOutDividerSet.
See the DigitalOut_Pins.py and DigitalOut_CustomBus.py examples

image.png

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...