Skip to content

Commit

Permalink
test: Add ad7768-1 attribute tests
Browse files Browse the repository at this point in the history
Signed-off-by: Julia Pineda <[email protected]>
  • Loading branch information
jpineda3 committed Jun 13, 2024
1 parent aa17f87 commit fc44a13
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions test/AD7768_1Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
properties(TestParameter)
% start. stop, step, tolerance, repeats
signal_test = {{1000,125000,2500,0.015,10}};
samples_per_frame = {{2^1,1048580,2^16,0.0,10}};
sample_rate = {'256000', '128000', '64000', ...
'32000', '16000', '8000', '4000', ...
'2000', '1000'};
common_mode_voltage = { '(AVDD1-AVSS)/2','2V5', ...
'2V05','1V9','1V65','1V1','0V9', ...
'OFF'};
end

methods(TestClassSetup)
Expand Down Expand Up @@ -72,6 +79,64 @@ function testAD7768_1Signal(testCase,signal_test)
m2k_class.contextClose();
end

function testAD7768_1AttrSamplesPerFrame(testCase,samples_per_frame)
% This is not written to the device. Should this even be tested?
adc = adi.AD7768_1.Rx;
adc.uri = testCase.uri;

start = samples_per_frame{1};
stop = samples_per_frame{2};
step = samples_per_frame{3};
tol = samples_per_frame{4};
repeats = samples_per_frame{5};
numints = round((stop-start)/step);
for ii = 1:repeats
ind = randi([0, numints]);
val = start+(step*ind);
disp("Setting SamplesPerFrame to " + string(val));
adc.SamplesPerFrame = val;
[data, valid] = adc();
[ret_val,~] = size(data);
adc.release();
testCase.assertTrue(valid);
testCase.assertTrue(sum(abs(double(data)))>0);
testCase.verifyEqual(ret_val,val,'RelTol',tol,...
'Frequency of signal unexpected')
end
end

function testAD7768_1AttrCommonModeVolage(testCase,common_mode_voltage)
% FIXME: Hangs unless board is rebooted
adc = adi.AD7768_1.Rx;
adc.uri = testCase.uri;
val = common_mode_voltage;
disp("Setting CommonModeVoltage to " + val);
adc.CommonModeVolts = val;
[data,valid] = adc();
ret_val = adc.getDeviceAttributeRAW('common_mode_voltage',16);
disp("Read attribute value: " + ret_val);
adc.release();
testCase.assertTrue(valid);
testCase.assertTrue(sum(abs(double(data)))>0);
testCase.assertTrue(strcmp(val,string(ret_val)));
end

function testAD7768_1AttrSampleRate(testCase,sample_rate)
% FIXME: Hangs unless board is rebooted
adc = adi.AD7768_1.Rx;
adc.uri = testCase.uri;
val = sample_rate;
disp("Setting SampleRate to " + val);
adc.SampleRate = val;
[data,valid] = adc();
ret_val = adc.getDeviceAttributeRAW('sampling_frequency',8);
disp("Read attribute value: " + ret_val);
adc.release();
testCase.assertTrue(valid);
testCase.assertTrue(sum(abs(double(data)))>0);
testCase.assertTrue(strcmp(val,string(ret_val)));
end

end

end
Expand Down

0 comments on commit fc44a13

Please sign in to comment.