The above code should be for the mux.
the below high lighted line is the wrong because mux is a combinational circuit and there is no rule that it should be triggered at the positive edge and there is no rule that it should work as a sequential circuit. It just requires high and low voltage. Therefore that always block is not at all necessary and only if statement is enough to execute the mux command.
!always @ (posedge s) begin is a wrong line remove that always block and execute.
In the above code mux is a combinational circuit and always block behaving for sequential circuit.
remove that block
module mux2_1 (I0,I1,s,y);
input i0,i1,s;
output y
if(s) y=i1;
else y=i0;
endmodule
The above code is for the finite state machine.
if statement block doesnot contain being block and output should be out1,out2 and not identation for if statement needed.
original code should be like this
module FSM(clk,a,out1,out2);
input clk,a;
output out1,out2 ;
always @(posedge clk) begin
if(state ==0)
if(a) state<=1;
else
if(~a) state <=0;
end
always @(state)being
if(state==0) out1=1;
else out2=1;
end
endmodule
2. What is wrong with the following code (More than one error may exist in each...
(15 pts) 1. Draw a logic diagram for the Verilog code. module Seq_Ckt ( CLK, PR, sel, Q); input CLK, PR, sel; output reg [2:0] Q; reg [2:0] y; assign Q = y; always @ (posedge PR, posedge CLK) begin if (PR== 1) then y <= 3'b111; else if (sel) begin y[2] <= y[1] ^ y[0]; y[1] <= y[2]; y[1]; end else y[2] <= y[2] ; y[1] <= y[1]; y[0]; y[O] <= y[0] <= end endmodule
Given the following verilog code, draw the corresponding state diagram for it. module mysterious (input reset, clk, TB, TA, output reg [1:0] LB, LA); reg [1:0] cstate, nstate; parameter S0 = 2'b00; parameter S1 = 2'b01; parameter S2 = 2'b10; parameter S3 = 2'b11; parameter grn = 2'b00; parameter ylw = 2'b01; parameter rd = 2'b10; // state register always @ (posedge clk, posedge reset) begin if (reset) cstate <= S0; else cstate <= nstate; end // next state logic...
Please explain what he verilog code does: module lab7_2_3( input clk, input Enable, input Clear, input Load, output [3:0] Q, reg [3:0] count, wire cnt_done ); assign cnt_done = ~| count; assign Q = count; always @(posedge clk) if (Clear) count <= 0; else if (Enable) if (Load | cnt_done) count <= 4'b1010; // decimal 10 else count <= count - 1; Endmodule
Answer the question below for the following code, What does reg (7:0) do? What does always @ (posedge Cik) do? C What causes 2"b01: if (Clk 1) Q<= >> 1 to execute? When it executes, what does it do module Shift_Register (Q, Data_in, Clk, Load, Shift_left, Shift_right); output [ 7:0] Q; reg [7:0] Q, input (7:0) Data_in; input Clk, Load, Shift_left, Shift_right; always @ (posedge Clk) if (Load) Q<Data_in; else case ( { Shift_left, Shift_right)) 2'600: if (Clk - 1)...
a Read the following codes in Verilog and the corresponding testbench file. Describe what the codes are doing by adding comments in the code. Then write down the simulation results of res1, res2, res3, and res4, respectively. Source code module vector_defn (num1, res1, res2, res3, res4); input [7:0] num1; output res1; output [3:0] res2; output [0:7] res3; output [15:0] res4; assign res1=num1[2]; assign res2=num1[7:4]; assign res3=num1; assign res4={2{num1}}; endmodule testbench: `timescale 1ns / 1ps module vector_defn_tb; reg [7:0] in1; wire...
Write a testbench for use in Quartus' ModelSim Altera in verilog for the following code of a 4x16 register: module regFile4x16 (input clk, input write, input [2:0] wrAddr, input [15:0] wrData, input [2:0] rdAddrA, output [15:0] rdDataA, input [2:0] rdAddrB, output [15:0] rdDataB); reg [15:0] reg0, reg1, reg2, reg3; assign rdDataA = rdAddrA == 0 ? reg0 : rdAddrA == 1 ? reg1 : rdAddrA == 2 ? reg2 : rdAddrA == 3...
3. Answer the question below for the following code. module Shift_Register8 (Q, Data_in, Clk, Load, Shift_left, Shift_right); output [ 7:0] Q; reg [7:0] Q; input [7:0] Data_in; input Clk, Load, Shift_left, Shift_right; always @ (posedge Clk) if (Load) Q<= Data_in; else case ( { Shift_left, Shift_right }) 2'600: if (Clk == 1) Q<=Q; 2'b01: if (Clk == 1) Q<= >> 1; 2'b10: if (Clk == 1) Q<=Q<< 1; default: Q<=Q; endcase endmodule a) What does reg (7:0] Q do? b)...
A sequential circuit has one input (X), a clock input (CLK), and two outputs (S and V). X, S and V are all one-bit signals. X represents a 4-bit binary number N, which is input least significant bit first. S represents a 4-bit binary number equal to N + 3, which is output least significant bit first. At the time the fourth input occurs, V = 1 if N + 3 is too large to be represented by 4 bits;...
Im building a clock using HDL system verilog and I need help implementing this instantiation method. Basically what happens is in the top module ClockCounter, positive clock edges are counted and passed into module timer using instantiation. Once the counter reaches MaxCount (59), a carry is generated which increments the minute clock. Once the minute clock reaches 59, another carry is generated which increments the hour clock. In module timer() below, I need help figuring out what variables in each...
Please help to complete the code and write the testbench to design the following adder. 1.In this section, you add pipeline stage. 8 bits are used at every pipeline stage.Use the following template to complete your Verilog coding. // Addition of two 16 bit, 2's complement nos., n1 and n2. 8 bits addition at a time. Result is 17 bits. module adder_b (clk, n1, n2, sum) ; input clk ; input [15:0] n1 ; input [15:0] n2 ; output [16:0]...