Design Project Progress


Design Projects 3 – PC Controlled Machine

By

Sandile Nzimande
20002501

TABLE OF CONTENTS


CHAPTER 1: INTRODUCTION

1.1 Introduction..……………………………………………………………………………………………………………..…………….……2

CHAPTER 2: BUILDING BLOCKS
2.1 Building Blocks………………………………………………………………………………………………………………..……………..2
2.1.1 The Control Terminal…………………………………………………………………………………………………….…….…….2
2.1.2 Switching and Power Circuit……………………………………………………………………………..….…………………..2
2.1.3 The Load……………………………………………………………………………………………………………………….……………3

CHAPTER 3: PROJECT DESIGN
3.1 Design……………………………………………………………………………………………………………………………………….…3
3.1.1 Block Diagram……………………………………………………………………………………………………………………………3
3.1.2 Circuit Diagram…………………………………………………………………………………………….…………………………..4
3.1.3 Flowchart…………………………………………………………………………………………………………………..……………..5
3.1.4 Software………………………………………………………………………………………………………………….……………….5

CHAPTER 4: RESULTS
4.1 Results…………………………………………………………………………………………………………………………….…………..6
4.1.1 Values measured…………………………………………………………………………………………….………………………..7
4.1.2 Values calculated………………………………………………………………………………………………………………..…….7
4.1.3 Formulae………………………………………………………………………………………………………………………………..….7

CHAPTER 5: CONCLUSION
5.1 Conclusion……………………………………………………………………………………………………………………………………..8

Annexure A Code Listing…………………………………………………………………………………………………….……………..9
Annexure B Bill Of Materials…………………………………………………………………………………………………….…….…16
Annexure C Data Sheets…………………………………………………………………………………………………………………..17



CHAPTER 1

1. Introduction
This PC based controller device allows one to wind cotton onto a spool using stepper motors. It consists of two stepper motors and is controlled via a computer parallel port.



CHAPTER 2

2.1 Building Blocks
The controller device is divided into 3 stages. The divisions were made according to its functions, which will offer simplicity and easy troubleshooting. The three stages are explained below.

2.1.1 The Control Terminal
The control terminal is the computer that runs the controlling software. The software written in C++
controls the parallel port interface by sending logic HI and LOW signals to the device being controlled

2.1.2 Switching and Power Circuit
This is the set of transistors connected to each data line from the control terminal. This circuit offers
significant current gains to the loads driven. The magnitude of the gains depends on the device used:

Ic = hfe x Ib
where Ic = load current, hfe = gain, Ib = input current


2.1.3 The Load
This is a pair of stepper motors which work alongside each other to complete the given task. The first
motor is responsible for winding cotton to the spool and the second distributes the cotton evenly
across the spool.



CHAPTER 3

3.1 Design
3.1.1 Block Diagram


Figure 3.1.1
Shown above is the block layout of the entire system. The computer controls the LPT interface,
the LPT interface sends control signals and switching circuit provides adequate power to the motors.



3.1.2 Circuit Diagram



Fig 3.1.2 – As mentioned earlier this circuit is divided into 3 main stages. The first stage is the computer
that controls the whole system. The second stage, the switching circuit which is a set of 4
transistors. Each set (Q1 to Q4 and Q5 to Q8) of these 4 transistors are identical and connect to
one stepper motor. Diodes D1 to D8 are protection diodes or snubbing diodes and provide a
safe way of dispersing the reverse current without damaging the transistor. The reverse is the
result of an inductive surge created when the coils are toggled. The last stage are the stepper
motors which connect directly to the switching circuit.



3.1.3 Flowchart



3.1.4 Software
The software interface for this system was written in C++ using the Bloodshed Dev C++
environment. Figure 3.1.4 illustrates the layout of the IDE. The source code for the 3 files shown
below can be found in Annexure A.



Fig 3.1.4 – Snapshot of the Bloodshed Dev C++ IDE



CHAPTER 4

4.1 Results



Figure 4.1.1 – The circuitry connected to each data line

4.1.1 Values measured using digital multimeter:
Voltages measured at LPT port pins: LOW = 0,0 v ; HIGH = 0,67 v
hfe = 240
VL = 0,68 v
Vce = 11,35 v
RL = 52,3 ohms


4.1.2 Values calculated:
Ic = 13 mA
Power = 24,18 W
Ib = 54 µA


4.1.3 Formulae:
Ic = hfe x Ib

Ic = VL / RL

P = V2 x R



CHAPTER 5

Conclusion
This system perfomed and achieved required task but further investigation is still in progress. The main concern was the low voltage levels at parallel port and specifically the logic HI which was far less than the expected value.

References
[1] IBM-PC Parallel Printer Port Programming Considerations, available at:
http://www.doc.ic.ac.uk/~ih/doc/par/doc/program.html

[2] P Horowitz, W Hill, The Art Of Electronics, 2nd Ed. Cambridge University Press 1980, 1987

[3] The Electronics Club – Transistors, available at:
http://www.kpsec.freeuk.com/components/tran.htm

[4] ePanorama.net – Powering devices from PC parallel port, available at:
http://www.epanorama.net/circuits/lptpower.html



ANNEXURE A: CODE LISTING

1.1 stepper-one.cpp


#include
#include
#include
#include
#include “delay.h”

/* Definitions in the build of inpout32.dll are: */
/* short _stdcall Inp32(short PortAddress); */
/* void _stdcall Out32(short PortAddress, short data); */
/* prototype (function typedef) for DLL function Inp32: */

typedef short (_stdcall *inpfuncPtr)(short portaddr);
typedef void (_stdcall *oupfuncPtr)(short portaddr, short datum);

#define PPORT_BASE 0×378

/* After successful initialization, these 2 variables
will contain function pointers.
*/
inpfuncPtr inp32fp;
oupfuncPtr oup32fp;

/* Wrapper functions for the function pointers
– call these functions to perform I/O.
*/
short inport (short portaddr)
{
return (inp32fp)(portaddr);
}
void outport (short portaddr, short datum)
{
(oup32fp)(portaddr,datum);
}
using namespace std;

int main(void)
{
Delay s;
HINSTANCE hLib;
short x;
int i;

/* Load the library */
hLib = LoadLibrary(“inpout32.dll”);

if (hLib == NULL) {
fprintf(stderr,”LoadLibrary Failed.\n”);
return -1;
}

/* get the address of the function */
inp32fp = (inpfuncPtr) GetProcAddress(hLib, “Inp32″);

if (inp32fp == NULL) {
fprintf(stderr,”GetProcAddress for Inp32 Failed.\n”);
return -1;
}
oup32fp = (oupfuncPtr) GetProcAddress(hLib, “Out32″);

if (oup32fp == NULL) {
fprintf(stderr,”GetProcAddress for Oup32 Failed.\n”);
return -1;
}
/*******************************************************/
/** IF WE REACHED HERE, INITIALIZED SUCCESSFUL ******/
/*******************************************************/
char direction;
char speed;
int n;

i = PPORT_BASE;
//outport(0x37A,43);
outport(0x037A,4); //write enable

while(1)
{
system(“cls”); //clears screen
cout<<"Enter direction: (Enter c-clockwise, a-counterclockwise and 'q' to quit)"; cin >> direction;
if(direction ==’q')
exit(1);
cin.clear();

cout<<"Speed: Slow or Fast? (s/f).."; cin >> speed;

float m = 1.08;
if(speed == ‘s’)
n = 10;
else
n= 0;

if(direction == ‘c’)
{
while(!kbhit())
{ outport(i,17);
s.delayMiliSeconds(n+m);

outport(i,34);
s.delayMiliSeconds(n+m);

outport(i,68);
s.delayMiliSeconds(n+m);

outport(i,136);
s.delayMiliSeconds(n+m);

outport(i,0);
s.delayMiliSeconds(n+m);
}
}
else if(direction ==’a')
{
while(!kbhit())
{
outport(i,0);
s.delayMiliSeconds(n+m);;

outport(i,136);
s.delayMiliSeconds(n+m);;

outport(i,68);
s.delayMiliSeconds(n+m);;

outport(i,34);
s.delayMiliSeconds(n+m);;

outport(i,17);
s.delayMiliSeconds(n+m);;

}
}

else if(direction ==’q')
exit(1);

}
outport(i,0); //reset port

/* finished – unload library and exit */
FreeLibrary(hLib);

getch();
return 0;
}
1.2 delay.cpp
#include
#include
#include
#include “delay.h”

Delay::Delay()
{
}
Delay::~Delay()
{
}
void Delay::delaySeconds( float seconds )
{
__int64 timeEllapsed;
__int64 timeStart;
__int64 timeDelta;

QueryPerformanceFrequency( (LARGE_INTEGER*)(&timeDelta ) );
QueryPerformanceCounter ( (LARGE_INTEGER*)(&timeStart ) );

__int64 timeToWait = (__int64)((double)timeDelta * (double)seconds);
timeEllapsed = timeStart;

while( ( timeEllapsed – timeStart ) < timeToWait ) { QueryPerformanceCounter( (LARGE_INTEGER*)(&timeEllapsed ) ); }; } void Delay::delayMiliSeconds( float miliseconds ) { __int64 timeEllapsed; __int64 timeStart; __int64 timeDelta; QueryPerformanceFrequency( (LARGE_INTEGER*)(&timeDelta ) ); __int64 timeToWait = (__int64)((double)timeDelta * (double)miliseconds/1000.0f); QueryPerformanceCounter ( (LARGE_INTEGER*)(&timeStart ) ); timeEllapsed = timeStart; while( ( timeEllapsed - timeStart ) < timeToWait ) { QueryPerformanceCounter( (LARGE_INTEGER*)(&timeEllapsed ) ); }; } void Delay::delayMicroSeconds( float microseconds ) { __int64 timeEllapsed; __int64 timeStart; __int64 timeDelta; QueryPerformanceFrequency( (LARGE_INTEGER*)(&timeDelta ) ); __int64 timeToWait = (__int64)((double)timeDelta * (double)microseconds / 1000000.0f); QueryPerformanceCounter ( (LARGE_INTEGER*)(&timeStart ) ); timeEllapsed = timeStart; while( ( timeEllapsed - timeStart ) < timeToWait ) { QueryPerformanceCounter( (LARGE_INTEGER*)(&timeEllapsed ) ); }; } 1.3 delay.h #ifndef __DELAY_H__ #define __DELAY_H__ class Delay { public: Delay(); ~Delay(); static void delaySeconds( float seconds ); static void delayMiliSeconds( float miliseconds ); static void delayMicroSeconds( float microseconds ); }; #endif

ANNEXURE B: Bill of materials

8 x BC237B Transistors at 0,48c each
8 x IN4007 diodes at 0,86c each
2 x 2515-02 12v stepper motors at R65,28c each
1 x DB25 male socket at R3,21c each
1 x 1m DB25 cable at R75,00 each

Total: R 219, 49

All components bought at Mantech Electronics – Durban, http://www.mantech.co.za/



ANNEXURE C: Datasheets


Transistors used:



Stepper Motors used:

Comments are closed.