Menu
  • HOME
  • TAGS

Or Reduce An Array of Vectors

Tag: vhdl

Needs to be placed on a real board, so will have to synthesize.

Using an old VHDL, libraries included:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;
use ieee.std_logic_misc.all;

Some signals:

type my_array is array (N-1 downto 0) of std_logic_vector(31 downto 0);
signal enable : my_array;
signal ored_enable: std_logic_vector(31 downto 0);

Signals get joined up in a generator:

my_gen: for i in 0 to (N-1) generate

    woah: entity work.my_entity

            port map(
                    clk => clk,
                    enable => enable(i)
                    );


 end generate;

ored_enable <= or_reduce(enable); -- this fails

I'm just trying to create a std_logic_vector which holds the ored signals from the array. Any ideas how I can simply achieve this?

Best How To :

First, I expect your last line to be a typo and read

ored_enable <= or_reduce(enable);

But this wouldn't work since or_reduce is only defined for std_logic_vector, not array of std_logic_vector. You can create your own reduce function:

function or_reduce(a : my_array) return std_logic_vector is
    variable ret : std_logic_vector(31 downto 0) := (others => '0');
begin
    for i in a'range loop
        ret := ret or a(i);
    end loop;

    return ret;
end function or_reduce;

Just put it in your architecture's declarations and it should work.

Count Edges over specific Period of Time in VHDL

vhdl,counter,reset,encoder

You're building a latch using a variable. Your synthesis tool inferred an asynchronous reset CLKSpeed for countQEPA and since your latch EdgesPerTime latches countQEPA when its write enable CLKSpeed is asserted, you only see the reset countQEPA value of 0. You should build proper synchronous logic: signal CountQEPA : integer...

Module without an EN - VHDL

vhdl,fpga

It is perfectly ok to have a component without moduleEN signal. In fact, most of the modules I have seen do not have an enable signal. However, if you plan to reset a submodule in runtime, it is more reliable to use a synchronous reset signal: process(clock, reset) begin if...

Best way to modify strings in VHDL

vhdl

Our PoC Library has quite a big collection on string operations/functions. There is a str_replace function in PoC.strings that should solve your question. There is also the PoC.utils package with non string related functions, that could also be helpful in handling strings and file I/O. A simple implementation: function replace(str...

Dynamic Arrray Size in VHDL

vhdl,ram,xilinx,vivado

You can't do that in VHDL. What kind of hardware would be generated by your code? If you don't know, the synthesizer won't either. The way to do this kind of thing is to set N to the largest value you want to support, and use size in your logic...

RAM to read/write in VHDL

vhdl

Your faulty code is: if Read='1' then -- buildin function conv_integer change the type -- from std_logic_vector to integer Data_out <= tmp_ram(conv_integer(Read_Addr)); else Data_out <= (Data_out'range => 'Z'); -- Faulty line end if; Data_out is an integer, not a std_logic_vector or derived type. Thus, it doesn't have a range (only...

How to get rid of scale factor from CORDIC

math,vhdl,fpga,rtl,cordic

Each step in the CORDIC algorithm add a scaling of cos(arctan(2^-i)) (or 1/sqrt(1+2^-2i)), so for a 4 steps CORDIC, the total scaling is: cos(arctan(2^-0))*cos(arctan(2^-1))*cos(arctan(2^-2))*cos(arctan(2^-3)) = 0.60883 If you add more iterations, it gets to 0.607252935 and some. As to what to do with that factor, it's up to you and...

Random Generator using UNIFORM

vhdl,uniform

When the purpose is to generate a random number on count1 for every rising edge of clk_i, then update the sensitivity list for the process to (assuming async reset by rst_i): rand: process (rst_i, clk_i) This will make the process reexecute at every change of rst_i or clk_i, where the...

generic adder “inference architecture”: simulation error

vhdl,xilinx,modelsim,inference

The length of U is N+1 (0 to N) Changing U <= to_unsigned(add_all,N); To U <= to_unsigned(add_all,N+1); Will prevent a length mismatch between the left hand side and right hand side of the signal assignment in architecture inference of adder_n. The passed parameter to to_unsigned specifies the length....

Others => '1' statement in Verilog

vhdl,verilog

A mix of parameter with curly braces will help in resolving (the inner curly brace will act as replication operator) Code eg: parameter MAX = 16; assign high_val = 1'b1; assign low_val = 1'b0; if ( data_track ==1'b1) my_array[MAX-1:MIN] <= {MAX{high_val}}; else my_array[MAX-1:MIN] <= {MAX{low_val}}; Here in the above code...

What does it mean whe you have: case state is when vale1 => state <= value2 in vhdl?

vhdl

As David points out, => is not an assignment symbol. It's a mapping symbol, or an association. Its use is consistent throughout VHDL - it's always used to associate something (often a name) with something else (often a value). Here, within a case statement, it's used to associate a case...

Write an inout Port in a testbench

vhdl

The sda and scl signals are std_ulogic where the "u" stands for unresolved, meaning that there can be only one driver for the signal, since there is no resolution function attached to the type to determine the signal value in case of multiple drivers. Change the type to std_logic for...

AXI4 (Lite) Narrow Burst vs. Unaligned Burst Clarification/Compatibility

vhdl,hdl

Your example is not a narrow burst, and should work. The reason narrow burst is not recommended is that it gives sub-optimal performances. Both narrow-burst and data realignement cost in area and are not recommended IMHO. However, DRE has minimal bandwidth cost, while narrow burst does. If your AXI port...

Why do I get no output at my VHDL multiplier?

vhdl,xilinx

Don't use a register with a load enable, use clock edge register. The iteration limit is a delta cycle limit in ISIM. Introducing a '1' in b you get a striking oscillator, a loop with delta cycle delays and inversion (the summing). Make num4, reg4 and reg8 clock edge driven...

VHDL Testbench over simulate

vhdl,testbed

Create a testbench. You can re-run it any time and extend it as the design grows. You can make it self-checking - compare outputs with expected values, assert when anything's wrong, and report a summary of any errors. You can use the full programming language to generate comprehensive tests, or...

Query on VHDL generics in packages

vhdl

There are some logical issues with your design. First, there's some maximum number of ports for a sub-hierarchy a design can tolerate, you have 192 'bits' of matrix inputs and outputs. Do you really believe this number should be configurable? At some point it will only fit in the very...

Multiple behaviours for single entity

testing,process,entity,vhdl

This seems like an example where using multiple architectures of the same entity would help. You have a file along the lines of: entity TestBench end TestBench; architecture SimpleTest of TestBench is -- You might have a component declaration for the UUT here begin -- Test bench code here end...

how do i initialize a std_logic_vector in VHDL?

vhdl,hdl,xilinx-ise

The ram can be initialized like: architecture Behavioral of test is type ram_type is array(4095 downto 0) of std_logic_vector(15 downto 0); signal ram : ram_type := (0 => "0010000000000100", 1 => "0001000000000101", 2 => "0011000000000110", 3 => "0111000000000001", 4 => "0000000000001100", 5 => "0000000000000011", 6 => "0000000000000000", others => (others...

Object is used but not declared?

vhdl,quartus-ii

Your entity is called uc, but the architecture b8 is of ua.

4-bit Shift register with flip flop

vhdl,flip-flop,shift-register

FF1: flipflop port map(Sin,Clock,Enable, Q(3)); This is good, it does exactly what your diagram ask. FF2: flipflop port map(Sin,Clock,Enable, Q(2)); This is not good. This connects the input D of FF2 to Sin, while the diagram connects it to Q(3). You could try doing something like: FF2: flipflop port map(Q(3),Clock,Enable,...

Logic synthesis from an arbitary piece of code

logic,vhdl,verilog,synthesis

Write your arbitrary code in VHDL, turning VHDL into gates is what a synthesis tool does. Not everything you write will be synthesisable; file handling can't be translated into gates, neither can anything that conventionally uses the heap (such as malloc, or pointers, in C, or "new" and access types...

Accessing a signal in both structural and behavioural architecture

architecture,signals,vhdl,counter

Your question while showing a declaration in one architecture for counter doesn't show a declaration for signal inSignal (it's a signal because it shows up in the sensitivity list of a process). Nor do you show the component declaration for MODULE. my_enity is end entity; architecture structural of my_entity is...

I cannot get the Xilinx uartlite IP to work

vhdl,verilog,fpga,xilinx,vivado

For posterity, Had to invert the reset and ensure all the inputs were initialized. Thank you for the helpful comments. I've attached a working simulation

VHDL average of Array through for loop

arrays,for-loop,vhdl,moving-average

It's not that efficient to add up a large number of samples each clock period like that; an adder with n inputs will consume a lot of logic resource as n starts to increase. My suggestion is to implement a memory buffer for the samples, which will have as many...

With the MESI protocol, a write hit also stalls the processor, right?

caching,architecture,multiprocessing,vhdl,mesi

Do not confuse latency with throughput. Invalidation messages will take multiple cycles to complete but you can pipeline the process. It is possible to built a pipelined cache, that is able to start the processing of new invalidation messages before the previous ones have been completed. The MESI protocol does...

Behavioral into FlipFlop Structural

process,vhdl,behavior,flip-flop

There are several things to change or improve. A structural VHDL model should describe your schematic, which you don't really do. First, why do you have shift_counter in your structural? You don't need that process. Second, you instantiate 4 of your flip-flop entity which are each 4 bits wide, while...

How to “sample” a value in VHDL?

case,vhdl,counter

Your requirement can be stated as : the process can be in two states - sampling, or not sampling, and to transition to not sampling when you sample. So you can do this with a state variable, which in this case can be a boolean - this turns your process...

Writing a Module Which Prevent Overwriting Previous Data in RAM

vhdl,ram

Since you know your write pointer is always ahead of your read, you can easily solve the problem with a code like this: tmp := ('1' & write_ptr) - read_ptr; count <= tmp(count 'range); -- Alternate syntax without tmp variable using numeric_std count <= resize(('1' & write_ptr) - read_ptr, count'length);...

Reset output after run

vhdl,bcd

In VHDL, a variable retains it's value between process re-entry. Thus, when you enter the process for the number X"000003", all your variables still have the value they add at the end of the processing of X"003565". A quick test shows that setting place to 1 at the start of...

VHDL audio sample volume control

audio,vhdl

So i find out what was my problem.. I was shifting sample vector right, but I just made it by "0" & sample(15 downto 1) but it was signed, so I had to copy MSB instead of adding just plain "0".. so answer is sample(15) & sample(15 downto 1) this...

Index value 0 to 8 could be out of prefix range 1 to 8 - VHDL

vhdl,synthesizer

It looks like you are indexing your vector with a value that has 9 values in its range (such as signal index : integer range 0 to 8), but your vector only has 8 values (so you need signal index : integer range 1 to 8). If you post the...

Power and timing reports of two different vhdl designs

performance,report,vhdl,timing,area

Digital circuit performances is measured in terms of: throughput, max operating frequency, latency, area and power. Your 3 clock cycles is the latency, which is quite easy to deduce from your VHDL since your FSM is 3 cycles from input to output. Max operating frequency and area are given by...

VHDL simulation stuck in for loop

loops,vhdl,multiplication

I'm of the opinion implementing a Montgomery multiplier in numeric_std function calls may not improve simulation as much as you'd like (while giving synthesis eligibility). The issue is the number of dynamically elaborated subprogram calls vs. their operand sizes vs. fitting in your CPU-running-Modelsim's L1/L2/L3 caches. It does do wonders...

VHDL: Convert String to Std_Logic_Vector

string,entity,vhdl,sha

You can convert a string to bits with a function like this (untested): function to_std_logic_vector(a : string) return std_logic_vector is variable ret : std_logic_vector(a'length*8-1 downto 0); begin for i in a'range loop ret(i*8+7 downto i*8) := std_logic_vector(to_unsigned(character'pos(a(i)), 8)); end loop; return ret; end function to_std_logic_vector; I don't think type string...

Process evaluated too many times

vhdl,fpga

Your problem is that you expect the sensitivity list to be observed after synthesis. The sensitivity list is strictly used for simulation. Simplified, simulators work on the assumption that they only need to re-evaluate a process when some input changes. Back when VHDL was specified, computing power to compute which...

Synthesizable multidimensional arrays in VHDL

arrays,multidimensional-array,vhdl

Your first array is not a multi dimensional array, it's a 2-times nested 1 dimensional array. Your example: type t11 is array (0 to c1_r2) of std_logic_vector(31 downto 0); type t1 is array (0 to r1) of t11; This definition is more clear: subtype t_dim1 is std_logic_vector(31 downto 0); type...

VHDL Component Port Mapping Issues

vhdl

LIBRARY ieee; USE ieee.std_logic_1164.all; ENTITY top_module IS PORT( X : IN STD_LOGIC_VECTOR(8 DOWNTO 0); CLK, LOAD: IN STD_LOGIC; LCD_RS, LCD_E : OUT STD_LOGIC; LCD_RW : OUT STD_LOGIC; LCD_ON : OUT STD_LOGIC; LCD_BLON : OUT STD_LOGIC; ); END ENTITY; ARCHITECTURE Behavior OF top_module IS component Sequence_Detector IS PORT( X :...

How to assign pins to natural type of ports in Xilinx

vhdl,fpga,xilinx

Unfortunately, the one place where you can't use type natural is top level ports, where they are mapped to physical device pins. This is because you need to connect each individual bit of the signal to its own pin, so you need some type that represents the signal as an...

Leon v3 ise-prog-prom error: impact:2070

vhdl,xilinx

This message is generated because your programmer cannot find any JTAG devices on the chain to program. It's not connected to the device you're trying to program. How to troubleshoot that specifically is hard to say, I would suggest for starters that you make sure the programmer is connected correctly...

VHDL clock divider flips between 0 and X every clk cycle

vhdl,clock,digital-design

The test bench drives the clk_out signal both from the uut instance and the clk_out_process process, and this makes the resolution function for the std_logic take effect. When both sources drive '0' then the resulting clk_out value will be '0', but if one source drives '0' and the other drives...

VHDL My timer don't work

vhdl

No one has actually answered your question: I don't understand why my outpout signal "count_sortie" is undefined in Vivado when I simulate it. To force to define my signal count_sortie, I add ":= 0" in the testbench file to simulate but "count_sortie" stays equal to '0' after the 60 seconds...

importing VHDL packages to SV from libraries other than WORK

vhdl,system-verilog,assertions

The problem seems to be indeed vendor-specific, as @toolic mentioned. For some reasons it works when I write the record elements in the lower case. The rest (signals, modules) I wrote in the same case as it was in VHDL, and it worked. Only the record elements caused problems until...

CRC Generator(sender) and Checker(receiver) - parallel implementation VHDL

vhdl,crc

There are 2 solutions: 1. Solution: You can compute the CRC over all your input data and append zeros at the end where the CRC will be inserted. The receiver calculates the CRC with the same algorithmn over all data (payload + crc). The CRC is zero if all data...

Multliplication of std_logic_vector with Floating Point

floating-point,vhdl,fixed-point

The "best" solution depends on the precision you need and resources you can afford (logic vs DSPs). Using floating point requires to convert input to floating point, loosing up to 8 bits in the process, do the multiplication and convert back. It cost a lot, too much if you ask...

VHDL modulo 2^32 addition

overflow,vhdl,sha

You are fine with unsigned(31 downto 0). The 2^MAX in the post you reference is an error and should read 2^length. The length of 31 downto 0 is 32. Think about it, 31 downto 0 can represent numbers from 0 to 2^32-1, it wouldn't make much sense if any addition...

LATCH Primitive disables outputs?

vhdl,synthesis,quartus

when WIN => deal <= '0'; dealTo <= '0'; dealToCardSlot <= "00"; if(playerWins) then greenLeds <= (others => '1'); elsif(dealerWins) then redLeds <= (others => '1'); else greenLeds <= (others => '0'); redLeds <= (others => '0'); end if; You do not assign redLeds if playerWins is false and...

Expression out of bounds on MATLAB with HDL coder app

arrays,matlab,loops,vhdl,hdl

I don't use the HDL coder, but I have a likely cause. From your code: H = 0; % Fill the first row to prepare the shift in the H matrix for i = 1 : 15 H( 1, i ) = H1(i); end Here, you define H to be...

Warning about getting “X”es for 4-valued logic VHDL

vhdl

The value of RC_Count_var becomes invalid because it has multiple conflicting drivers. In VHDL, whenever a signal is assigned in more than one process, it implies multiple drivers. These are usually not supported for synthesis and not recommended altogether. To make sure you do not have multiple drivers, simply makes...

Signal current cannot be synthesized, bad synchronous description

vhdl,fpga

The error 'bad synchronous description' usually means that you have described a register (clocked element) that does not exist in the hardware. In the case of your code, you have: if(A'event and A='1') then current <= nxt; end if; if(A'event and A='0') then current <= nxt; end if; -- etc...

How can I merge several Xilinx NGC netlists to an new netlist

vhdl,xilinx,synthesis,xilinx-ise,netlist

Internal debates on how easy it was to find the answer aside there's some cause for propagating the question and it's answer in Stackoverflow. The idea being Stackoverflow is a search resource before someone asks the same question again, striving to be a higher quality resource in general than found...

VHDL: (vcom-1136: std_logic_vector undefined)

syntax,vhdl

The use of IEEE.std_logic_1164.all is also required before the entity, like: library IEEE; use IEEE.std_logic_1164.all; entity lab2 is The first IEEE.std_logic_1164.all only applies to the package, and package body of the same package, but not to any other design objects like an entity or package, even if these happens to...