Jump to content
  • 0

AnalogIn triggered by WaveGen (revisited)


eivind_k

Question

Hi,

 

I am using an Analog Discovery 2 module and Windows 10. Up until now I have used the WaveForms GUI to control the AD2. For the current project however, I need to use the WaveForms SDK (dwf.dll version: 3.14.3) from a C/C++ application developed under Visual Studio. Basically I want to have a 200 Hz sine wave trigger the acquisition on scope channels 1+2. I have made a workspace that does exactly what I want it to do using the WaveForms GUI but so far trying to accomplish the same using the SDK and C does not work correctly. Electrically I have connected W1 to 1+ and 2+. The following screen dump shows the WaveForms GUI:

image.thumb.png.68fd2fe83b523ee37bc2e36bc5ae73a9.png

Repeatedly hitting the Record button and then exporting the data to file works fine. All data files starts at the beginning of the sine wave and have a zero crossing at the mid-point trigger position (0 ms).

The enclosed source code started it's life as a C implementation of the AnalogIn_Record_Trigger.py sample file but has since grown in the effort trying to make it work. Looking at the captured data I get larger than expected variations in where scope signals start. As seen in the screen shot the first sample of C1 and C2 should be very close to zero voltage. However, for the SDK version I the first sample of C1 and C2 varies by more that 100 ms.

If someone could shed some light on what possibly could make my code work as intended I would be very happy.

Best regards

Eivind 

 

AnalogIn_Record_trigger.cpp

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

Hi attila,

Thanks for the good advise to wait for the AnalogInStatus() to return DwfStateDone (=2). Seems like I missed this section when translating the AnalogIn_Record_trigger.py to AnalogIn_Record_trigger_py.cpp. That solved my problem (almost)... When running the enclosed c++ program (sorry, still running dwf.dll version: 3.14.3) I get something like the printout enclosed below. In this particular case we got 33 samples the first time the FDwfAnalogInStatusData2() functions are called. However, in this case the first "valid" sample is not at index 0 but rather at index 5. (The index of the first valid sample can vary from 2 to 120 and beyond). Samples prior to this first valid index are the samples preceding the samples at the desired trigger point. When the AnalogInStatus state machine finally returns the DwfStateDone code, the last value of iSample seems to coincide with the index of the sample at (or nearest to) the trigger point; i.e. in this particular case index 5. 

I can certainly use this "feature" to write a workaround to somehow shift the data to index 0 of the rdgSamplesX[] arrays. However, I would rather have my code place the first valid sample AT index 0 without resorting to the workaround. Is this somehow possible?

Best regards

eivind_k

iSample:        0       sts:    3       cAvailable      33      Idx     0
0       -0.134811       -0.133991
1       -0.111823       -0.111141
2       -0.0865024      -0.0856022
3       -0.0618483      -0.0610719
4       -0.0375274      -0.0368776
5       -0.0115406      -0.0106671
6       0.0137798       0.0145353
7       0.038767        0.0397377
8       0.0644206       0.0652762
9       0.0890747       0.0898065
10      0.114062        0.115009
11      0.139382        0.140211
12      0.16437       0.165414
13      0.189357        0.189944
14      0.21501        0.215819
15      0.239664        0.241021
16      0.265318        0.265551
17      0.289306        0.290082
18      0.314293        0.314948
19      0.338947        0.34015
20      0.363934        0.365017
21      0.388588        0.389547
22      0.412909        0.414078
23      0.437563        0.438944
24      0.462218        0.462802
25      0.486538        0.487669
26      0.511193        0.511863
27      0.53518 0.536393
28      0.559168        0.559579
29      0.582823        0.583438
30      0.606477        0.607296
31      0.630798        0.631826
32      0.65412 0.655349
iSample:        5       sts:    2       cAvailable      0
0       -0.137143       -0.136679
1       -0.112156       -0.111477
2       -0.0868355      -0.0862743
3       -0.0615151      -0.0610719
4       -0.0365279      -0.0358695
5       -0.0115406      -0.0106671  <==== First good sample
6       0.0137798       0.0145353
7       0.038767        0.0397377
8       0.0644206       0.0652762
9       0.0890747       0.0898065

AnalogIn_Record_trigger_py.cpp

Link to comment
Share on other sites

  • 0

Hi @attila

Thanks for good support. I am now running dwf.dll version 3.18.12 (will update). I finally managed to get AnalogOut to trigger acquisition of the two AnalogIn channels. Basically I had to add the following function calls to get the trigger to work properly:

FDwfAnalogOutRunSet( hdwf, 0, 1.0 / freqOut );
FDwfAnalogOutRepeatSet( hdwf, 0, 0 );   // Infinite
FDwfAnalogOutConfigure( hdwf, 0, 1);
FDwfAnalogInTriggerSourceSet( hdwf, trigsrcAnalogOut1 );

I am trying to track the resonance frequency of the target "contraption" and need to constantly update the AnalogOut output frequency. So far I haven't succeeded in doing so without first stopping the AnalogOut, then setting the new output frequency and finally restart the AnalogOut. This of course results in short interruptions in the driving circuitry. Is there a way to change the output frequency without stopping the AnalogOut?

Best regards

eivind_k


 

Link to comment
Share on other sites

  • 0

Hi @eivind_k

See WF SDK: AnalogOut_Phase.py

Use the following:
dwf.FDwfDeviceOpen... 
dwf.FDwfDeviceAutoConfigureSet(hdwf, c_int(0)) # 0 = the device will be configured only when calling FDwf###Configure
... initial settings ...
dwf.FDwfAnalogOutConfigure(hdwf, channel, c_int(1)) # 1 = start Wavegen channel
...
   dwf.FDwfAnalogOutNodeFrequencySet(hdwf, channel, AnalogOutNodeCarrier, c_double(hz)) # and/or 
   dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, channel, AnalogOutNodeCarrier, c_double(vAmp)) # and/or
   dwf.FDwfAnalogOutNodeOffsetSet(hdwf, channel, AnalogOutNodeCarrier, c_double(vOff)) # and/or ..
   dwf.FDwfAnalogOutConfigure(hdwf, channel, c_int(3)) # 3 = apply new settings on Wavegen channel
   ...

 

Link to comment
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
×
×
  • Create New...