-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathadis16488_example.m
132 lines (105 loc) · 2.73 KB
/
adis16488_example.m
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
%Copyright (c) 2018-2020 Analog Devices, Inc. All Rights Reserved.
%This software is proprietary to Analog Devices, Inc. and its licensors.
%
%Authors: Alex Nolan
clear
%Watch for user inputs to exit code execution
H = uicontrol('Style', 'PushButton', ...
'String', 'Break', ...
'Callback', 'delete(gcbf)');
%Get paths
wrapperPath = fullfile(strcat(pwd, '../../../../resources/FX3ApiWrapper.dll'));
regMapPath = fullfile(strcat(pwd, '../../../regmaps/ADIS16488_Regmap.csv'));
resourcePath = fullfile(strcat(pwd, '../../../../resources/'));
%Load wrapper DLL
NET.addAssembly(wrapperPath);
%Check if the FX3 object is already instantiated (and connected)
if(exist('Dut','var') ~= 1)
%Create FX3 wrapper, with ADIS1650x regmap
Dut = FX3ApiWrapper.Wrapper(resourcePath,regMapPath,FX3ApiWrapper.SensorType.StandardImu);
end
%Blink user LED at 5Hz
Dut.UserLEDBlink(5.0);
%disable dr active
Dut.SetDrActive(false);
%configure for 5MHz SPI clock, 5us stall
Dut.SetSCLKFreq(5000000);
Dut.SetSpiStallTime(5);
%reset DUT
Dut.ResetDut();
pause(0.5);
%print product ID
fprintf('Product ID: ADIS%d\n',uint32(Dut.ReadUnsigned('PROD_ID')));
%configure DR for DIO1, active high
Dut.WriteUnsigned('FNCTIO_CTRL', 0xC);
Dut.SetDrPin(1);
%set ODR to full rate
Dut.WriteUnsigned('DEC_RATE', 0);
%print data ready freq
fprintf('IMU data output rate %dHz\n',double(Dut.MeasurePinFreq(1)));
%enable dr active
Dut.SetDrActive(true);
%Create reglist
regs = NET.createArray('System.String',3);
regs(1) = 'X_ACCL_OUT';
regs(2) = 'Y_ACCL_OUT';
regs(3) = 'Z_ACCL_OUT';
%Enable pausing
pause on
%sample freq
Fs = 2000;
%sample period
T = 1/Fs;
% NFFT
L = 4096;
%fft frequency vector
f = Fs*(0:(L/2 - 1))/L;
%array to hold raw DUT data
rawData = [];
%data for each accel axis
x = zeros(1,L);
y = zeros(1,L);
z = zeros(1,L);
x_fft = [];
y_fft = [];
z_fft = [];
%index in raw data
i = 1;
while(ishandle(H))
rawData = int32(Dut.ReadSigned(regs, 1, L));
i = 1;
for n = 1:3:length(rawData)
x(i) = rawData(n);
y(i) = rawData(n + 1);
z(i) = rawData(n + 2);
i = i + 1;
end
%calc FFT
x_fft = fft(x);
y_fft = fft(y);
z_fft = fft(z);
%remove back half
x_fft = x_fft(1:(L/2));
y_fft = y_fft(1:(L/2));
z_fft = z_fft(1:(L/2));
%Scale to magnitude
x_fft = abs(x_fft);
y_fft = abs(y_fft);
z_fft = abs(z_fft);
%divide by fft length
x_fft = x_fft / L;
y_fft = y_fft / L;
z_fft = z_fft / L;
loglog(f, x_fft);
hold on;
loglog(f, y_fft);
loglog(f, z_fft);
hold off;
xlabel('Frequency (in hertz)');
title('ADIS1648x XL FFT');
pause(0.1)
end
%Turn off user LED
Dut.UserLEDOff;
%Clean up FX3
Dut.Disconnect;