⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ctrsignals.m

📁 A graphical user interface designed to control a confocal microscope.
💻 M
字号:
function CTRSignals(iDevice,Action)
% CTRSignals.
% The digital line 0 triggers the analog input, the waveform output, and
% the GPCTR_0. The GPCTR_1 generates a pulse that triggers the GPCTR_0. The
% GPCTR_0 generates a square wave train. The period and the duty cycle are defined to 
% match the X miror signal, in such a way that the laser is ON during the 
% scanning and OFF on the flyback.
%
% Input Arguments: 
% iDevice: board ID
% Action: type of action to be carried by the function
%         Start, Fast, Slow, Off, Stop
%
% Output Arguments:
%
%  Software Required:
%   MATLAB, with generic dll calling patch more information at:
%   http://www.mathworks.com/support/solutions/data/33513.shtml
%
% Usage:
% CTRSignals(iDevice,Action);


% Local variables
iDevice = int16(iDevice);
NILibName = 'nidaq32';

% Constant definition
% This are constants required for some NI-DAQ functions. See your NI-DAQ Function Reference Manual 
% for details. All the constants are defined at nidaqcns.h
ND_COUNTER_0 = uint32(13300);
ND_COUNTER_1 = uint32(13400);
%
ND_GPCTR0_OUTPUT = uint32(17400);
ND_GPCTR1_OUTPUT = uint32(17700);
%
ND_RESET = uint32(31200);
ND_PULSE_TRAIN_GNR = uint32(29600);
ND_SINGLE_TRIG_PULSE_GNR = uint32(33500);
ND_SINGLE_PULSE_GNR = uint32(33300);
ND_PROGRAM = uint32(29300);
ND_NONE = uint32(26300);
ND_DONT_CARE = uint32(15900);
ND_DISARM = uint32(15450);
%
ND_SOURCE = uint32(33700);
ND_INTERNAL_100_KHZ = uint32(19200);
ND_GATE = uint32(17100);
ND_GATE_POLARITY = uint32(17200);
ND_TOGGLE = uint32(34700);
ND_PULSE = uint32(29350);
ND_OUTPUT_MODE = uint32(27230);
%
ND_PFI_4 = uint32(28500);
ND_PFI_9 = uint32(29000);
%
ND_HIGH_TO_LOW = uint32(18100);
ND_LOW_TO_HIGH = uint32(24100);
%
ND_COUNT_1 = uint32(13500);
ND_COUNT_2 = uint32(13600);

% Carry out different actions
switch lower(Action)
    case 'start'
        % Load the library
        loadlibrary(NILibName,@NI);
    case 'fast'
        ulLOWcount_0 = uint32(130);
        ulHIGHcount_0 = uint32(70);
        ulLOWcount_1 = uint32(50);
        % Reset the GPCTR
        calllib(NILibName, 'GPCTR_Control', iDevice, ND_COUNTER_0, ND_RESET);
        calllib(NILibName, 'GPCTR_Control', iDevice, ND_COUNTER_1, ND_RESET);
       % Define application type
        calllib(NILibName, 'GPCTR_Set_Application', iDevice, ND_COUNTER_0, ND_PULSE_TRAIN_GNR);
        calllib(NILibName, 'GPCTR_Set_Application', iDevice, ND_COUNTER_1, ND_SINGLE_TRIG_PULSE_GNR);
        % Setup parameters
        calllib(NILibName, 'GPCTR_Change_Parameter', iDevice, ND_COUNTER_0, ND_SOURCE, ND_INTERNAL_100_KHZ);
        calllib(NILibName, 'GPCTR_Change_Parameter', iDevice, ND_COUNTER_0, ND_GATE, ND_PFI_9);
        calllib(NILibName, 'GPCTR_Change_Parameter', iDevice, ND_COUNTER_0, ND_GATE_POLARITY, ND_LOW_TO_HIGH);
        calllib(NILibName, 'GPCTR_Change_Parameter', iDevice, ND_COUNTER_0, ND_COUNT_1, ulLOWcount_0);
        calllib(NILibName, 'GPCTR_Change_Parameter', iDevice, ND_COUNTER_0, ND_COUNT_2, ulHIGHcount_0);
        calllib(NILibName, 'Select_Signal', iDevice, ND_GPCTR0_OUTPUT, ND_GPCTR0_OUTPUT, ND_LOW_TO_HIGH);
        %
        calllib(NILibName, 'GPCTR_Change_Parameter', iDevice, ND_COUNTER_1, ND_SOURCE, ND_INTERNAL_100_KHZ);
        calllib(NILibName, 'GPCTR_Change_Parameter', iDevice, ND_COUNTER_1, ND_GATE, ND_PFI_4);
        calllib(NILibName, 'GPCTR_Change_Parameter', iDevice, ND_COUNTER_1, ND_GATE_POLARITY, ND_HIGH_TO_LOW);
        calllib(NILibName, 'GPCTR_Change_Parameter', iDevice, ND_COUNTER_1, ND_COUNT_1, ulLOWcount_1);
        calllib(NILibName, 'GPCTR_Change_Parameter', iDevice, ND_COUNTER_1, ND_OUTPUT_MODE, ND_TOGGLE);
        calllib(NILibName, 'Select_Signal', iDevice, ND_GPCTR1_OUTPUT, ND_GPCTR1_OUTPUT, ND_LOW_TO_HIGH);
        % Output the square wave
        calllib(NILibName, 'GPCTR_Control', iDevice, ND_COUNTER_0, ND_PROGRAM);
        calllib(NILibName, 'GPCTR_Control', iDevice, ND_COUNTER_1, ND_PROGRAM);
    case 'slow'
        ulLOWcount_0 = uint32(260);
        ulHIGHcount_0 = uint32(140);
        ulLOWcount_1 = uint32(70);
        % Reset the GPCTR
        calllib(NILibName, 'GPCTR_Control', iDevice, ND_COUNTER_0, ND_RESET);
        calllib(NILibName, 'GPCTR_Control', iDevice, ND_COUNTER_1, ND_RESET);
       % Define application type
        calllib(NILibName, 'GPCTR_Set_Application', iDevice, ND_COUNTER_0, ND_PULSE_TRAIN_GNR);
        calllib(NILibName, 'GPCTR_Set_Application', iDevice, ND_COUNTER_1, ND_SINGLE_TRIG_PULSE_GNR);
        % Setup parameters
        calllib(NILibName, 'GPCTR_Change_Parameter', iDevice, ND_COUNTER_0, ND_SOURCE, ND_INTERNAL_100_KHZ);
        calllib(NILibName, 'GPCTR_Change_Parameter', iDevice, ND_COUNTER_0, ND_GATE, ND_PFI_9);
        calllib(NILibName, 'GPCTR_Change_Parameter', iDevice, ND_COUNTER_0, ND_GATE_POLARITY, ND_LOW_TO_HIGH);
        calllib(NILibName, 'GPCTR_Change_Parameter', iDevice, ND_COUNTER_0, ND_COUNT_1, ulLOWcount_0);
        calllib(NILibName, 'GPCTR_Change_Parameter', iDevice, ND_COUNTER_0, ND_COUNT_2, ulHIGHcount_0);
        calllib(NILibName, 'Select_Signal', iDevice, ND_GPCTR0_OUTPUT, ND_GPCTR0_OUTPUT, ND_LOW_TO_HIGH);
        %
        calllib(NILibName, 'GPCTR_Change_Parameter', iDevice, ND_COUNTER_1, ND_SOURCE, ND_INTERNAL_100_KHZ);
        calllib(NILibName, 'GPCTR_Change_Parameter', iDevice, ND_COUNTER_1, ND_GATE, ND_PFI_4);
        calllib(NILibName, 'GPCTR_Change_Parameter', iDevice, ND_COUNTER_1, ND_GATE_POLARITY, ND_HIGH_TO_LOW);
        calllib(NILibName, 'GPCTR_Change_Parameter', iDevice, ND_COUNTER_1, ND_COUNT_1, ulLOWcount_1);
        calllib(NILibName, 'GPCTR_Change_Parameter', iDevice, ND_COUNTER_1, ND_OUTPUT_MODE, ND_TOGGLE);
        calllib(NILibName, 'Select_Signal', iDevice, ND_GPCTR1_OUTPUT, ND_GPCTR1_OUTPUT, ND_LOW_TO_HIGH);
        % Output the square wave
        calllib(NILibName, 'GPCTR_Control', iDevice, ND_COUNTER_0, ND_PROGRAM);
        calllib(NILibName, 'GPCTR_Control', iDevice, ND_COUNTER_1, ND_PROGRAM);
    case 'disable'
        % Disable GPCTR_1  
        pause(1); 
        calllib(NILibName, 'GPCTR_Control', iDevice, ND_COUNTER_1, ND_DISARM);
    case 'off'
        ulLOWcount_0 = uint32(2);
        ulHIGHcount_0 = uint32(2^24-1);
        % Reset the GPCTR
        calllib(NILibName, 'GPCTR_Control', iDevice, ND_COUNTER_0, ND_RESET);
        calllib(NILibName, 'GPCTR_Control', iDevice, ND_COUNTER_1, ND_RESET);
       % Define application type
        calllib(NILibName, 'GPCTR_Set_Application', iDevice, ND_COUNTER_0, ND_PULSE_TRAIN_GNR);
        % Setup parameters
        calllib(NILibName, 'GPCTR_Change_Parameter', iDevice, ND_COUNTER_0, ND_SOURCE, ND_INTERNAL_100_KHZ);
        calllib(NILibName, 'GPCTR_Change_Parameter', iDevice, ND_COUNTER_0, ND_COUNT_1, ulLOWcount_0);
        calllib(NILibName, 'GPCTR_Change_Parameter', iDevice, ND_COUNTER_0, ND_COUNT_2, ulHIGHcount_0);
        calllib(NILibName, 'Select_Signal', iDevice, ND_GPCTR0_OUTPUT, ND_GPCTR0_OUTPUT, ND_LOW_TO_HIGH);
        % Output the square wave
        calllib(NILibName, 'GPCTR_Control', iDevice, ND_COUNTER_0, ND_PROGRAM);
    case 'stop'
        % Reset and disconnect the GPCTR 
        calllib(NILibName, 'GPCTR_Control', iDevice, ND_COUNTER_0, ND_RESET);
        calllib(NILibName, 'GPCTR_Control', iDevice, ND_COUNTER_1, ND_RESET);
        calllib(NILibName, 'Select_Signal', iDevice, ND_GPCTR0_OUTPUT, ND_NONE, ND_DONT_CARE);
        calllib(NILibName, 'Select_Signal', iDevice, ND_GPCTR1_OUTPUT, ND_NONE, ND_DONT_CARE);
        % Unload the library
        unloadlibrary(NILibName);        
end        

% Turn off warning about this library
warning off MATLAB:loadlibrary:classloaded

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -