FPGA Based System Design: Engr. Rashid Farid Chishti Lecturer, Dee, Fet, Iiui Chishti@Iiu - Edu.Pk Week 10
FPGA Based System Design: Engr. Rashid Farid Chishti Lecturer, Dee, Fet, Iiui Chishti@Iiu - Edu.Pk Week 10
WEEK 10
8 1000 1011
S3 S6
9 1001 1100
reset
module Test_BCD_to_Excess3; S0
1/0
wire y; wire [2:0]pstate; reg x, clk, reset; 0/1
BCD_to_Excess_3 BE1 (y, x, pstate, clk, reset);
S1 S4
initial begin reset = 1; 1/0
#7 reset = 0; #3 reset = 1; 0/1 0/0 1/1
1/1 0/0
end
0/1
initial begin clk = 0;
repeat (20) #5 clk = ~clk; S2 S5
end 0/1
initial begin x = 1; 0/0 1/1 1/0
repeat (10) #10 x = ~ x;
end
S3 S6
endmodule
1/1 0/0
S1 S0 S2
1/0 0/1
www.iiu.edu.pk 7 Saturday, November 27, 2021
Manchester Encoding
module NRZ_2_Manchester_Mealy (B_out, state, B_in, clock, reset_b);
output B_out; input B_in; input clock, reset_b; output state;
reg [1: 0] state, next_state; reg B_out;
parameter S0 = 0, S1 = 1, S2 = 2, dont_care_state = 2'bx, dont_care_out = 1'bx;
always @ (negedge clock or negedge reset_b)
if (reset_b == 0) state <= S0;
else state <= next_state; 1/1 0/0
always @ (state or B_in ) begin
S1 S0 S2
B_out = 0;
case (state) 1/0 0/1
S0: if (B_in == 0) begin next_state = S2; B_out = 0; end
else if (B_in == 1) begin next_state = S1; B_out = 1; end
S1: begin next_state = S0; B_out = 0; end
S2: begin next_state = S0; B_out = 1; end
default: begin next_state = dont_care_state;
B_out = dont_care_out; end
endcase
end
endmodule
module test_NRZ_2_Manchester_Mealy;
wire B_out; reg B_in, clk, rst; wire [1:0] state; reg clk2;
NRZ_2_Manchester_Mealy (B_out, state, B_in, clk, rst); 1/1 0/0
S1 S0 S2
1/0 0/1
initial begin rst = 1; #7 rst = 0; #3 rst = 1; end
initial begin clk = 0;
repeat (20) #5 clk = ~clk; end
initial begin clk2 = 1;
repeat (10) #10 clk2 = ~clk2; end
initial begin B_in = 1;
repeat (3) #40 B_in = ~ B_in; end
endmodule
www.iiu.edu.pk 9 Saturday, November 27, 2021