verilog代码风格——PN序列产生代码

该博客介绍了Verilog代码中PN序列(伪随机噪声序列)的生成方法。作者强调了编写Verilog代码时的注意事项,如变量赋值应分开、复位信号要干净等,并给出了PN序列产生模块的详细代码实现,包括不同长度PN序列的生成逻辑。代码中使用了时钟和复位信号作为触发,并通过状态变量控制序列的开始和结束,以及输出序列的使能。
摘要由CSDN通过智能技术生成

在编写Verilog代码时注意以下点:

1 、同一个模块中不同变量的赋值放在不同的always块里(这样可以便于程序的调试),一个always块的代码

       尽量不要超过十行。

2、同一个变量的赋值不能放在多个always块中,只能放在同一always块

2、复位信号一定要干净,尽量不要与其他的信号进行逻辑运算

3、利用时钟信号(clk)和复位信号(rst)做触发,尽量避免用中间变量的上升或者下降沿触发

示例代码如下(PN序列的产生):

//---------------------------------------------------------------------------------------------------

//-- Project name  : DTMB 1.0 IP Development

//-- Filename        : dtmb_pn_gen.v

//-- Called by        : dtmb_pn_gen.v                               

//-- Description    : DTMB fine channle estimation

//-- Moficiation History :

//-------------------------------------------------------------------------------------------

//--     Date           |        By                     |  Version  |  Change Description

//-------------------------------------------------------------------------------------------

//--  2014-07-24 |    Zhenzhen Peng |    0.2    |  Second   Version     

//----------------------------------------------------------------------------------------------

`timescale 1ns/10fs

 

modulepn_module2_m_function

  ( 

    // input

    i_clk_x16g                , // x16 clock, Gated 120.96MHz

    i_rst_n                       , // Negative reset for all EQ

    i_m_intiphase         , // Initial phase

    i_pn_mode              , // 0->255, 1->1023, 2->511, 3->x

    i_pn_length             , // 0->420, 1->595, 2->945, 3->x

    i_module2_start     , // PN start signal

 

    o_pn_gen_en          , // PN seq out enable

    o_pn_gen_start       , // PN start signal

    o_pn_gen_seq         , // PN sequence: 0->+PN , 1->-PN

     o_module2_count    // control the output signal 

  );

//=========================================================

// Parameter

//=========================================================   

parameter    D_W = 12,

                       output_lenght=2048  ; // output data lenght

 //=========================================================

// Interface definition

//=========================================================   

input                     i_clk_x16g            ; // x16 clock, Gated 120.96MHz

input                     i_rst_n                   ;// Negative reset for all EQ

input   [    1 : 0]    i_pn_mode           ;// 0->420, 1->595, 2->945, 3->x

input   [    9 : 0]    i_m_intiphase      ;// the PN initial phase

input                     i_module2_start  ; // pn_module2_m_function module start signal

input   [    9 : 0]    i_pn_length           ;// 0->420, 1->595, 2->945, 3->x

// output

output                 o_pn_gen_start        ; // PN start signal

output                 o_pn_gen_en           ;// PN seq out enable

output  [D_W-1 : 0] o_pn_gen_seq   ;// PN sequence: 0->+PN , 1->-PN

output  [   11 : 0]  o_module2_count  ; // control the output signal 

//=========================================================

// Behavior

//=========================================================  

reg                                    o_pn_gen_start       ;

reg                                    o_pn_gen_en          ; // PN seq out enable

reg signed [D_W-1 : 0] o_pn_gen_seq        ; // PN sequence: 0->+PN , 1->-PN

reg        [   11 : 0]             o_module2_count  ; // control the output signal of o_m_out,o_module2_over

 

reg                      m_flag           ;// m_flag=1, the shifting register is working

reg                      m_out            ; // the output bit value 

reg     [    9 : 0]    m_Init           ; // shifting register

 

// m_flag

always @(posedge i_clk_x16g or negedge i_rst_n)//a clk delay use to delivery the phase

begin                                    

  if(!i_rst_n)  m_flag<=1'b0;

  else if(i_module2_start) m_flag<=1'b1;

  else m_flag<=1'b0;

end

 

// o_module2_count

always @(posedge i_clk_x16gor negedge i_rst_n)

begin

  if(!i_rst_n)  o_module2_count<='b0;

  else if (m_flag )o_module2_count<=o_module2_count+1;

  else o_module2_c

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值