This assignment can be done using an assign statement.įor other bits, they are the result of the Ex-Or operation on theĬorresponding bit of the binary counter and the bit to the immediate right of it. The Most Significant Bit is the same as the Most Significant Bit of the binary counter. In the combinational logic part, an always_comb block is used, where the binary code to gray code conversion is done. Counter is a binary counter, and it has a modulus of 2 raised to the power of its width. Counter is an internal signal used to store the values and it gets incremented on the positive edge of the clock. In the sequential logic part, an always_ff block is used. #2 bit gray code counter verilog code verification#The Gray counter is also useful in design and verification in the VLSI domain. It will be helpful for error correction and signal transmission. b) Write a testbench for the module you wrote in part (a), using the same HDL coding, that will to functionally verify the code. Hint: Consult Exercise 3.28 of your textbook. Today gray code is widely used in the digital world. a) Write an HDL module (either System Verilog, Verilog, or VHDL) for a 4-bit UP/DOWN Gray Code counter. What happens in the code if the positive edge of the reset signal and the positive edge of the reset signal happen at the same time.The design is partitioned into 2 parts - one for combinational logic and another for sequential logic. Verilog Gray Counter Gray code is a kind of binary number system where only one bit will change at a time. What is the maximal binary number that this counter can count? d. In Gray code, these values are represented. In which numbering system does this counter count: decimal or binary? Explain your answer. For example, the representation of the decimal value 1 in binary would normally be 001 and 2 would be 010. What is the initial value of the counter? Explain your answer. Answer the below questions for the Verilog code given in practice example 1. module my counter(clk, reset, counter) module mycounter testbench() reg clk, reset wire [1:0) counter input clk, reset output (1:0) counter reg (1:0) counter up = 2 boo my counter test(clk, reset, counter) initial begin clk=0 forever #2 clk=-clk end always clk, negedge reset) begin if(!reset) counter_up <= 'boo else counter_up <= counter up + 2 bon initial begin reset=0 #1 reset=1 end end assign counter = counter.ur endmodule initial begin #1 $display("Worked by: Instructor") $display("Counter output =%b".counter) #4 $display("Counter output =%b".counter) #4 $display("Counter output =%b".counter) #4 $display("Counter output =%b".counter) #4 $display("Counter output =%b.counter) #4 $display("Counter output = %b".counter) #4 $display("Counter output =%b".counter) #4 end endmodule Verilog code and testbench of a 2-bit binary up counter. Transcribed image text: Practice Example 1. A Gray counter is a binary counter where only one bit changes at a time.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |