1. Zanjan University
Department of Electrical Engineering
Bachelor Thesis
Title
Making PLC (Programmable logic controller) by FPGA and
microcontroller
By
Mojtaba Hajimiri
Ali nilechi
Supervisor
Dr. Siroos Toofan
2. PLC (Programmable logic controller) is one of the important
parts in industry. So our purpose in this project were making a
PLC. Towards this end, an electrical circuit is designed based
on FPGA and other microcontrollers. Then, a PCB is designed
using altium designer, and the functionality of the board is
tested.
Our PLC in here contains 2 boards :
1- main board: this board consist of altera cyclone ii
EP2C8T144C8 FPGA and atmega128. we used this board as
our main board. We writes the PLCs main program in quartus
software (by graphical language-like FBD in PLC) on FPGA
and then we sends our commands to atmega128 microcontroller
that can be connected to our power board (by rs232 or ...).
2-power board: this board consists of atmega128
microcontroller as main processor and can been connected to
our main board (by rs232 or ...). We used this board as our
input-output board. this board consists of some protection
circuits in his inputs that can be acquire different types of
inputs. in this board we used relays to control automation
systems.
7. lcd & hmtr & mmc circuit:
1
2
3
4
5
6
HMTR
Header
6
V
C
C
V
C
C
G
N
D
G
N
D
rx0
tx0
V
C
C
G
N
D
V
C
C
3
1
2
1
0
K
R_LCD
RPot
G
N
D
1
2
3
4
5
6
7
8
eeprom
Header
4X2
G
N
D
G
N
D
1
VCC
2
V
O
3
R
S
4
R/W
5
E
6
DB0
7
DB1
8
DB2
9
DB3
1
0
DB4
1
1
DB5
1
2
DB6
1
3
DB7
1
4
A
1
5
K
1
6
LCD
1
2
3
4
5
6
7
8
9
1
0
m
m
c
Header
10
1
K
rmmc1
Res1
1
K
rmmc2
Res1
s
s
o
mosio
v
3
3
scko
v
3
3
v
3
3
G
N
D
misoo
c
4
c
5
c
6
c
7
c
0
c
1
c
2
V
C
C
G
N
D
V
C
C
SDA
14. atmega 128 schematic:
P
E
N
1
PE0
(RXD0/PDI)
2
PE1
(TXD0/PDO)
3
PE2
(XCK0/AIN0)
4
PE3
(OC3A/AIN1)
5
PE4
(OC3B/INT4)
6
PE5
(OC3C/INT5)
7
PE6
(T3/INT6)
8
PE7
(IC3/INT7)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