zoukankan      html  css  js  c++  java
  • 几个采样代码的对比

    输入: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

      

    资源用量:

      

    代码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 

     

    资源用量:

     

    代码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 

     

    资源用量:

     

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

  • 相关阅读:
    vs2008及以上的ActiveX测试容器在哪儿
    关于databinding的细节
    C#使用StackTrace获取方法被谁调用
    你是怎么走神的?
    怎样让SoapHttpClientProtocol不使用系统默认代理
    List的FindIndex和ForEach
    List的Capacity
    装箱和拆箱
    FileSystem.DeleteDirectory遇到"无法删除 文件:无法读取源文件或磁盘"
    一段关于测试和自定义Attribute的代码
  • 原文地址:https://www.cnblogs.com/Neddy/p/1984542.html
Copyright © 2011-2022 走看看