Added missing files from pulse-generator-1

This commit is contained in:
gianmarcogirau 2019-10-23 11:44:04 +01:00
commit ad1b8546d7
2 changed files with 453 additions and 0 deletions

View file

@ -0,0 +1,201 @@
-- megafunction wizard: %FIFO%
-- GENERATION: STANDARD
-- VERSION: WM1.0
-- MODULE: scfifo
-- ============================================================
-- File Name: sync_fifo_1.vhd
-- Megafunction Name(s):
-- scfifo
--
-- Simulation Library Files(s):
-- altera_mf
-- ============================================================
-- ************************************************************
-- THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
--
-- 14.1.1 Build 190 01/19/2015 SJ Web Edition
-- ************************************************************
--Copyright (C) 1991-2015 Altera Corporation. All rights reserved.
--Your use of Altera Corporation's design tools, logic functions
--and other software and tools, and its AMPP partner logic
--functions, and any output files from any of the foregoing
--(including device programming or simulation files), and any
--associated documentation or information are expressly subject
--to the terms and conditions of the Altera Program License
--Subscription Agreement, the Altera Quartus II License Agreement,
--the Altera MegaCore Function License Agreement, or other
--applicable license agreement, including, without limitation,
--that your use is for the sole purpose of programming logic
--devices manufactured by Altera and sold by Altera or its
--authorized distributors. Please refer to the applicable
--agreement for further details.
LIBRARY ieee;
USE ieee.std_logic_1164.all;
LIBRARY altera_mf;
USE altera_mf.all;
use work.common_pkg.all;
entity sync_fifo_1 is
generic (
FIFO_WIDTH : natural range 1 to 32;
FIFO_DEPTH : natural range 1 to 8182);
port (
sclr : in std_logic;
clock : in std_logic;
data : in std_logic_vector (FIFO_WIDTH-1 downto 0);
rdreq : in std_logic;
wrreq : in std_logic;
empty : out std_logic;
full : out std_logic;
q : out std_logic_vector (FIFO_WIDTH-1 downto 0);
usedw : out std_logic_vector (log2(FIFO_DEPTH)-1 downto 0)
);
end sync_fifo_1;
ARCHITECTURE SYN OF sync_fifo_1 IS
SIGNAL sub_wire0 : STD_LOGIC ;
SIGNAL sub_wire1 : STD_LOGIC ;
SIGNAL sub_wire2 : STD_LOGIC_VECTOR (FIFO_WIDTH-1 DOWNTO 0);
SIGNAL sub_wire3 : STD_LOGIC_VECTOR (log2(FIFO_DEPTH)-1 DOWNTO 0);
COMPONENT scfifo
GENERIC (
add_ram_output_register : STRING;
intended_device_family : STRING;
lpm_numwords : NATURAL;
lpm_showahead : STRING;
lpm_type : STRING;
lpm_width : NATURAL;
lpm_widthu : NATURAL;
overflow_checking : STRING;
underflow_checking : STRING;
use_eab : STRING
);
PORT (
sclr : IN STD_LOGIC ;
clock : IN STD_LOGIC ;
data : IN STD_LOGIC_VECTOR (FIFO_WIDTH-1 DOWNTO 0);
rdreq : IN STD_LOGIC ;
wrreq : IN STD_LOGIC ;
empty : OUT STD_LOGIC ;
full : OUT STD_LOGIC ;
q : OUT STD_LOGIC_VECTOR (FIFO_WIDTH-1 DOWNTO 0);
usedw : OUT STD_LOGIC_VECTOR (log2(FIFO_DEPTH)-1 DOWNTO 0)
);
END COMPONENT;
BEGIN
empty <= sub_wire0;
full <= sub_wire1;
q <= sub_wire2(FIFO_WIDTH-1 DOWNTO 0);
usedw <= sub_wire3(log2(FIFO_DEPTH)-1 DOWNTO 0);
scfifo_component : scfifo
GENERIC MAP (
add_ram_output_register => "OFF",
intended_device_family => "Cyclone V",
lpm_numwords => FIFO_DEPTH,
lpm_showahead => "OFF",
lpm_type => "scfifo",
lpm_width => FIFO_WIDTH,
lpm_widthu => log2(FIFO_DEPTH-1),
overflow_checking => "ON",
underflow_checking => "ON",
use_eab => "ON"
)
PORT MAP (
sclr => sclr,
clock => clock,
data => data,
rdreq => rdreq,
wrreq => wrreq,
empty => sub_wire0,
full => sub_wire1,
q => sub_wire2,
usedw => sub_wire3
);
END SYN;
-- ============================================================
-- CNX file retrieval info
-- ============================================================
-- Retrieval info: PRIVATE: AlmostEmpty NUMERIC "0"
-- Retrieval info: PRIVATE: AlmostEmptyThr NUMERIC "-1"
-- Retrieval info: PRIVATE: AlmostFull NUMERIC "0"
-- Retrieval info: PRIVATE: AlmostFullThr NUMERIC "-1"
-- Retrieval info: PRIVATE: CLOCKS_ARE_SYNCHRONIZED NUMERIC "0"
-- Retrieval info: PRIVATE: Clock NUMERIC "0"
-- Retrieval info: PRIVATE: Depth NUMERIC "256"
-- Retrieval info: PRIVATE: Empty NUMERIC "1"
-- Retrieval info: PRIVATE: Full NUMERIC "1"
-- Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING "Cyclone V"
-- Retrieval info: PRIVATE: LE_BasedFIFO NUMERIC "0"
-- Retrieval info: PRIVATE: LegacyRREQ NUMERIC "1"
-- Retrieval info: PRIVATE: MAX_DEPTH_BY_9 NUMERIC "0"
-- Retrieval info: PRIVATE: OVERFLOW_CHECKING NUMERIC "0"
-- Retrieval info: PRIVATE: Optimize NUMERIC "0"
-- Retrieval info: PRIVATE: RAM_BLOCK_TYPE NUMERIC "0"
-- Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING "0"
-- Retrieval info: PRIVATE: UNDERFLOW_CHECKING NUMERIC "0"
-- Retrieval info: PRIVATE: UsedW NUMERIC "1"
-- Retrieval info: PRIVATE: Width NUMERIC "32"
-- Retrieval info: PRIVATE: dc_aclr NUMERIC "0"
-- Retrieval info: PRIVATE: diff_widths NUMERIC "0"
-- Retrieval info: PRIVATE: msb_usedw NUMERIC "0"
-- Retrieval info: PRIVATE: output_width NUMERIC "32"
-- Retrieval info: PRIVATE: rsEmpty NUMERIC "1"
-- Retrieval info: PRIVATE: rsFull NUMERIC "0"
-- Retrieval info: PRIVATE: rsUsedW NUMERIC "0"
-- Retrieval info: PRIVATE: sc_aclr NUMERIC "0"
-- Retrieval info: PRIVATE: sc_sclr NUMERIC "1"
-- Retrieval info: PRIVATE: wsEmpty NUMERIC "0"
-- Retrieval info: PRIVATE: wsFull NUMERIC "1"
-- Retrieval info: PRIVATE: wsUsedW NUMERIC "0"
-- Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
-- Retrieval info: CONSTANT: ADD_RAM_OUTPUT_REGISTER STRING "OFF"
-- Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING "Cyclone V"
-- Retrieval info: CONSTANT: LPM_NUMWORDS NUMERIC "256"
-- Retrieval info: CONSTANT: LPM_SHOWAHEAD STRING "OFF"
-- Retrieval info: CONSTANT: LPM_TYPE STRING "scfifo"
-- Retrieval info: CONSTANT: LPM_WIDTH NUMERIC "32"
-- Retrieval info: CONSTANT: LPM_WIDTHU NUMERIC "8"
-- Retrieval info: CONSTANT: OVERFLOW_CHECKING STRING "ON"
-- Retrieval info: CONSTANT: UNDERFLOW_CHECKING STRING "ON"
-- Retrieval info: CONSTANT: USE_EAB STRING "ON"
-- Retrieval info: USED_PORT: clock 0 0 0 0 INPUT NODEFVAL "clock"
-- Retrieval info: USED_PORT: data 0 0 32 0 INPUT NODEFVAL "data[31..0]"
-- Retrieval info: USED_PORT: empty 0 0 0 0 OUTPUT NODEFVAL "empty"
-- Retrieval info: USED_PORT: full 0 0 0 0 OUTPUT NODEFVAL "full"
-- Retrieval info: USED_PORT: q 0 0 32 0 OUTPUT NODEFVAL "q[31..0]"
-- Retrieval info: USED_PORT: rdreq 0 0 0 0 INPUT NODEFVAL "rdreq"
-- Retrieval info: USED_PORT: sclr 0 0 0 0 INPUT NODEFVAL "sclr"
-- Retrieval info: USED_PORT: usedw 0 0 8 0 OUTPUT NODEFVAL "usedw[7..0]"
-- Retrieval info: USED_PORT: wrreq 0 0 0 0 INPUT NODEFVAL "wrreq"
-- Retrieval info: CONNECT: @clock 0 0 0 0 clock 0 0 0 0
-- Retrieval info: CONNECT: @data 0 0 32 0 data 0 0 32 0
-- Retrieval info: CONNECT: @rdreq 0 0 0 0 rdreq 0 0 0 0
-- Retrieval info: CONNECT: @sclr 0 0 0 0 sclr 0 0 0 0
-- Retrieval info: CONNECT: @wrreq 0 0 0 0 wrreq 0 0 0 0
-- Retrieval info: CONNECT: empty 0 0 0 0 @empty 0 0 0 0
-- Retrieval info: CONNECT: full 0 0 0 0 @full 0 0 0 0
-- Retrieval info: CONNECT: q 0 0 32 0 @q 0 0 32 0
-- Retrieval info: CONNECT: usedw 0 0 8 0 @usedw 0 0 8 0
-- Retrieval info: GEN_FILE: TYPE_NORMAL sync_fifo_1.vhd TRUE
-- Retrieval info: GEN_FILE: TYPE_NORMAL sync_fifo_1.inc FALSE
-- Retrieval info: GEN_FILE: TYPE_NORMAL sync_fifo_1.cmp FALSE
-- Retrieval info: GEN_FILE: TYPE_NORMAL sync_fifo_1.bsf FALSE
-- Retrieval info: GEN_FILE: TYPE_NORMAL sync_fifo_inst.vhd FALSE
-- Retrieval info: LIB_FILE: altera_mf

View file

@ -0,0 +1,252 @@
-------------------------------------------------------------------------------
-- Title : queue_and_delay_1
-- Project : project independent
-------------------------------------------------------------------------------
-- File : queue_and_delay_1.vhd
-- Author : Gianmarco Girau
-- Company : Global Inkjet Systems
-- Created : 2016-05-28
-- Last update: 2019-03-22
-- SVN ID : Git
-- Standard : VHDL'93
-------------------------------------------------------------------------------
-- Description:
-- Generic component implementing a queue and delay functionality: Apply a
-- static programmable delay to the input signal. Since the block is FIFO based
-- (2048 words), the user must make sure that the number of transitions on the
-- input signal happening within the programmed delay is lower than the size of the FIFO.
-- E.g.: if the user program a delay of 2 ms, the input signal must have less
-- than 1024 pulses in 2 ms => max pulse rate = 512kHz. The block rises the
-- error bit when this condition is violated.
-------------------------------------------------------------------------------
-- altera vhdl_input_version vhdl_2008
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library work;
use work.common_pkg.all;
entity queue_and_delay_1 is
generic(
use_ext_time : boolean := false;
queue_size : natural range 16 to 8192 := 1024);
port(
rstN : in std_logic;
clk : in std_logic;
init : in std_logic;
cnt_dir : in std_logic; -- specify the direction of the cnt (0 => up, 1 => down), when use_ext_time is set to ture
delay : in std_logic_vector(31 downto 0);
ext_time : in std_logic_vector(31 downto 0);
wave_in : in std_logic;
wave_out : out std_logic;
ovf_error : out std_logic);
end queue_and_delay_1;
architecture RTL of queue_and_delay_1 is
signal toggle_in, toggle_out, time_elapsed : std_logic;
signal wave_in_d, wave_out_i, pending_trans : std_logic;
signal fifo_rd_en, fifo_empty, fifo_full : std_logic;
signal cnt_dir_i, wave_out_i_d, new_event : std_logic;
signal wave_out_ii, shf_enable : std_logic;
signal delay_line : std_logic_vector(7 downto 0);
signal local_time, local_time_d, event_time : std_logic_vector(31 downto 0);
signal internal_time : std_logic_vector(31 downto 0); -- internally generated time when ext_time not being used
signal sLocal_time_minus_delay, sLocal_time_plus_delay : signed(local_time'high + 1 downto 0);
signal TR1_Local_time_minus_delay : signed(local_time'high + 2 downto 0);
begin -- RTL
-----------------------------------------------------------------------------
-- Detect transitions in the input signal and memorize those events in a
-- FIFO, together with a timetag. This process can be seen as a representation
-- of the input signal in a compressed format.
-----------------------------------------------------------------------------
toggle_in <= '1' when wave_in /= wave_in_d else '0';
pInputEdgeDetect : process(clk)
begin
if (clk = '1' and clk'event) then
wave_in_d <= wave_in;
end if;
end process pInputEdgeDetect;
iENTRY_QUEUE : entity work.sync_fifo_1
generic map(
FIFO_WIDTH => 32,
FIFO_DEPTH => queue_size)
port map(
sclr => init,
clock => clk,
data => local_time,
rdreq => fifo_rd_en,
wrreq => toggle_in,
empty => fifo_empty,
full => fifo_full,
q => event_time,
usedw => open);
-- Check Overflow error:
pCHECK_OVF : process(rstN, clk)
begin
if (rstN = '0') then
ovf_error <= '0';
elsif (clk = '1' and clk'event) then
if (init = '1') then
ovf_error <= '0';
elsif (toggle_in = '1' and fifo_full = '1') then
ovf_error <= '1';
end if;
end if;
end process pCHECK_OVF;
-- Time reference: either use the external one or generate it locally
gTIME_REF0 : if use_ext_time = true generate
pLATCH_LOCTIME : process(clk)
begin
if (clk = '1' and clk'event) then
local_time <= ext_time;
sLocal_time_minus_delay <= resize(signed(ext_time) - signed(delay), sLocal_time_minus_delay'length);
sLocal_time_plus_delay <= resize(signed(ext_time) + signed(delay), sLocal_time_plus_delay'length);
end if;
end process pLATCH_LOCTIME;
shf_enable <= '1' when local_time /= local_time_d else '0';
--pTimeElapsed : process(cnt_dir, local_time, event_time, delay)
pTimeElapsed : process(clk)
begin
if (clk = '1' and clk'event) then
local_time_d <= local_time;
cnt_dir_i <= cnt_dir;
if (cnt_dir_i = '0') then
if sLocal_time_minus_delay >= resize(signed(event_time), sLocal_time_minus_delay'length) then
time_elapsed <= '1';
else
time_elapsed <= '0';
end if;
else
if sLocal_time_plus_delay <= resize(signed(event_time), sLocal_time_plus_delay'length) then
time_elapsed <= '1';
else
time_elapsed <= '0';
end if;
end if;
new_event <= fifo_rd_en;
end if;
end process pTimeElapsed;
end generate gTIME_REF0;
gTIME_REF1 : if use_ext_time = false generate
pGEN_LOC_REF : process(rstN, clk)
begin
if (rstN = '0') then
internal_time <= (others => '0');
local_time <= (others => '0');
TR1_Local_time_minus_delay <= (others => '0');
elsif (clk = '1' and clk'event) then
local_time <= internal_time;
--TODO check that this still works - Q&D test bench?
TR1_Local_time_minus_delay <= resize(signed(b"0" & internal_time) - signed(b"0" & delay), TR1_Local_time_minus_delay'length);
if (init = '1') then
internal_time <= (others => '0');
else
internal_time <= std_logic_vector(unsigned(internal_time) + 1);
end if;
end if;
end process pGEN_LOC_REF;
new_event <= fifo_rd_en;
time_elapsed <= '1' when TR1_Local_time_minus_delay >= signed(resize(unsigned(event_time), TR1_Local_time_minus_delay'length)) else '0';
shf_enable <= '1';
end generate gTIME_REF1;
-----------------------------------------------------------------------------
-- Delay the input signal
-----------------------------------------------------------------------------
-- Read the signal transitions recorded in the FIFO, apply the static delay
pDELAY_WAVE_GEN : process(clk)
begin
if (clk = '1' and clk'event) then
if (init = '1' or (time_elapsed = '1' and new_event = '0')) then
pending_trans <= '0';
elsif (new_event = '1') then
pending_trans <= '1';
end if;
if (pending_trans = '0' and fifo_empty = '0' and fifo_rd_en = '0' and new_event = '0') then
fifo_rd_en <= '1';
else
fifo_rd_en <= '0';
end if;
end if;
end process pDELAY_WAVE_GEN;
pGEN_OUT : process(rstN, clk)
begin
if (rstN = '0') then
wave_out_i <= '0';
elsif (clk = '1' and clk'event) then
if (init = '1') then
wave_out_i <= wave_in_d;
elsif (toggle_out = '1') then
wave_out_i <= not wave_out_i;
end if;
end if;
end process pGEN_OUT;
-- Because of the intrinsic latency with the FIFO, a shift register is used
-- to achieve small delays (< 8).
pDELAY_THROUGH_SHF : process(clk)
begin
if (clk = '1' and clk'event) then
if (shf_enable = '1') then
delay_line <= delay_line(6 downto 0) & wave_in;
end if;
end if;
end process pDELAY_THROUGH_SHF;
toggle_out <= time_elapsed and pending_trans;
-- When using the external counter, the input signal might have multiple rising and
-- falling events whitout a change a value in the counter. When this happens,
-- the pulse width is not properly replicated in the output of the delay
-- block. To make the behaviour more predictable, when using the external
-- counter, a positive edge detector is inserted at the output.
gOUT_GEN0 : if use_ext_time = false generate
wave_out_ii <= wave_out_i when unsigned(delay) >= 8 else delay_line(to_integer(unsigned(delay(2 downto 0))));
pOUT_GEN0 : process(clk)
begin
if (clk = '1' and clk'event) then
wave_out <= wave_out_ii;
end if;
end process pOUT_GEN0;
end generate gOUT_GEN0;
gOUT_GEN1 : if use_ext_time = true generate
pOUT_GEN1 : process(clk)
begin
if (clk = '1' and clk'event) then
wave_out_i_d <= wave_out_i;
wave_out <= wave_out_i and not wave_out_i_d;
end if;
end process pOUT_GEN1;
end generate gOUT_GEN1;
end RTL;