T
Torsten Landschoff
Guest
Hello World!
I am new to VHDL and after getting my first FPGA configured to blink
an LED, I have a number of questions that I did not find any answers
for. While VHDL seems to be very high level in some aspects, I still
haven't found some features that I would expect are easy to implement.
generic prescaler entity
---------------------
For controlling the on and off time of my led, I used a prescaler to
scale down the 50 MHz clock of the FPGA to microseconds. The output of
the prescaler is connected to a timer which finally toggles the led.
The prescaler has the following component declaration:
component prescaler is
generic (
divider : unsigned );
port (
clock_in : in std_logic;
clock_out : out std_logic );
end prescaler;
To get a fixed time base, I instantiate the component like this:
tick_provider : component prescaler
generic map (
divider => CONV_UNSIGNED(CLOCKHZ / 1_000_000, 6) )
port map (
clock_in => clock, clock_out => tick_us );
Now I'd like to get rid of the "6" for the length of the unsigned
parameter but I did not find any way to infer the length required for
the binary representation of some value. Is there any way to do
something like that:
constant tick_divider : positive := CLOCKHZ / 1_000_000;
...
divider => CONV_UNSIGNED(divider, divider'width)
??
Any insight appreciated.
Greetings, Torsten
I am new to VHDL and after getting my first FPGA configured to blink
an LED, I have a number of questions that I did not find any answers
for. While VHDL seems to be very high level in some aspects, I still
haven't found some features that I would expect are easy to implement.
generic prescaler entity
---------------------
For controlling the on and off time of my led, I used a prescaler to
scale down the 50 MHz clock of the FPGA to microseconds. The output of
the prescaler is connected to a timer which finally toggles the led.
The prescaler has the following component declaration:
component prescaler is
generic (
divider : unsigned );
port (
clock_in : in std_logic;
clock_out : out std_logic );
end prescaler;
To get a fixed time base, I instantiate the component like this:
tick_provider : component prescaler
generic map (
divider => CONV_UNSIGNED(CLOCKHZ / 1_000_000, 6) )
port map (
clock_in => clock, clock_out => tick_us );
Now I'd like to get rid of the "6" for the length of the unsigned
parameter but I did not find any way to infer the length required for
the binary representation of some value. Is there any way to do
something like that:
constant tick_divider : positive := CLOCKHZ / 1_000_000;
...
divider => CONV_UNSIGNED(divider, divider'width)
??
Any insight appreciated.
Greetings, Torsten