image thumbnail
from Interfacing Stepper Motor using LPT1 by Sourav Ray
This is a simple yet powerful Program to drive Stepper Motor using Parallel Port.

steppermotor.m
         %||=====================================================||%
         %||  STEPPER MOTOR CONTROL USING MATLAB DAQ TOOL BOX    ||%
         %||=====================================================||%
         %||  ADAPTOR USE: PARALLEL PORT (LPT-1)                 ||%
         %||  AUTHOR: SOURAV RAY                                 ||%
         %||=====================================================||%

     %      1 1 1 1      	%|------------------------------------\\
     % 	  1 1 1 1 1 1  	    %| ParaStepCon Vs- 1.01                )} 
     % 	1 1         1 1	    %|------------------------------------//
     % 	1 1         1 1 	%|ParaStepCon is a simple programme to\\
     % 	1 1         1 1     %|drive a 12V stepper motor witha step ))
     % 0000 1 1       00000 %|angle of 1.8 deg., using a Parallel //
     % 00  0  1 1     00    %|port. Before starting rogramming, I \\
     % 0000      1 1  00    %|wasn't sure how to do interfacing in ))
     % 00	       1 100000 %|MATLAB. Specially there is not much //
     % ``````````` 1 1````` %|reference available in the site.So I\\
     % 	1 1         1 1	    %|have decided to set this programme as))
     % 	1 1         1 1	    %|a reference to new users. In next Vs//
     % 	1 1         1 1	    %|you can expect complete control of  \\
     % 	  1 1 1 1 1 1  	    %|stepper motor.               ~SOURAV ))
     % 	    1 1 1 1    	    %|------------------------------------//
       
%=========================================================================%
%           << PARALLEL PORT INTERFACING FOR STEPPER MOTOR >>             %
%            ``````````````````````````````````````````````               %
% ________                ___________          ___________                %
%         |D0____________|           |________|           |______         %
%   L     |D1____________|           |________|           |______   To    %
%         |D2____________|     #     |________|     #     |______ Stepper %
%   P     |D3____________| 74LS244   |________|  ULN2003  |______  Motor  %
%         |              |           |        |           |               %
%   T     |----------|   |           |        |           |               %
% ________|Pin 18-25 |   |___________|        |___________|               %
%                   GND                                                   %
%                                                                         %
%=========================================================================%



 PsC=figure('Name','ParaSteprCon Vs~1.01   (c)Sourav Ray','NumberTitle','off',...
             'Units','normalized',...
             'Resize','off',...
             'Visible','on',...
             'Color',[.4 .5 .9], ...
             'Toolbar', 'none',...
             'Tag','extacy',...
             'WindowStyle', 'normal');
                        
 p=[0; 0; 0; 0; 0; 0; 0; 0; 0; 0];
 q=[0; 0; 1; 1; 1; 1; 1; 1; 0; 0];
 bar=p;
  bar=horzcat(bar,p); 
 for w=1:199
     bar=horzcat(bar,q);
 end
 bar=horzcat(bar,p); 
  bar=horzcat(bar,p);
  extacy =  imshow(bar);
steps=[1 1 0 0; 0 1 1 0; 0 0 1 1; 1 0 0 1];
i=1;
k=1;
parport=digitalio('parallel','LPT1');
line=addline(parport,0:3,'out');

for j=1:200
 extacy =  imshow(bar);
 if j>198
   title('Stoped: Programme Ends','FontWeight','bold');
 else
   title('Snigle Rotation in Clockwise Direction','FontWeight','bold');
 end
 bar(:,j+2)=p;
 pval=steps(i,:);
 i=i+1;
 putvalue(parport,pval);
gval = getvalue(parport);
 if i>4
     i=1;
 end
 tic;
 while(toc<.2);
  pause(0.01);  % 04-05-09; changed from previous 'pause(0.001)', because this will generate functional A fractional pause of 0.01 seconds in most of the platform. Bug reported by Ample Hout <ah2594@columbia.edu> %
 end;
     
end
 pval = [0 0 0 0];
putvalue(parport,pval);
  gval = getvalue(parport);
  delete(parport);
clear parport;

Contact us at files@mathworks.com