Professional Documents
Culture Documents
@i@@N
Copyright 2012 Walid Balid - All rights reserved.
| 2011-2012
Page | 1
} {Serial Communications
0B
:
6B
:
.
.
.
.
Serial Communications
Parallel Communications
| 2011-2012
Asynchronous
Synchronous
LPT
I2C
ISA
EISA
SPI
PS2
o
o
VESA
ATA
RS-423
RS-485
SCSI
PCI
FireWire
PCMCIA
Ethernet
IEEE-1284
IEEE-488
Fiber Channel
InfiniBand
MIDI
DMX512
Serial ATA
SpaceWire
PCI Express
T-1, E-1
Page | 2
} {UART
1B
AVR :
Page | 3
:1 AVR ...UART
AVR UART :
MCU-A A MCU-A MCU-B
MCU-B A .D2 :
MCU-B B MCU-B MCU-A MCU-A B
.D1
...
| 2011-2012
Page | 4
:Bascom-AVR MCU-A
'-----------------------[Definitions]
$regfile = "m8def.dat"
$crystal = 8000000
$baud = 9600
'-----------------------[GPIO Configuration]
Config Pinb.0 = Input : Switch Alias Pinb.0 : Portb.0 = 1
Config Pinb.1 = Output : Led Alias Portb.1
'
'-----------------------[Variables]
Dim Var As Byte
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'--->[Main Program]
Do
If Ischarwaiting() = 1 Then
Var = Inkey()
If Var = "B" Then Toggle Led
End If
If Switch = 0 Then
Print "A" : Waitms 200
End If
Loop
End
'---<[End Main]
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:Bascom-AVR MCU-B
'-----------------------[Definitions]
$regfile = "m8def.dat"
$crystal = 8000000
$baud = 9600
'-----------------------[GPIO Configuration]
Config Pinb.0 = Input : Switch Alias Pinb.0 : Portb.0 = 1
Config Pinb.1 = Output : Led Alias Portb.1
'-----------------------[Variables]
Dim Var As Byte
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'--->[Main Program]
Do
If Ischarwaiting() = 1 Then
Var = Inkey()
If Var = "A" Then Toggle Led
End If
If Switch = 0 Then
Print "B" : Waitms 200
End If
Loop
End
'---<[End Main]
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Technology Processes Automation
Page | 5
| 2011-2012
} {RS232
2B
DTE .DCE
TTL :
:0 " "Space .+3V ~ +25V
:1 " "Mark .-3V ~ -25V
:x .-3V ~ +3V
: 25V GND
.500mA
| 2011-2012
Page | 6
:RS232
7B
)(Disadvantages
8B
)(Advantages
System-to-System
Chip-2-Chip
.Chip-2-Sensor
.
.RS232<>TTL
.Single Master/Single Slave
.
50
.
)(25
).(0 , 1
.
RS232 :
.
Address
Port
0x3F8
COM1
0x2F8
COM2
0x3E8
COM3
0x2E8
COM4
COMx DB-9Pin :
| 2011-2012
Page | 7
) (1, 2, 3, ., 9 :
Description
Function
Direction
Name
Pin
Carrier Detect
Control
In
CD
Receive Data
Data
In
RXD
Transmit Data
Data
Out
TXD
Control
Out
DTR
System Ground
Ground
---
GND
Control
In
DSR
Request to Send
Control
Out
RTS
Clear to Send
Control
In
CTS
Ring Indicator
Control
In
RI
| 2011-2012
Page | 8
:RS232
TxD RxD
:
Page | 9
RTS
.
:RS232
10B
SPECIFICATIONS
RS232
RS423
SINGLE-ENDED
SINGLE-ENDED
1DRIVER/1RECVR
1DRIVER/10RECVR
50 FT
4000 FT
20kb/s
100kb/s
25V
6V
5V to 15V
3.6V
25V
6V
3k to 7k
>=450
Mode of Operation
Total Number of Drivers and Receivers on One Line
Loaded
Unloaded
Power On
N/A
N/A
Power Off
6mA @ 2v
100uA
30V/S
Adjustable
15V
12V
3V
200mV
3k to 7k
4k min
Shield 24AWG
.100 16PF/FT
Page | 10
| 2011-2012
) (Synchronized ):(Asynchronous
1B
: )( : ) clock or
(strobe
) (.
: \ .
: ) ( : )(Start Bit
) (Stop Bit
.
| 2011-2012
Page | 11
:
.
:
: ) (Half-Duplex ).(Full-Duplex
.6, 7 or 8 bit :
).(Baud Rate
) (Parity Bit
).(Even or Odd
).(1, 1.5 or 2
) :(Half-Duplex
.
) :(Full-Duplex
.
) :(Parity Bit
.
Even 0
.1 .
10110010 > Parity Bit = 0 | 10110110 > Parity Bit = 1
Odd 0
.1 .
10110010 > Parity Bit = 1 | 10110110 > Parity Bit = 0
| 2011-2012
Page | 12
) :(N 5, 6, 7 or 8bit
: N=7bit .ASCII=127
) :(Baud Rate
:
300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, etc
| 2011-2012
= /
Page | 13
RS232 :
| 2011-2012
Page | 14
RS232 :
8250-UART
.
/ ):(IOR, Input/Output Register
COM1: 0x3F8 | COM2: 0x2F8
RxD .TxD
)( .
)( .8250
| 2011-2012
Page | 15
dxxx=1 .
COM ) (1 Active
IRQ4 COM1 IRQ3 .COM2
.
| 2011-2012
Page | 16
: COM3
.
:
8250 1.8432MHZ
"."Divisor
1.8432 106
=
16
: 9600bps Divisor
1.8432 106
1.8432 106
=
=
= 12
16
16 9600
D=12 UART8250:
| 2011-2012
Page | 17
Bit7=1 ).(LCR
) (LSB ).(0x3F8
) (MSB ).(0x3F9
Bit7=0 ).(LCR
COM :VB, MVS2008.net
) ActiveX & OCX
(Components
Bios .
.
VB6 MSComm (MSCOMM32.ocx) OCX
COM .
: System32
SP6 VB6 .
Standard EXE
VB6 Enterprice Edition
.
| 2011-2012
Page | 18
SerialPort ) (
.VB6
: :VB6
) (COM
.
).(Test1/ProjRS232.vbp
" "OutGoing " Send
"Data
" "InComing .
| 2011-2012
Page | 19
:
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.RThreshold = 1
MSComm1.InputLen = 0
MSComm1.InBufferCount = 0
End Sub
Private Sub cmdClear_Click()
txtOutput.Text = ""
txtInput.Text = ""
End Sub
Private Sub optCOM1_Click()
MSComm1.CommPort = 1
End Sub
Private Sub optCOM2_Click()
MSComm1.CommPort = 2
End Sub
Private Sub optOpen_Click()
MSComm1.PortOpen = True
End Sub
Private Sub optClose_Click()
MSComm1.PortOpen = Flase
End Sub
Private Sub optTXT_Click()
MSComm1.InputMode = comInputModeText
End Sub
Private Sub optBIN_Click()
MSComm1.InputMode = comInputModeBinary
End Sub
Private Sub cmdSendData_Click()
Technology Processes Automation
Page | 20
| 2011-2012
)MSComm1.Output = txtOutput.Text & Chr(13
End Sub
)(Private Sub cmdExit_Click
If MSComm1.PortOpen = True Then MSComm1.PortOpen = Flase
End
End Sub
)(Private Sub MSComm1_OnComm
Static sBuff As String
If MSComm1.CommEvent = comEvReceive Then
If optBIN.Value = True Then
)sBuff = sBuff & StrConv(MSComm1.Input, vbUnicode
txtInput.Text = sBuff
Else
txtInput.Text = txtInput.Text & MSComm1.Input
End If
End If
End Sub
:MSComm
MSComm1.CommPort = N
" "N .
"MSComm1.Settings = "Baud,Parity,Bits,Stop
) (.
MSComm1.RThreshold = n
") "comEvReceive (
n=0 .
MSComm1.InputLen = n
n=0
.
MSComm1.InBufferSize = n
).(1~1024
MSComm1.OutBufferSize = n
).(1~1024
MSComm1.InBufferCount = n
.
| 2011-2012
Page | 21
MSComm1.OutBufferCount = n
| .
) | ( " "Input .
var = MSComm1.InPut
MSComm1.OutPut = var
.
.
MSComm1.CommEvent = Value
Value
CD
comEvCD
CTS
comEvCTS
DSR
comEvDSR
RI
comEvRing
RThreshold .
SThreshold .
).(vbCrLf
comEvReceive
comEvSend
comEvEOF
| | .DTR ) (True 1 0
. ) (Flase 0 .
MSComm1.Handshaking = comNone|comRTS|comXOnXoff|comRTSXOnXOff
| 2011-2012
Page | 22
:
:
) :(Poling the Port
.
) (Header Byte ).(Footer Byte
) :(OnComm() event
OnComm .
.
| 2011-2012
Page | 23
: :Matlab
Matlab
:
)obj = serial('Port','PropertyName',PropertyValue,...
;)'Ser = serial('COM1','BaudRate',9600,'DataBits',8, 'Parity','non
) (.
)fopen(obj
;)fopen(Ser
)fclose(obj
;)fclose(Ser
)delete(obj
;)delete(Ser
) (TXT .
) (BIN .
)A = fscanf(fid, format
;)A = fscanf(Ser
) (TXT .
)A = fread(fid
;)A = fread(Ser
) (BIN .
| 2011-2012
Page | 24
:
ser = serial('COM1','BaudRate',9600,'DataBits',8);
fopen(ser)
fprintf(ser,'This is Test')
A = fscanf(ser);
fprintf(ser,A)
for i=1:5
fwrite(ser,i);
end
A = fread(ser);
fwrite(ser,A);
fclose(ser)
delete(ser)
clear ser
Page | 25
| 2011-2012
TTL<>RS232 ) (RS232
) (UART .Max232
| 2011-2012
Page | 26
TTL<>RS232 ) (RS232
) (UART .
| 2011-2012
Page | 27
} {RS485
3B
:RS485
RS485 .
) (A,B VA<VB
1 VA>VB .0
.1
RS485
A B
.
:RS485
.RS485
LTC
MAXIM
TI
ST
LTC485
MAX485
SN75176
ST485
| 2011-2012
Page | 28
:RS485
. RS485
SPECIFICATIONS
RS422
RS485
Differential
Differential
1DRIVER
1DRIVER
32DRIVER
1RECVR
10RECVR
10RECVR
32RECVR
50 FT
4000 FT
4000 FT
4000 FT
20kb/s
100kb/s
10Mb/s 100Kb/s
10Mb/s 100Kb/s
25V
6V
-0.25V to +6V
-7V to +12V
5V to 15V
3.6V
2.0V
1.5V
25V
6V
6V
6V
3k to 7k
>=450
100
54
Power On
N/A
N/A
N/A
100uA
Power Off
6mA @ 2v
100uA
100uA
100uA
30V/S
Adjustable
N/A
N/A
15V
12V
-10V to +10V
-7V to +12V
3V
200mV
200mV
200mV
3k to 7k
4k min
4k min
>=12k
Mode of Operation
Total Number of Drivers and
Receivers on One Line
Loaded
Unloaded
RS232
RS423
SINGLE-
SINGLE-
ENDED
ENDED
1DRIVER
RS-485 drivers provide a differential output of a minimum 1.5V across a 54- load
Page | 29
| 2011-2012
:
.RS485
:
.
RS485 :
A B
:
| 2011-2012
Page | 30
: RS485
. .
| 2011-2012
Page | 31
| 2011-2012
Page | 32
) (Max1487, 15pF
).(CAT5, 9pF/ft
| 2011-2012
Page | 33
RS485 :
:
PASSIVE DUPLEX CONTROL (AUTOMATIC)
| 2011-2012
Page | 34
= 07
.
| 2011-2012
Page | 35
MODBUS :RS485
MODEBUS
) (Multi Master/Slave
.
MODEBUS ) (Master Device ) Slave
.(Device
MODEBUS ) (Query ) (Master Device ):(Slave Device
CRC
Data
Start
Address Lo
Start
Address Hi
Function
Code
Byte
Count
Slave
Address
CRC
CRC Low
CRC Hi
Stream
Start
Address
Byte Count
Function
Code
Slave
Address
1~2 byte
0 ~ 252 byte
2 byte
1 byte
1 byte
1 byte
Data
| 2011-2012
Page | 36
) (Data t1.5
!
:
| Inter-character time-out (t1.5) = 750s
9600bps 70Byte
.Slave address
:
1000 = .
70 8 = 560
560
9600
58ms
.t3.5= 1.75ms
MODEBUS ) (Responce ) (Slave ):(Master
Slave
.
| 2011-2012
CRC
CRC Low
CRC Hi
Byte Count
Function
Code
Slave
Address
1~2 byte
1 byte
1 byte
1 byte
Page | 37
: ) (Slave .CRC
| :RS485
RS485 : ) (Half-Duplex ) (Full-Duplex
.
.
RS485
.
| 2011-2012
Page | 38
):(RS232<>RS458
.RS232<>RS458
| 2011-2012
Page | 39
):(RS232<>UART<>RS458
.RS232<>UART<>RS458 Max485
.RS232<>UART<>RS458
| 2011-2012
Page | 40
| 2011-2012
Page | 41
} {USB
4B
127
16
RS-232
50-100
20k -115k
RS-485
4000
10M
IrDA
115k
Microwire
10
2M
SPI
I2C
10
2.1M
40
18
3.4M
FireWire
64
15
400M-3.2G
IEEE-488
15
60
8M
Ethernet
1024
1600
10M/100M/1G
MIDI
50
31.5k
LPT
10-30
8M
USB
)(
bits/sec
:USB
.480Mb/s
Plug & Play .
.
127 .
:USB
USB 1.0 & USB 1.1 & USB 2.0 & USB 3.0 :USB :
Low Speed 1.5 Mbits/s .USB 1.0
Full Speed 12 Mbits/s .USB 1.1
| 2011-2012
Page | 42
:USB
USB Host Controlled )
(
USB
On-The-Go
.
USB :
.
.
USB HUB
.
| 2011-2012
Page | 43
:Plug& Play
USB Plug & Play
USB .
.
.
. VID, PID
USB
.
:USB
USB :
:A .
:B .
.
USB : +5v & GND .D- & D+
1
) VCC(
D-
)(
D+
)(
) GND 4(
USB D+&D- ' '1
' '1 '0' D+ D-
.
| 2011-2012
Page | 44
' '1
.
:
USB D- D+
:
: .D-
.1
.2 : .D+
.3 : .
| 2011-2012
Page | 45
:USB
USB
.USB
:(USB Device) USB USB
) (Host Controller IC ) (USB Function
USB .
:USB Function USB .
) :(Endpoint USB Function USB
| 2011-2012
Page | 46
:Pipe Pipe :
) ( .Pipe :
.1
.2
:Synchronization .
:(Packet Identity) PID
.
.3
:Address 128.
| 2011-2012
Page | 47
.4
.5
:Endpoint .
:(Cyclic Redundancy Check) CRC 5 .
) :(Data Packet :
.Data0
.1
.2 .Data1
1024bit CRC 16bit .
) :(Handshake Packet :
:Acknowledge .
:Not acknowledge
.
:Stall
.
| 2011-2012
Page | 48
USB
| 2011-2012
Page | 49
:USB
USB USB
:
) (Hardware .USB
.1
.2 .
USB
USB USB
UART
USB
.
FT232 USB<>UART
.FTDI
USB ) (Hardware
USB .
) (D2XX driver & VCP driver :
.COM
| 2011-2012
Page | 50
D2XX.DLL Driver
300 KB/s
3MB
| 2011-2012
Page | 51
11 .
PWREN# .
| 2011-2012
Page | 52
(Engine :
USB .USB
.CRC
.Start Of Packet, End Of Packet, Resume, Reset
.NRZI
).(PID
) (USB Transceiver USB2.0, USB1.1
D+ .
| 2011-2012
Page | 53
| 2011-2012
Page | 54
| 2011-2012
Page | 55
RS485
| 2011-2012
Page | 56
} {LabVIEW
5B
. :
.[428]Agilent VEE .[429]National Instruments LabVIEW.[430]Microsoft Visual Programming Language (MVPL) -
1-3
2-3 MVPL
| 2011-2012
Page | 57
LabVIEW
.
):(The Importance of Graphical Programming
13B
Moor
) (FPGAs, Multi-core MPUs, SoCs
. 30-3 .
3-3
)(
FPAG
) (Synthesizable .
.
: C
].[431,432
] [433 FPGA
. ] [434-436
) .(Dataflow 31-3
. 32-3 .
| 2011-2012
Page | 58
4-3
5-3
] .[437
] [438 ] [439
) (Flowchart .
:(LabVIEW Programming Environment) LabVIEW
14B
][428
1980s
].[422
) (Design ) (Prototype )Deploy ) MCUs,
MPUs, Multi-core, FPGAs, DSPs, ) PLC, Vision,
Page | 59
6-3 LabVIEW
-1 )(Front Panel
-2 )(Block Diagram
-3 )(Project Explorer
7-3 LabVIEW
| 2011-2012
Page | 60
16B
8-3 LabVIEW
)(Front Panel
9-3 LabVIEW
. 37-3 "."Controls Palette
Page | 61
):(Block Diagram
17B
. 38-3 .LabVIEW
39-3 "."Functions Palette
11-3 LabVIEW
Page | 62
40-3 .LabVIEW
13-3 LabVIEW
LabVIEW G
) (High-level Design Models Simulation-Module
Matlab-Simulink StateChart Module ) HDL,
14-3 LabVIEW
" "G
| 2011-2012
Page | 63
. " "G :
) object-oriented
) (recursion ) (event handling
.(programming
LabVIEW G
) (Dataflow
)(
- .C++ & C
G ) (Dataflow
- -
) ( LabVIEW
.
19B
:(Benefits of G Programming) G
.
" " ) (Visual Thinkers
.
.
.
G
)
| 2011-2012
Page | 64
42-3
.LabVIEW
15-3
LabVIEW
. LabVIEW
).(Execution Highlighting
LabVIEW
LabVIEW G :
) (Probes ) (Break Points ).(Step-by-Step
G
LabVIEW
| 2011-2012
Page | 65
LabVIEW
.
):(Automatic Parallelism and Performance
.
LabVIEW
C C++
. / ) (Producer/Consumer
G While
Queues
. 44-3 .Producer/Consumer
. 40
.
) (Pipelining, Task and Data Parallelism ) (Multithreading )
( .
| 2011-2012
Page | 66
. G ) (Multitasking
LabVIEW
.
" Implicit Parallelism
G . 45-3 .
LabVIEW
46-3
. 47-3 " "Data Parallelism Quad-core .LabVIEW
Page | 67
LabVIEW
Technology Processes Automation
Pipelining
4-Channels
LabVIEW
50-3 ) (Real-time
).(1,2,n
Core-1
23-3 LabVIEW
| 2011-2012
Page | 68
Core-2
.
FPGA
FPGA FPGA
].[433
G FPGA
G
) (Parallelism
. 51-3
LabVIEW FPGA .
| 2011-2012
Page | 69
.
.
G
LabVIEW
.
G
" "Profile Performance & Memory LabVIEW
LabVIEW .
52-3 .LabVIEW
25-3
LabVIEW
G
" ."LabVIEW Desktop Execution Trace Toolkit
:
. 53-3
"."Execution Trace
| 2011-2012
Page | 70
LabVIEW
LabVIEW .
LabVIEW ) (Formula Node
27-3 C LabVIEW
C-node
| 2011-2012
Page | 71
56-3
. LabVIEW
] .[444
.
Design Algorithm
Graphical
Programming
Simulate Program
Test System
1.
2.
Target Hardware
3.
Optimize Algorithm
Traditional Languages
Simulate Algorithm
29-3 -
| 2011-2012
Page | 72
30-3 .DSP
57-3 LabVIEW-DSP
LabVIEW
LabVIEW
.
58-3 ) (DAQ
. LabVIEW
) .(58-3a
50
).(58-3b
)(a
)(b
31-3
58-3 -59-3
LabVIEW .
.
| 2011-2012
Page | 73
32-3
59-3
) ( .60-3
Do-while Times-loop
.
33-3
)(b
34-3
| 2011-2012
Page | 74
FPGA
61-3
62-3
) (Floating point
.
35-3
FPGA
62-3 SRAM
FPGA LabVIEW DMA-FIFO 63-3
66 4000 !
66Pages ~4000Lines
36-3 FPGA
):(Conclusion
21B
Moor
Page | 75
. ) :
( .
: C
. )(LabVIEW
.
.
| 2011-2012
Page | 76
:LabVIEW
2B
LabVIEW :
NI LabVIEW 2011
NI VISA 511full
NI-VISA_Runtime
) (Write.vi COM
) (Read.vi COM...
:LabVIEW2011
:LabVIEW2011
23B
24B
30 2012
25B
| 2011-2012
Page | 77