as I am a bit stuck at the moment with the controller side of the project, it is time to have a go at a sinusoidal reference.
I really need to create a series of lookup tables that have the reference points with respect to gray code.
here is the m file:
clear
% set up first column as binary encoder
E_binary = transpose(0:1:4095);
Ia_binary(:,1) = E_binary;
Ib_binary(:,1) = E_binary;
Ic_binary(:,1) = E_binary;
% mechanical offset
Mech_offset = 500;
% phase offsets
Ia_offset = Mech_offset + 0;
Ib_offset = Mech_offset + 512/3;
Ic_offset = Mech_offset - 512/3;
Ia_binary(:,2) = sin((E_binary+Ia_offset)/512*2*pi);
Ib_binary(:,2) = sin((E_binary+Ib_offset)/512*2*pi);
Ic_binary(:,2) = sin((E_binary+Ic_offset)/512*2*pi);
%open the lookup table file
load b_to_g.mat;
%use lookup table function
for i = 1:4096
% use lookup to change to gray
Ia(i,1) = interp1(binary_to_gray(:,1),binary_to_gray(:,2),Ia_binary(i,1));
Ib(i,1) = interp1(binary_to_gray(:,1),binary_to_gray(:,2),Ib_binary(i,1));
Ic(i,1) = interp1(binary_to_gray(:,1),binary_to_gray(:,2),Ic_binary(i,1));
end
% copy 2nd column
Ia(:,2) = Ia_binary(:,2);
Ib(:,2) = Ib_binary(:,2);
Ic(:,2) = Ic_binary(:,2);
figure(1)
plot(Ia_binary(:,1),Ia_binary(:,2),Ib_binary(:,1),Ib_binary(:,2),Ic_binary(:,1),Ic_binary(:,2))
figure(2)
subplot(3,1,1)
plotmatrix(Ia(:,1),Ia(:,2))
subplot(3,1,2)
plotmatrix(Ib(:,1),Ib(:,2))
subplot(3,1,3)
plotmatrix(Ic(:,1),Ic(:,2))
here is the output:

i will use the transition from HE5 to HE1 as a reference. With the current setup, this is at 134.
from the plot in my previous post:
the increasing zero crossing for A will be 512/12 counts after the HE5 to HE1 reference.
the increasing zero crossing for B will be 512*5/15 counts after the HE5 to HE1 reference.
the increasing zero crossing for c will be 512*9/15 counts after the HE5 to HE1 reference.