Home Verilog Digital Design Digital Basics Python RF Basics

Legal Disclaimer

Chip Designing for ASIC/ FPGA Design engineers and Students
Digital-logic Design...  Dream for many students… start learning front-end…
Topics @TYH :- 4G LTE Tutorial, GVIM editor, Smart-Phone, Cloud Computing
Custom Search

Feedback ? Send it to admin@fullchipdesign.com or join me at fullchip@gmail.com

Legal Disclaimer

Initial stmts IF-ELSE Case stms Readmemh Function Testbench Binary to Gray Clock Crossing Half-adder Full-adder Tristate buffer Adder tb Counter_enable Blocking Operators Shift LSR Random Nos Sync RAM Verilog Tutorial
Verilog Tutorial.
Digital Basics Tutorial.
~\Desktop\gray.v.html /*Logic to convert binary numbers into Gray coded binary numbers is implemented in the following Verilog Code.
module binary2gray();
reg clk;
reg rstn;
reg [5:0] counter_binary, counter_binary_reg, counter_gray, counter_gray_reg;
integer count, file_wr;

/* Initial block to generate clock and reset */ 
initial  begin
    clk = 0; rstn = 0;  #100 rstn = 1;
    forever begin
        #10 clk = !clk; 
 end end    

/* Synchronous Logic for registering the data and incrementing the counter for binary data */
always @ (posedge clk or negedge rstn)
    if (!rstn) begin
        counter_binary_reg <= 'b0;
        counter_gray_reg <= 'b0;  end
    else begin 
        counter_binary_reg <= counter_binary + 1;
        counter_gray_reg <= counter_gray;
        $display("binary number= 6'b%b : gray en-coded binary number = 6'b%b", counter_binary_reg, counter_gray_reg);   end end

/* Logic is to get Gray code from Binary code */
function[5:0] binary2gray ;
    input[5:0] value;
    integer i;
        binary2gray[5] = value[5];
        for (i=5; i>0; i = i - 1)
            binary2gray[i-1] = value[i] ^ value[i - 1];

/* Get gray encoded output */
always @(*)
  counter_gray = counter_gray_reg;
  counter_binary = counter_binary_reg;
  counter_gray = binary2gray(counter_binary_reg); end

Verilog Binary to Gray Code conversion example. Click here to get 0-100 binary-gray-decimal conversion example
LTE - Long Term Evolution topics from here
Interview Questions. Main, FPGA, Digital Fundamentals
Return to Verilog Tutorial

A function is discussed below to convert binary number to gray code number. The function is then used in combinational RTL logic. This kind of conversions are widely used in digital design to implement asynchronous clock crossing interfaces. The gray code primarily used to convert counter values before sending across the async interface. With this technique only one bit is allowed to change and it limits the error to +/- 1.


Parameters passing, defparam & localparam

Alias, Array, Assertions


LTE - Long Term Evolution topics.
Clock Crossing.
INTERVIEW Questions: Start early in your Job interview preparations

How do you represent Universal NAND Gate.

Derive AND gate by using only NAND gates.

Derive OR gate by using only universal NAND gates.

Derive XOR gate by only using NAND gates. Discuss with truth -table.