No BSD License  

Highlights from
Stepper Motor ToolBox for MatLab v1.0

from Stepper Motor ToolBox for MatLab v1.0 by Sergio Alejandro González
Stepper Motor ToolBox for MatLab v1.0

powerwaves(fin,Vh,Vl,Tvs,V)
function [Wa, Wb] = powerwaves(fin,Vh,Vl,Tvs,V)
% PowerWaves, rutina para la generacion de la forma de onda 
% de corriente/tension de salida que va directamente a los 
% bobinados del motor. El motor se puede gobernar por corrientes 
% imopuesta o por tension. En el caso de corrientes impuestas las
% forma de onda de salida es casi ideal.
% En el caso de tension impuesta aparece el factor R/L.

%   Author: Sergio Alejandro Gonzalez 
%   Copyright (c) 1998-99 by S.A.Gonzalez.
%   $Revision: 1.0 $  $Date: 1999/02/25 16:17:20 $

error(nargchk(5,5,nargin))

%
% Wa and Wb wave generation :
%
MaxPts =	length(fin);
Wa	= zeros(1, MaxPts);
Wb	= zeros(1, MaxPts);
k	= 2;
j  = MaxPts;
while (j ~= 1) & ((k+Tvs) < MaxPts),
   if fin(k) ~= Vh
    Wa(k) = Wa(k-1);
    Wb(k) = Wb(k-1); 
    k=k+1;    
   else
    i=Tvs;
    if Wa(k-1) == 0
      while  (i ~= 0),
        Wa(k+Tvs-i) = V;
        Wb(k+Tvs-i) = -V;
        i=i-1;
      end  %while
     elseif (Wa(k-1) == V) & (Wb(k-1) == -V)
      while  (i ~= 0),
        Wb(k+Tvs-i) = V;
        Wa(k+Tvs-i) = V;
        i=i-1;
    	end  %while
 	  elseif (Wa(k-1) == V) & (Wb(k-1) == V)
      while  (i ~= 0),
      	Wa(k+Tvs-i) = -V;
      	Wb(k+Tvs-i) = V;
      	i=i-1;
      end  %while
 	  elseif (Wa(k-1) == -V) & (Wb(k-1) == V)
      while  (i ~= 0),
      	Wb(k+Tvs-i) = -V;
      	Wa(k+Tvs-i) = -V;
      	i=i-1;
      end  %while
 	  elseif (Wa(k-1) == -V) & (Wb(k-1) == -V)
      while  (i ~= 0),
      	Wa(k+Tvs-i) = V;
   		Wb(k+Tvs-i) = -V;
      	i=i-1;
      end  %while
    end %if
    
    k = k+Tvs;
  
   end %if
   j = j-1;
end  %while

Contact us at files@mathworks.com