Jump to content
  • 0

How to control the power supply of Analog Discovery 2 on MATLAB?


TheoMaria

Question

Hello,

I am aware and have controlled the Power supply as well as the individual channel voltage using Python. But I am unaware how to do the same on Matlab. I have read a few posts concerning this topic, where I read about using the h file to initialize the device and then use the power supply:

However, I am still confused as I could not use this due to an error "could not find file". Could anyone please let me know in detail (preferably step-by-step) on how to enable the power supply for AD2 on Matlab? 

 

Thank you! 

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Hi @TheoMaria

As it is in the second example:
 If you are using the DAQ do not call FDwfDeviceOpen since the device can be opened only once at a time.
 The DAQ will open the device the hdwf will get value 1 and use this in the FDwf functions.

I've modified your example: Waveform_Generation2.m

...
%% Power Supply
% Load library, "hfile" is a variable that points to the location of the library

% dummy read to open device
data = read(dq, seconds(1));

if ~libisloaded('dwf')
    loadlibrary('dwf', 'C:/Program Files (x86)/Digilent/WaveFormsSDK/inc/dwf.h');
end

if calllib('dwf','FDwfAnalogIOStatus', 1) == 0 % see if device is connected
    disp('No opened device')
    return
else
    disp('Enable PS')
    calllib('dwf','FDwfAnalogIOChannelNodeSet', 1, 0, 0, 1.0); % V+ enable
    calllib('dwf','FDwfAnalogIOChannelNodeSet', 1, 0, 1, 5.0); % V+ 5V
    calllib('dwf','FDwfAnalogIOChannelNodeSet', 1, 1, 0, 1.0); % V- enable
    calllib('dwf','FDwfAnalogIOChannelNodeSet', 1, 1, 1, -5.0); % V- -5V
    calllib('dwf','FDwfAnalogIOEnableSet', 1, 1); % master enable
    pause(1) % wait to settle
end

unloadlibrary('dwf')

%% Generate a Periodic Waveform and Record Input
...

 

Link to comment
Share on other sites

  • 1

Hi @TheoMaria

See the following:DWFtest.zip
The server does not allow me to add m code or m file, here you have a picture:

image.thumb.png.3536f22f0c8ab2aae025f8ef24884cb6.png

    calllib('dwf','FDwfParamSet', 4, 0); % DwfParamOnClose continue on Run
    calllib('dwf','FDwfDeviceAutoConfigureSet', phdwf.Value, 0); 
    calllib('dwf','FDwfAnalogIOChannelNodeSet', phdwf.Value, 0, 0, 1.0); % V+ enable
    calllib('dwf','FDwfAnalogIOChannelNodeSet', phdwf.Value, 0, 1, 5.0); % V+ 5V
    calllib('dwf','FDwfAnalogIOChannelNodeSet', phdwf.Value, 1, 0, 1.0); % V- enable
    calllib('dwf','FDwfAnalogIOChannelNodeSet', phdwf.Value, 1, 1, -5.0); % V- -5V
    calllib('dwf','FDwfAnalogIOEnableSet', phdwf.Value, 1); % master enable
    calllib('dwf','FDwfAnalogIOConfigure', phdwf.Value); % configure device

 

Edited by attila
Link to comment
Share on other sites

  • 1

Hi @TheoMaria

Probably you are using an old version of WF runtime 3.7.2 which is currently required by the DAQ AD support package.

If you are using the support package this will open the device then the other functions can be called, like this

function DWFtest2();

% make sure daq opens device
daqlist("digilent")
dq = daq("digilent")
ch_in = addinput(dq, "AD1", "1", "Voltage");
[singleReading, startTime] = read(dq)

% 32 bit system
%hfile = 'C:/Program Files/Digilent/WaveFormsSDK/inc/dwf.h';
%64 bit system
hfile = 'C:/Program Files (x86)/Digilent/WaveFormsSDK/inc/dwf.h';

if ~libisloaded('dwf')
    loadlibrary('dwf', hfile);
end

if calllib('dwf','FDwfAnalogIOStatus', 1) == 0 % see if device is connected
    disp('No opened device')
else
    disp('Enable PS')
    calllib('dwf','FDwfAnalogIOChannelNodeSet', 1, 0, 0, 1.0); % V+ enable
    calllib('dwf','FDwfAnalogIOChannelNodeSet', 1, 0, 1, 5.0); % V+ 5V
    calllib('dwf','FDwfAnalogIOChannelNodeSet', 1, 1, 0, 1.0); % V- enable
    calllib('dwf','FDwfAnalogIOChannelNodeSet', 1, 1, 1, -5.0); % V- -5V
    calllib('dwf','FDwfAnalogIOEnableSet', 1, 1); % master enable
end

unloadlibrary('dwf')

end

 

Link to comment
Share on other sites

  • 0
17 hours ago, attila said:

Hi @TheoMaria

See the following:DWFtest.zip
The server does not allow me to add m code or m file, here you have a picture:

image.thumb.png.3536f22f0c8ab2aae025f8ef24884cb6.png




    calllib('dwf','FDwfParamSet', 4, 0); % DwfParamOnClose continue on Run
    calllib('dwf','FDwfDeviceAutoConfigureSet', phdwf.Value, 0); 
    calllib('dwf','FDwfAnalogIOChannelNodeSet', phdwf.Value, 0, 0, 1.0); % V+ enable
    calllib('dwf','FDwfAnalogIOChannelNodeSet', phdwf.Value, 0, 1, 5.0); % V+ 5V
    calllib('dwf','FDwfAnalogIOChannelNodeSet', phdwf.Value, 1, 0, 1.0); % V- enable
    calllib('dwf','FDwfAnalogIOChannelNodeSet', phdwf.Value, 1, 1, -5.0); % V- -5V
    calllib('dwf','FDwfAnalogIOEnableSet', phdwf.Value, 1); % master enable
    calllib('dwf','FDwfAnalogIOConfigure', phdwf.Value); % configure device

 

Hello @attilathank you for your reply. I have tried this on Matlab as a function DWFtest, and called the function on my main file as DWFtest(). However, I ran into a few warnings which state that "The function FDwfParamSet is not found in the library". I go several warnings for all of the calllib parameters you mentioned on your file. Now, I know that my dwf.h file is in the following directory in my PC: hfile = 'D:/Digilent/WaveFormsSDK/inc/dwf.h' so I edited your file, but everything else remains the same. 

So could you please tell me how I can fix this?  

Also, when I run the main file for 5+ times, I run into the following error: 

Error detected using 'digilent' hardware:
Digilent devices with the following serial numbers are reserved by another program:
SN:210321A35F30. To unreserve these devices, close the application and call daqreset.

I have attached the main file, in case you would like to look at it.

I closed all the applications, even unplugged the USB to the AD2, and tried daqreset, but to no avail. I had to restart my PC to get rid of this problem. Do you know how to fix this too?

 

Thank you once again! :)

Waveform_Generation.m

Edited by TheoMaria
Link to comment
Share on other sites

  • 0
22 hours ago, attila said:

Hi @TheoMaria

Probably you are using an old version of WF runtime 3.7.2 which is currently required by the DAQ AD support package.

If you are using the support package this will open the device then the other functions can be called, like this





function DWFtest2();

% make sure daq opens device
daqlist("digilent")
dq = daq("digilent")
ch_in = addinput(dq, "AD1", "1", "Voltage");
[singleReading, startTime] = read(dq)

% 32 bit system
%hfile = 'C:/Program Files/Digilent/WaveFormsSDK/inc/dwf.h';
%64 bit system
hfile = 'C:/Program Files (x86)/Digilent/WaveFormsSDK/inc/dwf.h';

if ~libisloaded('dwf')
    loadlibrary('dwf', hfile);
end

if calllib('dwf','FDwfAnalogIOStatus', 1) == 0 % see if device is connected
    disp('No opened device')
else
    disp('Enable PS')
    calllib('dwf','FDwfAnalogIOChannelNodeSet', 1, 0, 0, 1.0); % V+ enable
    calllib('dwf','FDwfAnalogIOChannelNodeSet', 1, 0, 1, 5.0); % V+ 5V
    calllib('dwf','FDwfAnalogIOChannelNodeSet', 1, 1, 0, 1.0); % V- enable
    calllib('dwf','FDwfAnalogIOChannelNodeSet', 1, 1, 1, -5.0); % V- -5V
    calllib('dwf','FDwfAnalogIOEnableSet', 1, 1); % master enable
end

unloadlibrary('dwf')

end

 

Hi @attilaThank you for the reply again. I have tried the file you sent earlier, however the warnings would not go away, which I mentioned before (he function is not found in the library) as well as #pragma once in main file. The device does not open either. The error that I receive are:

1. Library not found (although I am sure the directory is correct like I mentioned before).

2. Error using calllib on line 19, I have attached the picture. [calllib('dwf','FDwfGetVersion',pBuffer);] 

Note: DFWPower() is the function that you have sent yesterday. 

Thank you for your help, I am aware that I am asking too much of you but I would really appreciate it if you can help me out. 

xyz.png

Edited by TheoMaria
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...