Professional Documents
Culture Documents
DATAPATH CIRCUIT
Inputs
FINITE STATE Outputs
resetn
MACHINE
clock
CONTROL CIRCUIT
EXAMPLES
EXAMPLE: CAR LOT COUNTER
If car enters the lot, the following sequence (A|B) must be followed:
B 00 → 10 → 11 → 01 → 00
If car leaves the lot, the following sequence (A|B) must be followed:
00 → 01 → 11 → 10 → 00
A A car might stay in a state for many cycles since the car speed is very large
compared to that of the clock frequency.
resetn
A
E E 10
ud Q
B FINITE STATE ud
MACHINE
CONTROL CIRCUIT
clock 10-bit counter
DATAPATH CIRCUIT
A|B/E|ud
00/00 10/00 11/00 01/00
resetn = 0 10/00
00/00
00/00 01/00
01/00 11/00 10/00
10/00 10/00
01/00 11/00
S6 S7 S8
01/00 11/00
00/10
no
AB=00
yes
S2
11 00
AB
10 01
S3 S6
00 10 01 00
AB AB
01 11 11 10
S4 S7
10 11 11 01
AB AB
00 01 10 00
S4 S8
00 01 10 00
E, ud 1 AB AB E 1
10 01
11 11
EXAMPLE: ACCUMULATOR
resetn
20
sign
extension
+ D Q Dout
sclr
8 8 20
Din D Q
E
E
Ei
E
sclr
restart FINITE STATE
MACHINE
DATAPATH CIRCUIT
10/10
S1 S2
X1/11
10/10
X1/11
▪ Algorithmic State Machine (ASM) Chart:
resetn=0
S1
1
restart Ei, sclr 1
0
E
1
Ei 1
S2
1
Ei, sclr 1 restart
0
E
1
Ei 1
4
A 0
4
B 1 4 HEX to 7
7
segments
C 4 2 decoder
D 4 3
Counter z
(0.001s)
0
E
1
S3
s 10
0
E
1
S4
s 11
1 0
E
EXAMPLE: BIT-COUNTING CIRCUIT (Parametric VHDL Code) (Video: VHDL coding in Vivado, n=8)
▪ It counts the number of bits in a register A that have the value ‘1’. SEQUENTIAL ALGORITHM
▪ Example: A=10110011 → count = 0101.
C 0
DIGITAL SYSTEM (FSM + Datapath circuit) while A 0
▪ FSM: as a ASM Chart. Modulo-n+1 bit counter (m bits): it has synchronous clear (𝑠𝑐𝑙𝑟). if a0 = 1 then
▪ Generic components: Behavior on the clock tick: C C + 1
end if
Counter modulo-n+1 (0 to n): n-bit Parallel access shift register:
right shift A
If E=0, the count stays. If E=0, the output is kept end while
if E = 1 then if E = 1 then
if sclr = 1 then if s_l = ‘1’ then
Q 0 Q D
elseif Q = n then else
Q 0 Q shift in ‘din’ (to the right)
else end if;
Q Q+1 end if;
end if;
end if; DA resetn=0
resetn S1
𝑛 EC, sclrC 1
0 din 0
LA s_l s
EA E A
𝑚 C
1
EC
E Q
Parallel Access 𝑛 Shift-Right EA, LA 1
sclrC
Right Shift (MSB to LSB) sclr
s_l = 1 → Load S2
s_l = 0 → Shift
counter: m bits
𝑚= 𝑛
LA EA 1
z
0
EA 1
z a0
DATAPATH CIRCUIT S3
done 1 0
a0
FINITE STATE
MACHINE done 1
s 0 1
s
EC 1
clock
resetn
DA 00110110 00001110
A 00 00 36 1B 0D 06 03 01 00 00 00 0E 07 03 01 00 00
state S1 S1 S2 S2 S2 S2 S2 S2 S2 S3 S1 S2 S2 S2 S2 S2 S3
C 0000 0000 0000 0000 0001 0010 0010 0011 0100 0100 0100 0000 0000 0001 0010 0011 0011
sclrC
EC
done
EA
LA
5 Instructor: Daniel Llamocca
ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY
ECE-2700: Digital Logic Design Fall 2023
EXAMPLE: SEQUENTIAL MULTIPLIER (Parametric VHDL Code) (Video: VHDL coding in Vivado, n=4)
Example: 1 1 1 1 x
1 1 0 1
P 0, Load A,B
1 1 1 1 P 0 + 1111
while B 0
0 0 0 0 P 1111
if b0 = 1 then
1 1 1 1
P P + A P 1111 + 111100 = 1001011
1 1 1 1
end if P 1001011 + 1111000 = 11000011
left shift A 1 1 0 0 0 0 1 1
right shift B P 0, A 1111, B 1101
end while b0=1 P P + A = 1111. A 11110, B 110
b0=0 P P = 1111. A 111100, B 11
b0=1 P P + A = 1111 + 111100 = 1001011. A 1111000, B 1
b0=1 P P + A = 1001011 + 1111000 = 11000011. A 11110000, B 0
𝑛 𝑛 DataB
DataA 00..0
𝑛 "00..0"&DataA 𝑛
resetn
0 din 0 din
L s_l L s_l
E E A E E B
sclrP
𝑛 Shift-left 𝑛 Shift-right
EP
E
L
s z +
FSM 𝑛
b0
EP E z b0
sclrP sclr P
done 𝑛
DATAPATH CIRCUIT
1 0
z
S3 0
done 1 b0
1
0 1
s EP 1
clock
resetn
DA 1111 1111
DB 1111 1101
A 00 00 0F 1E 3C 78 F0 E0 E0 E0 0F 1E 3C 78 F0 E0 E0
B 0000 0000 1111 0111 0011 0001 0000 0000 0000 0000 1101 0110 0011 0001 0000 0000 0000
state S1 S1 S2 S2 S2 S2 S2 S3 S1 S1 S2 S2 S2 S2 S2 S3 S1
P 00 00 00 0F 2D 69 E1 E1 E1 00 00 0F 0F 4B C3 C3 C3
done
sclrP
EP
0
E
R G B R G B 0 1
x
0 0 0 0 0 0
1 0 0 1 1 0
x=0 x=1 S2a S2b
0 1 0 0 1 1
RGB 100 RGB 110
0 0 1 1 0 1
0 0
E E
resetn 1 1
S3a S3b
RGB 010 RGB 011
'1' E Counter
(0.5s) z
0 0
E E
DATAPATH CIRCUIT 1 1
S4a S4b
E R RGB 001 RGB 101
x FINITE STATE G
MACHINE B
1 0 0 1
E E
Standard
DLC3
DLC2
DLC1
DLC0
RTR
IDE
11-bit identifier CRC sequence (15 bits) 1
r0
Format:
Start of Start of
Arbitration Field Control Field Data Field Data Field CRC Field ACK End of Frame
Frame Frame
Recessive bits
Extended
DLC3
DLC2
DLC1
DLC0
ACK
SRR
RTR
IDE
slot
11-bit base identifier 18-bit extended identifier 1
r1
r0
Format:
✓ S1: captures the first bit, though there is no other bit to compare it to.
1
✓ S2: captures the other incoming bits, and it compares two consecutive bits at a
time. If they match, then CC+1, otherwise C0. This can happen indefinitely Ex 1, v d 1
until C=3 and these two bits match (i.e., after 4 comparisons, we determined that
5 consecutive bits are identical). Then, we move to S3. no EC 1
✓ S3: It determines whether the stuffed bit is correct. If the 5th and 6th bits match, x=xq slcrC 1
there is an error. On the next cycle, 𝑥_𝑑 is invalid and we do not assert the valid y es
flag v, as we are de-stuffing this extra bit. We then return to S1 and start over.
▪ In the figure, we start right after resetn was asserted. Cases: 111111, 000001. E=1. zC
0
EC 1
1
clock S3
x
0
x_d E
state S1 S2 S2 S2 S2 S3 S1 S2 S2 S2 S2 S3 S1 1
no
C 0 0 1 2 3 3 3 0 1 2 3 3 3 x=xq
y es
v
err 1
stuff_err
UART Interface
▪ This interface transfers data asynchronously (clock is not FT2232 Artix-7 - Nexys4
transmitted; transmitter and receiver use their own clocks). Micro
TXD
▪ Data communication: RXD (receive pin), TXD (transmit pin). The USB C4 (RXD)
FT2232 chip inside the Nexys-4 board is in charge of handling
RXD D4 (TXD)
the USB communication with a computer.
▪ Format of a Frame: Start bit (‘0’), 8 to 9 data bits (LSB
transmitted first), optional parity bit, and a stop bit (‘1’).
▪ Transmitter: Simple design that transmit the data frame at the Baud rate (or bit rate in bps).
▪ Receiver: It uses a clock signal whose frequency is a multiple (usually 16) of the incoming data rate.
EQ EC
resetn E Q 3 E Q n EC 1 (C 0), ER 1
0 sclr 0 sclr
clock zQ zC
z z 0
zQ EQ 1 (Q Q+1)
counter counter
0 to 7 0 to N-1 1
S5
TXD 1
STOP bit
1 0
EC 1 (C 0) zC EC 1 (C C+1)
PS/2 Interface
▪ This interface transfers data synchronously (clock is transmitted PIC24FJ128 Artix-7 - Nexys4
alongside data).
▪ The PIC24FJ128 chip (auxiliary function microcontroller) inside the
Connector
USB Host
Nexys-4 DDR board emulates an old-style PS/2 bus and presents a
PS/2 protocol to the FPGA. The PS/2 bus signals are converted to the PS2_CLK F4
USB protocol. Thus, we can interface with a USB keyboard or mouse
PS2_DAT
as if they were using the PS/2 protocol. B2
▪ PS/2 bus uses a bidirectional two-wire serial bus (PS2_CLK and
PS2_DATA) to communicate with a host. The FPGA plays the role of the host.
▪ Format of a Frame: Start bit (‘0’), 8 data bits (LSB transmitted first), parity bit (odd), and a stop bit (‘1’).
▪ Timing Diagram: Data (1 byte) is captured on the falling edge. The following are times found in the Nexys-4 DDR datasheet:
T [60 us,100 us], tSU, tHD [5 us,25 us]
PS2_CLK
T tSU tHD
resetn
0 0
ps2cf fall_edge
START bit
1 ps2cf 1
S2
1
fall_edge ps2d
0
1 S2
ps2cf
0
+ Parity + STOP bit
f all_edge 1 0
8 DATA bits
fall_edge
E, EQ 1
done_d 1
1 0
zQ
▪ Filter: It makes sure that ps2c (PS2_CLK) is constant for at least 8 clock cycles (FPGA operating frequency) before ps2cf
is assigned a ‘1’ or a ‘0’. This mitigates the presency of glitches that may have been interpreted as falling edges. The choice
of 8 cycles is based on actual testing (use more cycles if you notice glitches affecting the functioning of the circuit.
Filter
ps2c din
0 s_L RIGHT SHIFT clock
1 E REGISTER
8 ps2c
ps2cf
all 1's? all 0's?
a b DE a b
0 0 X0 D ps2cf
0 1 01 E
1 0 11
1 1 01
ps2d 10 8 8
D Q DOUT
my_ps2read DOUT10 E
ps2c 0
8 Er done_r
done_r
DOUT8 done
1
no
FSM dout8=F0
resetn KEY-UP
CODE
y es
clock
S2
done_r 0
SCAN
1
CODE
Er 1
clock
done_r
DOUT8 F0 3C
DOUT 3C
done
𝑎𝑜 = 𝜎 (∑ 𝑎𝑖 × 𝑤𝑖
𝑖
𝑏)
S
✓ A popular and simple scalar function is the Rectified Linear Unit (ReLU):
𝜎(𝑧) = 𝑧 if 𝑧 ≥ 0, otherwise 𝜎(𝑧) = 0.
✓ Example (this is what appears in the timing diagram, where 𝒛 and 𝒂𝒐 are in hexadecimal format):
𝑤1 = 04, 𝑤 = 0 , 𝑤3 = 0 , 𝑤4 = 08, 𝑤5 = 0 . 𝑏 = 06
If 𝑎1 = 04, 𝑎 = 0𝐸, 𝑎3 = 0𝐶, 𝑎4 = 05, 𝑎5 = 0𝐴.
Then 𝒛 = 44 − −4 5(−8) −6 = −40 = 0𝐹𝐷8. Finally, 𝒂𝒐 = 0000
✓ Components:
Counter 0 to 4: If E=1, sclr=1, then Q 0. If E=1, sclr=0, then Q Q+1. Also: z=1 if Q = 4, else z=0.
Register: If E=1, sclr=1→ Clear. If E=1, sclr=0 → Load data.
44 Signed Multiplier: Combinational circuit, whose result is 8-bits wide (sign-extended to 12 bits).
ReLU: Combinational Block that implements the ReLU operation. For example, if 𝒛 = 0𝐹𝐷8, then 𝒂𝒐 = 0000
✓ FSM: The process begins when s is asserted, at this moment we capture 𝑎1 , 𝑎 , 𝑎3 , 𝑎4 , 𝑎5 on the input registers. Then 𝒛
is updated until the counter reaches its maximum value (4). The signal done is asserted when the final result is computed.
4 4 4 4 4 4
0 1 2 3 4
4
E 0
4
4
1
E
4 4 ALGORITHM
2
E sign extension
4 8
3 to 12 bits
E
4
4
E
0 1 sb
12 12
3
i +
12
E
sclr
resetn
sclro
sclri
Ei
Eo
E 3
Ei
clock E Q i
12 sclri sclr
z zi
sb
s FSM Counter
zi ReLU
0 to 4
12
done
12 Instructor: Daniel Llamocca
ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY
ECE-2700: Digital Logic Design Fall 2023
FSM:
clock
resetn=0
resetn S1
Ei, sclri 1
0x4EC5A
0
s s
state S1 S1 S2 S2 S2 S2 S2 S3 S4 S1 1
E, Eo, sclro 1
i 000 000 000 001 010 011 100 000 000 000
S2
E Eo 1
sclri 0
zi Ei 1
Ei i=4? 1
sb Ei, sclri 1
S3
sclro sb 1, Eo 1
Eo S4
done 1
000 000 000 010 00E 006 FDE FD2 FD8 FD8
0 1
000 000 000 010 00E 006 000 000 000 000 s
done
SWITCHES
LEDS
E
IN
E
OUT
4
0
4 4
1 BUS
4
2
4
3 E E E
R1 R0 A B
2
ALU
E_OUT
E_IN
E_R1
E_R0
E_A
SM
op
E
G
4
E_G
w
IR
5 done
CONTROL CIRCUIT
▪ Instruction Set
Every time w=1, we grab the instruction from IR and execute it.
Instruction = |f2|f1|f0|Ry|Rx|. This is called ‘machine language instruction’ or Assembly instruction.
✓ Opcode (operation code): IR(4..2). These bits specify the operation to be performed.
✓ Operands: IR(1..0). These bits specify the register indices to be used in the operation:
Rx: index of the register where the result of an operation is stored (we also read data from Rx). Rx can be R0 or R1.
Ry: index of the register where we only read operands from. Ry can be R0 or R1.
▪ Control Circuit:
E_OUT
Here, the Control Circuit could be implemented as
E_IN
E_A
E_G
SM
op
an FSM. However, in order to simplify the FSM
design, the Control Circuit was built out of some CONTROL
combinational units, a register, and an FSM. The CIRCUIT 2 4
5-bit instruction is captured on the signal IRq.
w
3 done
✓ Ex: Every time we want to enable register 𝑅𝑥, f FSM
the FSM only asserts Ex (instead of controlling
E_R0, E_R1 directly). The decoder takes care
of generating the enable signal for the
E_IR Ex Rx Ry
corresponding register 𝑅𝑥. Rx w DECODER 0
5 5 E_R0
IR D Q IRq with
Ex E enable 1 E_R1
E
opcode
E_IR
IRq = |f2|f1|f0|Ry|Rx|
0
w
1
E_IR 1
S2
000 111
E_IN 1 f
110
001
SM 00, Ex 1
010
011 100 101
S7
done 1
0 1
w
n n
Data_in D Q
Data
BUS
E E E E E
R0 R1 R2 R3 A B
ALU
E_R2
O_R2
E_R3
O_R3
E_R0
O_R0
E_R1
O_R1
E_A
op
E
G
E_ext
4
E_G
O_G
w
done
7 CONTROL CIRCUIT
fun
▪ Instruction Set
Every time w = '1', we grab the instruction from 𝑓𝑢𝑛 and execute it.
𝐼𝑛𝑠𝑡𝑟𝑢𝑐𝑡𝑖𝑜𝑛 = |𝑓 |𝑓1 |𝑓0 |𝑅𝑦1 |𝑅𝑦0 |𝑅𝑥1 |𝑅𝑥0 |. This is called ‘machine language instruction’ or Assembly instruction:
✓ 𝑓 𝑓1 𝑓0 : Opcode (operation code). This is the portion that specifies the operation to be performed.
✓ 𝑅𝑥: Register where the result of the operation is stored (we also read data from 𝑅𝑥). 𝑅𝑥 can be R1, R2, R3, R4.
✓ 𝑅𝑦: Register where we only read data from. 𝑅𝑦 can be R1, R2, R3, R4.
f Operation Function
000 Load Rx, Data Rx Data
001 Move Rx, Ry Rx Ry
010 Add Rx, Ry Rx Rx + Ry
011 Sub Rx, Ry Rx Rx - Ry
100 Not Rx Rx NOT (Rx)
101 And Rx, Ry Rx Rx AND Ry
110 Or Rx, Ry Rx Rx OR Ry
111 Xor Rx, Ry Rx Rx XOR Ry
▪ Control Circuit:
This is made out of some combinational units, a register, and a FSM:
✓ Ex: Every time we want to enable register 𝑅𝑥, the FSM only asserts Ex (instead of controlling E_R0, E_R1, E_R2, E_R3
directly). The decoder takes care of generating the enable signal for the corresponding register 𝑅𝑥.
✓ Eo, so: Every time we want to read from register 𝑅𝑦 (or 𝑅𝑥), the FSM only asserts Eo (instead of controlling O_R0,
O_R1, O_R2, O_R3 directly) and so (which signals whether to read from 𝑅𝑥 or 𝑅𝑦). The decoder takes care of generating
the enable signal for the corresponding register 𝑅𝑥 or 𝑅𝑦.
7 7 Rx1 0 0
fun D Q funq DECODER 1 E_R0
Rx0 E_R1
E_fun E 1 with 2 E_R2
enable 3 E_R3
Ex
E
Ry 2 0 0 0
2 O_R0
2 DECODER 1
Rx 1 O_R1
1 with 2 O_R2
enable 3 O_R3
Eo
E
so
E_ext
O_G
E_G
E_A
op
Ex Eo so
4
w
3 done
f FSM
resetn=0
S1
0
w
1
E_fun 1
S2
Eo, Ex 1
done 1 010
011 100 101
1
5
4
stop
resetn
?
2 3 clock
sel[1..0]
00
01
10
11
3
z
E
Q ?? FINITE STATE 1-to-2 buf buf(1) buf(0)
MACHINE s decoder
z
counter (0.5s) x = 00 → Lights change every 1.5 s
x = 01 → Lights change every 1.0 s
x = 10 → Lights change every 0.5 s
Q ??
x = 11 → Lights change every 0.25 s
counter (0.25s)
0
E
1
00 11
sel
01 10
S2 S5 S8 S11
0 0 0 0
E E E E
1 1 1 1
S3 S6 S9 S12
0 0 0 0
E E E E
1 1 1 1
S4 S7 S10 S13
0 0 0 0
E E E E
1 1 1 1
▪ Algorithmic State Machine (ASM) chart: This is the FSM that controls the output MUX
resetn=0
S1
s0
0
E
1
S2
s1
1 0
E