• 0
Sign in to follow this  
Kawai

How to transmit 1000bit data to the pattern generator by using VBA or Pyhthon in Analog Discovery 2.

Question

Hello,

 

I’m trying to generate the data whose length is over 1000bits by using the pattern generator in Analog discovery 2. I use Microsoft Excel VBA or Python and command FDwfDigitalOutDataSet. But the VBA cannot treat the int data whose length is over 1000bit in binary. Is there any way to transmit the large data to the pattern generator by using VBA or Python?

 

Thanks.

Share this post


Link to post
Share on other sites

11 answers to this question

Recommended Posts

  • 0

Hi @Kawai

You can use the 4th configuration which allocates 16k samples for the pattern generator. 

Use configuration index 3 (zero based) in the SDK, like:
FDwfDeviceConfigOpen(-1, 3, &hdwf)

i4.png.13787a78bb78ee9e59f3dde27c88efe9.png

Share this post


Link to post
Share on other sites
  • 0

 

Hi Attila

 

Thank you for your reply.

Actually, I already use the command FDwfDeviceConfigOpen(-1, 3, &hdwf) and I successfully use the 16k buffer.

My question is how to send the data to the 16k buffer. I want to use command FDwfDigitalOutDataSet in VBA or Python for automatic measurement (not Wavefomr GUI). For example, I want to generate the data 11111111….11111111(1k bit stream) by using the pattern generator. But to my knowledge, FDwfDigitalOutDataSet(hdwf, 1, &HFFFFFFFF, 33) is the longest bit setting and I can set only 32 bit data stream like 11..11(32 bit stream) . Is there any way to set the 1k bit stream by using the command FDwfDigitalOutDataSet. ?

I don’t want to decrease the operating frequency because I want to send short data stream after 1k bit data.

 

Thanks.

Share this post


Link to post
Share on other sites
  • 0

Hi @Kawai

The FDwfDigitalOutDataSet rgBits argument is an array and these bits are output in least significant bit first order.

It was a long time ago when I used VB... The rgBits is "var () As Any" and you could use "Dim rg() As Byte".

 

FDwfDigitalOutDataSet(
HDWF hdwf, int idxChannel, void *rgBits, unsigned int countOfBits)


Parameters:

- hdwf – Interface handle.

- idxChannel – Channel index.

- rgBits – Custom data array.

- countOfBits – Number of bits.

The function above is used to set the custom data bits. The function also sets the counter initial, low and high value, according the number of bits. The data bits are sent out in LSB first order. For TS output, the count of bits is the total number of output value (I/O) and output enable (OE) bits, which should be an even number.

Custom Data Bits

BYTE

0

 

 

 

 

 

1

 

 

Bits

0

1

2

3

...

7

0

1

...

Output

I/O(0)

OE(0)

I/O(1)

OE(1)

...

OE(3)

I/O(4)

OE(4)

...

Edited by attila

Share this post


Link to post
Share on other sites
  • 0

Hi Attila

 

I tried the code listed below. The initial setting is not listed.

 

Public Declare PtrSafe Function FDwfDigitalOutDataSet Lib "dwf.dll" (ByVal hdwf As Long, ByVal idxChannel As Long, ByRef var() As Any, ByVal countOfBits As Long) As Long

Dim rg(8) As Byte

 

    rg(0) = 0

    rg(1) = 1

    ...

    rg(7) = 1

 

Call FDwfDigitalOutDataSet(hdwf, 7, rg(), 8)

 

But the data array rg() doesn’t seem to be transferred to pattern generator.

The output depends on only countOfBits.

Is it possible for Analog Discovery 2 to receive the array data ?

If VBA is not useful for this situation, Python code example is also OK for me.

 

Share this post


Link to post
Share on other sites
  • 0

Hi @Kawai

The function expects bit sequence. Bits from an array of bytes will be used in least significant bit and byte first.

Each byte contains 8 bits. To send 9 bits use:

rg(0) = 0xAA // this is sequence of 8 bits: 01010101
rg(1) = 0x01 // from this byte we use 1 bit: 1
FDwfDigitalOutDataSet(hdwf, 7, rg(), 9)

Share this post


Link to post
Share on other sites
  • 0

Hi Attila

 

I tried this code.

 

    rg(0) = &HAA

    rg(1) = &H1

    Call FDwfDigitalOutDataSet(hdwf, 7, rg(), 9)

 

The expected output of the pattern generator is 010101011.

But in my condition the output of the pattern generator is 100000000.

How to set the output data of the pattern generator?

Share this post


Link to post
Share on other sites
  • 0

Hi @Kawai

I'm not sure what could be wrong there.

Could it be a problem on the receiver side? In case you are using a different device make sure to have ground connection between these.

For me the following code gives the expected result:

rgdSamples = (c_byte*6)(*[0xFF,0x80,0xC0,0xE0,0xF0,0x00])
# 1kHz sample rate custom on IO pin 3
dwf.FDwfDigitalOutEnableSet(hdwf, c_int(3), 1)
dwf.FDwfDigitalOutTypeSet(hdwf, c_int(3), DwfDigitalOutTypeCustom)
dwf.FDwfDigitalOutDividerSet(hdwf, c_int(3), c_int(int(hzSys.value/1e3))) # 100MHz/1k for 1kHz sample rate
dwf.FDwfDigitalOutDataSet(hdwf, c_int(3), byref(rgdSamples), c_int(6*8))

dwf.FDwfDigitalOutConfigure(hdwf, c_int(1))

i1.png.d56bdad29ec442c5fe74adb237519fa6.png

Share this post


Link to post
Share on other sites
  • 0

Hi attila

 

Thanks, I tried your code in Python and I got the same result as you mentioned.

I think the receiver side is OK.

Is there any way to use set the pattern generator in VBA? If no, I’m going to use Python.

Share this post


Link to post
Share on other sites
  • 0

Hi Attila

 

Thanks, I successfully send the data to the pattern generator. The codes are shown below.

I use rg instead of rg() in Declare sentence.

 

Public Declare PtrSafe Function FDwfDigitalOutDataSet Lib "dwf.dll" (ByVal hdwf As Long, ByVal idxChannel As Long, ByRef rg As Any, ByVal countOfBits As Long) As Long

Call FDwfDigitalOutDataSet(hdwf, 7, var(0), 16).

 

But I found another question that the pattern generator output depends on the setting FDwfDigitalOutCounterInitSet. I’ll make another thread about this question and close this thread.

 

Thanks.

Share this post


Link to post
Share on other sites
  • 0

I got the following question:

My task is to send custom data on Pattern Generator and Capture it in Logic Analyzer.
I was trying to get familiarize by going through the docs/examples.
When sent the custom data as mentioned in DigitalOut_Pins.py, I could see the waveform as below: 
rgdSamples = (c_byte*6)(*[0xFF,0x80,0xC0,0xE0,0xF0,0x00])
# 1kHz sample rate custom on IO pin 3
dwf.FDwfDigitalOutEnableSet(hdwf, c_int(3), 1)
dwf.FDwfDigitalOutTypeSet(hdwf, c_int(3), DwfDigitalOutTypeCustom)
dwf.FDwfDigitalOutDividerSet(hdwf, c_int(3), c_int(int(hzSys.value/1e3))) # 100MHz/1k for 1kHz sample rate
dwf.FDwfDigitalOutDataSet(hdwf, c_int(3), byref(rgdSamples), c_int(6*8))
dwf.FDwfDigitalOutConfigure(hdwf, c_int(1))

i1.png

I have used your picture from one of your response in another thread. 
My main question is : when the internal frequency is 100MHz and divider is set to 100MH/1K, how does it provide 1KHz sample rate?
Also I don't understand how come the pulse width varying from 1ms to  2ms to 3ms to 4ms and 8 ms. and then repeats.
Could you please care to explain how the above settings results in this waveform?
Thanks a Lot.

 

With divider value of 100000 the bit sample rate will be 1kHz, 1ms, 100MHz/100000
The bits are sent out in least significant bit first order, like: 0xFF will be 8ms high; 0x80 will be 7ms low and 1ms high; 0xC0 will be 6ms low and 2ms high;
By default the pattern is repeated. If you want to output the pattern only once, set the run time equal to the pattern length in time:
dwf.FDwfDigitalOutRunSet(hdwf, c_double(6*8/1e3)) # 48ms = 6*8 bits /1kHz = 48 bits * 1ms
dwf.FDwfDigitalOutRepeatSet(hdwf, c_int(1)) # once

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
Sign in to follow this