VHDL assigning decimal values to std_logic_vector - syntax

I'm trying to add a decimal value to a 10 bit std_logic_vector without having to describe every bit. Though it might not be worth the trouble in this particular scenario, i believe it will be very good to know in the future.
So far i have:
signal h_cnt : std_logic_vector(9 downto 0);
... --code
h_cnt <= std_logic_vector(to_unsigned(9, 10));
I get an error message saying:
*Error (10482): VHDL error at vhdl_vga.vhd(70): object "to_unsigned" is used but not declared
*
could anyone help me with this one?
Thanks in advance

I had to replace the libraries i was using.
use ieee.numeric_std.all;
is what i needed.

Related

Instantiate VHDL entity with 2D array from SystemVerilog

There seems to be very little documentation on how to pass 2D arrays between VHDL and SystemVerilog. I have a port of the following type in VHDL:
package my_package is
type my_array_t is array (natural range <>) of std_logic_vector(N-1 downto 0);
end my_package
entity my_entity is
port(
my_input : in my_array_t(M-1 downto 0);
my_output : out my_array_t(M-1 downto 0);
);
end entity;
And the following SystemVerilog signal:
wire [N-1:0] my_input_s[M-1:0];
wire [N-1:0] my_output_s[M-1:0];
I believe these two types are completely equivalent. However, I can't go between each other without getting errors. Instantiating the VHDL module from SystemVerilog:
my_entity my_entity_inst(
.my_input(my_input_s),
.my_output(my_output_s)
);
The error I get is "formal port 'my_input' of type 'my_array_t' does not match with actual type 'logic'", similarly for the output signal. I tried different combination of array types in SystemVerilog (fully packed, fully unpacked) but none works. Note that in my case, I don't have the freedom of changing the VHDL declaration, I must find a way to make it work solely from SystemVerilog. Thus, this question can't help me.
How do I instantiate my VHDL module from SystemVerilog in the most straightforward way?
To be successful in instantiating VHDL in Verilog or SV stick to the basic types (types built into the original VHDL, not custom packages) in VHDL such as std_logic and std_logic vector.
For this case where you can't modify the VHDL file with custom port types, I recommend writing a VHDL wrapper (mydesign_wrapper.vhd) that instantiates the entity which uses the custom types and converts the ports to std_logic and std_logic_vector types for use at the top/entity of the wrapper design. Instantiate the new wrapper file in the Verilog or SystemVerilog file. An array of std_logic_vector would be represented as several std_logic_vector ports using the wrapper.
There is no standard for VHDL inside Verilog/SV, therefore support is limited and varies between tools, vendors, and versions.

error: entity cannot be at the top of a design, generic has no default value

I've just started VHDL and its proving to be more difficult than I gave it credit for. At the moment im trying to get my head around the 'generic' area of operation. I've cut down my code as much as possible (this extract doesn't do anything but still produces the error) and still haven't managed to crack it. If one of you could help I would be very greatful!
thanks in advance.
library IEEE;
entity ALU is
GENERIC (constant cst:integer range 15 downto 0);
end ALU;
architecture behavioural of ALU is
begin
End behavioural;
.
error:entity "alu" cannot be at the top of a design
alu.vhdl:6:19: generic "cst" has no default value

Trouble using a variable as boundary in a std_logic_vector with the downto

I am trying to do the following: in a process, after declaring a variable of type natural...
VARIABLE Pointer: NATURAL := 0;
... I assign it to a value, Pnt, which is a signal of type std_logic_vector(3 downto 0):...
Pointer := to_integer(unsigned(Pnt));
... and later on (in the begin part of the process) I use this value, Pointer, to point to a portion (a byte) of a big std_logic_vector called Buffer:
Buffer(Pointer*8+7 downto Pointer*8) <= ...something...
Unfortunately, while compiling, I receive the following error:
Error (10327): VHDL error at OutputInterface.vhd(38): can't determine definition of operator ""*"" -- found 0 possible definitions
I have imported numeric_std, writing at the very top of my file the " use IEEE.numeric_std.all; "
Why is this error happening? Thank you in advance for your precious help and I hope I provided enough and organized information around the question!
The reason is that your indexer: Pointer variable is changing. This is not allowed in VHDL if the compiler cannot resolve section to combinatorial logic.
If the compiler can only realize a sequential implementation, then it will complain of an error.
Depending on your vendor. It is sometimes very difficult to get the compiler to understand that the logic you are describing can actually be combinatorial.
Additionally make sure to check that you have no inferred latched, if not this will surely not work

std_logic_signed is used but not declared

I am new to VHDL. I am trying to use a std_logic_signed signal but I keep getting the error "std_logic_signed is used but not declared". As far as I can tell I have used the right libraries but googeling the error resulted in a lot of conflicting answers.
Here is my sample program:
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
entity bird is
end entity bird;
architecture arch of bird is
--Declare signals
signal speed : std_logic_signed (7 downto 0);
begin
end architecture arch;
What is causing the error and how do I fix it?
Because the type name is SIGNED:
grep -i signed std_logic_arith.vhdl
std_logic_arith.vhdl: type SIGNED is array (NATURAL range <>) of STD_LOGIC;
...
There isn't a type declared named std_logic_signed.
Instead of declaring speed with a type mark of std_logic_signed use signed:
--Declare signals
signal speed : signed (7 downto 0);

VHDL syntax for arrays of clocks (accepted by synthesis but not Active-HDL simulator)

I've a problem with some VHDL syntax in some old code that I want to reuse. It is accepted by the synthesis tool (Synplify) but the simulator (Aldec Active-HDL 8.3) gives the following error. (Note: This construction was accepted by a previous version of this simulator).
#Error: COMP96_0228: buffered_data.vhdl : (19, 28): The actual must be denoted by a static signal name, if the actual is associated with a signal parameter of any mode.
I get that the error doesn't like the (i) in the signal clk(i) but I don't want to unroll the loop to (0),(1),etc because it's used in several different configurations for different port sizes and I'm sure there must be a way to describe this.
My solution so far is to encapsulate one instance in it's own entity/arch hierarchy and use a "generate" to instantiate once for each port but I don't like it. Any better ideas?
Very simplified example showing exactly my issue. (The intent is to ensure that data is first clocked into the FPGA using its own associated clock before anything else)
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity input_buffer is
port(
clk : in std_logic_vector;
data_in : in std_logic_vector;
data_out : out std_logic_vector
);
end input_buffer;
architecture rtl of input_buffer is
constant c_NumOfPorts : integer := 3;
begin
p_process: process(clk)
begin
for i in 0 to c_NumOfPorts-1 loop
if rising_edge(clk(i)) then -- error here
data_out(i) <= data_in(i);
end if;
end loop;
end process;
end rtl;
If you change the loop inside the process into a generate statement outside the process, it works fine in ModelSim (I don't have Aldec available), and IMHO seems cleaner than a single process with a bunch of clocks. I would also typically use a generic to define the port widths, rather than pulling them in as a constant inside the architecture, but I figure you've got some reason for doing it that way:
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity input_buffer is
port(
clk : in std_logic_vector;
data_in : in std_logic_vector;
data_out : out std_logic_vector
);
end input_buffer;
architecture rtl of input_buffer is
constant c_NumOfPorts : integer := 3;
begin
gen : for i in 0 to c_NumOfPorts-1 generate
begin
p_process: process(clk(i))
begin
if rising_edge(clk(i)) then -- error here
data_out(i) <= data_in(i);
end if;
end process;
end generate;
end rtl;
FWIW, I get the same with Modelsim:
Model Technology ModelSim PE vcom 10.0a Compiler 2011.02 Feb 20 2011
-- Loading package STANDARD
-- Loading package TEXTIO
-- Loading package std_logic_1164
-- Compiling entity input_buffer
-- Compiling architecture rtl of input_buffer
** Error: clk.vhd(19): (vcom-1450) Actual (indexed name) for formal "s" is not a static signal name.
** Error: clk.vhd(25): VHDL Compiler exiting
As an aside - is there a reason for your use of the constant and not just doing this?
for i in clk'range loop
But no actual answer has occurred to me yet, sorry!

Resources