signal moving from clk1 to clk2
module 3stage_sync(d, q3);
always @(posedge clk2) begin
q1 <= d;
q2 <= q1;
q3 <= q2;
end
endmodule
q3 : 3 stage synchronized signal WRT clk2 domain
STA:
If a design has 100 FF’s, there will be alteast 99 ‘2-ff’ combinations
SDF : Standard Delay Format
always @(posedge clk) begin
q <= d;
end
SDF annotation:
STA analysis is done using Primetime tool.
PVT(Process voltage temparate) variation results in different delay values for same logic
o one corner gives best case timing
o anoterh corner gives worst case timing
Setup violation:
o D input at capture flop is reaching late and violating the setup time of capture flop
How to fix Setup violatin:
o
Setup time equation:
LFF_CLK_TO_Q + COMB_DLEAY + SETUP_TIME <= CLOCK_TP + CLOKC_PATH_DELAY_BW_LAUNCH_AND_CAPTURE_FLOP
HVT and LVT cells to change gate specific delay values
Hold time equation:
COMB_DLEAY >= Hold time
it has no relation to clock frequency
Hold time violation fixing:
Increase the COMB_DLEAY
5 states:
Gray code counter : how gray code counter avoids meta stability or glitches at design boundaries
BELOW CODE INFERS LATCH:
always@(*)
if (something)
nothing = 0;
else if (something_else)
nothing = 1;
BELOW CODE INFERS COMBINATIONAL LOGC:
always@(*)
nothing = 0;
if (something)
nothing = 0;
else if (something_else)
nothing = 1;
swapping of 2 numbers using blocking assignments : Race condition
setup or hold violation of DFF will result in metastability
glitch : Asynchous FIFO results in glitches -> which can further result in metastability
wr_ptr : 4’b0111
when we do a write, wr_ptr will be = 4’b1000
0111 -> 0101 -> 0100 -> 0000 -> 1000
if above 3 intermediate states, matches with rd_ptr value, it will results in empty glitch
Solution:
21.
reg [3:0] d;
always @(posege clk) begin
q1 = d;
q2 = q1;
q3 = q2;
end
above code synthesizes to 4 FF (1 state having 4 FF, all 4 FF are parallel)
22.
reg [3:0] d;
always @(posege clk) begin
q1 <= d;
q2 = q1;
q3 <= q2;
end
above code synthesizes to 8 FF (4 FF per stage)
always @(posedge clk) begin
if (rst) count <= 0;
else count <= count + 1;
end
up-counter can also be impelmented using gates only:
C2C1C0 N2N1N0
0 0 0 0 0 1
0 0 1 0 1 0
0 1 0 0 1 1
0 1 1 1 0 0
1 0 0 1 0 1
1 0 1 1 1 0
1 1 0 1 1 1
1 1 1 0 0 0
Karnaugh map:
N2 = c2bc1c0 + c2c1b + c2c0b
N1 = c1^c0
N0 = ~c0;
Does it require any sequential elements or is it purely combinational?
o if the output is dependent on current state and inputs, then it is sequential
o if the output is only dependent on inputs, with no dependence on curerny output or current state, then it is combinational
module up_counter();
and g1(n1, cb[2], c[1], c[0]);
and g2(n2, c[2], cb[1]);
and g3(n3, c[2], cb[0]);
xor g4(n4, c[1], c[0]);
or g5(n5, n1, n2, n3);
dff g6(c[2], n5, clk, rst);
dff g7(c[1], n4, clk, rst);
dff g8(c[0], cb[0], clk, rst);
endmodule
module dff();
endmodule
################################################################
SESSION-2
always @(posdge clk) begin
case (state)
“S_NO_ACTIVE_INTR” : begin
if (intr_in != 0) begin
next_state = S_INTR_GIVEN_TO_PROC;
end
end
“S_INTR_GIVEN_TO_PROC” : begin
if (intr_servd == 1) begin
next_state = S_INTR_SERVICED_BY_PROC;
end
end
“S_INTR_SERVICED_BY_PROC” : begin
end
endcase
end
always @(next_state) begin
state = next_state;
end
always @(posedge sclk) begin
case (spi_data_state)
“S_NO_DATA” : begin
end
“S_TX_DATA” begin
data_o = data[count];
count = count +1;
if (count == 8) begin
tx_done = 1;
next_spi_data_state = S_NO_DATA;
end
end
“S_RX_DATA” begin
end
endcase
end
always @(posdge clk) begin
case (state)
“S_IDLE” : begin
if (tfr_req == 1) begin
next_state = S_ADDR;
end
end
“S_ADDR” : begin
/*
for(i=0; i < 8; i=i+1) begin
@(posedge sclk);
mosi = addr[i];
end
*/
spi_data_state = S_TX_DATA;
if (tx_done == 1) next_state = S_IDLE_BW_ADDR_DATA;
end
“S_IDLE_BW_ADDR_DATA” : begin
next_state = S_DATA:
end
“S_DATA” : begin
for(i=0; i < 8; i=i+1) begin
@(posedge sclk);
mosi = data[i];
end
next_state = S_IDLE;
end
endcase
end
always @(next_state) begin
state = next_state;
end
module piso(clk, rst, data_i, valid_i, ready_o, data_o, valid_o, ready_i)
//assign wr_en = valid_i;
//assign ready_o = full;
//to generate wr_en to FIFO, following conditions should meet
//1. valid_i = 1
//2. full = 0
always @(posedge wr_clk) begin
wr_en = 0;
if (valid_i & ~full) begin
wr_en = 1;
wdata = data_i;
end
end
async_fifo fifo_i(wr_clk, rd_clk, rst, wdata, wr_en, rdata, rd_en);
always @(posedge rd_clk) begin
case (tx_state)
“S_NO_TRANSMIT” : begin
//transmit_in_progress_f = 0;
if (~transmit_in_progress_f && ~empty) begin
rd_en = 1;
next_tx_state = S_READ_FROM_FIFO;
end
end
“S_READ_FROM_FIFO” : begin
rd_en = 0;
transmit_in_progress_f = 1;
transmit_data_on_serial(rdata);
transmit_in_progress_f = 0;
end
//”S_TRANSMIT_IN_PROGRESS” : begin
//end
endcase
end
task transmit_data_on_serial(input reg [7:0] data);
begin
for (int i = 0; i < 8; i=i+1) begin
@(posedge clk_out);
data_o = data[i];
end
end
endtask
/*
always @(posedge rd_clk) begin
rd_en = 0;
if (~transmit_in_progress_f && ~empty) begin
rd_en = 1;
@(posedge rd_clk);
//tx_data = rdata;
transmit_data_on_serial(rdata);
end
end
*/
endmodule
31 Q: Digital design complete
it creates a pattern:
011 -> 100 -> 010 -> 101
32 Q:
a = x~z + ~yz
f = (x~z + ~yz)~y + xy = x~y~z + ~yz + xy = x + ~yz
33.
1010
1’s compl: 0101
2’s compl: 1010 + 1 = 1011
1st stge : 1011
2nd stage: 0100 -> 1011 + 1 = 1100
3rd stage: 0011 -> 1100 + 1 = 1101
34.
Puzzle (number max, min):
3 cascaded :
1 2 3 4 => 2 1 4 3 => 2 4 1 3 => 4 2 3 1 => 4 3 2 1 => 4 3 2 1
4 3 2 1 => 4 3 2 1 => 4 2 3 1 => 4 2 3 1 => 4 3 2 1 => 4 3 2 1
4 1 2 3 => 4 1 3 2 => 4 3 1 2 => 4 3 2 1 => 4 2 3 1 => 4 2 3 1
Next solution:
1 2 3 4 => 2 1 4 3 => 2 4 1 3 => 4 2 3 1 => 4 2 3 1 => 4 3 2 1
4 3 2 1 => 4 3 2 1 => 4 3 2 1 => 4 3 2 1 => 4 3 2 1 => 4 3 2 1
4 1 2 3 => 4 1 3 2 => 4 3 1 2 => 4 3 1 2 => 4 3 2 1 => 4 3 2 1
3 1 4 2 => 3 1 4 2 => 3 4 1 2 => 3 4 1 2 => 4 3 2 1 => 4 3 2 1