I am pretty happy with how the logging is going now. With the new board, all the measuerements (piezo, current, back emf, strain gauge) come in on the same task and are logged to one file. I then have one matlab script to make all these files into one matrix.
Making all the files into one matrix makes subsequent calculations much faster as they can all be matrix operations with no loops.
the use of the new pcb with the or gates and the one shot circuit also ensures that I get every encoder position.
Here is the m file that I use to convert all the text files into a matrix:
clear;
% set up the DAQ parameters
number_of_revolution = 11;
one_revolution = 4096;
length = number_of_revolution*one_revolution;
% read in the Encoder data
fid = fopen('Encoder.txt');
Encoder = textscan(fid, '%f');
fclose(fid);
E_gray = Encoder{1};
% Read in the time data
fid = fopen('Time_Stamp.txt');
counter = textscan(fid, '%f');
fclose(fid);
T = counter{1};
% Read in the Analog data
fid = fopen('Analog.txt');
Analog = textscan(fid, '%f %f %f %f %f %f %f %f %f %f %f');
fclose(fid);
A(:,1,1) = Analog{1};
A(:,1,2) = Analog{2};
A(:,1,3) = Analog{3};
A(:,1,4) = Analog{4};
A(:,1,5) = Analog{5};
A(:,1,6) = Analog{6};
A(:,1,7) = Analog{7};
A(:,1,8) = Analog{8};
A(:,1,9) = Analog{9};
A(:,1,10) = Analog{10};
A(:,1,11) = Analog{11};
% convert encoder to binary from gray
load g2b16_lookup.mat;
encoder_lookup_16bit = g2b16_lookup(:,2);
disp('converting encoder from gray code to binary...')
for i = 1:length
% provide status to the screen
if mod(i,one_revolution) == 0
number_of_rotations_converted = i/one_revolution
end
E(i,1) = encoder_lookup_16bit(E_gray(i)+1);
end
% create matrix for all the data one collumn for one revolution
% for each speed we have a 3 dimensions matrix (first dimension : encoder,
% second dimension : number of revolutions)and after
% Layer 1 : encoder
% Layer 2 : time
% Layer 3 : IA
% Layer 4 : IB
% Layer 5 : IC
% Layer 6 : P1
% Layer 7 : P2
% Layer 8 : P3
% Layer 9 : P4
% Layer 10 : BA
% Layer 11 : BB
% Layer 12 : BC
% Layer 13 : SG
% Find the index for E = 4095
disp('offsetting all the readings...')
j = 0;
E_start_found = 0;
while E_start_found == 0
j=j+1;
if E(j,1) == 4095;
E_start_found = 1;
end
end
offset = j;
% now I have to take offset off all the readings
E_offset(1:(length - one_revolution),1,:) = E(offset:(length - one_revolution + offset - 1),1,:);
T_offset(1:(length - one_revolution),1,:) = T(offset:(length - one_revolution + offset - 1),1,:);
A_offset(1:(length - one_revolution),1,:) = A(offset:(length - one_revolution + offset - 1),1,:);
% now I have to put the offset vectors into the matrix
disp('compiling the vectors into a matrix...')
n = 0;
for i = 1:(length - one_revolution)
if E_offset(i,1) == 4095;
n = n + 1;
end
Matrix_temp((i-(n-1)*one_revolution),n,1)=E_offset(i,1);
Matrix_temp((i-(n-1)*one_revolution),n,2)=T_offset(i,1);
Matrix_temp((i-(n-1)*one_revolution),n,3:13)=A_offset(i,1,1:11);
end
% flip the matrix so that the encoder is in increasing order
Matrix = flipdim(Matrix_temp,1);
% save the data
save('AfmMatrix.mat', 'Matrix')
then it is easy to plot any of the measurements.
ie
clear;
% read in the raw data
load('AfmMatrix.mat', 'Matrix');
raw(:,:,:,1) = Matrix;
% plot I
for i = 1:3
figure(1)
subplot(3,1,i)
plot(raw(:,:,i+2,1));
end
% plot P
for i = 1:4
figure(2)
subplot(4,1,i)
plot(raw(:,:,i+5,1));
end
It is worth noting that I need to take one additional revolution when I am logging in labview so that I can start my matrix at encoder position 1.
current

piezo