几个采样代码的对比

输入:singalclk_clr8bit count
输出:dout

_clr low dout 输出 low

_clr hi   clk 升沿采样,连续count singal hi dout输出为hi
      否则  dout 输出为low
 
代码1

LIBRARY ieee;
USE ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

--  Entity Declaration

ENTITY countup1 IS
 PORT
 (
  singal,clk,n_rst : IN STD_LOGIC;
  countset     : IN STD_LOGIC_VECTOR(7 downto 0);  
  sinout      : OUT STD_LOGIC
 );

 
END countup1;


--  Architecture Body

ARCHITECTURE a_architecture OF countup1 IS
begin
 process(n_rst,clk)
  VARIABLE count : std_logic_vector(7 downto 0);
  begin
    if n_rst  = '0' then
     count := "00000000" ;
    else
     if rising_edge(clk) then
       if singal = '1' then
        count := count + 1 ;
        if count > 254 then
         count := "11111100";
        end if ;
       else
        count := "00000000" ;
       end if ;
     end if ;
    end if ;
    if count > countset then
     sinout <= '1' ;
    else
     sinout <= '0' ;
    end if ;
   
  end process;


END a_architecture;

RTL Viewer

  2011031510305925.jpg

资源用量:

2011031510414786.jpg  

代码2

LIBRARY ieee;
USE ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

--  Entity Declaration

ENTITY countup2 IS
 PORT
 (
  singal,clk,n_rst : IN STD_LOGIC;
  countset     : IN STD_LOGIC_VECTOR(7 downto 0);  
  sinout      : OUT STD_LOGIC
 );

 
END countup2;


--  Architecture Body

ARCHITECTURE a_architecture OF countup2 IS
begin
 process(n_rst,clk)
  VARIABLE count : std_logic_vector(7 downto 0);
  begin
   if n_rst  = '0' then
    count := countset ;
   else
    if rising_edge(clk) then
     if singal = '1' then
      if count = 0 then
       sinout <= '1' ;
      else
       count := count - 1 ;
       sinout <= '0' ;
      end if ;
     else
      count := countset ;
      sinout <= '0' ;
     end if ;
    end if ;
   end if ;
  end process;
END a_architecture;

RTL Viewer 

 2011031510431483.jpg

资源用量:

 2011031510435853.jpg

代码3

module sample(
input signal,
input clk,
input clr_n,
input[7:0] count,
output reg dout);

reg[7:0] cnt;
always@(posedge clk or negedge clr_n)
begin
 if(!clr_n) begin cnt <= 1'b0; dout <= 1'b0; end
 else begin
       if(signal) 
  begin
           if((cnt<count) && !dout)  begin cnt <= cnt + 1'b1; dout <= 1'b0; end
           else       begin cnt <= 1'b0; dout <= 1'b1; end
  end
       else  begin cnt <= 1'b0; dout <= 1'b0; end
    end
end
endmodule

RTL Viewer 

 2011031510451216.jpg

资源用量:

 2011031510453167.jpg

比一比三个代码,哪个好些?

posted on 2011-03-15 10:30  Neddy11 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/Neddy/archive/2011/03/15/1984542.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值