0

What I'm trying to do is pretty simple, just generating a pulse from a basic counter. My code is shown below. My question is if there's an efficient way of comparing a std_logic_vector and an integer? I only need to compare them at that one instance in the process. Also, can you do aritmetic on a 4 bit signal as shown in my code? DO you need a specific library?

signal Top16: std_logic; -- 1 clk spike at 16x baud rate    
signal Div16: std_logic_vector(3 downto 0);

DIVISOR: natural := 120 -- Can be 120 or 60, depending on user preference.    
------------------------------------------------------------------------

    process (RST, LCLK_MULT_BUFG)
    begin
        if RST='1' then
            Top16 <= '0';  --1 bit signal
            Div16 <= x"0";  -- 4 bit signal
        elsif rising_edge(LCLK_MULT_BUFG) then
            Top16 <= '0';
                if Div16 = Divisor then  -----> signal to integer comparison?
                    Div16 <= 0;
                    Top16 <= '1';  
                else
                    Div16 <= Div16 + 1;   -----arithmetic on std_logic_vector??
                end if;
        end if;

EDIT:

The number of bits within the Div16 std_logic_vector will vary depending on the size of Divisor chosen (shown below). How to correctly format this? What libraries will be needed?

DIVISOR: natural := 120 -- Can be 120 or 60, depending on user preference.
constant COUNTER_BITS : natural := integer(ceil(log2(real(DIVISOR))));
signal Div16: std_logic_vector(COUNTER_BITS);  
4

2 に答える 2

0

算術演算には、 を使用できますstd_logic_unsigned。このライブラリには、次の関数が含まれています。

function "+"(L: STD_LOGIC_VECTOR; R: INTEGER) return STD_LOGIC_VECTOR;
function "+"(L: INTEGER; R: STD_LOGIC_VECTOR) return STD_LOGIC_VECTOR;

比較のために、使用している場合はそのままにしておくことができますstd_logic_unsigned。このライブラリには、次の関数が含まれています。

function "="(L: STD_LOGIC_VECTOR; R: INTEGER) return BOOLEAN;
function "="(L: INTEGER; R: STD_LOGIC_VECTOR) return BOOLEAN;

Div16 を として定義してunsignedから を使用することもできますnumeric_std。このライブラリには、比較のために次の関数が含まれています。

function "=" ( L: NATURAL; R: UNSIGNED) return BOOLEAN;
function "=" ( L: UNSIGNED; R: NATURAL) return BOOLEAN;

そして追加のために:

function "+" ( L: UNSIGNED; R: NATURAL) return UNSIGNED;
function "+" ( L: NATURAL; R: UNSIGNED) return UNSIGNED;
于 2015-08-20T19:23:01.580 に答える