From 2720de350cb73d6f24f55bbf22ae1f4b1724e067 Mon Sep 17 00:00:00 2001 From: Julia Pineda Date: Thu, 13 Jun 2024 13:54:50 +0800 Subject: [PATCH] test: Add ad7768-1 attribute tests Signed-off-by: Julia Pineda --- test/AD7768_1Tests.m | 65 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/test/AD7768_1Tests.m b/test/AD7768_1Tests.m index f0e33fa..4e0075e 100644 --- a/test/AD7768_1Tests.m +++ b/test/AD7768_1Tests.m @@ -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) @@ -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