SlideShare a Scribd company logo
1 of 44
Download to read offline
Penang Skills Development Center
BTEC Higher National Diploma
A project report submitted in partial fulfillment
of the award of Higher National Diploma
Title: Central Control Switching System
Author: Goh Hoe Hin, Yau Soon Ting
Supervised
by: Mr. PC Mok
Date: 10th
July 2003
Abstract
This report will introduce you a device that able to handle up to 32 switches,
remotely. No special previous software or hardware knowledge is required in order to
use this device. Although, of course, any prior background in these 2 fields will be
helpful. This report starts with the software part introduction, followed by the
hardware part for this device. Nothing is left out. By the time you finish this report,
you will be able to handle this device without major problems.
Mr. Yau and myself build this device, this includes the software developing and
hardware designing. We did not really refer to any standard circuit from other
resources, but apply what we have learnt through out the course, base on concept. We
have been hit by several problems but luckily we solved them one by one. For the
software development, I did approach some software experts for assistance, but only
limit to certain routines and problem.
One final point: Although both of us, as the amateur in this field build this project, but
we had done our best, not only to fulfill the official requirement but also our own
satisfaction. If time and opportunity is given, we would be able to achieve something
better. After all, both of us have learnt a lot of experiences and knowledge while
solving problems.
2
Acknowledgement
The ideas, concept and structure of this project have come from many sources: ex-
lecturer like Gladys Fan (who is also a good friend of mine); members in
Subduck.com, who have given me a lot of precious advices to solve certain C++
subroutines, very often students in my course like Say Aun, Gaik Hoay and Tracy,
who have asked the questions I need to hear in order to make the project more user-
friendly.
Colleagues in a same company around me are wonderful, especially Raj, who used to
find the weak points of this project in order for me to work on improvements. And of
course, the best person who worked closely with me, brainstormed on any issues and
keep finding improvement of this project is my partner, Mr. Yau Soon Thing. He is
staying kind of far away from my house but travel to see me every weekend just to get
this project done step-by-step.
Lastly, we both would like to thank Mr. Mok, our supervisor of this project, who has
given us a lot of useful information, clear our doubt while we were in trouble and so
on.
3
Contents
Title Page
Introduction 6
Program Chapter
1. Project Overview 7
2. Theoretical Development & Design 8
2.1. Some History of C++ 8
2.2. Differences of C and C++ 8
2.3. Initial Plan & Later Changes of the Program 8
2.3.1. Information of Demultiplexer 8
2.3.2. Manual Clock Pulse 9
2.3.3. Any special training needed? 9
2.4. Outline and Algorithm 10
2.4.1. Function 10
2.4.2. File I/O 11
2.4.3. Parallel Port 12
2.4.4. Looping Techniques 12
3. Project Construction 14
3.1. Parallel Port 14
3.1.1. Overview & Pins Description 14
3.1.2. Software Interfaces with Hardware Port 14
3.2. The Program & Source Code 15
3.2.1. Source code flow 15
3.2.2. ON/OFF operation 15
3.2.3. Hardware Toggle 15
3.2.4. Software Toggle 16
3.2.5. Enable Switch (G1/G2) 16
3.3. Other Features 17
4. Problems & Solutions 18
Hardware Chapter
5. Project Overview 20
6. Theoretical Development & Design 21
6.1. Demultiplexer 21
4
6.2. JK Flip-flop 21
6.3. Darlington Switch 21
6.4. Relay Functions 22
6.5. Backup Switch 22
6.6. Feedback System 22
7. Project Construction 23
7.1. Circuit Simulations 23
7.2. Metal Case 23
7.3. Connections between PCBs 23
7.4. The Ventilator 23
7.5. Communication Switches 23
7.6. Feedback System 24
7.7. Backup Switch 24
7.8. Casing Outlook 24
8. Problems & Solutions 25
9. Evaluation Results and Data 26
10. Discussions & Conclusions 27
10.1.Software 27
10.2.Hardware 28
References 31
Appendix 2 32
Appendix 3 33
Appendix 5 (Available in file named Appendix 5.doc) 37
Appendix 6 38
Appendix 7 39
Appendix 8 42
Appendix 9 43
Appendix 10 45
Datasheets 46
5
Introduction
Have you ever imagined how tough to turn ON and OFF all the lights, air
conditioner, etc. in a building? This is the routine job for the building
management staff everyday. Before you arrived and after you left your
office, they have to check and manage those switches, level by level!
This project is mainly used to solve this problem. With the assistance of this project,
you can sit back and relax, let this device helps you to manage your switches daily,
without leaving your chair! Besides, this device will also indicate you the status of
any equipment it controls.
This device consists of 2 major portions: Program Chapter (program written in
C++) and Hardware Chapter (interface board, processing board, etc). The 1st
set of
this report will give you full explanation of the software development procedures, the
flow, extra knowledge gained as well as problems we met and how we solved it. To
further understand the structure of hardware portion, please refer to the 2nd
set of this
report.
6
Program Chapter
1. Project Overview
The concept of the program is pretty simple. We know that computers are
operating under both logic “1” and “0”(ON of OFF). So, with this simple theory,
we brainstormed out the structure of this device, let both “1” and “0” replace our
fingers. When you select to turn ON a particular electric equipment from the
monitor screen, the program will help you to send a logic “1” and translate the
equipment selected into a code, sending out from the parallel port (printer port –
25pins). When the interface board receives the signal, it will identify which
equipment you have selected. After confirming the code address, it will transfer
the logic “1” to the processing board. The processing board will then operate the
relevant relay to help you turn ON the equipment.
To make the program more flexible and user-friendly, I have designed a couple of
tools, which allow users to have more control in order to suit into different
environment. For example, users may customize each and every switch name.
Besides, I have gather 4 switches into 1 group (or module in the program). This
will greatly help the users to identify the switch and area. Users also may change
the name of the group (e.g. Ground Floor, Canteen, Guard House and etc.)
This program will also “remember” the status of every switch, so that users will
not accidentally double ON or OFF a certain switch. Those switch status can also
be reset. The usage of this RESET is used when there is any power trip that
caused the whole building black out. After the power resume, status can be
RESET back to OFF or ON, depending on the situation.
This program can control up to 32 switches. Hardware wise, the boards are
designed to be expandable. Hence, users do not need to purchase all 32 switches if
they do not have so much electric equipment to be controlled.
7
2. Theoretical Development and Design
There are a lot of different programming languages to use for interfaces with
external devices. We have chosen C++.
2.1. Some History of C++
The C programming language was developed at Bell Labs during the early
1970's. Quite unpredictably it derived from a computer language named B
and from an earlier language BCPL. Initially designed as a system
programming language under UNIX it expanded to have wide usage on many
different systems. C++ was designed to support the features of C such as
efficiency and low-level support for system level coding. Added to this were
features such as classes with inheritance and virtual functions, derived from
the Simula67 language, and operator overloading, derived from Algol68.
2.2. Differences of C and C++
Although the languages share common syntax they are very different in
nature. C is a procedural language. When approaching a programming
challenge the general method of solution is to break the task into successively
smaller subtasks. This is known as top-down design. C++ is an object-
oriented language. To solve a problem with C++ the first step is to design
classes that are abstractions of physical objects. These classes contain both
the state of the object, its members, and the capabilities of the object, its
methods. After the classes are designed, a program is written that uses these
classes to solve the task at hand.
2.3. Initial Plan & Later Changes of The Program
Initially, we planned to control 8 switches only. So it is pretty simple to have
all 8 parallel port pins to directly connect to the hardware and drive the
operation. But it seems not healthy at all as we have limited the future
expansion of our project. So we chose an extra component called
demultiplexer.
2.3.1. Information of Demultiplexer
To design the program that can drive a demultiplexer, we must first
understand its input and output flow. From Table 3.2 and 3.2.5 in
Appendix 3, we understand that the selected 74LS154 is an active-low
demultiplexer. Whichever point we select, it will send a LOW to it and
8
the rest will be set to HIGH. There are another 2 enable pins (G1/G2)
that shall not be forgotten, we need to control them in our program.
But how do we to control them? You may refer to the “Project
Construction 3.2.5” below.
2.3.2. Manual Clock Pulse
The following task to further the program design work should be
controlling the switches. Since we are going to use the demultiplexer to
have more than 8 switches, hence we will use TOGGLE instead of
SET and RESET method. We wanted to generate a “clock-pulse” for
the 74LS112 JK flip-flop because we know if we set both J and K at
HIGH, the output will toggle from one to another at every clock edge.
For further detail information about this method, you may refer to the
“Project Construction 3.2” below.
2.3.3. Any special training needed?
No, this program is a prototype and will be used by variety level of
users come from different region, different working environment.
Hence, the program must be:
• User-friendly
The interface menus and messages are written in common English
language, pretty simple to be understood. All possible choices that
will be made by users have been considered and no “surprise”
errors will appear to users. After all, the program will guide users
step-by-step to complete their tasks.
• Self-explanatory
Messages and notes that will be displayed to users are all self-
explanatory, meaning that the program will never ask any
complicated configurations from users.
• Flexibility
Flexible to be applied in different usages and working environment
This program is designed in general way, not really specific for
user type, environment, etc. Users can customize the interface
menus according to their need
9
2.4. Outline and Algorithm
The program that used for this project is called “switch.cpp” (Refer to Source
Code in Appendix 2. This program is used to control 32 switches maximum.
Hence, as expected, there will be a lot of looping tasks in the source code
because a same task will be repeated for 32 different switches. In this
program, I used some skills such as function, file I/O, variables array
manipulating, parallel port I/O, different looping techniques and etc. The
program flow chart can be seen in Chart 2.4 in Appendix 2.
2.4.1. Function
The techniques, or we called it “style”, that used in function calls of a
C/C++ program, varied from different users. There is no fixed method
that we should obey in order to get certain tasks done. In this program,
we are practicing a few techniques.
2.4.1.1.Pass value only to functions
Here we just passed a set of variables to the function, the function
will process a certain tasks with the variables given. After
completed, the program will return to the main() function and
continue with the rest of instructions. Refer to our source code in
Appendix 2, line 830 and 877. This technique is good to perform
repeated tasks; which required no value returned. For this
technique, we should declare “void” during the function prototype
declaration.
2.4.1.2.Pass a pointer value to functions
This technique has a little difference with the above. It does not
directly pass a value to the function but a memory location
(memory pointer). You can refer to the example in the source code
in Appendix 2, line 813. Since we do not ask for any return value
from this function, it declared as “void” in the prototype
declaration.
2.4.1.3.Pass and return value from functions
This technique normally used for a repeated calculation; which
required some calculated answer/data to be returned to the main()
function. In our source code, the example can be referred to line
10
778. There are 4 variables passing out from the main() function and
required this function to return the value of “d” after finished
performing the tasks. As you noticed, in the prototype declaration
we used “int” instead of “void”. This “int” indicates the data type
of the return value.
2.4.2. File I/O
This is one of the new knowledge I have learnt. This program needs to
store a lot of data such as Module/Switch name, Switch status, etc. In
order to use the file I/O, we need to include the <fstream.h> file. This
file contains declarations for file I/O functions that the program needs
to use. We will be using two classes “ifstream” and “ofstream” for
input and output respectively.
2.4.2.1.Reading from a file (ifstream)
In order to read data from a file, we must declare an object for it to
open a file. E.g.:
ifstream fin (“test.txt”);
After opening the file, we will be using the in-stream object to
perform the reading job. E.g.:
fin >> data1 >> data2;
The example above shows how to input “data” into a file but
somehow if the data is a string, which contains space, we will use
the example below:
fin.getline (var, number_of_char_in_var_buffer);
After finished extracting data from file, do remember to close the
function, i.e.:
fin.close();
The “fin” is actually a name that we use for the I/O function. It can
be any name.
2.4.2.2.Writing to a file (ofstream)
In fact, both reading and writing are almost same. Only differences
are the declaration and the symbol. To declare an object for it to
write into a file, you must first open the file. This time, the file can
be either exist or not exist. If the function can find the file name
you keyed in, it will use it. Else, it will create a new one.
11
ofstream fout (“test.txt”);
After opening the file, you will use the following example to write
data into it, e.g.:
fout << data1 << data2;
Same with “ifstream”, you need to close the function by using:
fout.close();
Take note that the symbol used for reading file is “>>” (extraction)
and “<<” (insertion) is for writing file.
2.4.3. Parallel Port
Parallel port, so-called Printer port, is one of the ready-made I/O
port for a standard PC. Since this is the default port, it has it’s own
port address to be located by the PC. No matter what type of
language you use in your program, you have to use back the same
address. In C++, the address is 0x0378H. It is in hexadecimal form.
For further detail explanation, please refer to the next chapter.
2.4.4. Looping Techniques
The looping techniques basically can be categorized into 3 types:
• For Statement
The For statement is quite officially used by most
programmers. It has a characteristic of letting the program
knows about the basic condition, initial value of a variable and
increment.
• While Statement
The While statement is quite user-friendly (at least I felt that).
It does not really state down all the important data such as
initial value for a variable and the incremental value. It’s job is
very simple, just loop. It only asks for one thing, which is “until
when” you want the looping happen. So, normally users will
put the initial value for the looping counter before the While
statement and the incremental value will be inside the loop. The
reason I felt that it is user-friendly because when you write a
program, certain time we might not know exactly how many
12
times we want it to loop and what initial value we should put
for the counter. It is quite “layman” type of looping statement.
• Do… While Statement
This technique quite similar to the While statement but it
happened in another way round. It asks the program to perform
a task, just like a normal program flow but before it ends the
braces, there is a While condition waiting and bounce back the
flow until it fulfills the condition. Just like a gate asking for a
pass before going out. If the counter is still not reaching the
condition, it will be looping back.
13
3. Project Construction
The construction of this project has been categorized into several portions as
below:
3.1. The Parallel Port
The main communication gateway for the program with external hardware is
parallel port; hence let’s start some introduction. The standard PC parallel
port (printer port) is a 25-pin D-Type connector. It is very handy for testing
and controlling devices. It provides an easy way to implement a small amount
of I/O.
3.1.1. Overview & Pins Description
The original IBM-PC’s parallel printer port had a total of 12 digital
outputs and 5 digital inputs via 3 consecutive 8-bit ports in the
processor’s I/O space, as shown in diagram below:
113
1425
D7 D0D1D2D3D4D5D6
S7 S3S4S5S6 C3 C2 C1 C0
• 8 output pins accessed via the DATA port (D0~D7)
• 5 input pins accessed via the STATUS port (S3~S7)
• 4 output pins accessed via the CONTROL port (C0~C3)
• The remaining 8 pins are ground (pin 18~25)
3.1.2. Software Interfaces with Hardware port.
To communicate with the parallel port, there are certain addresses and
registers that you need to use in the source code. There are 3 Base
addresses for the parallel port, which are 0x0378, 0x0278 and
0x03BC. Refer to the Table 3.1.2 in Appendix 3.
The 0x03BC is MDPA system (Monochrome Display and Printer
Adapter). The 0x0378 and 0x0278 are Primary and Secondary Printer
Adapter respectively. Hence we have chosen 0x0378 to be our
communication port. The Data Port pins were driven by a 74LS374
octal latch, which could source 2.6mA and sink 24mA. There were
14
0.0022µF capacitors between each line and ground to reduce
transients. It is advised that the external device not to pull these lines to
ground as it will potentially cause the 74LS374 to source for more
current than it could handle without damage. Whereas, the Control Port
pins were driven by the 7405 inverting open collector buffers, pulled to
+5 volts via 4.7K resistors. All lines except C2 (pin 16) are inverted
before going to the output pins. The C2 line is double-inverted before
going to pin 16.
3.2. The Program and Source Code
Basically the program is used to send signals out from the 0x0378 port, of
course, via a specified pin. The first electronic component that receives these
signals is the 74LS154, a 4-to-16 active-low demultiplexer.
The program utilized the Data pins and divided it into 2 portions as shown in
Diagram 3.2 in Appendix 3. As you can see, we are not fully utilized the 8-
bit data registers. Even if we only use 8 data pin from a parallel port, we can
achieve up to 256 switches control (28
=256) We separated the 8-bit registers
into two; the first demultiplexer will be controlled by the 00h~0Fh (4-bit; 24
=
16 outputs). The same goes to the second demultiplexer, but the control bit
will be 00h~F0h. Refer to Table 3.2 in Appendix 3.
3.2.1. The source code and how it flows?
The source code can be referred in Appendix 2.
3.2.2. How does the ON/OFF operate?
The operation concept is pretty simple, we are actually toggling the
switch, regardless of the current status is ON or OFF. So one question
will pop up, “Will the users know whether they are turning it ON or
OFF?” In fact, the program has the capability to remember the
ON/OFF status. Hence, the hardware job is only toggling it will do.
3.2.3. Hardware Toggle
Refer to the Table 3.2.3 for 74LS112A in Appendix 3, when both J
and K of the flip-flop had supplied to HIGH, the output will fully
depend on the CLK signal. When there is a clock pulse, the value of
output Q will toggle. The 74LS112A is a negative-edge triggered flip-
flop. When any pin of the demultiplexer been selected, it will send a
15
LOW signal to the selected flip-flop CLK pin, which seems like a
negative-edge clock pulse and this will trigger the JK flip-flop.
3.2.4. Software Toggle (Manual Clock Pulse)
From the Hardware Toggle explanation above, we know that we need
to generate a series signal in sequence HIGH-LOW-HIGH to the
hardware. Hence, in the source code, we purposely utilized the G1/G2
strobe pin. If both of these strobe pins been set HIGH, all the output of
the demultiplexer will be turned HIGH. So, before any operation done
by users, the program will send a HIGH to both strobe pins. When any
switch been selected, the signal will be waiting at the input pin of the
demultiplexer but they can’t enter the demultiplexer because both
strobe pins are still HIGH. After that, the program will send a LOW
signal to both strobe pins and this will enable the demultiplexer to
accept the signal that has been waiting at the input pins. Once this
operation has done, the program will loop back and trigger the G1/G2
strobe and the JK flip-flop will receive another HIGH signal. Refer to
Diagram 3.2.4 in Appendix 3.
3.2.5. Enable Switch & G1/G2 of Demultiplexer
Refer to the Table 3.2.5 for 74LS154 in Appendix 3; to enable the 4-
line input, we need to set both G1 and G2 (pin 18 & 19) LOW. Since
we are utilizing 2 demultiplexer, the program source code must be able
to select and enable which demultiplexer we need, i.e. while
controlling first 16 switch, we need to disable the second
demultiplexer.
Refer to Software Chapter, Section 3.1.3 of this report, besides the 8
data pins; we still have 4 control pins. Hence, we used 2 of them to
control the strobe pins for both demultiplexers; they are pin 1 and pin
14. Both pins are active-low triggered. To set both of them HIGH,
simply send a 0x00 to the Control registers. To select the first
demultiplexer, we send a 0x01 and for the second demultiplexer, 0x02
will be sent.
16
3.3. Other Features
This program has included a few features besides the switches operating
menu (Diagram 3.3 in Appendix 3). They are:
3.3.1. Switches Status (Diagram 3.3.1 in Appendix 3)
Besides the indicator LED found in the hardware device, users might
also check the status for each switch from this menu.
3.3.2. Change Items Name (Diagram 3.3.2 in Appendix 3)
This feature is a MUST for users. It will help you to categorize all
switches into groups. Users are freely changing any name found in the
database to suit in different environment.
3.3.3. Configuration Reset (Diagram 3.3.3 in Appendix 3)
This menu will allow users to RESET 3 type of database, such as
Module Name, Switch Name and Switch Status.
The program cannot predict any issue happened with the hardware
such as power trip/failure, malfunction and etc. So, if the hardware or
the area that controlled by this hardware has power failure, users need
to RESET the switches status in the database because all switches
controlled by this program have turned OFF.
17
4. Problems & Solutions
Through out the implementation of this program, I faced quite a lot of problems,
which nearly caused me giving up.
• What is the address for Parallel Port and how to apply them?
This problem attacked me in the very beginning of this project. I have sourced
for books and Internet. That useful information has collected from different
sources and they can be found in the “Reference” chapter.
• Confusions of variables naming convention.
This program used a lot of variables. They consist of character and numeric-
type. If they are not properly named, the program development and future
maintenance will be difficult. In fact, there are a lot of variables can be reused
but I prefer create another new one. This is to ease my debugging job.
• How to save/read data in a file?
Since I am going to store some “permanent” data for this program, I need to
write them into a file. I have sourced for books from libraries, not all of them
have this kind of information. Lastly I found it from a website.
• Why certain variable can be used in function but some of them cannot?
When I try to pass a string-type variable to the function, it doesn’t work. No
matter how I swapped around the instructions, the result still failed. I have
joined in a C++ discussion forum (www.subduck.com) and found some
friends who willing to teach me besides the value passing, some other new
skills. To pass a string-type variable, we should put a “*” in front. The “*” is
actually pointing the program to the memory address of the variable. We are
not able to pass the whole string to a function.
• Why my compiler shows error on instructions that previously working fine?
Braces and semi-colons are commonly used in C++ programming. Although it
seems small stuff but if you forgot or extra put in 1, it is going to a
catastrophe. The compiler will never tell, but will give you a lot of error
against those correct-format instructions. Make a habit of leaving indent each
time when there is a set of brace-instruction putting semi-colon. Some
examples can be referred in my source code in Appendix 2.
• Are double-quotes (“…”) and single-quotes (‘…’) the same?
18
The usage of single quote (‘…’) is to display 1 character and for double quotes
(“…”) is to display a sequence of characters.
• Why I can’t apply the variable that has declared at the beginning of the
program?
Take note that the C++ programming language is case-sensitive. It is
recommended to use all-capital or small letter word to prevent mistakes.
Another possibility is, the variable declared is different type with the usage.
I found more and more interested in C++ programming. This project made me
learn more about it.
19
Hardware Chapter
5. Project Overview
The external hardware is built to perform tasks that commanded by the program
that we discussed in earlier chapter. Components that used in this hardware are
quite simple, including demultiplexer, JK flip-flop, Transistors, Diodes, Relays
and SPDT switch. To make this hardware safer and easier to be troubleshot, we
have separated it into few parts and each part will carry out different task. First
part is the Main Operation Room, second part will be the Feedback System for
output and the last part is the Output. Each part will be stored in different case to
prevent any physical damage.
The Main Operation Room is built by metal case covered with a transparent
plastic cover. All main operating boards can be found in this area. The Feedback
System is built by a metal plate with all related components attach to it. LEDs
fixed here to indicate the feedback. The Output is a simple expansion power
socket set. This socket set has been modified for this controlling system.
This hardware device is just a prototype, but it is expandable. Refer to Diagram 5
in Appendix 5.
20
6. Theoretical Development and Design
Refer to Block Diagram 6 for the flow in the Appendix 6. The development was
done in several portions as below:
6.1. Demultiplexer
The signal sent out by PC contains both HIGH and LOW (5V and 0V). These
signals will be delivered to demultiplexer via Parallel Port Input board. A
total of 8 data signals will be separated to 2 parts, flowing into 2
demultiplexers. When there is any selection made, the demultiplexer will
receive the signal and select the relevant output and set it to be LOW. The
rest of the output pins will be stayed HIGH. This is because the TTL
74LS154 that we used is an active-low demultiplexer. Refer to Table 3.2.5 of
Appendix 3 for the Truth Table. Due to the future expansion need, we
design the demultiplexer board to contain 2 74LS154, which will give a total
32 outputs.
6.2. Demultiplexer to JK Negative Edge Triggered
From the output of demultiplexer board, the signal will be sent to JK Flip-flop
Board. The 74LS112 we used is a negative-edge flip-flop. Assume that, a
selection has been made; the demultiplexer will send a LOW to the output.
This signal will be received by JK flip-flop. Since it is a LOW and the flip-
flop is already in “toggle” mode, the output of JK will toggle. The output of
JK will be connected to the Darlington switch and a set of LED indicator.
After that, the output of JK will be set to HIGH back by the program (without
users knowledge).
6.3. Darlington Switch
The output of JK flip-flop will connect directly to the base pin of first
transistor in the Darlington switch. This signal acts as Enable to the
Darlington switch. Both Collector pins of the transistors are connected to the
return of Relay. Hence, when the transistors are “enabled”, the current from
the Relay will flow through the Collector and Emitter to ground and the Relay
will start to operate. Refer to Diagram 6.3 in Appendix 6.
In fact, the basic concept of Darlington and One Single Transistor are the
same. The only difference is Darlington will amplified the gain and this will
sufficient enough to drive load such as relay, motor or coil.
21
6.4. Relay Functions
When the time t<0 (before start), the Relay is supplied with 5V from DC
source. Meanwhile, 240V from AC source has been ready at the contact point
of Relay. When an “enable” signal sent to Darlington by JK flip-flop, the coil
of Relay will be energized and the contact point will be switched.
6.5. Backup Switch
This board is actually a backup system. If there is any malfunction or
operation failure happened to the PC or any part of the Main Operation
Room fail to perform, users still can use this Backup System to manually
control the switch.
6.6. Feedback System
This feedback system consists of a 22Ω resistor, a 1N4001 diode, a zener
diode and a LED, connected in parallel. Refer to Diagram 6.6 in Appendix 6
for the connection. The zener diode regulates the voltage dropped across
LED, to protect any damage to the LED. Refer to Figure 6.6 below, notice
that as the reverse voltage is increased but the leakage current remains
essentially constant until the breakdown voltage is reached where the current
increases dramatically. This breakdown voltage is the zener voltage for zener
diodes. While for the conventional rectifier or diode it is imperative to operate
below this voltage; the zener diode is intended to operate at that voltage, and
so finds its greatest application as a voltage regulator.
Figure 6.6
22
7. Project Constructions
This project has four portions to be constructed. They are Demultiplexer Board,
JK Board (JK + Darlington), Relay Board and Backup Switch Board (refer to
Diagram 5 in Appendix 5). Besides, we designed our own Power Supply Board,
Parallel Port Input Board and the LED Indicator Board. The purpose to
separate the whole circuit into several boards is for future expansion. Users do not
need to purchase all 32 switches if they only have minor needs Refer to the
Diagram 7 for the constructions of the hardware is shown in the Appendix 7.
7.1. Circuit Simulations
The very first stage, we use the electronic simulation application to construct
our circuit. Basically this is to confirm the fundamental flow of the circuit.
Refer to Diagram 7.1 in Appendix 7.
7.2. Metal Case
Since this project has more than one PCB, we intend to design a case to place
all boards, to protect any physical damage to the boards as well as easy
handling. Hence, the size of each PCB must be considered.
7.3. Linkage between PCB’s board
For the connection between each boards, we used wires and 4-pin connectors.
Care must be taken while arranging the wire, as the pin-to-pin arrangement is
in sequence.
7.4. The Ventilator
There are a few components will potentially generate heat, such as the
Voltage Regulators (7805, 7812 and 7824). So we fixed a small ventilation
fan (12VDC, 0.9W) to increase the air ventilation. This is to expand the
lifespan for the said components.
7.5. Communications Switch
A DPDT switch is used in the Parallel Port Input Board. When a PC is
rebooting, it will perform POST (Power On Self Test) and some signals will
be sent to each peripherals including parallel port. Those signals are
considered unwanted signals to our project. So, before rebooting the PC, we
need to switch the enable pins (G1/G2) of demultiplexer to 5VDC, base on the
Truth Table, by doing this, the demultiplexer will ignore any input from PC.
23
7.6. Feedback System
During our discussion, there are a few ways to construct a feedback system
but we planned to build a simple and low cost system. After some
calculations, we have chosen a 22Ω, 10W resistor to connect in series with
the load. The reason is this resistor will not consume too much current and the
voltage dropped across (VR) will be quite minimum. Of course, the value of
VR varies depending on the wattage of the load we use (refer to Table 7.6 in
Appendix 7). So, to protect both LED and Zener diode, we should put 2
resistors in series with the 1N4001 diode and LED respectively.
7.7. Backup Switch
Refer to Diagram 7.7 of Appendix 7, this backup system is designed to
allow both way control to load.
7.8. Casing Outlook
The outlook of the project with metal case can be seen in Diagram 7.8 of
Appendix 7.
24
8. Problems and Solutions
A couple of problems have been encountered during the construction of this
hardware device but they have been solved. Refer to the summary below:
8.1. How to design a PCB board?
Initially we planned to design this project into a single PCB to save up some
time and cost. But this idea seems like not recommended as it will cause
difficulties for troubleshooting and not cost-effective as users need to
purchase all 32 switches in one time. Besides, distortions such as cross talk
and EMF interference will interrupt each other. Therefore the multilevel
board idea is implemented. With this, we can overcome those disadvantages
said above. To design a tidier circuit and minimize human error, we use an
application called PCB Designer to design our circuit. After that, we print it
out onto a wax paper by using laser jet printer. Then, we attach the surface of
the wax paper with circuit onto a blank PCB and iron it on top. Later, the
powder of the laser jet, which formed up the circuit stuck onto the PCB. Now
we can start to etch the PCB.
8.2. How to drive the Relay?
When the first revision of theoretical circuit formed, we used one transistor to
drive the Relay. Unfortunately it didn’t work. After studied some reference
through Internet, seems like the gain produced by one transistor is not
sufficient enough to drive the coil. So we changed our circuit to use two
Relays connected as Darlington pair. Refer to Diagram 8.2 in Appendix 8.
8.3. How to reduce noise interference?
A test was carried out after the completion of the hardware and interference
had occurred when relay switched the output. It caused the output selection to
be hey-wired and totally not stable. To be more precisely, noise is interfering
the components operation such as Demultiplexer, JK FF and Transistors. We
strongly believe that the contact point of the relay switch generates the noise.
Therefore, a new approach is to replace the OEG relay with an AC Output
Module from OPTO 22. For further information, please refer to the datasheet
in Appendix. After the change, the problem of noise interference generated by
relay has solved and the hardware is operated smoothly. Refer to Diagram
8.3 of Appendix 8 for the comparison of both types of relays.
25
9. Evaluations results and data
Base on the data collected, there are some differences of voltage value between
the measured and theoretical value.
9.1. Output voltage from external power source.
The output voltage theoretically should be 5VDC and 12VDC. But the
measurement showed lesser – approx. 4.89VDC and 11.81VDC. So the
difference between these two outputs is 2.2% and 1.58% respectively. Refer
to Table 9.1 of Appendix 9.
9.2. Parallel port output voltage to Demultiplexer
The HIGH and LOW state of a parallel port output should give a reading of
5VDC and 0VDC. But the actual value from the measurement is averagely
4.48VDC, the difference is 10.3%. Refer to Table and Diagram 9.2 of
Appendix 9.
9.3. Demultiplexer output voltage to JK FF
The theoretical value of a HIGH state should be 5VDC, but from the practical,
it was averagely about 3.73VDC. Luckily the minimum value of High Level
Input Voltage (VIL) for 74LS112 is 2VDC, hence, the JK Flip-flop still able to
operate. The difference between theoretical and practical value is 25.4%.
Refer to Table and Diagram 9.3 of Appendix 9.
9.4. Supply voltage to Darlington Pair
The input voltage for Darlington pair transistor theoretically is 5VDC. Base on
datasheet, the maximum supply is 6VDC. But at the practical result the input
voltage is 4.671VDC. The difference between is 6.58%. In the characteristics
of the transistor when it is in a Darlington pair, the voltage drop across the
collector is 4.09Vdc and the voltage droop across the emitter-base is
0.310Vdc. Meanwhile at the output value of the transistor is 4.83Vdc. The
ratio of difference between practical and theoretical output voltage is 96.6%.
26
10. Discussion and Conclusion
This project is a combination of software and hardware; numerous of experiments
and debugs have been done throughout the prototype implementation. Let’s
discuss and conclude what have achieved in this project.
10.1.Software
10.1.1. Temporary Memory
This program is used to control switches that operated by the external
hardware. Hence, a certain number of memories are needed, used to
store temporary data that have been made by users. As you know, C++
and most of the programming language are same, which allow users to
store data in variable (data register). Unfortunately this is not effective
enough. Data stored in Data register of microprocessor will disappear
once the supplied power has been cut off.
Conclusion:
The conclusion for this argument is, instead of using temporary
memory such as variable, I have found and learned the technique on
how to utilize file I/O to store in physical hard disk. With this
approach, data will not lost even the supplied power has been cut off,
provided the program stores the data appropriately.
10.1.2. Looping
As we know, the number of instructions used by a particular program
will also utilize the resources for a microprocessor. This program
performed a lot of repeated job because a same task will be applied
onto 32 different switches. Hence, if we do not use “loop” function, the
computer processing time will be slow down and the program will be
compiled in huge size.
Conclusion:
3 types of looping technique can be used in C++ (refer to Section
2.4.2.4). Due to this, I have gained a lot of hands-on practice on how to
use these techniques. Besides, during the implementation, I tried to
save the processor time as much as I can.
10.1.3. Functions (Sub-routines)
27
During the debugging, I found that a certain repeated job that will be
performed by this program could not apply “looping” technique. The
reason is a few data will be changed when the same task applied onto
the subsequent switches. For example, when the program operates on
the second switch, the hex code of the port (parallel & enable), the
variable name and memory location for a certain array will be differ.
Conclusion:
Looping instruction is not able to carry so much data, unless I use
nested loop. For a certain tasks, which have more data changes,
probably a couple layer of nested loop will be needed. This is not a
recommended practice as this will increase the mistake and also caused
the microprocessor to spend more unnecessary looping time. By using
Function Calls, I can simply solve all these problems and my program
look tidier to ease the debugging job.
10.2.Hardware
10.2.1. Supplied Voltage not sufficient as per Theoretical Concept
During the brainstorming and circuit developing, a certain voltage
values are expected to supply for components such as Main DC supply,
voltage value of level LOW and HIGH from Parallel port,
Demultiplexer, JK Flip-flop and Transistors. Somehow, the actual
measurements are decreased from expected. For detail information,
please refer to Appendix 9.
Conclusion:
In fact, this is considered normal because the material we used such as
cable, wire, components, PCB and connectors have certain resistance.
The values from Theoretical concept are all “ideal” expectation, which
is pretty difficult to achieve in reality. What we can do is, try to design
the circuit as smooth as possible, prevent using unnecessary
components, reduce wires usages and etc.
28
10.2.2. Unexpected Interference
Our project has been attacked by unwanted interference without our
knowledge. This happened during our “test run” on our project. The
output results were not stable while we controlled a certain relay to
switch.
Conclusion:
We have analyzed and realized that, this condition was caused by
electromagnetic field interference or so-called noise. While we send
out signals to switch the relay, the contact point inside the relay
generates those noises. After a long time searching for resources, we
found out that a type of relay called Solid State Relay will never
generate any noise that could sufficient enough to interfere our output
result.
10.2.3. Feedback
The initial intention of this feedback system is to indicate to users
when there is any failure with the equipment we controlled. There are
only 2 possible consequences that caused by failure, either open circuit
or short. So this feedback system must be able to detect them.
Conclusion:
How to build such a system? The first thing came to our mind is
putting something in series with our equipment. But this will have a
disadvantage. What if the component that in series with our equipment
fails? This will caused open circuit to our equipment. So, we have to
use certain component, which can last long, and not easily
malfunction. First, we connect a resistor rating 22Ω, 10W in series
with our equipment. Then, we connect a set of diode, zener diode and
LED in parallel with this 22Ω resistor. Refer to Diagram 6.6 in
Appendix 6. With this connection, the first diode 1N4001 will convert
the AC voltage drop across 22Ω resistor to become DC value. The
zener diode (rated 5.1V, 1W) has connected in such a way to provide
voltage regulation to the LED. (Note: Voltage dropped across zener
and LED are the same, as they are in parallel). The zener diode will
ensure only 5.1 V allowed to drop across it.
29
Base on Diagram 10.2.3a, with the increase of power (watt), the
resistance of the load will reduce. As we can understand, lower
resistance will allow more current to flow through. In the same time,
the voltage dropped across resistor 22Ω will increase because V=IR.
(Refer to Diagram 10.2.3b) The entire purpose for this zener is to
protect the LED.
When open circuit occurred in the load, LED will not light up and
when short circuit, a 2A fuse has fixed before 22Ω resistor will burn
off. But to be more secure, get two more resistors rated 220Ω, connect
them in series with the 1N4001 diode and LED respectively. The fuse
will protect the feedback system and the resistor acts as current limiter,
to protect both zener and LED.
30
References
C++ from Ground Up Author: Herbert Schildt
Publisher: McGraw-Hill (1994)
C++ Through Example Author: P.Sellappan
Publisher: Times (1994)
Thinking in C++ Author: Bruce Eckel
Publisher: Prentice Hall (1995)
Inside the C++ Object Model Author: Stanley B. Lippman
Publisher: Addison-Wesley (1994)
Parallel Port Complete Author: Jan Axelson
Publisher: Lakeview Research (2000)
Subduck http://www.subduck.com
The EE Compendium http://ee.cleversoul.com
About.com http://www.cpemma.co.uk
GameDev.net http://www.gamedev.net
The University of Strathclyde http://www.eee.strath.ac.uk/ug-info
Cpemma.Co http://www.cpemma.co.uk
EDN Access http://www.e-insite.net/ednmag
AMS (American Micro
Semiconductor)
http://www.americanmicrosemi.com
Hyper Physics http://hyperphysics.phy-
astr.gsu.edu/hbase/hframe.html
-
31
Appendix 2
Chart 2.4
Is "q" selected?
START
Displaying Main Menu with 5 choices:
1. Switches Operation
2. Display Swithces Status
3. Change Switches & Modules name
4. Configuration / Master Reset
5. Quit
Is first choice
made?
Is second
choice made?
Is third choice
made?
Is forth choice
made?
Is fifth choice
made?
Displaying 8 modules and Quit choices
in menu for selection
Is choice made
within 1-8?
Is Quit
selected?
Displaying 4
switches in menu
Is choice made
within 1-4?
Ask for ON or OFF
Is it ON?
Send logic "1" to
parallel port.
Send logic "0" to
parallel port.
Displaying 8 modules and Quit choices
in menu for selection
Is choice made
within 1-8?
Is Quit
selected?
Display switches
status for the
selected module
and waiting for any
key stroke to
continue
Selection of
changing Module
or Switch name.
Select "q" to quit to
Main Menu
Is Module
selected?
Is Switch
selected?
Display 8 modules
for selection
Is choice made
within 1-8?
Display 8 modules
for selection
Is choice made
within 1-8?
Display 4
switches for the
selected module
Display Old name
and prompt for
New name.
Display "Wrong
selection"
messague, wait for
5 seconds.
Display Old name
and prompt for
New name.
Is choice
made within
1-4?
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
YesYes
Yes
Yes
Yes
No
No
No
No
No
No
No
No
No
No
No
No NoNo
No No
No
A warning page given
with selections to
continue or abort with
choices Yes or No.
Is Yes
selected?
A confirmation for
resetting Module
and Switch name.
Is Yes
selected?
Select ON or OFF
for all switches
status.
Is ON
selected?
Is OFF
selected?
Change all
switches status
to ON
Change all
switches status
to OFF
Yes Yes
Yes
Yes
Yes
No
No
No
No
No
Reset all Modules
and Switches
name to default.
Another
confirmation for
changing switches
status
Is Yes
selected?
END
Yes
Yes
32
Appendix 3
Parallel Port Registers
Registers Name Address
Data Register Base + 0x00
Status Register Base + 0x01
Control Register Base + 0x02
Data Register Bit Definitions
Bit Function Low High
7(MSB) D7 0 1
6 D6 0 1
5 D5 0 1
4 D4 0 1
3 D3 0 1
2 D2 0 1
1 D1 0 1
0(LSB) D0 0 1
Table 3.1.2
Control Register Bit Definitions
Bit Function Low High
7(MSB) Not Used - -
6 Not Used - -
5 Not Used - -
4 Interrupt Control Disable Enable
3 Select Selected Not Selected
2 Initialize False True
1 Auto Feed True False
0(LSB) Strobe (Active-Low) True False
33
Diagram 3.2
D1
pin3
D2
pin4
D3
pin5
D4
pin6
D5
pin7
D6
pin8
D7
pin9
D0
pin2
DEMUX 2 DEMUX 1
ABCD ABCD
16
Output
16
Output
Table 3.2
Output SelectionInput
(hex) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
00
01
02
03
04
05
06
07
08
09
0A
0B
0C
0D
0E
0F
Table 3.2.3
34
Diagram 3.2.4
Pin D0 (20
)
Pin D3 (23
)
Pin D2 (22
)
Pin D1 (21
)
Pin C0
Time
JK1 O/P (Q)
JK15 O/P (Q)
JK14 O/P (Q)
JK13 O/P (Q)
JK12 O/P (Q)
JK11 O/P (Q)
JK10 O/P (Q)
JK9 O/P (Q)
JK8 O/P (Q)
JK7 O/P (Q)
JK6 O/P (Q)
JK5 O/P (Q)
JK4 O/P (Q)
JK3 O/P (Q)
JK2 O/P (Q)
t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16
Note:
t1 Input 0000
JK1 Triggered
t2 Input 0001
JK2 Triggered
t3 Input 0010
JK3 Triggered
t4 Input 0011
JK4 Triggered
t5 Input 0100
JK5 Triggered
t6 Input 0101
JK6 Triggered
t7 Input 0110
JK7 Triggered
t8 Input 0111
JK8 Triggered
t9 Input 1000
JK9 Triggered
t10 Input 1001
JK10 Triggered
t11 Input 1010
JK11 Triggered
t12 Input 1011
JK12 Triggered
t13 Input 1100
JK13 Triggered
t14 Input 1101
JK14 Triggered
t15 Input 1110
JK15 Triggered
t16 Input 1111
JK16 Triggered
JK16 O/P (Q)
Table 3.2.5
35
Diagram 3.3
Diagram 3.3.1
Diagram 3.3.2
Diagram 3.3.3
36
Appendix 6
Block Diagram 6
START
Turn on the
hardware external
power supply
(240Vac)
Turn on the PC
and open the
software.
Connect the
parallel port cable
from PC to
hardware.
Check the
communication
switch is connects
or disconnect.
Is it
connecting?
Flip on the switch
Reset the
Hardware
configurations
Select the require
output.
Send Signal from
PC to Demux
(74LS154)
Demux (74LS154)
will select the
require output. The
output is in a high
state (5Vdc)
Signal will reach
JK FF (74LS112)
negative edge
trigger.
JK FF will be
trigger by 5Vdc
from Demux, and
then through the
LED indicator
LED indicator will
turn on the
selected output
Is the indicator
shown the correct
selected output?
Reset and reselect
240Vac will
through control
switch
Relay will turn on,
and 240Vac will
supply through.
Transistor will turn
o the Relay /
(Opto 22) Solid
state relay.
Transistor will turn
on and act as
switch
Switch to relay
control?
Direct Power
Source
240Vac supply to
feedback system.
Feedback light
up?
Check the 240Vac
supply
Output supply
240Vac
END
Yes
No
Yes No
Yes
No
Yes
No
Diagram 6.3 Diagram 6.6
37
Appendix 7
Diagram 7
JK Board Darlington Circuit Demultiplexer Board
Diagram 7.1
Diagram 7.7
LOAD
Relay
SPDT
LOAD
LOAD
LOAD
240V
AC
38
Diagram 7.1.2
START
Design Simulation
on Electronics
Workbench V.5.12
Ready The
Components and
PCB's Board. Also
Prepare the
Dimensions.
Print out the
Circuitry track
layout
Is all the
connection abides
on PCB board?
Is the
component
blocking each other
on the layout?
Rectify error and
Rework
Rectify error and
Rework
Transfer to PCB
board and perform
etching
Perform visual
inspections and
continuing test
Re-etch new PCB
board
Is Etching
success or fail?
Is failure
beyond repair?
Repair the PCB
board
Drill hole and clean
the surface of the
PCB board with
sand paper
Place components
and solder it, cut
off protruding
component leads
Are all
components in
right place?
Re-work and place
in correct positions
Perform testing
Is the project
works?
Troubleshoot and
repair
END
Yes
No
NoNo
No
No
No
Yes
Yes
Yes
Yes
Yes
Table 7.6
VIN R PLOAD RLOAD RTOTAL ITOTAL VR
230 22 10 5290 5312 0.043298 0.95256
230 22 20 2645 2667 0.086239 1.897263
230 22 40 1322.5 1344.5 0.171067 3.763481
230 22 80 661.25 683.25 0.336626 7.405781
230 22 100 529 551 0.417423 9.183303
230 22 150 352.6667 374.667 0.613879 13.50534
230 22 300 176.3333 198.333 1.159664 25.51261
230 22 500 105.8 127.8 1.799687 39.59311
230 22 600 88.16667 110.167 2.087746 45.93041
230 22 700 75.57143 97.5714 2.357247 51.85944
230 22 800 66.125 88.125 2.609929 57.41844
230 22 900 58.77778 80.7778 2.847318 62.64099
230 22 1000 52.9 74.9 3.070761 67.55674
39
Diagram 7.8
Side View 1 Side View 2
Front View Top View
Top View – Zoom Top View - Components
40
Appendix 8
Diagram 8.2
Single Transistor Switch Darling Pair Switch
Diagram 8.3
Internal Circuitry for
OEG OMI-SH-212L Relay
Internal Circuitry for
OPTO 22 G4 OAC5A Relay
41
Appendix 9
42
43
Appendix 10
Power vs. Resistance
0
1000
2000
3000
4000
5000
6000
10 20 40 80 100 150 300 500 600 700 800 900 1000
Power / Watt
Resistance/Ohm
Load Resistance
Diagram 10.2.3a
Power vs. Total Current & Voltage Dropped Across Resistor
0
0.5
1
1.5
2
2.5
3
3.5
10 20 40 80 100 150 300 500 600 700 800 900 1000
Power / Watt
Current/A
0
10
20
30
40
50
60
70
80
Voltage(VR)/Volt
Total Current Voltage Drop Across Resistor 22Ohm
Diagram 10.2.3b
44
Royston
Goh
Digitally signed
by Royston Goh
DN: cn=Royston
Goh, c=MY
Date:
2004.02.02
14:07:32 ZSignature
Not Verified

More Related Content

Similar to report

Auto Metro Train to Shuttle Between Stations
Auto Metro Train to Shuttle Between StationsAuto Metro Train to Shuttle Between Stations
Auto Metro Train to Shuttle Between StationsMadhav Reddy Chintapalli
 
Automatic Irrigation System Project Report
Automatic Irrigation System Project ReportAutomatic Irrigation System Project Report
Automatic Irrigation System Project ReportEr Gupta
 
Unit III ARM Interface and ARM Programming
Unit III ARM Interface and ARM Programming Unit III ARM Interface and ARM Programming
Unit III ARM Interface and ARM Programming Dr. Pankaj Zope
 
ContentsTeam Work Schedule3Team Task Assignment3Project .docx
ContentsTeam Work Schedule3Team Task Assignment3Project .docxContentsTeam Work Schedule3Team Task Assignment3Project .docx
ContentsTeam Work Schedule3Team Task Assignment3Project .docxbobbywlane695641
 
My thesis work on Cognitive automation of Electric appliances
My thesis work on Cognitive automation of Electric appliancesMy thesis work on Cognitive automation of Electric appliances
My thesis work on Cognitive automation of Electric appliancesAkhil Reddy Rondla
 
ABC Consolidated Financial InfoABC Companys current financial inf.docx
ABC Consolidated Financial InfoABC Companys current financial inf.docxABC Consolidated Financial InfoABC Companys current financial inf.docx
ABC Consolidated Financial InfoABC Companys current financial inf.docxransayo
 
Polyline download and visualization over terrain models
Polyline download and visualization over terrain modelsPolyline download and visualization over terrain models
Polyline download and visualization over terrain modelsgraphitech
 
BLUETOOTH CONTROLLED ROBOCAR
BLUETOOTH CONTROLLED ROBOCARBLUETOOTH CONTROLLED ROBOCAR
BLUETOOTH CONTROLLED ROBOCARPulkit Singhal
 
How to search for a good quality pcb designing
How to search for a good quality pcb designingHow to search for a good quality pcb designing
How to search for a good quality pcb designingCrimp Circuits Inc
 
ARDUINO EMBEDDED SYSTEM
ARDUINO EMBEDDED SYSTEMARDUINO EMBEDDED SYSTEM
ARDUINO EMBEDDED SYSTEMVishal GARG
 
Chapter 2(1)
Chapter 2(1)Chapter 2(1)
Chapter 2(1)TejaswiB4
 
REP.01 PROJ-FX01 Smart Home RP-v2
REP.01 PROJ-FX01 Smart Home RP-v2REP.01 PROJ-FX01 Smart Home RP-v2
REP.01 PROJ-FX01 Smart Home RP-v2Ricardo Pereira
 
Algorithm,Pseudocode,Flowchart.pptx
Algorithm,Pseudocode,Flowchart.pptxAlgorithm,Pseudocode,Flowchart.pptx
Algorithm,Pseudocode,Flowchart.pptxDrThenmozhiKarunanit
 
Ball Collecting game report
Ball Collecting game report Ball Collecting game report
Ball Collecting game report Dileep Maurya
 

Similar to report (20)

Auto Metro Train to Shuttle Between Stations
Auto Metro Train to Shuttle Between StationsAuto Metro Train to Shuttle Between Stations
Auto Metro Train to Shuttle Between Stations
 
Automatic Irrigation System Project Report
Automatic Irrigation System Project ReportAutomatic Irrigation System Project Report
Automatic Irrigation System Project Report
 
Unit III ARM Interface and ARM Programming
Unit III ARM Interface and ARM Programming Unit III ARM Interface and ARM Programming
Unit III ARM Interface and ARM Programming
 
Altera up1
Altera up1Altera up1
Altera up1
 
ContentsTeam Work Schedule3Team Task Assignment3Project .docx
ContentsTeam Work Schedule3Team Task Assignment3Project .docxContentsTeam Work Schedule3Team Task Assignment3Project .docx
ContentsTeam Work Schedule3Team Task Assignment3Project .docx
 
My thesis work on Cognitive automation of Electric appliances
My thesis work on Cognitive automation of Electric appliancesMy thesis work on Cognitive automation of Electric appliances
My thesis work on Cognitive automation of Electric appliances
 
Led cube presentation
Led cube presentationLed cube presentation
Led cube presentation
 
ABC Consolidated Financial InfoABC Companys current financial inf.docx
ABC Consolidated Financial InfoABC Companys current financial inf.docxABC Consolidated Financial InfoABC Companys current financial inf.docx
ABC Consolidated Financial InfoABC Companys current financial inf.docx
 
Mini Project- USB Temperature Logging
Mini Project- USB Temperature LoggingMini Project- USB Temperature Logging
Mini Project- USB Temperature Logging
 
Polyline download and visualization over terrain models
Polyline download and visualization over terrain modelsPolyline download and visualization over terrain models
Polyline download and visualization over terrain models
 
BLUETOOTH CONTROLLED ROBOCAR
BLUETOOTH CONTROLLED ROBOCARBLUETOOTH CONTROLLED ROBOCAR
BLUETOOTH CONTROLLED ROBOCAR
 
How to search for a good quality pcb designing
How to search for a good quality pcb designingHow to search for a good quality pcb designing
How to search for a good quality pcb designing
 
ARDUINO EMBEDDED SYSTEM
ARDUINO EMBEDDED SYSTEMARDUINO EMBEDDED SYSTEM
ARDUINO EMBEDDED SYSTEM
 
Lab2F22.pdf
Lab2F22.pdfLab2F22.pdf
Lab2F22.pdf
 
Chapter 2(1)
Chapter 2(1)Chapter 2(1)
Chapter 2(1)
 
Documentation
DocumentationDocumentation
Documentation
 
MAJOR PROJECT
MAJOR PROJECT MAJOR PROJECT
MAJOR PROJECT
 
REP.01 PROJ-FX01 Smart Home RP-v2
REP.01 PROJ-FX01 Smart Home RP-v2REP.01 PROJ-FX01 Smart Home RP-v2
REP.01 PROJ-FX01 Smart Home RP-v2
 
Algorithm,Pseudocode,Flowchart.pptx
Algorithm,Pseudocode,Flowchart.pptxAlgorithm,Pseudocode,Flowchart.pptx
Algorithm,Pseudocode,Flowchart.pptx
 
Ball Collecting game report
Ball Collecting game report Ball Collecting game report
Ball Collecting game report
 

report

  • 1. Penang Skills Development Center BTEC Higher National Diploma A project report submitted in partial fulfillment of the award of Higher National Diploma Title: Central Control Switching System Author: Goh Hoe Hin, Yau Soon Ting Supervised by: Mr. PC Mok Date: 10th July 2003
  • 2. Abstract This report will introduce you a device that able to handle up to 32 switches, remotely. No special previous software or hardware knowledge is required in order to use this device. Although, of course, any prior background in these 2 fields will be helpful. This report starts with the software part introduction, followed by the hardware part for this device. Nothing is left out. By the time you finish this report, you will be able to handle this device without major problems. Mr. Yau and myself build this device, this includes the software developing and hardware designing. We did not really refer to any standard circuit from other resources, but apply what we have learnt through out the course, base on concept. We have been hit by several problems but luckily we solved them one by one. For the software development, I did approach some software experts for assistance, but only limit to certain routines and problem. One final point: Although both of us, as the amateur in this field build this project, but we had done our best, not only to fulfill the official requirement but also our own satisfaction. If time and opportunity is given, we would be able to achieve something better. After all, both of us have learnt a lot of experiences and knowledge while solving problems. 2
  • 3. Acknowledgement The ideas, concept and structure of this project have come from many sources: ex- lecturer like Gladys Fan (who is also a good friend of mine); members in Subduck.com, who have given me a lot of precious advices to solve certain C++ subroutines, very often students in my course like Say Aun, Gaik Hoay and Tracy, who have asked the questions I need to hear in order to make the project more user- friendly. Colleagues in a same company around me are wonderful, especially Raj, who used to find the weak points of this project in order for me to work on improvements. And of course, the best person who worked closely with me, brainstormed on any issues and keep finding improvement of this project is my partner, Mr. Yau Soon Thing. He is staying kind of far away from my house but travel to see me every weekend just to get this project done step-by-step. Lastly, we both would like to thank Mr. Mok, our supervisor of this project, who has given us a lot of useful information, clear our doubt while we were in trouble and so on. 3
  • 4. Contents Title Page Introduction 6 Program Chapter 1. Project Overview 7 2. Theoretical Development & Design 8 2.1. Some History of C++ 8 2.2. Differences of C and C++ 8 2.3. Initial Plan & Later Changes of the Program 8 2.3.1. Information of Demultiplexer 8 2.3.2. Manual Clock Pulse 9 2.3.3. Any special training needed? 9 2.4. Outline and Algorithm 10 2.4.1. Function 10 2.4.2. File I/O 11 2.4.3. Parallel Port 12 2.4.4. Looping Techniques 12 3. Project Construction 14 3.1. Parallel Port 14 3.1.1. Overview & Pins Description 14 3.1.2. Software Interfaces with Hardware Port 14 3.2. The Program & Source Code 15 3.2.1. Source code flow 15 3.2.2. ON/OFF operation 15 3.2.3. Hardware Toggle 15 3.2.4. Software Toggle 16 3.2.5. Enable Switch (G1/G2) 16 3.3. Other Features 17 4. Problems & Solutions 18 Hardware Chapter 5. Project Overview 20 6. Theoretical Development & Design 21 6.1. Demultiplexer 21 4
  • 5. 6.2. JK Flip-flop 21 6.3. Darlington Switch 21 6.4. Relay Functions 22 6.5. Backup Switch 22 6.6. Feedback System 22 7. Project Construction 23 7.1. Circuit Simulations 23 7.2. Metal Case 23 7.3. Connections between PCBs 23 7.4. The Ventilator 23 7.5. Communication Switches 23 7.6. Feedback System 24 7.7. Backup Switch 24 7.8. Casing Outlook 24 8. Problems & Solutions 25 9. Evaluation Results and Data 26 10. Discussions & Conclusions 27 10.1.Software 27 10.2.Hardware 28 References 31 Appendix 2 32 Appendix 3 33 Appendix 5 (Available in file named Appendix 5.doc) 37 Appendix 6 38 Appendix 7 39 Appendix 8 42 Appendix 9 43 Appendix 10 45 Datasheets 46 5
  • 6. Introduction Have you ever imagined how tough to turn ON and OFF all the lights, air conditioner, etc. in a building? This is the routine job for the building management staff everyday. Before you arrived and after you left your office, they have to check and manage those switches, level by level! This project is mainly used to solve this problem. With the assistance of this project, you can sit back and relax, let this device helps you to manage your switches daily, without leaving your chair! Besides, this device will also indicate you the status of any equipment it controls. This device consists of 2 major portions: Program Chapter (program written in C++) and Hardware Chapter (interface board, processing board, etc). The 1st set of this report will give you full explanation of the software development procedures, the flow, extra knowledge gained as well as problems we met and how we solved it. To further understand the structure of hardware portion, please refer to the 2nd set of this report. 6
  • 7. Program Chapter 1. Project Overview The concept of the program is pretty simple. We know that computers are operating under both logic “1” and “0”(ON of OFF). So, with this simple theory, we brainstormed out the structure of this device, let both “1” and “0” replace our fingers. When you select to turn ON a particular electric equipment from the monitor screen, the program will help you to send a logic “1” and translate the equipment selected into a code, sending out from the parallel port (printer port – 25pins). When the interface board receives the signal, it will identify which equipment you have selected. After confirming the code address, it will transfer the logic “1” to the processing board. The processing board will then operate the relevant relay to help you turn ON the equipment. To make the program more flexible and user-friendly, I have designed a couple of tools, which allow users to have more control in order to suit into different environment. For example, users may customize each and every switch name. Besides, I have gather 4 switches into 1 group (or module in the program). This will greatly help the users to identify the switch and area. Users also may change the name of the group (e.g. Ground Floor, Canteen, Guard House and etc.) This program will also “remember” the status of every switch, so that users will not accidentally double ON or OFF a certain switch. Those switch status can also be reset. The usage of this RESET is used when there is any power trip that caused the whole building black out. After the power resume, status can be RESET back to OFF or ON, depending on the situation. This program can control up to 32 switches. Hardware wise, the boards are designed to be expandable. Hence, users do not need to purchase all 32 switches if they do not have so much electric equipment to be controlled. 7
  • 8. 2. Theoretical Development and Design There are a lot of different programming languages to use for interfaces with external devices. We have chosen C++. 2.1. Some History of C++ The C programming language was developed at Bell Labs during the early 1970's. Quite unpredictably it derived from a computer language named B and from an earlier language BCPL. Initially designed as a system programming language under UNIX it expanded to have wide usage on many different systems. C++ was designed to support the features of C such as efficiency and low-level support for system level coding. Added to this were features such as classes with inheritance and virtual functions, derived from the Simula67 language, and operator overloading, derived from Algol68. 2.2. Differences of C and C++ Although the languages share common syntax they are very different in nature. C is a procedural language. When approaching a programming challenge the general method of solution is to break the task into successively smaller subtasks. This is known as top-down design. C++ is an object- oriented language. To solve a problem with C++ the first step is to design classes that are abstractions of physical objects. These classes contain both the state of the object, its members, and the capabilities of the object, its methods. After the classes are designed, a program is written that uses these classes to solve the task at hand. 2.3. Initial Plan & Later Changes of The Program Initially, we planned to control 8 switches only. So it is pretty simple to have all 8 parallel port pins to directly connect to the hardware and drive the operation. But it seems not healthy at all as we have limited the future expansion of our project. So we chose an extra component called demultiplexer. 2.3.1. Information of Demultiplexer To design the program that can drive a demultiplexer, we must first understand its input and output flow. From Table 3.2 and 3.2.5 in Appendix 3, we understand that the selected 74LS154 is an active-low demultiplexer. Whichever point we select, it will send a LOW to it and 8
  • 9. the rest will be set to HIGH. There are another 2 enable pins (G1/G2) that shall not be forgotten, we need to control them in our program. But how do we to control them? You may refer to the “Project Construction 3.2.5” below. 2.3.2. Manual Clock Pulse The following task to further the program design work should be controlling the switches. Since we are going to use the demultiplexer to have more than 8 switches, hence we will use TOGGLE instead of SET and RESET method. We wanted to generate a “clock-pulse” for the 74LS112 JK flip-flop because we know if we set both J and K at HIGH, the output will toggle from one to another at every clock edge. For further detail information about this method, you may refer to the “Project Construction 3.2” below. 2.3.3. Any special training needed? No, this program is a prototype and will be used by variety level of users come from different region, different working environment. Hence, the program must be: • User-friendly The interface menus and messages are written in common English language, pretty simple to be understood. All possible choices that will be made by users have been considered and no “surprise” errors will appear to users. After all, the program will guide users step-by-step to complete their tasks. • Self-explanatory Messages and notes that will be displayed to users are all self- explanatory, meaning that the program will never ask any complicated configurations from users. • Flexibility Flexible to be applied in different usages and working environment This program is designed in general way, not really specific for user type, environment, etc. Users can customize the interface menus according to their need 9
  • 10. 2.4. Outline and Algorithm The program that used for this project is called “switch.cpp” (Refer to Source Code in Appendix 2. This program is used to control 32 switches maximum. Hence, as expected, there will be a lot of looping tasks in the source code because a same task will be repeated for 32 different switches. In this program, I used some skills such as function, file I/O, variables array manipulating, parallel port I/O, different looping techniques and etc. The program flow chart can be seen in Chart 2.4 in Appendix 2. 2.4.1. Function The techniques, or we called it “style”, that used in function calls of a C/C++ program, varied from different users. There is no fixed method that we should obey in order to get certain tasks done. In this program, we are practicing a few techniques. 2.4.1.1.Pass value only to functions Here we just passed a set of variables to the function, the function will process a certain tasks with the variables given. After completed, the program will return to the main() function and continue with the rest of instructions. Refer to our source code in Appendix 2, line 830 and 877. This technique is good to perform repeated tasks; which required no value returned. For this technique, we should declare “void” during the function prototype declaration. 2.4.1.2.Pass a pointer value to functions This technique has a little difference with the above. It does not directly pass a value to the function but a memory location (memory pointer). You can refer to the example in the source code in Appendix 2, line 813. Since we do not ask for any return value from this function, it declared as “void” in the prototype declaration. 2.4.1.3.Pass and return value from functions This technique normally used for a repeated calculation; which required some calculated answer/data to be returned to the main() function. In our source code, the example can be referred to line 10
  • 11. 778. There are 4 variables passing out from the main() function and required this function to return the value of “d” after finished performing the tasks. As you noticed, in the prototype declaration we used “int” instead of “void”. This “int” indicates the data type of the return value. 2.4.2. File I/O This is one of the new knowledge I have learnt. This program needs to store a lot of data such as Module/Switch name, Switch status, etc. In order to use the file I/O, we need to include the <fstream.h> file. This file contains declarations for file I/O functions that the program needs to use. We will be using two classes “ifstream” and “ofstream” for input and output respectively. 2.4.2.1.Reading from a file (ifstream) In order to read data from a file, we must declare an object for it to open a file. E.g.: ifstream fin (“test.txt”); After opening the file, we will be using the in-stream object to perform the reading job. E.g.: fin >> data1 >> data2; The example above shows how to input “data” into a file but somehow if the data is a string, which contains space, we will use the example below: fin.getline (var, number_of_char_in_var_buffer); After finished extracting data from file, do remember to close the function, i.e.: fin.close(); The “fin” is actually a name that we use for the I/O function. It can be any name. 2.4.2.2.Writing to a file (ofstream) In fact, both reading and writing are almost same. Only differences are the declaration and the symbol. To declare an object for it to write into a file, you must first open the file. This time, the file can be either exist or not exist. If the function can find the file name you keyed in, it will use it. Else, it will create a new one. 11
  • 12. ofstream fout (“test.txt”); After opening the file, you will use the following example to write data into it, e.g.: fout << data1 << data2; Same with “ifstream”, you need to close the function by using: fout.close(); Take note that the symbol used for reading file is “>>” (extraction) and “<<” (insertion) is for writing file. 2.4.3. Parallel Port Parallel port, so-called Printer port, is one of the ready-made I/O port for a standard PC. Since this is the default port, it has it’s own port address to be located by the PC. No matter what type of language you use in your program, you have to use back the same address. In C++, the address is 0x0378H. It is in hexadecimal form. For further detail explanation, please refer to the next chapter. 2.4.4. Looping Techniques The looping techniques basically can be categorized into 3 types: • For Statement The For statement is quite officially used by most programmers. It has a characteristic of letting the program knows about the basic condition, initial value of a variable and increment. • While Statement The While statement is quite user-friendly (at least I felt that). It does not really state down all the important data such as initial value for a variable and the incremental value. It’s job is very simple, just loop. It only asks for one thing, which is “until when” you want the looping happen. So, normally users will put the initial value for the looping counter before the While statement and the incremental value will be inside the loop. The reason I felt that it is user-friendly because when you write a program, certain time we might not know exactly how many 12
  • 13. times we want it to loop and what initial value we should put for the counter. It is quite “layman” type of looping statement. • Do… While Statement This technique quite similar to the While statement but it happened in another way round. It asks the program to perform a task, just like a normal program flow but before it ends the braces, there is a While condition waiting and bounce back the flow until it fulfills the condition. Just like a gate asking for a pass before going out. If the counter is still not reaching the condition, it will be looping back. 13
  • 14. 3. Project Construction The construction of this project has been categorized into several portions as below: 3.1. The Parallel Port The main communication gateway for the program with external hardware is parallel port; hence let’s start some introduction. The standard PC parallel port (printer port) is a 25-pin D-Type connector. It is very handy for testing and controlling devices. It provides an easy way to implement a small amount of I/O. 3.1.1. Overview & Pins Description The original IBM-PC’s parallel printer port had a total of 12 digital outputs and 5 digital inputs via 3 consecutive 8-bit ports in the processor’s I/O space, as shown in diagram below: 113 1425 D7 D0D1D2D3D4D5D6 S7 S3S4S5S6 C3 C2 C1 C0 • 8 output pins accessed via the DATA port (D0~D7) • 5 input pins accessed via the STATUS port (S3~S7) • 4 output pins accessed via the CONTROL port (C0~C3) • The remaining 8 pins are ground (pin 18~25) 3.1.2. Software Interfaces with Hardware port. To communicate with the parallel port, there are certain addresses and registers that you need to use in the source code. There are 3 Base addresses for the parallel port, which are 0x0378, 0x0278 and 0x03BC. Refer to the Table 3.1.2 in Appendix 3. The 0x03BC is MDPA system (Monochrome Display and Printer Adapter). The 0x0378 and 0x0278 are Primary and Secondary Printer Adapter respectively. Hence we have chosen 0x0378 to be our communication port. The Data Port pins were driven by a 74LS374 octal latch, which could source 2.6mA and sink 24mA. There were 14
  • 15. 0.0022µF capacitors between each line and ground to reduce transients. It is advised that the external device not to pull these lines to ground as it will potentially cause the 74LS374 to source for more current than it could handle without damage. Whereas, the Control Port pins were driven by the 7405 inverting open collector buffers, pulled to +5 volts via 4.7K resistors. All lines except C2 (pin 16) are inverted before going to the output pins. The C2 line is double-inverted before going to pin 16. 3.2. The Program and Source Code Basically the program is used to send signals out from the 0x0378 port, of course, via a specified pin. The first electronic component that receives these signals is the 74LS154, a 4-to-16 active-low demultiplexer. The program utilized the Data pins and divided it into 2 portions as shown in Diagram 3.2 in Appendix 3. As you can see, we are not fully utilized the 8- bit data registers. Even if we only use 8 data pin from a parallel port, we can achieve up to 256 switches control (28 =256) We separated the 8-bit registers into two; the first demultiplexer will be controlled by the 00h~0Fh (4-bit; 24 = 16 outputs). The same goes to the second demultiplexer, but the control bit will be 00h~F0h. Refer to Table 3.2 in Appendix 3. 3.2.1. The source code and how it flows? The source code can be referred in Appendix 2. 3.2.2. How does the ON/OFF operate? The operation concept is pretty simple, we are actually toggling the switch, regardless of the current status is ON or OFF. So one question will pop up, “Will the users know whether they are turning it ON or OFF?” In fact, the program has the capability to remember the ON/OFF status. Hence, the hardware job is only toggling it will do. 3.2.3. Hardware Toggle Refer to the Table 3.2.3 for 74LS112A in Appendix 3, when both J and K of the flip-flop had supplied to HIGH, the output will fully depend on the CLK signal. When there is a clock pulse, the value of output Q will toggle. The 74LS112A is a negative-edge triggered flip- flop. When any pin of the demultiplexer been selected, it will send a 15
  • 16. LOW signal to the selected flip-flop CLK pin, which seems like a negative-edge clock pulse and this will trigger the JK flip-flop. 3.2.4. Software Toggle (Manual Clock Pulse) From the Hardware Toggle explanation above, we know that we need to generate a series signal in sequence HIGH-LOW-HIGH to the hardware. Hence, in the source code, we purposely utilized the G1/G2 strobe pin. If both of these strobe pins been set HIGH, all the output of the demultiplexer will be turned HIGH. So, before any operation done by users, the program will send a HIGH to both strobe pins. When any switch been selected, the signal will be waiting at the input pin of the demultiplexer but they can’t enter the demultiplexer because both strobe pins are still HIGH. After that, the program will send a LOW signal to both strobe pins and this will enable the demultiplexer to accept the signal that has been waiting at the input pins. Once this operation has done, the program will loop back and trigger the G1/G2 strobe and the JK flip-flop will receive another HIGH signal. Refer to Diagram 3.2.4 in Appendix 3. 3.2.5. Enable Switch & G1/G2 of Demultiplexer Refer to the Table 3.2.5 for 74LS154 in Appendix 3; to enable the 4- line input, we need to set both G1 and G2 (pin 18 & 19) LOW. Since we are utilizing 2 demultiplexer, the program source code must be able to select and enable which demultiplexer we need, i.e. while controlling first 16 switch, we need to disable the second demultiplexer. Refer to Software Chapter, Section 3.1.3 of this report, besides the 8 data pins; we still have 4 control pins. Hence, we used 2 of them to control the strobe pins for both demultiplexers; they are pin 1 and pin 14. Both pins are active-low triggered. To set both of them HIGH, simply send a 0x00 to the Control registers. To select the first demultiplexer, we send a 0x01 and for the second demultiplexer, 0x02 will be sent. 16
  • 17. 3.3. Other Features This program has included a few features besides the switches operating menu (Diagram 3.3 in Appendix 3). They are: 3.3.1. Switches Status (Diagram 3.3.1 in Appendix 3) Besides the indicator LED found in the hardware device, users might also check the status for each switch from this menu. 3.3.2. Change Items Name (Diagram 3.3.2 in Appendix 3) This feature is a MUST for users. It will help you to categorize all switches into groups. Users are freely changing any name found in the database to suit in different environment. 3.3.3. Configuration Reset (Diagram 3.3.3 in Appendix 3) This menu will allow users to RESET 3 type of database, such as Module Name, Switch Name and Switch Status. The program cannot predict any issue happened with the hardware such as power trip/failure, malfunction and etc. So, if the hardware or the area that controlled by this hardware has power failure, users need to RESET the switches status in the database because all switches controlled by this program have turned OFF. 17
  • 18. 4. Problems & Solutions Through out the implementation of this program, I faced quite a lot of problems, which nearly caused me giving up. • What is the address for Parallel Port and how to apply them? This problem attacked me in the very beginning of this project. I have sourced for books and Internet. That useful information has collected from different sources and they can be found in the “Reference” chapter. • Confusions of variables naming convention. This program used a lot of variables. They consist of character and numeric- type. If they are not properly named, the program development and future maintenance will be difficult. In fact, there are a lot of variables can be reused but I prefer create another new one. This is to ease my debugging job. • How to save/read data in a file? Since I am going to store some “permanent” data for this program, I need to write them into a file. I have sourced for books from libraries, not all of them have this kind of information. Lastly I found it from a website. • Why certain variable can be used in function but some of them cannot? When I try to pass a string-type variable to the function, it doesn’t work. No matter how I swapped around the instructions, the result still failed. I have joined in a C++ discussion forum (www.subduck.com) and found some friends who willing to teach me besides the value passing, some other new skills. To pass a string-type variable, we should put a “*” in front. The “*” is actually pointing the program to the memory address of the variable. We are not able to pass the whole string to a function. • Why my compiler shows error on instructions that previously working fine? Braces and semi-colons are commonly used in C++ programming. Although it seems small stuff but if you forgot or extra put in 1, it is going to a catastrophe. The compiler will never tell, but will give you a lot of error against those correct-format instructions. Make a habit of leaving indent each time when there is a set of brace-instruction putting semi-colon. Some examples can be referred in my source code in Appendix 2. • Are double-quotes (“…”) and single-quotes (‘…’) the same? 18
  • 19. The usage of single quote (‘…’) is to display 1 character and for double quotes (“…”) is to display a sequence of characters. • Why I can’t apply the variable that has declared at the beginning of the program? Take note that the C++ programming language is case-sensitive. It is recommended to use all-capital or small letter word to prevent mistakes. Another possibility is, the variable declared is different type with the usage. I found more and more interested in C++ programming. This project made me learn more about it. 19
  • 20. Hardware Chapter 5. Project Overview The external hardware is built to perform tasks that commanded by the program that we discussed in earlier chapter. Components that used in this hardware are quite simple, including demultiplexer, JK flip-flop, Transistors, Diodes, Relays and SPDT switch. To make this hardware safer and easier to be troubleshot, we have separated it into few parts and each part will carry out different task. First part is the Main Operation Room, second part will be the Feedback System for output and the last part is the Output. Each part will be stored in different case to prevent any physical damage. The Main Operation Room is built by metal case covered with a transparent plastic cover. All main operating boards can be found in this area. The Feedback System is built by a metal plate with all related components attach to it. LEDs fixed here to indicate the feedback. The Output is a simple expansion power socket set. This socket set has been modified for this controlling system. This hardware device is just a prototype, but it is expandable. Refer to Diagram 5 in Appendix 5. 20
  • 21. 6. Theoretical Development and Design Refer to Block Diagram 6 for the flow in the Appendix 6. The development was done in several portions as below: 6.1. Demultiplexer The signal sent out by PC contains both HIGH and LOW (5V and 0V). These signals will be delivered to demultiplexer via Parallel Port Input board. A total of 8 data signals will be separated to 2 parts, flowing into 2 demultiplexers. When there is any selection made, the demultiplexer will receive the signal and select the relevant output and set it to be LOW. The rest of the output pins will be stayed HIGH. This is because the TTL 74LS154 that we used is an active-low demultiplexer. Refer to Table 3.2.5 of Appendix 3 for the Truth Table. Due to the future expansion need, we design the demultiplexer board to contain 2 74LS154, which will give a total 32 outputs. 6.2. Demultiplexer to JK Negative Edge Triggered From the output of demultiplexer board, the signal will be sent to JK Flip-flop Board. The 74LS112 we used is a negative-edge flip-flop. Assume that, a selection has been made; the demultiplexer will send a LOW to the output. This signal will be received by JK flip-flop. Since it is a LOW and the flip- flop is already in “toggle” mode, the output of JK will toggle. The output of JK will be connected to the Darlington switch and a set of LED indicator. After that, the output of JK will be set to HIGH back by the program (without users knowledge). 6.3. Darlington Switch The output of JK flip-flop will connect directly to the base pin of first transistor in the Darlington switch. This signal acts as Enable to the Darlington switch. Both Collector pins of the transistors are connected to the return of Relay. Hence, when the transistors are “enabled”, the current from the Relay will flow through the Collector and Emitter to ground and the Relay will start to operate. Refer to Diagram 6.3 in Appendix 6. In fact, the basic concept of Darlington and One Single Transistor are the same. The only difference is Darlington will amplified the gain and this will sufficient enough to drive load such as relay, motor or coil. 21
  • 22. 6.4. Relay Functions When the time t<0 (before start), the Relay is supplied with 5V from DC source. Meanwhile, 240V from AC source has been ready at the contact point of Relay. When an “enable” signal sent to Darlington by JK flip-flop, the coil of Relay will be energized and the contact point will be switched. 6.5. Backup Switch This board is actually a backup system. If there is any malfunction or operation failure happened to the PC or any part of the Main Operation Room fail to perform, users still can use this Backup System to manually control the switch. 6.6. Feedback System This feedback system consists of a 22Ω resistor, a 1N4001 diode, a zener diode and a LED, connected in parallel. Refer to Diagram 6.6 in Appendix 6 for the connection. The zener diode regulates the voltage dropped across LED, to protect any damage to the LED. Refer to Figure 6.6 below, notice that as the reverse voltage is increased but the leakage current remains essentially constant until the breakdown voltage is reached where the current increases dramatically. This breakdown voltage is the zener voltage for zener diodes. While for the conventional rectifier or diode it is imperative to operate below this voltage; the zener diode is intended to operate at that voltage, and so finds its greatest application as a voltage regulator. Figure 6.6 22
  • 23. 7. Project Constructions This project has four portions to be constructed. They are Demultiplexer Board, JK Board (JK + Darlington), Relay Board and Backup Switch Board (refer to Diagram 5 in Appendix 5). Besides, we designed our own Power Supply Board, Parallel Port Input Board and the LED Indicator Board. The purpose to separate the whole circuit into several boards is for future expansion. Users do not need to purchase all 32 switches if they only have minor needs Refer to the Diagram 7 for the constructions of the hardware is shown in the Appendix 7. 7.1. Circuit Simulations The very first stage, we use the electronic simulation application to construct our circuit. Basically this is to confirm the fundamental flow of the circuit. Refer to Diagram 7.1 in Appendix 7. 7.2. Metal Case Since this project has more than one PCB, we intend to design a case to place all boards, to protect any physical damage to the boards as well as easy handling. Hence, the size of each PCB must be considered. 7.3. Linkage between PCB’s board For the connection between each boards, we used wires and 4-pin connectors. Care must be taken while arranging the wire, as the pin-to-pin arrangement is in sequence. 7.4. The Ventilator There are a few components will potentially generate heat, such as the Voltage Regulators (7805, 7812 and 7824). So we fixed a small ventilation fan (12VDC, 0.9W) to increase the air ventilation. This is to expand the lifespan for the said components. 7.5. Communications Switch A DPDT switch is used in the Parallel Port Input Board. When a PC is rebooting, it will perform POST (Power On Self Test) and some signals will be sent to each peripherals including parallel port. Those signals are considered unwanted signals to our project. So, before rebooting the PC, we need to switch the enable pins (G1/G2) of demultiplexer to 5VDC, base on the Truth Table, by doing this, the demultiplexer will ignore any input from PC. 23
  • 24. 7.6. Feedback System During our discussion, there are a few ways to construct a feedback system but we planned to build a simple and low cost system. After some calculations, we have chosen a 22Ω, 10W resistor to connect in series with the load. The reason is this resistor will not consume too much current and the voltage dropped across (VR) will be quite minimum. Of course, the value of VR varies depending on the wattage of the load we use (refer to Table 7.6 in Appendix 7). So, to protect both LED and Zener diode, we should put 2 resistors in series with the 1N4001 diode and LED respectively. 7.7. Backup Switch Refer to Diagram 7.7 of Appendix 7, this backup system is designed to allow both way control to load. 7.8. Casing Outlook The outlook of the project with metal case can be seen in Diagram 7.8 of Appendix 7. 24
  • 25. 8. Problems and Solutions A couple of problems have been encountered during the construction of this hardware device but they have been solved. Refer to the summary below: 8.1. How to design a PCB board? Initially we planned to design this project into a single PCB to save up some time and cost. But this idea seems like not recommended as it will cause difficulties for troubleshooting and not cost-effective as users need to purchase all 32 switches in one time. Besides, distortions such as cross talk and EMF interference will interrupt each other. Therefore the multilevel board idea is implemented. With this, we can overcome those disadvantages said above. To design a tidier circuit and minimize human error, we use an application called PCB Designer to design our circuit. After that, we print it out onto a wax paper by using laser jet printer. Then, we attach the surface of the wax paper with circuit onto a blank PCB and iron it on top. Later, the powder of the laser jet, which formed up the circuit stuck onto the PCB. Now we can start to etch the PCB. 8.2. How to drive the Relay? When the first revision of theoretical circuit formed, we used one transistor to drive the Relay. Unfortunately it didn’t work. After studied some reference through Internet, seems like the gain produced by one transistor is not sufficient enough to drive the coil. So we changed our circuit to use two Relays connected as Darlington pair. Refer to Diagram 8.2 in Appendix 8. 8.3. How to reduce noise interference? A test was carried out after the completion of the hardware and interference had occurred when relay switched the output. It caused the output selection to be hey-wired and totally not stable. To be more precisely, noise is interfering the components operation such as Demultiplexer, JK FF and Transistors. We strongly believe that the contact point of the relay switch generates the noise. Therefore, a new approach is to replace the OEG relay with an AC Output Module from OPTO 22. For further information, please refer to the datasheet in Appendix. After the change, the problem of noise interference generated by relay has solved and the hardware is operated smoothly. Refer to Diagram 8.3 of Appendix 8 for the comparison of both types of relays. 25
  • 26. 9. Evaluations results and data Base on the data collected, there are some differences of voltage value between the measured and theoretical value. 9.1. Output voltage from external power source. The output voltage theoretically should be 5VDC and 12VDC. But the measurement showed lesser – approx. 4.89VDC and 11.81VDC. So the difference between these two outputs is 2.2% and 1.58% respectively. Refer to Table 9.1 of Appendix 9. 9.2. Parallel port output voltage to Demultiplexer The HIGH and LOW state of a parallel port output should give a reading of 5VDC and 0VDC. But the actual value from the measurement is averagely 4.48VDC, the difference is 10.3%. Refer to Table and Diagram 9.2 of Appendix 9. 9.3. Demultiplexer output voltage to JK FF The theoretical value of a HIGH state should be 5VDC, but from the practical, it was averagely about 3.73VDC. Luckily the minimum value of High Level Input Voltage (VIL) for 74LS112 is 2VDC, hence, the JK Flip-flop still able to operate. The difference between theoretical and practical value is 25.4%. Refer to Table and Diagram 9.3 of Appendix 9. 9.4. Supply voltage to Darlington Pair The input voltage for Darlington pair transistor theoretically is 5VDC. Base on datasheet, the maximum supply is 6VDC. But at the practical result the input voltage is 4.671VDC. The difference between is 6.58%. In the characteristics of the transistor when it is in a Darlington pair, the voltage drop across the collector is 4.09Vdc and the voltage droop across the emitter-base is 0.310Vdc. Meanwhile at the output value of the transistor is 4.83Vdc. The ratio of difference between practical and theoretical output voltage is 96.6%. 26
  • 27. 10. Discussion and Conclusion This project is a combination of software and hardware; numerous of experiments and debugs have been done throughout the prototype implementation. Let’s discuss and conclude what have achieved in this project. 10.1.Software 10.1.1. Temporary Memory This program is used to control switches that operated by the external hardware. Hence, a certain number of memories are needed, used to store temporary data that have been made by users. As you know, C++ and most of the programming language are same, which allow users to store data in variable (data register). Unfortunately this is not effective enough. Data stored in Data register of microprocessor will disappear once the supplied power has been cut off. Conclusion: The conclusion for this argument is, instead of using temporary memory such as variable, I have found and learned the technique on how to utilize file I/O to store in physical hard disk. With this approach, data will not lost even the supplied power has been cut off, provided the program stores the data appropriately. 10.1.2. Looping As we know, the number of instructions used by a particular program will also utilize the resources for a microprocessor. This program performed a lot of repeated job because a same task will be applied onto 32 different switches. Hence, if we do not use “loop” function, the computer processing time will be slow down and the program will be compiled in huge size. Conclusion: 3 types of looping technique can be used in C++ (refer to Section 2.4.2.4). Due to this, I have gained a lot of hands-on practice on how to use these techniques. Besides, during the implementation, I tried to save the processor time as much as I can. 10.1.3. Functions (Sub-routines) 27
  • 28. During the debugging, I found that a certain repeated job that will be performed by this program could not apply “looping” technique. The reason is a few data will be changed when the same task applied onto the subsequent switches. For example, when the program operates on the second switch, the hex code of the port (parallel & enable), the variable name and memory location for a certain array will be differ. Conclusion: Looping instruction is not able to carry so much data, unless I use nested loop. For a certain tasks, which have more data changes, probably a couple layer of nested loop will be needed. This is not a recommended practice as this will increase the mistake and also caused the microprocessor to spend more unnecessary looping time. By using Function Calls, I can simply solve all these problems and my program look tidier to ease the debugging job. 10.2.Hardware 10.2.1. Supplied Voltage not sufficient as per Theoretical Concept During the brainstorming and circuit developing, a certain voltage values are expected to supply for components such as Main DC supply, voltage value of level LOW and HIGH from Parallel port, Demultiplexer, JK Flip-flop and Transistors. Somehow, the actual measurements are decreased from expected. For detail information, please refer to Appendix 9. Conclusion: In fact, this is considered normal because the material we used such as cable, wire, components, PCB and connectors have certain resistance. The values from Theoretical concept are all “ideal” expectation, which is pretty difficult to achieve in reality. What we can do is, try to design the circuit as smooth as possible, prevent using unnecessary components, reduce wires usages and etc. 28
  • 29. 10.2.2. Unexpected Interference Our project has been attacked by unwanted interference without our knowledge. This happened during our “test run” on our project. The output results were not stable while we controlled a certain relay to switch. Conclusion: We have analyzed and realized that, this condition was caused by electromagnetic field interference or so-called noise. While we send out signals to switch the relay, the contact point inside the relay generates those noises. After a long time searching for resources, we found out that a type of relay called Solid State Relay will never generate any noise that could sufficient enough to interfere our output result. 10.2.3. Feedback The initial intention of this feedback system is to indicate to users when there is any failure with the equipment we controlled. There are only 2 possible consequences that caused by failure, either open circuit or short. So this feedback system must be able to detect them. Conclusion: How to build such a system? The first thing came to our mind is putting something in series with our equipment. But this will have a disadvantage. What if the component that in series with our equipment fails? This will caused open circuit to our equipment. So, we have to use certain component, which can last long, and not easily malfunction. First, we connect a resistor rating 22Ω, 10W in series with our equipment. Then, we connect a set of diode, zener diode and LED in parallel with this 22Ω resistor. Refer to Diagram 6.6 in Appendix 6. With this connection, the first diode 1N4001 will convert the AC voltage drop across 22Ω resistor to become DC value. The zener diode (rated 5.1V, 1W) has connected in such a way to provide voltage regulation to the LED. (Note: Voltage dropped across zener and LED are the same, as they are in parallel). The zener diode will ensure only 5.1 V allowed to drop across it. 29
  • 30. Base on Diagram 10.2.3a, with the increase of power (watt), the resistance of the load will reduce. As we can understand, lower resistance will allow more current to flow through. In the same time, the voltage dropped across resistor 22Ω will increase because V=IR. (Refer to Diagram 10.2.3b) The entire purpose for this zener is to protect the LED. When open circuit occurred in the load, LED will not light up and when short circuit, a 2A fuse has fixed before 22Ω resistor will burn off. But to be more secure, get two more resistors rated 220Ω, connect them in series with the 1N4001 diode and LED respectively. The fuse will protect the feedback system and the resistor acts as current limiter, to protect both zener and LED. 30
  • 31. References C++ from Ground Up Author: Herbert Schildt Publisher: McGraw-Hill (1994) C++ Through Example Author: P.Sellappan Publisher: Times (1994) Thinking in C++ Author: Bruce Eckel Publisher: Prentice Hall (1995) Inside the C++ Object Model Author: Stanley B. Lippman Publisher: Addison-Wesley (1994) Parallel Port Complete Author: Jan Axelson Publisher: Lakeview Research (2000) Subduck http://www.subduck.com The EE Compendium http://ee.cleversoul.com About.com http://www.cpemma.co.uk GameDev.net http://www.gamedev.net The University of Strathclyde http://www.eee.strath.ac.uk/ug-info Cpemma.Co http://www.cpemma.co.uk EDN Access http://www.e-insite.net/ednmag AMS (American Micro Semiconductor) http://www.americanmicrosemi.com Hyper Physics http://hyperphysics.phy- astr.gsu.edu/hbase/hframe.html - 31
  • 32. Appendix 2 Chart 2.4 Is "q" selected? START Displaying Main Menu with 5 choices: 1. Switches Operation 2. Display Swithces Status 3. Change Switches & Modules name 4. Configuration / Master Reset 5. Quit Is first choice made? Is second choice made? Is third choice made? Is forth choice made? Is fifth choice made? Displaying 8 modules and Quit choices in menu for selection Is choice made within 1-8? Is Quit selected? Displaying 4 switches in menu Is choice made within 1-4? Ask for ON or OFF Is it ON? Send logic "1" to parallel port. Send logic "0" to parallel port. Displaying 8 modules and Quit choices in menu for selection Is choice made within 1-8? Is Quit selected? Display switches status for the selected module and waiting for any key stroke to continue Selection of changing Module or Switch name. Select "q" to quit to Main Menu Is Module selected? Is Switch selected? Display 8 modules for selection Is choice made within 1-8? Display 8 modules for selection Is choice made within 1-8? Display 4 switches for the selected module Display Old name and prompt for New name. Display "Wrong selection" messague, wait for 5 seconds. Display Old name and prompt for New name. Is choice made within 1-4? Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes YesYes Yes Yes Yes No No No No No No No No No No No No NoNo No No No A warning page given with selections to continue or abort with choices Yes or No. Is Yes selected? A confirmation for resetting Module and Switch name. Is Yes selected? Select ON or OFF for all switches status. Is ON selected? Is OFF selected? Change all switches status to ON Change all switches status to OFF Yes Yes Yes Yes Yes No No No No No Reset all Modules and Switches name to default. Another confirmation for changing switches status Is Yes selected? END Yes Yes 32
  • 33. Appendix 3 Parallel Port Registers Registers Name Address Data Register Base + 0x00 Status Register Base + 0x01 Control Register Base + 0x02 Data Register Bit Definitions Bit Function Low High 7(MSB) D7 0 1 6 D6 0 1 5 D5 0 1 4 D4 0 1 3 D3 0 1 2 D2 0 1 1 D1 0 1 0(LSB) D0 0 1 Table 3.1.2 Control Register Bit Definitions Bit Function Low High 7(MSB) Not Used - - 6 Not Used - - 5 Not Used - - 4 Interrupt Control Disable Enable 3 Select Selected Not Selected 2 Initialize False True 1 Auto Feed True False 0(LSB) Strobe (Active-Low) True False 33
  • 34. Diagram 3.2 D1 pin3 D2 pin4 D3 pin5 D4 pin6 D5 pin7 D6 pin8 D7 pin9 D0 pin2 DEMUX 2 DEMUX 1 ABCD ABCD 16 Output 16 Output Table 3.2 Output SelectionInput (hex) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F Table 3.2.3 34
  • 35. Diagram 3.2.4 Pin D0 (20 ) Pin D3 (23 ) Pin D2 (22 ) Pin D1 (21 ) Pin C0 Time JK1 O/P (Q) JK15 O/P (Q) JK14 O/P (Q) JK13 O/P (Q) JK12 O/P (Q) JK11 O/P (Q) JK10 O/P (Q) JK9 O/P (Q) JK8 O/P (Q) JK7 O/P (Q) JK6 O/P (Q) JK5 O/P (Q) JK4 O/P (Q) JK3 O/P (Q) JK2 O/P (Q) t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 Note: t1 Input 0000 JK1 Triggered t2 Input 0001 JK2 Triggered t3 Input 0010 JK3 Triggered t4 Input 0011 JK4 Triggered t5 Input 0100 JK5 Triggered t6 Input 0101 JK6 Triggered t7 Input 0110 JK7 Triggered t8 Input 0111 JK8 Triggered t9 Input 1000 JK9 Triggered t10 Input 1001 JK10 Triggered t11 Input 1010 JK11 Triggered t12 Input 1011 JK12 Triggered t13 Input 1100 JK13 Triggered t14 Input 1101 JK14 Triggered t15 Input 1110 JK15 Triggered t16 Input 1111 JK16 Triggered JK16 O/P (Q) Table 3.2.5 35
  • 36. Diagram 3.3 Diagram 3.3.1 Diagram 3.3.2 Diagram 3.3.3 36
  • 37. Appendix 6 Block Diagram 6 START Turn on the hardware external power supply (240Vac) Turn on the PC and open the software. Connect the parallel port cable from PC to hardware. Check the communication switch is connects or disconnect. Is it connecting? Flip on the switch Reset the Hardware configurations Select the require output. Send Signal from PC to Demux (74LS154) Demux (74LS154) will select the require output. The output is in a high state (5Vdc) Signal will reach JK FF (74LS112) negative edge trigger. JK FF will be trigger by 5Vdc from Demux, and then through the LED indicator LED indicator will turn on the selected output Is the indicator shown the correct selected output? Reset and reselect 240Vac will through control switch Relay will turn on, and 240Vac will supply through. Transistor will turn o the Relay / (Opto 22) Solid state relay. Transistor will turn on and act as switch Switch to relay control? Direct Power Source 240Vac supply to feedback system. Feedback light up? Check the 240Vac supply Output supply 240Vac END Yes No Yes No Yes No Yes No Diagram 6.3 Diagram 6.6 37
  • 38. Appendix 7 Diagram 7 JK Board Darlington Circuit Demultiplexer Board Diagram 7.1 Diagram 7.7 LOAD Relay SPDT LOAD LOAD LOAD 240V AC 38
  • 39. Diagram 7.1.2 START Design Simulation on Electronics Workbench V.5.12 Ready The Components and PCB's Board. Also Prepare the Dimensions. Print out the Circuitry track layout Is all the connection abides on PCB board? Is the component blocking each other on the layout? Rectify error and Rework Rectify error and Rework Transfer to PCB board and perform etching Perform visual inspections and continuing test Re-etch new PCB board Is Etching success or fail? Is failure beyond repair? Repair the PCB board Drill hole and clean the surface of the PCB board with sand paper Place components and solder it, cut off protruding component leads Are all components in right place? Re-work and place in correct positions Perform testing Is the project works? Troubleshoot and repair END Yes No NoNo No No No Yes Yes Yes Yes Yes Table 7.6 VIN R PLOAD RLOAD RTOTAL ITOTAL VR 230 22 10 5290 5312 0.043298 0.95256 230 22 20 2645 2667 0.086239 1.897263 230 22 40 1322.5 1344.5 0.171067 3.763481 230 22 80 661.25 683.25 0.336626 7.405781 230 22 100 529 551 0.417423 9.183303 230 22 150 352.6667 374.667 0.613879 13.50534 230 22 300 176.3333 198.333 1.159664 25.51261 230 22 500 105.8 127.8 1.799687 39.59311 230 22 600 88.16667 110.167 2.087746 45.93041 230 22 700 75.57143 97.5714 2.357247 51.85944 230 22 800 66.125 88.125 2.609929 57.41844 230 22 900 58.77778 80.7778 2.847318 62.64099 230 22 1000 52.9 74.9 3.070761 67.55674 39
  • 40. Diagram 7.8 Side View 1 Side View 2 Front View Top View Top View – Zoom Top View - Components 40
  • 41. Appendix 8 Diagram 8.2 Single Transistor Switch Darling Pair Switch Diagram 8.3 Internal Circuitry for OEG OMI-SH-212L Relay Internal Circuitry for OPTO 22 G4 OAC5A Relay 41
  • 43. 43
  • 44. Appendix 10 Power vs. Resistance 0 1000 2000 3000 4000 5000 6000 10 20 40 80 100 150 300 500 600 700 800 900 1000 Power / Watt Resistance/Ohm Load Resistance Diagram 10.2.3a Power vs. Total Current & Voltage Dropped Across Resistor 0 0.5 1 1.5 2 2.5 3 3.5 10 20 40 80 100 150 300 500 600 700 800 900 1000 Power / Watt Current/A 0 10 20 30 40 50 60 70 80 Voltage(VR)/Volt Total Current Voltage Drop Across Resistor 22Ohm Diagram 10.2.3b 44 Royston Goh Digitally signed by Royston Goh DN: cn=Royston Goh, c=MY Date: 2004.02.02 14:07:32 ZSignature Not Verified