Time base 0

Post your MATLAB discussions here
Post Reply
korkikian
Newbie
Posts: 0
Joined: Tue Nov 26, 2013 10:03 pm

Time base 0

Post by korkikian »

Hello,

I am trying to run 3207A with timebase equal to 0, however I always get the error: PICO_INVALID_TIMEBASE

I have disabled the second channel B (see the code below) and I am giving the trigger on external channel.

Do you have any idea what is wrong with it?
I am using Windows 8, I could run timebase=1, Matlab is 32 bit (Pico libraries are 32 bits also).

Code: Select all

%% Set Path
% Edit as required
addpath('C:\Users\Roman\Desktop\Pico\Wrapper\Release\Win32')
addpath('..\');
addpath('..\Functions');
addpath('C:\Users\Roman\Desktop\Pico');

%% Load in PicoStatus values
PicoStatus;

%% Declare variables
global data;

data.TRUE = 1;
data.FALSE = 0;
data.BUFFER_SIZE = 1000;

% Data Buffers
pBufferChA = libpointer('int16Ptr',zeros(data.BUFFER_SIZE,1));
pBufferChB = libpointer('int16Ptr',zeros(data.BUFFER_SIZE,1));

data.timebase = 0;  % 5kS/s for 320XA/B, 10kS/s for 340XA/B
data.oversample = 1;

data.scaleVoltages = data.TRUE;
data.inputRangesmV = [10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000];

plotData = data.TRUE;

%% Device Connection
% Create device
ps3000a_obj = icdevice('PS3000a_IC_drv', ''); % Specify serial number as 2nd argument if required.

% Connect device
connect(ps3000a_obj);

% Provide access to enumerations and structures
[methodinfo, structs, enuminfo, ThunkLibName] = PS3000aMFile;

%% Show unit information

info_status = invoke(ps3000a_obj, 'GetUnitInfo')

%% Obtain Maximum & Minimum values 
max_val_status = invoke(ps3000a_obj, 'ps3000aMaximumValue')

disp('Max ADC value:');
ps3000a_obj.maxValue

min_val_status= invoke(ps3000a_obj, 'ps3000aMinimumValue')

%% Channel settings
% Channel settings - create a struct

% Channel A
channelSettings(1).enabled = data.TRUE;
channelSettings(1).DCCoupled = data.TRUE;
channelSettings(1).range = enuminfo.enPS3000ARange.PS3000A_50MV;

% Channel B
channelSettings(2).enabled = data.FALSE;
channelSettings(2).DCCoupled = data.TRUE;
channelSettings(2).range = enuminfo.enPS3000ARange.PS3000A_5V;

%% Set Defaults for Channels
status_set_defaults = invoke(ps3000a_obj, 'setDefaults', channelSettings)

%% Set Simple Trigger

enable = data.TRUE;
source = enuminfo.enPS3000AChannel.PS3000A_EXTERNAL; 
threshold = mv2adc(1000, data.inputRangesmV(enuminfo.enPS3000ARange.PS3000A_5V + 1), ps3000a_obj.maxValue);
direction = enuminfo.enPS3000AThresholdDirection.PS3000A_RISING;
delay = 0;              
autoTrigger_ms = 0; % Wait indefinitely

trigger_status = invoke(ps3000a_obj, 'ps3000aSetSimpleTrigger', ...
    enable, source, threshold, direction, delay, autoTrigger_ms)

%% Set Data Buffers
channelA = enuminfo.enPS3000AChannel.PS3000A_CHANNEL_A;

status = invoke(ps3000a_obj, 'ps3000aSetDataBuffer', ... 
    channelA, pBufferChA, data.BUFFER_SIZE, 0, 0);

%% Set Timebase
timeIndisposed = 0;
maxSamples = data.BUFFER_SIZE;
timeIntNs = 0;
segmentIndex = 0;

[get_timebase2_status, timeIntNs1, maxSamples1] = invoke(ps3000a_obj, 'ps3000aGetTimebase2', ...
        data.timebase, data.BUFFER_SIZE, ...
        timeIntNs, data.oversample, maxSamples, segmentIndex);

%% Run Block

preTriggerSamples = 200;
postTriggerSamples = data.BUFFER_SIZE - preTriggerSamples;
segmentIndex = 0;

% Prompt to press a key to begin capture
input_str = input('Press ENTER to begin data collection.', 's');

% Run block and retry if power source not set correctly
s = serial('COM3','BaudRate',115200);
fopen(s)
p = hex2dec(['00';'11'; '22'; '33'; '44'; '55'; '66'; '77'; '88'; '99'; 'aa'; 'bb'; 'cc'; 'dd'; 'ee'; 'ff']);

for iCnt = 1:1
    
    retry = 1;
    
    %Restart the acquisition
    while retry == 1
        [run_block_status, timeIndisposedMs] = invoke(ps3000a_obj, 'ps3000aRunBlock', ...
        preTriggerSamples, postTriggerSamples, data.timebase, ...
        data.oversample, segmentIndex)

        % Check power status
        if run_block_status ~= PicoStatus.PICO_OK
            if (run_block_status == PicoStatus.PICO_POWER_SUPPLY_CONNECTED || ...
                    run_block_status == PicoStatus.PICO_POWER_SUPPLY_NOT_CONNECTED || ...
                    run_block_status == PicoStatus.PICO_POWER_SUPPLY_UNDERVOLTAGE)

                %change_power_src_status = invoke(ps3000a_obj, 'ChangePowerSource', run_block_status)
                change_power_src_status = ps3000aChangePowerSource(ps3000a_obj, run_block_status)
            else
                % Display error code in Hexadecimal
                fprintf('ps3000aRunBlock status: 0x%X', run_block_status);
            end
        else
            retry = 0;
        end
    end

    % Confirm if device is ready
    [ready_status, ready] = invoke(ps3000a_obj, 'ps3000aIsReady')

    while(ready == 0)
        [ready_status, ready] = invoke(ps3000a_obj, 'ps3000aIsReady')
        
        fwrite(s,p,'uint8')
        res = fread(s,16);
        [dec2hex(res)]'
    end

    fprintf('Ready: %d\n', ready);
    disp('Data collected');

    %% Get Values
    startIndex = 0;
    downSampleRatio = 1;
    downSampleRatioMode = enuminfo.enPS3000ARatioMode.PS3000A_RATIO_MODE_NONE;
    segmentIndex = 0;
    overflow_ptr = 0;

    [get_values_status, numSamples, overflow] = invoke(ps3000a_obj, 'ps3000aGetValues', ...
        startIndex, data.BUFFER_SIZE, downSampleRatio, downSampleRatioMode, ...
        segmentIndex, overflow_ptr)

    if(get_values_status ~= PicoStatus.PICO_OK)  
        % Check if Power Status issue
        if(get_values_status == PicoStatus.PICO_POWER_SUPPLY_CONNECTED || ...
            get_values_status == PicoStatus.PICO_POWER_SUPPLY_NOT_CONNECTED || ...
                get_values_status == PicoStatus.PICO_POWER_SUPPLY_UNDERVOLTAGE)

            if(get_values_status == PicoStatus.PICO_POWER_SUPPLY_UNDERVOLTAGE)
                pwr_status = ps3000aChangePowerSource(ps3000a_obj, get_values_status)
            else
                fprintf('Power Source Changed. Data collection aborted.\n');
                plotData = data.FALSE;
            end
        else
            fprintf('ps3000aGetValues status: 0x%X', get_values_status);
            plotData = data.FALSE;
        end
    end

    %% Stop the device
    stop_status = invoke(ps3000a_obj, 'ps3000aStop');

    %% Convert data values to milliVolt values
end

%Close serial port
fclose(s)
clear s

%% Disconnect device
disconnect(ps3000a_obj);

What I get with this code is:
  • ps3000aRunBlock status: 0xE
    run_block_status =

    14


    timeIndisposedMs =

    0

Hitesh

Re: Time base 0

Post by Hitesh »

Hi korkikian,

The setDefaults function enables all the channels on the scope by default.

Please try replacing this line with 2 calls to ps3000aSetChannel for Channels A and B respectively.

What does the response from the call to ps3000aGetTimebase2 give?

Regards,

korkikian
Newbie
Posts: 0
Joined: Tue Nov 26, 2013 10:03 pm

Re: Time base 0

Post by korkikian »

Hitesh wrote:Hi korkikian,

The setDefaults function enables all the channels on the scope by default.

Please try replacing this line with 2 calls to ps3000aSetChannel for Channels A and B respectively.

What does the response from the call to ps3000aGetTimebase2 give?

Regards,
Thank you very much for the response. Finally I understood that I have to run only one probe. Now I can't activate ETS mode on Matlab (the question is in another branch).

airul2180
Newbie
Posts: 0
Joined: Wed Dec 05, 2012 2:55 am

Re: Time base 0

Post by airul2180 »

Hello, i am using Pico3205a and i believed that the code almost same with you. Unfortunately, when i run your code this error came out. can you help me what going on with my code or Matlab.I am using Matlab2007b.Thanks

Hitesh

Re: Time base 0

Post by Hitesh »

Hi,

Have you called ps3000aSetChannel and turned channel B off?

Regards,

airul2180
Newbie
Posts: 0
Joined: Wed Dec 05, 2012 2:55 am

Re: Time base 0

Post by airul2180 »

Hello,
How to call ps3000aSetChannel using code. can you teach me.tq

Hitesh

Re: Time base 0

Post by Hitesh »

Hi,

This function mirrors the API function defined in the main Programmer's Guide for the device:

http://www.picotech.com/document/pdf/ps ... .en-10.pdf
PICO_STATUS ps3000aSetChannel
(
int16_t handle,
PS3000A_CHANNEL channel,
int16_t enabled,
PS3000A_COUPLING type,
PS3000A_RANGE range,
float analogueOffset
)
Please try:

Code: Select all

status.setChB = invoke(ps3000a_obj, 'ps3000aSetChannel', enuminfo.enPS3000AChannel.PS3000A_CHANNEL_B, ...
    0, dcCoupled, range, analogueOffset)
Note the '0' being passed for the 'enabled' parameter.

Hope this helps.

Post Reply