Analog I/O Demo 2 – Basic analog to digital converters demo¶
Note
You can only use ADC/DAC with the full version of a device; the lite version does not have ADC/DAC capabilities.
This demo is straight forward, it is designed to send voltages to the digital to analogue converters. It also reads them back with an internal or physical loopback.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | function DatapixxAdcBasicDemo(internalLoopback)
% DatapixxAdcBasicDemo([internalLoopback=1])
%
% Demonstrates the basic functions of the Datapixx analog to digital converters.
% Prints the input voltage range, and current input voltage, for all channels.
%
% Optional argument:
%
% internalLoopback = 1 if DAC outputs should be internally looped back to ADC inputs
% Otherwise the ADC converts the actual voltages on the db-25 pins
%
% Also see: DatapixxAdcAcquireDemo, DatapixxAdcStreamDemo
%
% History:
%
% Oct 1, 2009 paa Written
% Oct 29, 2014 dml Revised
AssertOpenGL; % We use PTB-3
% Get internal loopback argument
if nargin < 1
internalLoopback = [];
end
if isempty(internalLoopback)
internalLoopback = 1;
end
% Open Datapixx, and stop any schedules which might already be running
Datapixx('Open');
Datapixx('StopAllSchedules');
Datapixx('RegWrRd'); % Synchronize Datapixx registers to local register cache
% DAC outputs can be looped back to ADC inputs inside the DATAPixx.
% There are 4 DAC channels, and 16 ADC channels, plus 2 ADC reference channels,
% so the internal loopback maps DAC outputs to multiple ADC inputs:
% DAC0 => ADC0/2/4/6/8/10/12/14
% DAC1 => ADC1/3/5/7/9/11/13/15
% DAC2 => REF0
% DAC3 => REF1
% Even if we are not doing an internal loopback, we'll still program the DAC outputs.
% This allows us to do an _external_ loopback;
% ie: wire the DAC outputs to the ADC inputs right on the db-25 connector.
% We'll arbitrarily program the 4 DAC channels to 5V, 2.5V, -2.5V, -5V
if (internalLoopback == 1)
Datapixx('EnableDacAdcLoopback'); % We'll read back what's on the DAC outputs
else
Datapixx('DisableDacAdcLoopback'); % We'll read what's really on the input db-25
end
Datapixx('SetDacVoltages', [0:3 ; 5 2.5 -2.5 -5]);
Datapixx('EnableAdcFreeRunning'); % ADC's convert continuously
Datapixx('RegWrRd'); % Write local register cache to hardware
Datapixx('RegWrRd'); % Give time for ADCs to convert, then read back data to local cache
% Show how many ADC channels are in the Datapixx
nChannels = Datapixx('GetAdcNumChannels');
fprintf('\nDatapixx has %d ADC channels\n\n', nChannels);
% Show the input voltage range, and current value, for each ADC channel
adcRanges = Datapixx('GetAdcRanges');
adcDataVoltages = Datapixx('GetAdcVoltages');
for channel = 0:nChannels-1
fprintf('Channel %d input range is %g to %g Volts, current value is %g Volts\n',...
channel, adcRanges(1, channel+1), adcRanges(2, channel+1), adcDataVoltages(channel+1));
end
% Job done
Datapixx('Close');
fprintf('\n\nDemo completed\n\n');
|