Lectures
Lectures
CSE 360
Lectures
Prepared By
Ejaz Jamil
Contact
Name: Consultation Hours:
Ejaz Jamil Mon, 2:00-3:20PM,
In the Lab,
and on Appointment
Email:
[email protected]
Office:
12 Kalabagan 1st Lane
Phone: Dhaka 1205
01776196371
Sections
1 Classes: 2 Classes:
Mon (UB30602)
Mon, Wed (UB30603)
9:30-11:00AM
3:30-4:50PM
Thu (UB30401)
Lab:
Thu (UB50201,UB60806) 12:30-2:00PM
2:00-4:50PM Lab:
Mid Term: Monday (UB40401)
11:00AM-1:50PM
February 27
Mid Term:
Final:
February 27
April 8
Final:
Project:
April 8
April 7
Project:
April 7
I Instructors Discretion
N
F Grading Attendance 5%
O Extra Credit 10%
Quiz 1 5%
Quiz 2 5%
Quiz 3 5%
Homework 20%
Final Exam 30%
Mid Term 15%
Sub Total 80%
Product Design Project 10%
Lab + Lab Assignments 10%
Total 100%
I
N
T Syllabus Hardware Coverage:
E Sensors/transducers
1. Hardware Interfacing
R
Datasheet Analysis
Multiplexing
Memory (SRAM, DRAM, SDRAM, DDR)
F
Hardware Design using Timing
I
PCB Design 4. AC Motors (Induction, Synchronous)
Product Design 8. Heatsinking
N Serial Interfaces (I2C, RS-232, 422, 485, USB, 1394,
Prototyping
G
2. Software Design
SATA, SAS)
10. Power Supplies (Standard, Switching)
Writing Generic Micro 11. GPIO
12. Bus Interfacing
Kernel
13. DMA
IPC and I/O 14. Parallel Interfaces (SCSI, ATA, PCI)
Event Driven Programming 15. Wireless
Interrupts UARTs
Timers & Watch Dog 17. Hard Disks, SSD
19. Laser
Device Drivers
Input Devices (keyboard, touch, mouse)
Memory Management A/D - D/A Converters
User Interface
Multi-processing
I
N
T
R Text Books
O
1. Volume 1, Introduction to ARM Cortex-M
Microcontrollers (fifth edition, 2nd printing- June
2014), 2014, ISBN: 978-1477508992
2. Volume 2, Real-Time Interfacing to ARM Cortex-
M Microcontrollers (fourth edition, 1st printing
June 2014), 2014, ISBN: 978-1463590154
3. Volume 3, Real-Time Operating Systems for
ARM Cortex-M Microcontrollers (third edition,
9/2014), 2014, ISBN: 978-1466468863
Abstract: (required)
Introduction: (required)
Topic titles: (these titles are related to the subject matter of the paper)
Summary: (required)
Author Biography: (optional)
Acknowledgments: (optional)
References: (required)
GUI
D
A
T Prototype Design
A
S Mechanical DesignSpark
3D Printing
H Design Mechanical
E
E
T Electronic
Eagle CAD
Schematic PCB Layout PCB
Design Design Design Etching
Solder Mask
Metal Stencil
Etched
Solder Paste Pick & Place
PCB
Solder Mask
UV Method
Completed Reflow
PCB Oven
Brake
Simple 3 story elevator
Flywheel
Speed Control Motor
Speed
Control
Sensor
M = We-Wc
3 1 Horsepower = One metric horsepower
Hall Sensor is needed to lift 75 kilograms (avg. body
Accelerometer L1 weight of a person) by 1 meter (3.28 feet)
in 1 second.
Pressure
Sensor
We F2
2
Work = Mg(3h)
L2 Magnet
Counterweight
F1 How many
1 horsepower motor is
Wc needed?
Alignment
Sensor
W1 h 10 hp
F0
10 people
W2
0
Hydraulic Damper or
Shock Absorber
S
E
N
S Sensors - Accelerometer
O
https://www.sparkfun.com/products/10953
R
S
m F=ma
m Piezoelectric
m Capacitor
Si
S
E
N
S Accelerometer Integrator
O
R
S C
C
from
Accelerometer,
Vacc Vn i
R
Velocity Vn i
R
Distance
i Vp
i Vp
Opamp Opamp
Integrator Integrator
PHOTO
DIODE
In Proximity
Von Neumann vs Harvard
Arch.
Program and Data memory Program and Data memory
are same. are separate.
BUS INTERFACING
●
Modern processors use
Harvard Arch.
●
Reads Instruction and Data at the same
●
Cannot read Instruction and Data at the time
same time ●
Data memory may be of different byte
●
Data memory must be same length as length than Instruction
Instruction
Bus – Data, Address, Control
bus
A tri-state bus which is shared by all
devices
BUS INTERFACING
Display
CPU
I/O
Bus Errors/Conflict
Only one I/O is allow to share a bus at any one time as
OUTPUT.
If two or more I/O use the bus as OUTPUT causes bus
BUS INTERFACING
conflict.
If one I/O is used as OUTPUT and multiple I/O are used
as INPUT causes NO bus error.
I/O Types:
1. Open Drain
2. Open Collector
3. Read Only
4. Write Only
5. Read/Write
6. TTL
7. Unbuffered
Electrical Characteristics of
Pins V IH,max
This transistor does not
VCC VIH,min
exist in Open Drain ICC
Output VIL,max
ELECTRICAL ANALYSIS
0V
I/O VIL,min
IS
VCC = Supply Voltage
TS ICC = Supply Current
RPU IS = Source Current
Vout IK = Sink Current
IIL RPU = Internal Pull Up Resistor
RPD = Internal Pull Down Resistor
Vin VIH,max = Max logic high voltage
VIH,min = Min logic high voltage
IIH TK VIL,max = Max logic low voltage
B
Y
A
Inverter Delay
AND Delay
A
B
Y
74, 54 and 40 Series Glue
Logic ICs
Used for interfacing with other circuits
74 and 54 is the Transistor Transistor Logic
GLUE LOGIC
by fabrication
FPGA – Field Programmable
Gate Array
FPGA is an array of gates
Interconnection between gates are
GLUE LOGIC
programmable
Put all your external logic gates into a
single FPGA
Minimize chip count by using FPGA
Popular FPGA vendors: Xilinx, Altera
Density: 1M+ gates
Use VHDL or Verilog to build your logic
circuit.
74HC Series by Function
Buffers/inverters/drivers Analog switches
Bus switches Decoders/demultiplexers
Counters/frequency dividers Digital comparators
Encoders Digital multiplexers
Gates FIFO registers
- AND gates Flip-flops
- Combination gates Full adders
- Configurable multi-function Level shifters/translators
gates Multivibrators
- EXCLUSIVE-NOR gates Parity generators/checkers
- EXCLUSIVE-OR gates Phase-locked loops
- NAND gates Schmitt triggers
- NOR gates Shift registers/LED drivers
- OR gates Transceivers
Latches/registered drivers
Wired And
CO1 . RO1 .
. .
. .
. .
. .
. .
CO2 . RO2 .
. .
CO = CO1 + CO2 + 1 1 1 1
= + +
CO3 R I RO 1 R O 2 R O 3
CO3 RO3
Effects Fan In
- Input Capacitance Increases
- Input Resistance Decreases
Load Consideration – Fan
Out
Fan Out = Number of outputs that a gate can drive
RI1
. .
CI1 .
.
. .
. RI2
.
. .
. .
. CI2 .
. .
1 1 1 1 RI3
= + +
CI = CI1 + CI2 + CI3 RO RI 1 RI 2 RI 3
CI3
Effects
- Input Capacitance Increases
- Output Resistance Decreases
- Source IS & Sink Ik current is shared by more inputs
Open Drain/Collector Output
Some device's output is open drain (for CMOS) or collector (for
bipolar) to allow the following:
TK TK
Effects
- If a terminal is open drain or collector, the terminal must pass through a
load to VCC.
Simple Zener Regulator
V CC −V Z
VCC RM=
IM
RM
IP = I A + IB + … + I K IM
IM = IZ +
…
IP
VZ IA IB IK
IZ
A B … K
IM
RM
ELECTRICAL ANALYSIS
IM = IZ + RP VA RAB VB … RBK VK
IP
VZ IA IB IK
IP IAB IBK
IZ Z
IZA
A RA IZB
B RB … I K RK
ZK
3. Zener = 0.7V V CC −V D
R P=
VD = IS
Diode
Drop RP
I/O I/O
IK IS VD =
Diode
IK = Sink Current Drop
IS = Source Current
RP = Current limiting/protection
resistor
How to find the value of current limiting resistor to drive LED
NOTES
1. Always consider Diode Drop (0.5V – 0.7V for diode/zener, 2V for LED)
2. Get IK and IS from datasheet
3. Do not use value less than protection resistor RP.
Wrong Circuits
VCC VCC
Missing RP Missing RP
ELECTRICAL ANALYSIS
I/O I/O
IK IS
IK = Sink Current
IS = Source Current
RP = Current limiting/protection
resistor
How to find the value of current limiting resistor to drive LED
NOTES
1. Current limiting resistors must be present.
2. Excessive Source or Sink current will flow, if the limiting resistor is not
present.
3. Excessive heat will be generated.
4. Will damage the LED
Zero Crossing Detector
Positive Cycle Current How to calculate value of current
Diode Drop, limiting/protection resistor.
0.7V
On each Diode
ELECTRICAL ANALYSIS
VS
VS = 2 * 0.7 + RP.IT + 2.0
AC → RP.IT = VS – 3.4
V S −3 . 4
R P=
IT
RP IT
NOTE: LED voltage drop is higher
than diode voltage drop.
RED
LED Choose Opto-Transistor that meets:
Drop,
2V
Reverse breakdown voltage > VS,max
IT = Opto-transistor Trigger IT = current through RP
Current
RP = Current Protection Resistor
Level Translator
ELECTRICAL ANALYSIS
High Low
Voltage Voltage
Logic Logic
Level
Translator
NOTES
1. Low and High voltage circuits are isolated.
2. Assures proper level translation without overdrive.
3. Interfaces low voltage powered device with higher voltage powered
device.
4. Can be implemented with very simple circuits
Level Translator Design
VCC,L VCC,H VCC,L VCC,H
ELECTRICAL ANALYSIS
RP RP RP
RP VHV
VLV Inverted
Output
VLV VHV
Transistor Properties
VCC V C =V CC −I CE RL =V CC −h FE I BE R L
I CE
where , h FE=
ICE I BE
ELECTRICAL ANALYSIS
RL
Output
BUS INTERFACING
Selector
Demultiplexer
Input Output
BUS INTERFACING
Selector
Johnson Counter
Johnson counter is
useful to delay pulses
BUS INTERFACING
by specific number of T
0
clock cycles.
1 T
2 2T
3 3T
0 4
1 5 nT
Input
6
Output
T 7
7
Outputs
n = bit index
Selector
4017 Johnson Counter
Expansion
BUS INTERFACING
E E E
Semiconductor Memory
System
SRAM – Fastest. Use: cache, buffer, pipeline
DRAM – Fast. Use: Mass memory, data
SDRAM – Fast with auto-refresh. SDRAM
MEMORY
000 DRAM
Column Addr
Selector
B
CAS
Bit 7 1 0
line
0
A
MEMORY
1
Data
Word line Output
Logic
Row Addr
Selector
Address,
RAS
101011 RAS
001
(53h)
000 001
CAS
Memory access is designed on the above general concept where the cell intersected by two demultiplexer (address
decoders, A and B). The selected is then multiplexed into a common output. NOTE. The organization of each memory is
different, but the general memory access concept is similar.
STATIC RAM
1. Very Fast
2. Used as On-chip Cache
3. Less dense than DRAM
4. Expensive
5. Retains data for little power
MEMORY
DRAM File: Memory\DRAM_MSM5117400F.pdf
4 M x 4 DRAM
MEMORY
0 1 row 1 1 X
0 0 col 1 1 X
0 0 - 1 0 data read
0 0 - 0 1 data to write
address
MEMORY
read write
DRAM [Continued]
MEMORY
P or DMA
Synchronous DRAM (SDRAM)
SDRAM has Clock
Micron MT48LC32M8A2 – 8 Meg x 8 x 4 banks
File: Memory\SDRAM_Micron_MT48LC32M8A2.pdf
MEMORY
SDRAM ADVANTAGES
Read/Write burst mode.
Synchronized with main clock
MEMORY
Auto refresh feature
Built-in commands
Faster than DRAM
READ/Write Burst
READ
MEMORY
WRITE WRITE/READ
DDR SDRAM
File: Memory\DDR2_SDRAM_Micron_1Gb_DDR2.pdf
READ or WRITE
or WRITE
MEMORY
READ/WRITE
Ferroelectric RAM (FRAM)
1. Practically no restrictions on read/write limits
2. Almost 151 years data retention
3. Fast serial interface (SPI or I2C)
MEMORY
ATmega2560 Memory Map
MEMORY
NAND
MEMORY
NOR
Micron 8GB NAND Flash
MEMORY
Micron NAND Flash Page
Read Timing [Micron flash...]
MEMORY
Micron NAND Flash Page
Read Timing [Micron flash...]
MEMORY
Micron NAND Flash Random
Read Timing [Micron flash...]
MEMORY
Micron NAND Flash Block
Erase Timing [Micron
flash...]
MEMORY
NAND Flash NOR Flash
Read Speed One third the speed of NOR 3-4 times the speed of NAND
Contains the full circuit for a flash drive
USB 2.0
Supports Numonyx, Hynix, Samsung, Toshiba, Micron, Renesas
MEMORY
flash chips
Up to 12 MB/s for read and 8 MB/s for write operations in single
channel
Up to 4 NAND Flash supported per channel
NAND Flash support table (page 10, section 4.1)
Upto 4GB x 4 = 16GB flash support
Micro SD
4 Bit bus
MEMORY
Designing With Memory
a
A a
b
B c
DISPLAY
C d f b
D g
74LS248 e
LT 74HC4511 f
BI g e c
RBI h
d h
Any microcontroller
DISPLAY
000
X
B LED
DISPLAY
Col 7 1 0 R G B
0
A 1 R
1= On Row G
0=Off
B
7
Y
Intensity of each LED
(3,5) is controlled by PWM
001 or Current Limiting
Raster Timing
1/64 Frame
DISPLAY
1 Frame = 64
LED
Basic OLED
Construction
-
Cathode
Emissive Layer
Conductive Layer
Anode
+
OLED (Continued)
Types of OLED Basic AMOLED
1. AMOLED = Active Matrix Construction
OLED
-
Cathode
2. PMOLED = Passive Matrix
DISPLAY
Conductive Layer
PMOLED is composed of TFT (Thin Film Transistor)
+
OLED cells organized in
matrix without TFT. Storage In AMOLED, each OLED cell
Capacitor sits on a TFT.
Anode Each TFT also feature a
storage capacitor which holds
a charge to keep the LED
brightness high during
OLED cell is refresh.
sandwitched
Cathode
between andode
and cathode
Pulse Width Modulation
By changing the pulse,
A the RMS value of the
V signal can be
DATA ACQUISITION
Vrms controlled
t
TH
T RMS of two pulse: RMS of three pulse:
2 a12+ a22 2 a12+ a22 +a23
a =
rms a =
rms
2 3
a1 a3 a4 a5 a6 an
RMS of n pulse:
... TH
t 2 2 2
a + a ... a
∑n a 2
n δt ∑ a
2
n ∫ a 2 (t)dt
a2rms=
1 2 n n 0
= = =
1 2 3 4 5 n n n n δt T
TH TH TH
1 1 A2 T
a = ∫ a (t) dt= ∫ A dt= ∫ dt= A2 H
2
rms
2 2
T 0 T 0 T 0 T
a rms= A
√ TH
T
=A √ D where, D=
√ TH
T
= duty cycle of the pulse
Heat Sensors - Thermistor
Ni/Mn/Co Oxide
Thermistor
MORE SENSORS
RT
10R
NTC Type
Thermistor R
To ADC
Features: 0.1RT
Thermocouple
MORE SENSORS
10R
To ADC
Symbol
Features:
VCC
VCC
Rb
Rm
CF R R2
1
Permanently
Charged Electret
-
Diaphragm +
Rb
Mic DC
Bias Audio
Isolation
Circuit Pre Amp
R2
A=
R1
Op Amps Ideal OpAmp
A=
Ri =
Non- +VCC
Inverting Very Large Gain, Ro = 0
Input typically 106
to internal impedance
Inverting -VSS
Input
Ro
+
High Input
Vi Ri AVi Vo
Impedance _
Current drain by
inputs are low
Gain = A
Op Amps (contd.) V0
Vin
Non-inverting OpAmp
Vp
Vin R1
V n=( )V
Vo R1 +R 2 O
Vn The output is in phase
R2 with the input in non-
V O=(1+ )V inverting configuration
OP AMP
R1 n
R2
Therefore,
Vin = Vn
R2
V O=(1+ )V in
R1
Op Amps (contd.) V0
R2
Vo
Vp For ideal OpAmp,
Therefore,
Vin = Vn
V in −V n −V o−V n
=
R1 R2
V in −V o
=
R1 R2
R2
V =−( R 2 )V V O=(− )V in
o
R 1 in R1
Op Amps (contd.)
Summing OpAmp
R1 i0 R0
V1 i1 +i 2 +i+3=i 0
i1
Vn V 1 −V n V 2−V n V 3 −V n −V 0−V n
R2 + + =
V2 R1 R2 R3 R0
OP AMP
V 1 V 2 V 3 −V 0
i2 Vp Vo + + =
R1 R 2 R 3 R 0
R3
V3
R0 R R
V o =−( V 1+ 0 V 2 + 0 V 3 )
R1 R2 R3
i3
Therefore, R0 R0 R0
V o =−( V 1+ V 2 + V 3 )
Vin = Vn R1 R2 R3
Input – Mechanical Switches
Push Buttons, Keyboards, Switch Arrays Interfacing
Input
A
B
MECHANICAL INPUT
C Keypad
A
X
Microcontroller
Y
1 2 3 Z
B
Inputs
Output
X Y Z
Example: If Switch 5 is pressed,
Outputs then Y = LOW, B = LOW.
Disadvantage:
A keyboard scanning routine had
to run continuously.
NOTE: If the I/O ports have Input Pull Up
resistor, they should be activated. Ideal should be to scan only after
keyboard interrupt.
Input – Mechanical Switches
(Contd.) +VCC Interrupt based approach +VCC
RPU
MECHANICAL INPUT
Interrupt
Hardware Debouncer
Bouncing – rapid
transition of states due to
mechanical switch's
friction and contact.
DC Inductive Load
Normally Normally Single Pole
Open relay Closed Double Throw
relay
VCC
Snubbe
r Diode
ACTUATORS
RR
IR
RP Relay is a binary actuator that have two state: ON or OFF. If
relay activation causes the relay to turn ON, this type of
R relay is called Normally Open.
VCE(sat)
There is also Normally ON relay, which is Closed when it is
C not activated.
VR
VCC
Snubbe
r Diode RC
ACTUATORS
Relay
t
RR
IR RC = tHL
RP
Snubber diode is required to suppress the back-emf created
R by the Relay's inductor. The faster the Fall time (lower t HL)
VCE(sat)
the higher is the voltage.
v
C d( )
di RR L dv L VR
V be =−L R =−L =− V be =−
dt dt R R dt R R t HL
To minimize Vbe, the fall time, tHL, should be increased. By
using the RC circuit at the base of the transistor, and
Example: choosing, = RC (time constant) to 100 ms, reverse emf can
L = 10mH, RR = 10, VR = 1V, tHL = be significantly reduced.
1s
If, = RC = tHL = 100ms,
−3
−(10 * 10 H)∗(1V)
V be = =1000 V
(10∗Ω ) * (1∗10−6 sec ) −(10 * 10−3 H )∗( 1V )
V be = =0.01V
( 10 Ω )∗(100∗10 -3 sec)
DC Motors [Types] Brushless
DC Motor Parameters:
Voltage Rating
Current Rating
Starting Current
Horse Power
Torque Permanent Stepper
Magnet
DC
MOTOR
Motor Brushed
Separately
Excited
NOTE
1. DC motor generates reverse emf.
2. A snubber diode required during surge.
3. DC motor is like short circuit at startup. Stepper Motor
4. Brushed DC motor has high initial torque. Parameters:
Voltage Rating
Current Rating
Starting Current
Shunt Series Step Size
Torque
Polarity of Coil
See Videos:
DC Motor How it works - YouTube.mp4
Brushless DC Motor How it works - YouTube.mp4
DC Motors [Types] Brushless
DC Motor Parameters:
Voltage Rating
Current Rating
Starting Current
Horse Power
Torque Permanent Stepper
Magnet
DC
MOTOR
Motor Brushed
Separately
Excited
NOTE
1. DC motor generates reverse emf.
2. A snubber diode required during surge.
3. DC motor is like short circuit at startup. Stepper Motor
4. Brushed DC motor has high initial torque. Parameters:
Voltage Rating
Current Rating
Starting Current
Shunt Series Step Size
Torque
Polarity of Coil
See Videos:
DC Motor How it works - YouTube.mp4
Brushless DC Motor How it works - YouTube.mp4
AC Motors [Types] Induction Motor:
AC Motor Parameters: 1. Most common
Voltage Rating
Current Rating 2. Good initial torque
Starting Current
Horse Power
Induction 3. Single to 3 Phase
Torque
1-3 Phase
AC
MOTOR
Motor
Synchronous
3 Phase
Synchronous Motor:
1. Constant speed irrespective of load
2. Low initial torque
3. Usually 3 Phase
Brushed DC Motor
N N N N
S S S S
A
X
N N N
A
MOTOR
N
S
S
S X S Y
S
B
Y
N N N N
S S S S
A Y
A
+ - + - + - + -
X
B
B
Y
In brushed DC motor turns on the coil that is perpendicular to the
magment
Brushed Motor Pros/Cons
Less Expensive Periodic maintenance
Simpler Construction Brush friction reduce
Replaceable brush torque
No driver electronics Lower speed
MOTOR
N N S N N N N
N A A A
N S S
P
S P
S P
MOTOR
S S
B B B
X X X
Polarity Reversed
1 2 3 4 5 6 1 The positions 4, 5 and 6 is
AB the repeat of 1, 2 and 3
with direction of current
PQ reversed.
XY
Some brushless motors
have Hall sensor to locate
the position of the rotor.
BLDC Wiring
A
B B
N
N
N
N S
N
N
A S
N S S
S
MOTOR
C
C
Y Configuration
Delta Configuration
B B
BLDC typically have 3 wires
colored Red, Black and Blue, and
3 additional wires for motors with Series
A sensors.
Excitation
Parallel
C Excitation
C A
BLDC Pros/Cons
High Torque/Speed Need sensors
Higher efficiency Complex driver
Low electrical noise circuits
Smaller size Costlier
MOTOR
kV Rating
RPM.
A
A
N
MOTOR
B
B
S
C
X Y Z
X Y Z
B B
MOTOR
X Z Y X Z Y
+V +V GND
A 3 A 4
GND
+ +
V
C V
C N S
S
N
B B
X Z Y X Z Y
+V GND GND +V
GND
A
GND
A A
1 A
2 3 4
N N
+ +V
+ S +
C VC S N C
V C
V N
N
B B B
B
Y Y X Z Y
X Z X Z +V Y X Z +V GND
GND GND
GND
MOTOR
A A A
5
A
6 7 8
+ + +
+
VC VC NS VC N
V
C N
S
N
B B B B
X Z Y Z Y X Z Y X Z Y
X
+V +
GND +V +
GND GND
V V
A
A
N
MOTOR
S C
X Z
X Y
Bipolar Motor have four
wires
GND
A A
N
1 2
S
S S N
S
+V
B B
MOTOR
X Y X +V Y
GND
Bi-Polar motor full-step
A
+V A 4
3
S
N S S
S
N
GND B
B
X Y +V
X Y GND
GND +V A
A A A
N
1 2 3 4
N
S
N S N
N
+V B B B
+V B
Y Y +V X Y
X +V X Y X
+V
MOTOR
+V A +V A A A
5 6 7 N 8
N NS N
S
N N
B B B +V B
X Y Y X Y X Y
X
+V +V +V
1 0 +V 0 0 -V 0
2 0 +V +V 0 -V V
3 0 0 +V 0 0 V
4 +V 0 +V 0 V V
5 +V 0 0 0 V 0
6 +V 0 0 +V V -V
MOTOR
7 0 0 0 +V 0 -V
8 0 +V 0 +V -V -V
Bi-Polar: Half Step Sequence
A B X Y
1 0 1 0 0
2 0 1 1 0
3 0 0 1 0
4 1 0 1 0
5 1 0 0 0
6 1 0 0 1
MOTOR
7 0 0 0 1
8 0 1 0 1
Micro Stepping
IAB IXY
8 I I/2
9 I 0
10 I -I/2
11 I -I
12 I/2 -I
13 0 -I
14 -I/2 -I
15 -I -I
16 -I -I/2
Servo Motor
Servo motor is a geared motor with position detector and
command input to set the angle precisely.
Command input is typically
pulse width (or duty cycle)
variation at a fixed frequency
(e.g. 50Hz)
MOTOR
IN
Motor
POT
Gear Command
s Decoder
+
Typical angle
-
control
-90o to +90o
MOSFET
N CHANNEL MOSFET
POWER ELECTRONICS
More Reading:
MotorController\NXP_APPCHP3.pdf
MOSFET [Continued]
POWER ELECTRONICS
A B
MOTOR
N-Channel N-Channel
SDA
Sensors
Serial Memory
Serial I/O
A/D D/A Converters
GPIO
I2C Protocol State Machine
Starting Communication with Slave
Direction 0 =
128 Addresses master → slave
32 of them are 7-bit Address 1-bit Dir
reserved Data is sent in
command 8-bit blocks
SERIAL INTERFACING
D7 D6 D5 D4 D3 D2 D1 D0
Idle
ACK
Master
M SDA → 0 M SDA = 0 SDA = 0 S
SDA = 1 Slave
SCL → 0 SCL → ∏ SCL → ∏
SCL = 1
SCL
Master drives
Clock transition must happen when data is the clock at
stable initial
communication
I2C Protocol State Machine
Master writes n bytes to the slave
Start
Restart Sent by master
Ack = 0, slave
acknowledged
Dir=0
Ack = 1, slave
SERIAL INTERFACING
A6 A5 A4 A3 A2 A1 A0 Ack not
acknowledged
Master drives
the clock at
initial
communication
D7 D6 D5 D4 D3 D2 D1 D0 Ack
SDA
SCL
Master drives
Clock sent by master the clock at
initial
Repeat n times
communication
With different data
I2C Protocol State Machine
Master reads n bytes from the slave
Start
Restart Sent by master
Ack = 0, slave
acknowledged
Dir=1
Ack = 1, slave
A6 A5 A4 A3 A2 A1 A0 Ack not
SERIAL INTERFACING
acknowledged
Master drives
the clock at
initial
communication
D7 D6 D5 D4 D3 D2 D1 D0 Ack
SDA
SCL
Master drives
Clock sent by master the clock at
initial
Repeat n times
§ In the last data packet, master does not With different data
communication
acknowledge
I2C Protocol Example
Slave Address is 9C. Master sends b6 (hex) to slave. Then reads 7a from slave
from same address.
9C = 1001 1100
Start Leading 1 will be
ignored
I2C uses 7 bit address B6 = 1011 0110
SERIAL INTERFACING
0=Write
SDA 0 0 1 1 1 0 0 1 0 1 1 0 1 1 0
0=Ack
0=Ack
SCL
0 0 1 1 1 0 0 0 1 1 1 1 0 1 0
SCL
TWPS1, TWPS0
SERIAL INTERFACING
Serial Peripheral Interface (SPI)
https://learn.sparkfun.com/tutorials/serial-peripheral-interface-spi
SS – Slave Select
SCK – Serial Clock
MOSI – Master Out
SERIAL INTERFACING
MISO – Master In
SPI Use:
LCD Display
Sensors
Input Device
SPI Communication (contd).
SPI communication may use one edge for transmission,
other edge for reception.
Transmits at
Falling edge
T R T R T R T R
SERIAL INTERFACING
SCK
d0 d1 d2 d3
MOSI
MTx
d0 d1 d2 d3
MISO
MRx
Clock transition must happen when data is
stable
Receives at
Rising Edge
UART – Universal Asynchronous Short range
Tx 1 0 b0 b1 b2 b3 b4 b5 b5 b7 1 0
Rx 0 b0 b1 b2 b3 b4 b5 b6 b7 1
A6 A5 A4 A3 A2
Shift
Previous
Stop 3ba9 = 0011 1011 1010 1001
Start Stop
One frame
1 0 0 1 0 1 0 1
Tx 1 0 1
b0 b1 b2 b3 b4 b5 b6
b7
MSB is sent next
b0 b1 b2 b3 b4 b5 b6
b7
●
RS485 is multi-drop, means that the same serial line can be used by
multiple RS485 channels. In a sense, RS485 acts like a serial bus.
●
RS495 is extensively used in industrial applications for connecting
electromechanical devices to the controller boards.
RS485
Differential Pair wire
Distance 1200m
SERIAL INTERFACING
Universal Serial Bus (USB)
Version 3.0: http://www.usb.org/developers/docs/
Version 2.0: http://www.usb.org/developers/docs/usb20_docs/
History:
SERIAL INTERFACING
Features
●
Host controlled → host regulates communication
●
One host per bus.
●
OTG → Host negotiation protocol allows two devices negotiate for
the role of host.
●
7 bit address → 127 devices can be connected
●
Driver Auto load/unload
●
Bandwidth allocation with guaranteed latency
USB (contd) NRZi Encoding
0 1 0 0 1 1 0 0 0 1 1
SERIAL INTERFACING
Data
NRZi
D-
D+
Device Device
Hub
Data Packet
Hub
Device Device
[USB] Protocol
– SCR
– TRIAC
– DIAC
MOSFET
H BRIDGE
POWER TRANSISTOR
SCR Photos
POWER ELECTRONICS
More Reading:
http://www.allaboutcircuits.com/vol_3/chpt_7/5.html
POWER ELECTRONICS
SCR [Continued]
POWER ELECTRONICS
SCR [Continued]
POWER ELECTRONICS
SCR – AC Control
TRIAC Photos
High Voltage High Current
More Reading:
http://www.allaboutcircuits.com/vol_3/chpt_7/4.html
TRIAC Characteristics
POWER ELECTRONICS
IH - Holding current is
the minimum current to
keep the TRIAC in ON
state.
Brake
Rotary
Encoder
Simple 3 story elevator
M = We-Wc
Flywheel
Speed Control Motor
Speed
Control
Sensor
3 1 Horsepower = One metric
Hall Sensor horsepower is needed to lift 75
Accelerometer L1
kilograms (avg. body weight of a
person) by 1 meter (3.28 feet) in 1
second.
Pressure
Sensor
We F2
2
Work = Mg(3h)
L2 Magnet
Counterweight
F1
1
Wc
Alignment
Sensor
W1 h
F0
How many
W2
0 horsepower motor
Hydraulic Damper or is needed?
Shock Absorber
10hp
10 people
GND
A A + A
A
N
1 2 3 4
N
S
S
S N
S
N
N
+ B B B
+ B
Y Y + X Y
X X Y X
+ +
MOTOR
+ A + A A A
5 6 7 N 8
NS N
S
N
S
S
S
N N
B B B + B
X Y Y X Y X Y
X
+ + +
1 2 3 45 6 78 1
XY
AB
Induction Motor
AC Induction Motor -
Direction Control
POWER ELECTRONICS
Opto Isolator based motor control
POWER ELECTRONICS
Electronic Circuit Analysis - 3
RL RP
RL RP
VS
Before IGT
ELECTRICAL ANALYSIS
VS IT IGT
Trigger
AC VGT Diode
Drop,
0.7V
VGT Diode
Drop, VS = RL.IGT + 0.7 + RP.IGT + VGT
0.7V
→ RP.IGT = VS - RL.IGT – 0.7 -
How to calculate minimum and maximum
VGT
value of current limiting/protection V S −R L I GT −V GT −0 .7
resistor. R P=
I GT
VS Drop, +ve
IT VDIAC
Trigger
AC VGT Diac
Drop,
VDIAC
VGT IGT RL RP
R R VGT Diac
Drop,
VDIAC
L L VS = RL.IGT + VDIAC + RP.IGT + VGT
V IT V → RP.IGT = VS - RL.IGT – VDIAC - VGT
After After -ve
V S −R L I GT −V GT −V DIAC
S +ve S Trigger IT R P=
I GT
Trigger
RP,min & RP,max is also computed similarly.
Electronic Circuit Analysis - 5
RL RP
Opto-TRIAC uses the same
equation for RP .
For Opto-TRIAC
VS
ELECTRICAL ANALYSIS
θ= 2π 2πt
θ=
t T T 2π 2π 2 2π
21 2 1 2 A 2
a = ∫ a (t)d θ= ∫ ( A sin(θ) ) d θ= ∫ ( sin θ ) d θ
rms
2π 0 2π 0 2π 0
2 2π 2 2π 2π 2π
A2
[ ]
2
2 A
rms
1
a = ∫ ( 1−cos ( 2 θ ) ) d θ=
2π 0 2
A
∫
4π 0
( 1−cos ( 2 θ ) ) d θ=
A
4π [1
θ− sin ( 2θ )
2 ]
0
a =
2
rms
4π
1
θ− sin(2 θ)
2 0
RMS control with conduction angle
A2
2
1 a = rms
2
2
π 2π
A2 A2
T/2 t2 T
a = 2
rms
4π
1
[
θ− sin(2 θ) +
2 θ 4π
1
]
θ− sin (2 θ)
2 1
[ ] θ2
=Pterm + N term
2
0 t1 21 Pterm =
A
4π
1
[
π−θ 1+ sin(2 θ 1)
2 ]
2 2
conduction angle
N term=
A
4π [
1
2 π−θ 2+ sin(2 θ 2) =
2
A
4π
1
] [
π−θ 1+ sin(2 π+2 θ1 )
2 ]
2 2
2
a =
rms
A
4π
[ 2(π−θ 1)+sin (2 θ1 ) =
A
2π
1
2
] [
(π−θ1 )+ sin(2θ 1)
]
2 2
( a rms
a rms | max ) [ 1 1
= π α− sin(2 α )
2 ] a =
A
2
rms
2π
1
α − sin(2 α )
2 [ ]
RMS control with conduction angle
2
a rms
( ) [ 1 1
] At /2:
2
a rms
( a rms | max ) a rms | max
= π α− sin(2 α )
2
2
a rms
( a rms | max ) [ 1 1
]
= π π − sin(2 π ) =0.5
2 2 2
AC CONTROL
Power Circuit Simulation
High power circuit should almost always be
simulated
POWER ELECTRONICS
Lower Frequency
DATA ACQUISITION
O O O O
O O O I
O O I
I
O O I
O
O I I
O
O I I
I
O I
O I
O I
O O
Many optical readers are
R
designed to use gray code. O O O I I O O
Gray Code is reflected binary
number. R indicates Reflection. O O I I I O I
Imagine a folding along the thick O I
I
I I I
I
line, the top bits are folded (or
O I I I I
O O
reflected) at the bottom.
R
O O I I I O I
O O
Gray Coded data can be sent
O I I I I O I
I I
with less bandwidth.
R
O I I I O
I O I O I
R
I I I I O
O O O O O
Gray code use
Use
Rotary Switch
Mechanical Encoder
Low BW Transmit
Gray Code +
+
Gray code to Binary Conversion
I I I O
O O
A B C X Y
DATA ACQUISITION
AB
O O O 00 01 11 10
O O O
C
0 O I O I 0
O O I O O I
X
O I O I 1 O I O I 1
+
I O
O I O I
O I
R AB+AB
I I I O
O O
I I
I
I O
I
C
+
0 1
I I X
O I
+
I O
0 O I 0
I
O O
I
I I Y
1 I O 1
Gray Binary
XC+XC I I O I I O O I
Gray Code +
+
Binary to Gray code Conversion
I I I O
O I
X Y Z A B C
DATA ACQUISITION
XY
O O O 00 01 11 10
O O O
Z
0 O I O I 0
O O I O O I
B
O I
O
O I
I 1 O I O I 1
O I
I
O I
O +
R XY+XY
I O I I
O O
I O
I
I I
I +
XY
I I
I O O I
+
00 01 11 10
Z
I I
I I O O
0 O I I O 0
C
Binary Gray 1 I O O I 1
I I O I I O I I
YZ+ZY
Gray Code
Gray to Binary code Conversion
I O I I O I I O I I O I I O I I
DATA ACQUISITION
+ + + + + + + + + + + + + + +
I I O I I O I I O I I O I I O I
+ + + + + + + + + + + + + + +
I O I I O I I O I I O I I O I I
Op Amps (contd.)
OpAmp Integrator
C
V in −V n d (−V o−V n )
=C
R dt
Vin Vn i
R dV o V in For ideal OpAmp
−C ( )=
OP AMP
dt R V p = V n & Vp = 0
Vo for integrator
i Vp
dV o =−( 1 )V in dt
RC
V o =−( 1 )∫ V in dt
RC
1
V o =−( )∫ V in dt
RC
Op Amps (contd.)
OpAmp Differentiator
R
−V o −V n d (V in −V n )
=C
R dt
i
C Vn
Vin Vo dV For ideal OpAmp
−( )=C ( in )
OP AMP
R dt V p = V n & Vp = 0
Vo for integrator
i V =−RC dV in
Vp o
dt
dV in
V o =−RC
dt
Passive Low Pass Filters (LPF)
Gain = Vo/Vin
Ideal Filter 1st Order
2 2
Power Gain, Pgain = Vo /V in
= Gdb
2
Gain
At cutoff frequency, Gain is half 0dB 2nd Order
(0.5). -3dB
Pass Band
Gdb=10 log 10 (P gain)
fc
FILTER
P output
GdBm=10 log 10 ( ) Attenuation
1mW R
Vin Vo
Attenuation
0dB
-3dB
1
f c= Pass Band
2πRC
fc
FILTER
C C C
Vin Vo Vin Vo
R
st
R R
1 Order 2 nd
Order
Active LPF
Glog
-3dB
Glog = -3.01
fc
Q = Quality Factor
Pmax 0dB
Example: Design a low pass
audio filter to be used after DAC 1
with cutoff = 3kHz
P3db -3dB f c=
2πRC
R C=
1 R C= 1
=5.31∗10−5
Q
fC 1
Q=
3
2π f c 2 π 3.10
=
Choose C = 1nF BW 2
R = 5.31*10-5/1*10-9 =53.1K
You can also choose R first
BW
Active HPF
Glog
-3dB
Attenuation
Pass Band
R fc = Cutoff Frequency
Beyond cutoff frequency
gain is rapidly attenuated
Vin C C
Gain = Vo/Vin
FILTER
Vo
R
Q = Quality Factor
R C=
1 R C= 1 =3.18∗10−3 R = 3.18*10-3/1*10-6 =3.2K
2π fc 2 π 50
You can also choose R first
Audio Amplifier Example
RV RV RV
VCC RHP V o =−( V B+ V M + V T )
1 R2 CHP CHP RB RM RT
f F= A=1+ C
2 π RF C F R1
+
Rm RHP RT
CF High Pass
C Filter C
+ +
AUDIO
RF RM RV
+
CLP
R2 RLP RLP
C
R1 +
+
Mic CLP RB
RC High
Bias Audio Low Pass Audio
Pass Filter
Circuit Pre Amp Filter Mixer
Rm = Electret microphone bias resistor. Get from Microphone's datasheet. Typical value 1K
fFCutoff frequency of High Pass RC filter. Choose minimum fc equal to line frequency (50
Hz).
To ADC or
Pre-amp gain. Typical gain 100. Choose R2 = 100K. Find R1 from the gain equation.
Audio Amp
fCCutoff frequency of Bass and Treble filter. Usually (500 Hz).
RV = Master volume control. Choose RV = 100K. 1 1
RT, RM, RB = Treble and Bass boost. Can be equal to RV. f C= =
2 π R HP C HP 2 π RLP C LP
C = Coupling capacitor (1F for audio)
Audio Power Amplifier Example
Stereo Power Amp
AUDIO
Datasheet: Lectures\PowerElectronics\AudioPowerAmp_tpa3121d2.pdf
Nyquist Sampling Theorem
Given a signal, y(t) = A sin(2ft+
The signal can be fully reproduced without loss of
data if the signal is sampled at 2f.
DATA ACQUISITION
Vin
Sample Vout
Time, tS
C
T = Hold Time
Sample is held
until the next data
is available After Analog filtering the high
DATA ACQUISITION
frequency component is
removed resulting in a
smooth output
T = Hold Time
VIN
b2 b0 One Bit
2R b0 = 1
R
2R
VIN
b1
R 2R R Two Bit
V IN
2R VIN V OUT = b1b0 = 01
4
VIN
b0
b0 2R 2R
2R
R Combinational Logic
D2 0 0 0 0 1 1 1 1 D2
R
D1
DATA ACQUISITION
D1 0 0 1 1 0 0 1 1
D0 0 1 0 1 0 1 0 1 D0
R b6 0 0 0 0 0 0 0 1
b5 0 0 0 0 0 0 1 1
R b4 0 0 0 0 0 1 1 1
b3 0 0 0 0 1 1 1 1
b2 0 0 0 1 1 1 1 1
R
b1 0 0 1 1 1 1 1 1
b0 0 1 1 1 1 1 1 1
R
●
Very Fast: MAX104 Flash ADC is
1Gsps, 8-bit
R ●
Need 2N-1 fast comparators for
N bits
●
Very Expensive
●
Used only in special applications
R +Vin
[0..VCC ]
Data Acquisition Z b7 b6 b5 b4 b3 b2 b1 b0
N bit ADC 0 1 0 1
Approximation Registers
1 1 0 1 1
Vin Z
Logic
1 1 0 1 1 1
0 1 0 1 1 0 1
DAC 0 1 0 1 1 0 0 1
1 1 0 1 1 0 0 1 1
Operation
The approximation is set with the current bit (msb) set to 1.
If Z → 0, the current bit is set to 0 (=Z) and the next bit becomes 0 1 0 1 1 0 0 1 0
the current bit (set to 1).
If Z → 1, Z becomes the current bit. Output
At each iteration, one bit of approximation is completed.
Data Acquisition Z b7 b6 b5 b4 b3 b2 b1 b0
192 1 1 1
convergence
DATA ACQUISITION
160 0 1 0 1
178
176 1 1 0 1 1
184 1 1 0 1 1 1
192
184
180
179
178
178
176
160
180 0 1 0 1 1 0 1
128
178 0 1 0 1 1 0 0 1
0 1 2 3 4 5 6 179 1 1 0 1 1 0 0 1 1
7 8
178 0 1 0 1 1 0 0 1 0
Output
Reconstruction from Pulse Width
Using Digital Filters, the original waveform can be reconstructed
FIFO
DATA ACQUISITION
S6 S5 S4 S3 S2 S1 S0
PWM signal
+
yout
Reconstructed
waveform Digital Filter Example
Coefficients an determine the
behavior of the filter
Data Acquisition (cont.) a
1-bit
Sample is held DAC
until the next data
is available
7V
7
6
5
4
7 7 7
3 6 6 6
2 4 4 4
3
1 2 2
0
1 1
0
1 -2 -3 -2
2 -4
Oversamples -5
3
-7
4 Standard
5 Samples
6
7
1u
-7V
T = Hold Time
Delta Sigma ADC (contd.)
yout = x[-3]+x[-2]+x[-1]+x[0]+x[1]+x[2]+x[3]
Max 1
Low pass filter using 3 past sample, 1
1
current sample, 3 future sample
Vin Vdac Vint Vout 2
DATA ACQUISITION
0 3 8
1.00 -1 2.00 1 4
4.00 1 3.00 1 5 6
6.00 1 5.00 1 6
4
7.00 1 6.00 1 7
7.00 1 6.00 1 7
2
7.00 1 6.00 1 7
6.00 1 5.00 1 7
0
4.00 1 3.00 1 5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
3.00 1 2.00 1 3
-2
2.00 1 1.00 1 1
0.00 1 -1.00 -1 -1
-4
-2.00 -1 -1.00 -1 -3
-3.00 -1 -2.00 -1 -5
-6
-5.00 -1 -4.00 -1 -7 1 current
-7.00 -1 -6.00 -1 -5 sample
-8
-4.00 -1 -3.00 -1 -3
-2.00 -1 -1.00 -1 -1 3 past 3 future
sample sample
1.00 -1 2.00 1 1
2.00 1 1.00 1 2
4.00 1 3.00 1 3 Pulses Values Samples
Delta Low Pass
6.00 1 5.00 1 4 Decimator
Sigma Digital Filter
Saturation Arithmetic
Original signal Saturated signal
Max Max
DATA ACQUISITION
Distortion
Unsaturated signal caused by
saturation
Max
A processor with built in saturation arithmetic
will saturate the result to the highest positive or
negative value instead of overflowing.
Noise caused by
overflow
Saturation Arithmetic (cont.)
Digital Signal Processors and some Microprocessors
have Saturation hardware and instructions
DATA ACQUISITION
Saturated Shift:
2n-1 -2n
2's complement = 0x8000 (inverting the bits) + 1 = 0x7FFF + 1 = 0x8000 = -32768 (dec)
2's complement 1 = 0x0001 + 1 = 0xFFFE + 1 = 0xFFFF = -1 (dec)
Fixed Point Numbers
If a fractional numbers range is known, fixed point
number may be used
n
DATA ACQUISITION
0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10
2-n 1 0.5 0.25 0.125 0.0625 0.03125 0.015625 0.0078125 0.00390625 0.001953125 0.0009765625
A 0 1 0 1 0 0 1 1 0 0 1 0.6494140625 Q1.10
m=8
DATA ACQUISITION
B 0 0 0 1 1 0 0 1 0 1 1 0.79296875 Q3.8
Multiplication
n+m=18 Actual
Q4.18 0.5149650574 0.514965057373046875
A*B 0 0 0 0 1 0 0 0 0 0 1 1 1 1 0 1 0 1 0 0 1 1
Divide
n+m=18 0.8189620972 Actual
Q4.18 0.8189655172413793103448275862069
A/B 0 0 0 0 1 1 0 1 0 0 0 1 1 0 1 0 0 1 1 1 1 0
Before divide, shift left A by m bits to preserve precision
Addition/Subtraction
Must align the point. B ← (n-m) 0r A → (n-m) before addition
(← is shift left, → shift right)
Floating Point Numbers
ANSI/IEEE Std 754-1985 is the most widely used
format for floating point
DATA ACQUISITION
31 30 23 22 0
S e7..e0 1.m1..m23
mantissa
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
2-1 2-2 2-3 2-4 2-5 2-6 2-7 2-8 2-9 2-10 2-11 2-12 2-13 2-14 2-15 2-16 2-17 2-18 2-19 2-20 2-21 2-22 2-23
Conversion:
Page. 105
ISR(INT1_vect)
Program Memory {
/* ISR for INT1 */
Reset Vector,
Address of main() }
0x0000
int main(void)
0x0002 Address of ISR(INT0_vect) {
/* user code */
0x0004 }
Address of ISR(INT1_vect)
MSP430 Boot Sequence in C
ISR(NMI_vect)
{
See MSP430F21x2 /* ISR for INT0 */
interrupt vector }
SOFTWARE
addresses
ISR(ADC10_vect)
Program Memory {
/* ISR for INT1 */
Reset Vector,
Address of main() }
0xFFFE
int main(void)
0xFFFC Address of ISR(NMI_vect) {
/* user code */
0xFFEA }
Address of ISR(ADC10_vect)
ARM Cortex M3 Boot
Sequence in C
See Cortex M3 NVIC
interrupt vector ISR(GPIOC_vect)
SOFTWARE
locations {
/* ISR for GPIOC */
}
ISR(GPIOB_vect)
Program Memory {
/* ISR for GPIOB */
Reset Vector,
Address of main() }
0x0000 0004
int main(void)
0x0000 0048 Address of ISR(GPIOC_vect) {
/* user code */
0x0000 0044 }
Address of ISR(GPIOB_vect)
Kahn Network - Introduction
Kahn Network is used to model distributed system (also used in
CONCURRENT SYSTEM MODELING
P1 •••
P2
Producer Consumer
Block Block
Kahn Network – Elevator Example
Kahn Network – Elevator Switches
CONCURRENT SYSTEM MODELING
Identical processes.
ASC- Only one will be called.
FIFO Analogy with Threads
UP
K-FIFO
SW SRT
Stop elevator
and open door
ST
FL
Floor
Level
sensor
●
When an elevator's internal switch is pressed, the sequence must be ordered
such that, if the elevator is going up, then the sequence is ascending, or if going
down, its descending.
●
When a floor is reached, the elevator must stop
Micro Kernel
Kernel functions:
A set of routines that does the init()
following: add_proc()
loop()
fifo_put()
3. Virtual Memory (optional)
4. Scheduling
5. Messaging
Messages
FIFO First In First Out
Producer
ISR(INT0_vect)
{
/* ISR for INT0 */
/* Call Device Driver */
FIFO Size = 3 /* Get Values */
Message *m;
INT0 INT1 message /* Create Message */
m = create_message(...);
fifo_put(m);
INT1 INT0 message }
.
µP ISR(INT1_vect)
SOFTWARE
.
. {
...
INTn /* Create Message */
m = create_message(...);
fifo_put(m);
}
INT1 message
Consumer
FIFO creates a queue to int main(void)
free ISR from blocking {
other interrupts. The Message *m;
main task is processed in while(fifo_wait()) {
the consumer thread or m = fifo_get();
process(m);
the main thread.
}
INT0 message }
consumed
Kernel functions:
proc_t p;
p = process_pool[i];
if (p == NULL)
break;
ret = p(&m);
}
} add_proc:
proc_main(&m); Add function pointers of processes
}
}
void add_proc(proc_t p) {
int i = 0;
for(i=0;i<PROC_SIZE;i++) {
proc_t pi = process_pool[i];
init: if (pi == NULL) {
Initialize I/O ports direction registers process_pool[i] = p;
Initialize Interrupt registers process_pool[i+1] = NULL;
Initialize Timers return;
Initialize A/D D/A converters }
Initialize Device Driver }
}
Initialize Processes
Enable Interrupts
Kernel Data Flow Hardware
main.c
Start Initialize
Processor
Init Read
Initialize Open
FIFO
Write
Device
SOFTWARE
Interrupts
Add
Processes
Create
Message Normal
Process 1 Processing
Process
Device Driver
General Implementation
Hardware Device
int device_open();
int device_init();
if (semaphore > 0)
Device Driver return 1;
if (!semaphore)
semaphore = 1;
NAND Flash
Critical Section
Critical Section is a part of code in a multi-
tasking software system when this part of
the code an be executed by one process
only.
Inter Process Communication
Critical Section Implementation
Semaphore variable stores the
process id. If it is 0, then no
unsigned char mem_semaphore;
process is using the shared
memory typedef struct shared_mem {
Shared int from_id;
int to_id;
Memory
SOFTWARE
unsigned char[SHARED_MEM_SIZE];
int size;
} shared_t;
Device Driver
int send_data(int from_id, int to_id, char*
bytes, int size) {
Shared Memory
if (mem_semaphore && mem_semaphore != 1)
Critical Section is used return 1;
to access shared if (!mem_semaphore)
resources like Shared mem_semaphore = 1;
Memory
shared_write(int from_id, int to_id,
bytes, size);
Critical Section
Critical Section is a part of code in a mem_semaphore = 0;
multi-tasking software system which return 0; /* success */
}
an be executed by one process only
while other processes wait for its
chance.
Petri Net - Introduction
Petri Net is used to model concurrent system of events in the form of
CONCURRENT SYSTEM MODELING
Place Transition
Petri Net – Design
A transition can have multiple places as INPUT and each INPUT
CONCURRENT SYSTEM MODELING
Fired Output
Input Tokens are
Tokens different
After tokens are fired
Tokens Firing
Places If any input is empty
(i.e., without tokens,
no transition can be
fired.
Petri Net – Conflict
Conflict occurs when a single token is shared by two transitions.
CONCURRENT SYSTEM MODELING
t t1
1
t2 t2
Conflict visualization
Petri Net visualizes conflicts clearly and in a system
design, these conflicts could be avoided by eliminating
such conflicts from redesign.
Petri Net – Elevator Example
Elevator Door Opening Petri Net
CONCURRENT SYSTEM MODELING
H1
1. Motor is OFF
2. Hall1 and Hall2 sensors are ON
Hall 1
3. Accelerometers indicate ZERO
Sensor
velocity
Elevator
H2 leveled with
floor
Motor Off
Indicator
H1
2
H1
1
H22 H2
M M
3 4
H1 H1
H2 H2
M M
Multi-Processing
µP 1 µP 2 µP n
MULTI PROCESSING
...
Connect
µP 1 µP 2
ARM Cortex
A Series
Lectures\ARM\cortex_a72_mpcore_trm_100095_0001_02_en.pdf
ARM Cortex M3 Core
Datasheet:
Lectures\ARM\ATSAM3N.pdf
CORTEX M3
GPIO – 8..36
Analog Comparator – 3
DAC – 1
SPI – 4
I2C – 2
TIMER – 2
UART – 2
USART – 2
PWM – 4
Executed Instructions
Fe De Ex
A
B A
C B A
CORTEX M3
D C B A
E D C B
F E D C
G F E D
H G F E
H G F
H G
H
ARM Cortex M3
Nested Vectored Interrupt Controller (NVIC)
●
33 Interrupts in SAM3N (M3 core supports 240
interrupts)
CORTEX M3
●
16 priority levels (0 → high priority)
●
Level or pulse input
●
Low latency
●
Dynamic reprioritization
●
Grouping and sub-priority fields
●
Interrupt tail-chaining
●
External NMI (Non Maskable Interrupt)
ARM Cortex M3 Interrupts
Timer count down
interrupt usually used to
create multi-tasking
switching
Caused by illegal or
undefined instruction,
invalid instruction state or
fault in exception return
3.5 GB
CORTEX M3
2.5 GB
1.5 GB
1.0 GB
0.5 GB
ARM Cortex M3
Process Stack
Pointer
CORTEX M3
MSR Instruction to
switch stack poiner
Processing
CORTEX M3 Read Modify Write
Read-Modify-Write instructions are required for exclusive
locking. Cortex M3 have built in instructions for it.
Interrupts occurring at these points may cause STREX{cond} Rd, Rt, [Rn {, #offset}]
lock failure. Therefore, interrupts must be Stores to memory location pointed by Rn
disabled to achieve locking in a multi-cycle with optional offset the value in Rt if the
exclusive lock request
optional cond is met.
CORTEX M3 Read Modify Write with Bit Banding
Cortex M3 allows easy bit manipulation without using AND, OR and SHIFT. Flipping a
bit is simply accessing bit-band memory location and read/write new value.
This operation of reading the bit, modifying it and writing the bit is atomic.
CORTEX M3
m-addr X X X X X 1 X X x
0 0 0 0 0 0 0 1 y=1
1 0 0 0 0 0 1 0 0 y <<= n
2 0 1
1 0 1
0 1
0 1
0 0
1 1
0 1
0 y ~= y
3 X X X X X 0
1 X X y &= x
bb-addr = 0x2200:0000
m-addr
X X X X X 1 X X x 0ffset = 0x0200:0000
m-addr+1
X X X X X X
1 X X Peripheral bit band region
m-addr = 0x4000:0000
X
7 X
6 X
5 X
4 X
3 12 X
1 X
0 bb-addr = 0x4200:0000
0ffset = 0x0200:0000
X X X X X X
1 X X
X
7 X
6 X
5 X
4 X
3 12 X
1 X
0 bb-addr = m-addr + 8*4 + offset
0x2200:0040
CORTEX M3 - Bit Banding regions and map
CORTEX M3
1 byte
Cortex M3 – Memory Protection Unit
Memory Protection Unit divides memory into 0-7 overlapping
regions with individual and isolated read/write privilege.
Cortex M3 Memory
CORTEX M3
0 1 2 3 4 6 5 7
Region 6 is
inside Region
5
If memory is protected,
X
Address X
Size X
Type X
Access 1
Permission
unauthorized access will give rise
to Exception interrupt.
X
MPUBASEx X MPUATTRx
Example:
NULL Pointer exception is write
NOTE: Cortex M3 - ATSAM3N does not have MPU, but TI LM3S300 have it.
protected memory. Any write will
cause exception Interrupt.
See Datasheet: ARM\TI_ARM_Cortex3_lm3s300.pdf
Pre-emptive Multi tasking
Cortex M3 have built-in hardware to support preemptive multi-
tasking with minimal overhead
PendSV Interrupt
~ 20ms
CORTEX M3
S L E S L E S L E S L
Loads context from data structure. Continue executing the Saves the context
This includes, setting all the program using the last for later use.
registers, and Program Counter. used context.
directly from
memory/IO to
Address Bus memory/IO.
DMA controller
can transfer
blocks of data
from one device
I/O I/O to another at
very high speed
while the
processor is
Memory I/O Device ACK processing with
internal data.
Memory Memory REQ
Direct Memory Access (DMA)
Memory DMA I/O
Controller Device
Memory I/O
Block Block
DMA
Single Single
Block Block
TXTDIS RXTDIS
To setup DMA from memory to I/O, set TPR to start memory location and TCR to number of
bytes to transfer. Set RPR to the start I/O location and RCR to the number of bytes to transfer.
Enable Transmit by setting TXTEN and enable receive by setting RXTEN channel bit.
LVDS Signal for Displays
Low Voltage Differential Signal CLOCK
LVDS
RED
LVDS LCD
1. Used by most LCD and OLED displays for I/O
OLED
2. In LVDS, the electric fields created by the differential are GREEN
coupled, which minimize loss due to radiation. LVDS Matrix
3. LVDS signal cancels induced noise by the receiver. BLUE
4. Controlled LVDS can be exceptionally fast: 6.4 Gbps is LVDS
tested. Typical speed: 100 MHz to 2 GHz.
DISPLAY
LVDS application
TMDS (Transition Minimized
Differential Signal)
DISPLAY
DC Signal
All 1s
DISPLAY
All 0s
HDMI HDMI – High Definition Multimedia Interface
Details:
Screen \Lectures\Display\DMD_101_dlpa008a.pdf
White
Light
Digital Micromirror Device
(DMD) works by directing
light toward or away from the
screen creating the image
DISPLAY
Mirror
physical output.
Frame Buffer – The entire Video Encoder – Encodes
VGA
image is created in the frame the frame buffer into video
buffer memory. stream suitable for various HDMI
output specifications.
TV OUT
Output
Video Video
Driver LCD LVDS
Frame Buffer Encoder
Display Port
Laser (Continued)
optic cable
Laser Laser
Transceiver Transceiver
Texas Instruments
11.3-Gbps LASER DRIVER Laser Diodes with
integrated photodiode
LASER
[BUS] PCI
PCI = Peripheral Component Interconnect
Used on all desktop PCs and Macs
BUS INTERFACING
Transfer up to 528 MB/s, PCI-X up to 4 GB/s
Up to 256 devices per system
Supports 5V and 3.3V signaling
Optimized for transferring blocks of data
Any device on bus can initiate bus transactions
Little-endian byte ordering
Supports plug-and-play
[BUS] SCSI - Small Computer
System Interface
A bus that uses SCSI communication
protocol
BUS INTERFACING
Bridge
Range:
ZigBee = 150ft
ZWave = 300ft
Dynamic re-routing
ZigBee
SENSOR NETWORK
Lectures\SensorNetwork\ds_xbeezbmodules.pdf
SMT
Transistors Advantages
●
Small Size
Ball Grid
Array (BGA)
●
Low Inductance
●
Double Sided Boards
●
Low Price
●
Good Temperature
SMT
Capacitors
Tolerance
●
Small PCB
●
Mechanically Rigid
SMT
Resistors
●
Fast Assembly by Pick &
Place Machine
Quad Flat
Pack (QFP)
SMT
Tantalum
Capacitors
Surface Mount Processors
Package L x W, mm L x W, in Watt
SENSOR NETWORK
W
Top SMT Capacitor
View Construction
Packag Package
e 25 12 0.25 x 0.12 Dimension
Style
E24 Standard Resistor Values
Standard Resistor Values ( 5%)
1.0 10 100 1.0K 10K 100K 1.0M
1.1 11 110 1.1K 11K 110K 1.1M
1.2 12 120 1.2K 12K 120K 1.2M
1.3 13 130 1.3K 13K 130K 1.3M 101/24 = 1.1
1.5 15 150 1.5K 15K 150K 1.5M
1.6 16 160 1.6K 16K 160K 1.6M
1.8 18 180 1.8K 18K 180K 1.8M Rnext = Rprev * 1.1
2.0 20 200 2.0K 20K 200K 2.0M
2.2 22 220 2.2K 22K 220K 2.2M
2.4 24 240 2.4K 24K 240K 2.4M
2.7 27 270 2.7K 27K 270K 2.7M
3.0 30 300 3.0K 30K 300K 3.0M
3.3 33 330 3.3K 33K 330K 3.3M
3.6 36 360 3.6K 36K 360K 3.6M
3.9 39 390 3.9K 39K 390K 3.9M
4.3 43 430 4.3K 43K 430K 4.3M
4.7 47 470 4.7K 47K 470K 4.7M
5.1 51 510 5.1K 51K 510K 5.1M
5.6 56 560 5.6K 56K 560K 5.6M
6.2 62 620 6.2K 62K 620K 6.2M
6.8 68 680 6.8K 68K 680K 6.8M
7.5 75 750 7.5K 75K 750K 7.5M
8.2 82 820 8.2K 82K 820K 8.2M
9.1 91 910 9.1K 91K 910K 9.1M
E12 Standard Capacitor Values
101/12 = 1.21