搜索
bottom↓
回复: 2

帮忙看看代码,testbench文件第一次写,感觉波形不对啊?

[复制链接]

出0入0汤圆

发表于 2012-9-18 11:17:54 | 显示全部楼层 |阅读模式
如题

下面分别是.V文件 与.Vt文件

module gate_ch
(
        rstn,
        gate_ch1,
        gate_ch2,
        gate_ch3,       
        clk_1hz,
        clk_10hz,
        clk_100hz,
        clk_1khz,
       
        gate_out,
        scan_freq,
        error,
        flag
);

        input rstn;
        input gate_ch1, gate_ch2, gate_ch3;
        input clk_1hz, clk_10hz, clk_100hz;
        input clk_1khz;

        output wire scan_freq;                
        output reg [1:0]flag;
        output reg gate_out;
        output reg error;

        /********************************************/
       
        reg [2:0]count5; // 产生扫描信号时的分频计数值
        reg gate;
       
        always @( posedge clk_1khz or negedge rstn )
        begin
                if( !rstn )
                        begin
                                flag = 2'b01;
                                gate <= 0;
                                error <= 1;
                                count5 <= 0;
                        end
                else
                        begin
                                if( gate_ch1 == 0 && gate_ch2 == 1 && gate_ch3 == 1 )
                                        begin
                                                flag = 2'b01;       
                                                gate <= clk_1hz;
                                                error <= 1;
                                        end
                                else if( gate_ch1 == 1 && gate_ch2 == 0 && gate_ch3 == 1 )
                                        begin
                                                flag = 2'b10;
                                                gate <= clk_10hz;
                                                error <= 1;
                                        end                                
                                else if( gate_ch1 == 1 && gate_ch2 == 1 && gate_ch3 == 0 )
                                        begin
                                                flag = 2'b11;
                                                gate <= clk_100hz;
                                                error <= 1;
                                        end                                        
                                else
                                        begin
                                                error <= 0;
                                        end
                        end
        end
       
        /********************************************/       
               
        always @ ( posedge gate or negedge rstn )
        begin
                if( !rstn )
                        begin
                                gate_out <= 0;
                        end
                else
                        begin
                                gate_out <= ~gate_out;
                        end
        end

        /********************************************/       
       
        assign scan_freq = clk_1khz;

        /********************************************/
       
endmodule
       


.Vt文件如下:

`timescale 1 us/ 1 ps
module gate_ch_vlg_tst();

        reg clk_1hz;
        reg clk_1khz;
        reg clk_10hz;
        reg clk_100hz;
        reg gate_ch1;
        reg gate_ch2;
        reg gate_ch3;
        reg rstn;
       
        // wires                                               
        wire error;
        wire [1:0]flag;
        wire gate_out;
        wire scan_freq;
       
        /*************************/
       
        gate_ch i1
        (
                .clk_1hz( clk_1hz ),
                .clk_1khz( clk_1khz ),
                .clk_10hz( clk_10hz ),
                .clk_100hz( clk_100hz ),
                .error( error ),
                .flag( flag ),
                .gate_ch1( gate_ch1 ),
                .gate_ch2( gate_ch2 ),
                .gate_ch3( gate_ch3 ),
                .gate_out( gate_out ),
                .rstn( rstn ),
                .scan_freq( scan_freq )
        );

        /********************************************/
       
        initial                                                
                begin                                                  
                        rstn = 0;
                        #10 rstn = 1;
                       
                        clk_1hz = 0;
                        forever #500000 clk_1hz = ~clk_1hz;
                       
                        clk_10hz = 0;
                        forever #50000 clk_10hz = ~clk_10hz;
               
                        clk_100hz = 0;
                        forever #5000 clk_100hz = ~clk_100hz;
                       
                        clk_1khz = 0;
                        forever #500 clk_1khz = ~clk_1khz;
                       
                end
               
        /********************************************/
       
        reg [1:0]item;
       
        always @ ( posedge clk_1khz or negedge rstn )  
                if( !rstn )
                        begin
                                item <= 2'd1;
                        end
                else
                        case( item )
                                1:
                                        begin
                                                gate_ch1 <= 0;
                                                gate_ch2 <= 1;
                                                gate_ch3 <= 1;
                                                item <= 2'd2;
                                        end
                                       
                                2:
                                        begin
                                                gate_ch1 <= 1;
                                                gate_ch2 <= 0;
                                                gate_ch3 <= 1;
                                                item <= 2'd3;
                                        end
                               
                                3:
                                        begin
                                                gate_ch1 <= 1;  
                                                gate_ch2 <= 1;  
                                                gate_ch3 <= 0;
                                                item <= 2'd1;       
                                        end
                       
                        endcase
                       
        /********************************************/
                       
endmodule


大侠们,给点建议,在此谢过!

阿莫论坛20周年了!感谢大家的支持与爱护!!

知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)

出0入0汤圆

 楼主| 发表于 2012-9-18 11:19:05 | 显示全部楼层
波形在这里~

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

 楼主| 发表于 2012-9-18 17:08:56 | 显示全部楼层
.Vt 文件写好了,波形也出来了!

// Simulation tool : ModelSim-Altera (Verilog)

`timescale 1 ps/ 1 ps
module gate_ch_vlg_tst();

        reg clk_1hz;
        reg clk_1khz;
        reg clk_10hz;
        reg clk_100hz;
        reg gate_ch1;
        reg gate_ch2;
        reg gate_ch3;
        reg rstn;
       
        // wires                                               
        wire error;
        wire [1:0]flag;
        wire gate_out;
        wire scan_freq;
       
        /*************************/
       
        gate_ch i1
        (
                .clk_1hz( clk_1hz ),
                .clk_10hz( clk_10hz ),
                .clk_100hz( clk_100hz ),               
                .clk_1khz( clk_1khz ),
                .error( error ),
                .flag( flag ),
                .gate_ch1( gate_ch1 ),
                .gate_ch2( gate_ch2 ),
                .gate_ch3( gate_ch3 ),
                .gate_out( gate_out ),
                .rstn( rstn ),
                .scan_freq( scan_freq )
        );

        /********************************************/
       
        initial                                                
        begin
       
                rstn = 1;
                #10 rstn = 0;
                #10 rstn = 1;
               
                gate_ch1 = 1;
                gate_ch2 = 0;
                gate_ch3 = 1;
               
                clk_1khz = 0;
                forever
                        #500 clk_1khz = ~clk_1khz;                               

        end

        /********************************************/
       
        initial
        begin       
                clk_1hz = 0;
                forever
                        #500000 clk_1hz = ~clk_1hz;
        end

        /********************************************/
       
        initial
        begin
                clk_10hz = 0;
                forever
                        #50000 clk_10hz = ~clk_10hz;
        end

        /********************************************/
       
        initial
        begin
                clk_100hz = 0;
                forever
                        #5000 clk_100hz = ~clk_100hz;
        end
               
        /********************************************/
       
endmodule




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-7-24 09:23

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表