shaiko
Advanced Member level 5
- Joined
- Aug 20, 2011
- Messages
- 2,644
- Helped
- 303
- Reputation
- 608
- Reaction score
- 297
- Trophy points
- 1,363
- Activity points
- 18,302
I described a delay generator based on a shift register.
CLOCK - Global clock.
RESET - Global reset.
"INPUT" - Input signal to apply the delay on.
"DELAY_DURATION" - Desired time (in nano seconds) to delay the input.
"OUTPUT" - The "INPUT" signal delayed by "DELAY_DURATION" nanoseconds.
"FREQUENCY" - The frequency of the global clock that drives the design.
My code:
At my Modelsim TB I drive DELAY_DURATION port with the value: "000000010011100010000" (decimal 10000) and press the run key.
Simulation terminates immediately with a fatal error pointing to the line I marked in red:
Strange enough, when I omit the erroneous line and rerun the simulation
"required_number_of_cycles" becomes "000000000000111110100" (500 decimal) as it should!
Any ideas?
CLOCK - Global clock.
RESET - Global reset.
"INPUT" - Input signal to apply the delay on.
"DELAY_DURATION" - Desired time (in nano seconds) to delay the input.
"OUTPUT" - The "INPUT" signal delayed by "DELAY_DURATION" nanoseconds.
"FREQUENCY" - The frequency of the global clock that drives the design.
My code:
Code:
library ieee ;
use ieee.std_logic_1164.all ;
use ieee.numeric_std.all ;
library work ;
use work.package_functions_general.all ;
entity delay_generator is
generic
(
FREQUENCY : positive := 50000000
) ;
port
(
CLOCK : in std_logic ;
INPUT : in std_logic ;
RESET : in std_logic ;
DELAY_DURATION : in unsigned ;
OUTPUT : out std_logic
);
end entity delay_generator ;
architecture synthesizable_generator_delay of delay_generator is
constant width_unsigned_frequency : positive := log_2_decimal ( FREQUENCY ) ;
constant unsigned_frequency : unsigned := to_unsigned ( FREQUENCY , width_unsigned_frequency ) ;
constant maximum_possible_delay_duration : unsigned ( DELAY_DURATION ' range ) := ( others => '1' ) ;
constant maximum_possible_cycles_to_delay : unsigned := cylces_from_time ( maximum_possible_delay_duration , "ns" , unsigned_frequency ) ;
constant shift_register_width : positive := to_integer ( maximum_possible_cycles_to_delay ) ;
signal shift_register : unsigned ( shift_register_width - 1 downto 0 ) := ( others => '0' ) ;
signal required_number_of_cycles : unsigned ( 31 downto 0 ) := ( others => '0' ) ;
begin
required_number_of_cycles <= cylces_from_time ( DELAY_DURATION , "ns" , unsigned_frequency ) ;
[COLOR="#FF0000"]OUTPUT <= shift_register ( to_integer ( required_number_of_cycles ) ) ;[/COLOR]
shifting_left : process ( RESET , CLOCK ) is
begin
if RESET = '1' then
shift_register <= ( others => '0' ) ;
elsif rising_edge ( CLOCK ) then
shift_register <= shift_register ( shift_register ' high - 1 downto 0 ) & INPUT ;
end if ;
end process shifting_left ;
end architecture synthesizable_generator_delay ;
At my Modelsim TB I drive DELAY_DURATION port with the value: "000000010011100010000" (decimal 10000) and press the run key.
Simulation terminates immediately with a fatal error pointing to the line I marked in red:
This suggests that the signal "required_number_of_cycles" is supposedly 2097151 . Looking at the waveform window indeed shows that the signal is given this value (when it should've been given "000000000000111110100" (500 decimal).** Fatal: (vsim-3734) Index value 2097151 is out of range 104856 downto 0.
Strange enough, when I omit the erroneous line and rerun the simulation
Code:
--OUTPUT <= shift_register ( to_integer ( required_number_of_cycles ) ) ;
Any ideas?