a little C code to VHDL

L

Loppy

Hi,

I need translate the C code:

int incrementarmodL(int input,int mod)
{
int salida;

salida = (input+2)%mod;
return salida;
}

To VHDL but I Can´t translate because I don´t understand very well
the REM operation in VHDL.

The VHDL code that I am triying :

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
--use IEEE.NUMERIC_STD.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
--use IEEE.STD_LOGIC_UNSIGNED.ALL;



entity incmodL is
generic ( constant paso: std_logic_vector(7 downto 0):="00000010";
constant cero: std_logic_vector(7 downto 0):="00000000"
);

port ( entrada : in std_logic_vector(7 downto 0);
modulo : in std_logic_vector(7 downto 0);
reset : in std_logic;
salida : inout std_logic_vector(7 downto 0)
);
end incmodL;

architecture comportamiento of incmodL is
signal tmp : std_logic_vector(7 downto 0):="00000000";

begin

process(entrada,modulo,reset)
begin
if reset='1' then
salida <= cero;
else
tmp <= entrada or paso;
salida <= tmp REM modulo ;
end if;
end process;
end comportamiento;

but my compiler tell me that : REM can not have such operands in this
context.

anybody can help me.


Thanks.
 
J

Jeremy Ralph

Are you trying to write synthesizable code? If so you should be aware
that /, **, mod, and rem are not synthesizable, except for perhaps
powers of 2 or static values (i.e. values bound at compile-time).

For behavioural code, the REM operator from Numeric_Std works on
UNSIGNED, INTEGER, NATURAL, SIGNED -- not sure about std_logic_vector.
Perhaps try converting tmp and modulo to UNSIGNED before doing the REM
operation, assigning the result to an UNSIGNED.
 
L

Loppy

I have tried:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
--use IEEE.STD_LOGIC_ARITH.ALL;
--use IEEE.STD_LOGIC_UNSIGNED.ALL;



entity incmodL is
generic ( constant paso: std_logic_vector(7 downto 0):="00000010";
constant cero: std_logic_vector(7 downto 0):="00000000"
);

port ( entrada : in std_logic_vector(7 downto 0);
modulo : in std_logic_vector(7 downto 0);
reset : in std_logic;
salida : inout std_logic_vector(7 downto 0)
);
end incmodL;

architecture comportamiento of incmodL is
signal tmp : std_logic_vector(7 downto 0):="00000000";
signal tmp2 : integer;
begin

process(entrada,modulo,reset)

function fmodulo(valor,modl: integer) return integer is
variable tmp3: integer;
begin
if valor < modl then
return valor;
else
tmp3 := valor;

tmp3:=tmp3-modl;
while tmp3 >= modl loop
tmp3:=tmp3-modl;
end loop;

return tmp3;

end if;
end function fmodulo;

begin
if reset='1' then
salida <= cero;
else
tmp <= entrada or paso;

tmp2 <=
fmodulo(to_integer(unsigned(tmp)),to_integer(unsigned(modulo)));

salida <= std_logic_vector(to_unsigned(tmp2,8));

end if;
end process;
end comportamiento;

but don´t work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,585
Members
45,080
Latest member
mikkipirss

Latest Threads

Top