NRZI encode

NRZI diagram[2] 

 

First part is encoder, second part is decoder. Small modification is in the bit_stream sampling part.

Some comments:

1. use DFF to buffer the input 

2. use 1'b1 instead of 1, because during synthesis, 1 will be viewed as integer type:

example, like adder, cnt + 1'b1; 1'b1 will get extended to align with cnt.

if for assignment, cnt <= 1;// 1 will get truncated to align with cnt, better to use 1'b1 

NRZI encoder

// file: nrzi.v
// author: rui
// comments: input serial input
// output nrzi code
// algorithm: nrzi0 means change, nrzi1 means no change

`timescale 1ns/1ns
module nrzi( input bstream, clk, rst_n,
     output  reg nrzi_code);
reg nrzi_temp, bstream_temp;

always@(bstream_temp  or bstream)  begin
    nrzi_temp = ~(bstream_temp ^ bstream);  //  0: change, 1: no change
end

always@( posedge clk  or  negedge rst_n)  begin
     if(!rst_n) 
         begin 
            nrzi_code <=  1; bstream_temp <= bstream; 
         end
     else 
         begin 
            nrzi_code <= nrzi_temp;  bstream_temp <= bstream; 
         end
end
endmodule 
 


testbench

// file: nrzi_top.v
// author: rui
// comments: testbench for nrzi encode

` include  " nrzi.v "
`timescale 1ns/1ns
module nrzi_top;
reg bit_stream= 0;
reg clk= 1, rst_n= 1;
wire nrzi_code;

nrzi encoder1(.bstream(bit_stream), .clk(clk), .rst_n(rst_n), .nrzi_code(nrzi_code));

always # 5 clk = ~clk;

initial  begin
    # 5 rst_n =  0;
    # 20 rst_n =  1;
end

initial  begin
     repeat( 20) # 10 bit_stream = $random;
    # 10 $finish;
end

initial  begin
    $dumpfile( " nrzi.vcd ");
    $dumpvars;
end
endmodule 


Simulation result

 

Reference

[1] http://www.ece.msstate.edu/~reese/EE8993/lectures/verilog_rtl/verilog_rtl.pdf

[2]http://www.oguchi-rd.com/technology/nrzi.pdf

[3]http://gbenthien.net/encoding.pdf
 

转载于:https://www.cnblogs.com/chenrui/archive/2012/04/05/2432944.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值