Test and Measurement Forum

AWG problems using PS5442B

Post your MATLAB discussions here

AWG problems using PS5442B

Postby GrahamP » Wed Jul 06, 2016 4:33 pm

Hello,

I am trying to produce a 1kHz sine wave using the AWG, and then read it in on channel A to see the output. As far as I'm aware, I need to convert frequency (1 kHz) to phase - see the code below. However, I cannot get the code to run correctly due to the following two problems.

1) Using startDelta, I get an error stating,
Parameter must be scalar
.
2) After removing startDelta (as in the example code), the code never triggers, but hangs with
runBlock: Waiting for device to become ready...


How do I correctly use the AWG to give me a 1kHz sine wave?

Many thanks!

Code: Select all
PS5000aConfig;

%% DEVICE CONNECTION
% Create a device object.
ps5000aDeviceObj = icdevice('picotech_ps5000a_generic.mdd');
% Connect device object to hardware.
connect(ps5000aDeviceObj);

%% FUNCTION GENERATOR - SIMPLE
% Configure property value(s).
% Output a Sine wave, 2000mVpp, 0mV offset (uses preset frequency)
% invoke(ps5000aDeviceObj, 'setSigGenBuiltInSimple', 0, 2000, 0);
awgBufferSize = get(ps5000aDeviceObj, 'awgBufferSize');
%x = [0:(2*pi)/1023:2*pi];
sampleSize = 1024;
t = linspace(0,2e-3,sampleSize);
f = 1e3;
y = normalise(sin(2*pi*f*t));

dacFrequency = 200e6;
startDelta = freq2delta(f, sampleSize, awgBufferSize, dacFrequency);

% Set parameters
offsetMv = 0;
pkToPkMv = 2000;
increment = 0; % Hz
dwellTime = 1; % seconds
sweepType = ps5000aEnuminfo.enPS5000ASweepType.PS5000A_UP;
operatiom = PicoConstants.FALSE;
operation = ps5000aEnuminfo.enPS5000AIndexMode.PS5000A_SINGLE;
shots = 1;
sweeps = 0;
triggerType = ps5000aEnuminfo.enPS5000ASigGenTrigType.PS5000A_SIGGEN_RISING;
triggerSource = ps5000aEnuminfo.enPS5000ASigGenTrigSource.PS5000A_SIGGEN_SOFT_TRIG;
extInThresholdMv = 0;

% Call function
invoke(ps5000aDeviceObj, 'setSigGenArbitrary', offsetMv, pkToPkMv, startDelta, increment, dwellTime, ...
    y, sweepType, operatiom, operation, shots, sweeps, triggerType, triggerSource, extInThresholdMv);

% Trigger the AWG
invoke(ps5000aDeviceObj, 'ps5000aSigGenSoftwareControl', 1);

%invoke(ps5000aDeviceObj, 'setSigGenArbitrarySimple', 0, 2000, y);

%% Set input channel parameters
% Channel A enabled, the rest disabled. Page 78 of programmers guide
invoke(ps5000aDeviceObj, 'ps5000aSetChannel', 0, 1, 1, 6, 0);
invoke(ps5000aDeviceObj, 'ps5000aSetChannel', 1, 0, 1, 6, 0);
invoke(ps5000aDeviceObj, 'ps5000aSetChannel', 2, 0, 1, 6, 0);
invoke(ps5000aDeviceObj, 'ps5000aSetChannel', 3, 0, 1, 6, 0);   
[status, resolution] = invoke(ps5000aDeviceObj, 'ps5000aSetDeviceResolution', 12);

%% SET SIMPLE TRIGGER
% Channel     : 0 (PS5000A_CHANNEL_A)
% Threshold   : 0 (mV)
% Direction   : 2 (Rising)
% Delay       : 0
% Auto trigger: 0 (wait indefinitely)
[status] = invoke(ps5000aDeviceObj, 'setSimpleTrigger', 0, 0, 0, 2, 0, 0);

%% GET TIMEBASE

% Driver default timebase index used - use ps5000aGetTimebase or
% ps5000aGetTimebase2 to query the driver as to suitability of using a
% particular timebase index then set the 'timebase' property if required.

% timebase     : 65 (default)
% segment index: 0

[status, timeIntervalNanoSeconds, maxSamples] = invoke(ps5000aDeviceObj, 'ps5000aGetTimebase', 100, 0);

Nsamples = 2048;
samplingRate = 1/(double(timeIntervalNanoSeconds)*1e-9);

%% SET BLOCK PARAMETERS AND CAPTURE DATA

% Set pre-trigger samples.
set(ps5000aDeviceObj, 'numPreTriggerSamples', 0);
set(ps5000aDeviceObj, 'numPostTriggerSamples', Nsamples);  %% Samples to record after trigger

% Capture a block of data:
% segment index: 0
[status] = invoke(ps5000aDeviceObj, 'runBlock', 0);

% Retrieve data values:
% start index       : 0
% segment index     : 0
% downsampling ratio: 1
% downsampling mode : 0 (PS5000A_RATIO_MODE_NONE)

[chA, chB, chC, chD, numSamples, overflow] = invoke(ps5000aDeviceObj, 'getBlockData', 0, 0, 1, 0);

% Stop the device
[status] = invoke(ps5000aDeviceObj, 'ps5000aStop');

%% PROCESS DATA
% Plot data values.
figure;

% Calculate time (nanoseconds) and convert to milliseconds
% Use timeIntervalNanoSeconds output from ps5000aGetTimebase or
% ps5000aGetTimebase2 or calculate from Programmer's Guide.
timeNs = double(timeIntervalNanoSeconds) * double([0:numSamples - 1]);
timeMs = timeNs / 1e6;

% Channel A
plot(timeMs, chA, 'b');
title('Channel A');
xlabel('Time (ms)');
ylabel('Voltage (mV)');

%% DEVICE DISCONNECTION

% Disconnect device object from hardware.
disconnect(ps5000aDeviceObj);

GrahamP
Newbie
 
Posts: 0
Joined: Wed Jul 06, 2016 11:49 am

Re: AWG problems using PS5442B

Postby GrahamP » Mon Jul 18, 2016 9:26 am

Bump :) Could anyone please assist?

Many thanks

Graham
GrahamP
Newbie
 
Posts: 0
Joined: Wed Jul 06, 2016 11:49 am

Re: AWG problems using PS5442B

Postby Hitesh » Tue Jul 19, 2016 12:52 pm

Hi Graham,

Where is the error occurring - when you call the freq2delta() function or the Instrument Driver's 'setSigGenArbitrary' function?

Regards,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2063
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: AWG problems using PS5442B

Postby GrahamP » Fri Jul 22, 2016 2:01 pm

Hi Hitesh,

It fails on this line:

Code: Select all
invoke(ps5000aDeviceObj, 'setSigGenArbitrary', offsetMv, pkToPkMv, startDelta, increment, dwellTime, ...
    y, sweepType, operatiom, operation, shots, sweeps, triggerType, triggerSource, extInThresholdMv);


Thanks,

Graham
GrahamP
Newbie
 
Posts: 0
Joined: Wed Jul 06, 2016 11:49 am

Re: AWG problems using PS5442B

Postby Hitesh » Mon Jul 25, 2016 9:22 am

Hi Graham,

Which version of the picotech_ps5000a_generic.mdd Instrument Driver are you using (it is displayed when the conncetion is made)?

Does the example run without modification?

Regards,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2063
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: AWG problems using PS5442B

Postby GrahamP » Mon Aug 01, 2016 3:47 pm

Hi Hitesh,

EDIT: yes, the PS5000A_IC_GenericDriver_Sig_Gen.m example code does run. My code in the original post does not.

This is the output - I'm using version 1.1.20.
Instrument Device Object Using Driver : picotech_ps5000a_generic.mdd

Instrument Information
Type: Oscilloscope
Manufacturer: Pico Technology Ltd.
Model: PicoScope 5000 Series

Driver Information
DriverType: MATLAB generic
DriverName: picotech_ps5000a_generic.mdd
DriverVersion: 1.1.20

Communication State
Status: open
GrahamP
Newbie
 
Posts: 0
Joined: Wed Jul 06, 2016 11:49 am

Re: AWG problems using PS5442B

Postby Hitesh » Mon Aug 01, 2016 4:33 pm

Hi Graham,

The reason for the error is that the start delta phase was being passed in as an argument.

The setSigGenArbitrary() function of the Instrument Driver does not take a input arguments for the start and stop delta phases as it makes use of the startFrequency and stopFrequency properties of the Instrument Driver which are specified in Hertz. The Instrument Driver converts these values to delta phase values inside the function call.

To output a wave with a constant frequency ensure that startFrequency and stopFrequency are equal as follows:

Code: Select all
%% FUNCTION GENERATOR - SIMPLE
% Configure property value(s).
% Output a Sine wave, 2000mVpp, 0mV offset (uses preset frequency)
% invoke(ps5000aDeviceObj, 'setSigGenBuiltInSimple', 0, 2000, 0);
awgBufferSize = get(ps5000aDeviceObj, 'awgBufferSize');
%x = [0:(2*pi)/1023:2*pi];
sampleSize = 1024;
t = linspace(0,2e-3,sampleSize);
f = 1e3;
y = normalise(sin(2*pi*f*t));

dacFrequency = 200e6;
startDelta = freq2delta(f, sampleSize, awgBufferSize, dacFrequency); % Not required as calculated by the Instrument Driver

% Set parameters

% Set the frequency in the Instrument Driver
set(ps5000aDeviceObj, 'startFrequency', f);
set(ps5000aDeviceObj, 'stopFrequency', f);

offsetMv = 0;
pkToPkMv = 2000;
increment = 0; % Hz
dwellTime = 1; % seconds
sweepType = ps5000aEnuminfo.enPS5000ASweepType.PS5000A_UP;
operation = PicoConstants.FALSE;
sweepType = ps5000aEnuminfo.enPS5000AIndexMode.PS5000A_SINGLE;
shots = 1;
sweeps = 0;
triggerType = ps5000aEnuminfo.enPS5000ASigGenTrigType.PS5000A_SIGGEN_RISING;
triggerSource = ps5000aEnuminfo.enPS5000ASigGenTrigSource.PS5000A_SIGGEN_SOFT_TRIG;
extInThresholdMv = 0;

% Call function
invoke(ps5000aDeviceObj, 'setSigGenArbitrary', offsetMv, pkToPkMv, increment, dwellTime, ...
    y, sweepType, operation, sweepType, shots, sweeps, triggerType, triggerSource, extInThresholdMv);

% Trigger the AWG
invoke(ps5000aDeviceObj, 'ps5000aSigGenSoftwareControl', 1);

Looking at rest of the script, are you feeding the output signal back in to channel A or will the output signal be sent to another piece of equipment which sends a signal back to another channel on the PicoScope?

Regards,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2063
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire


Return to MATLAB

Who is online

Users browsing this forum: No registered users and 0 guests