I am working with an online learning tool for VHDL, trying to make a
frequency reducer using generics.
The basic idea is: Set 'DIVIDE_BY' to a value, then get 'clk_en_out' = 1
on every 'DIVIDE_BY'th rising edge of 'clk_in' for one pulse, before
setting it back to 0.
E.g.: DIVIDE_BY = 8: wait for 7 rising edges, on the 8th, set clk_en_out
= 1, on the 9th, set it back to 0, repeat.
If 'reset' = 1, reset the cycle and start at 0.
Unfortunately, I do not know what values the tool tests, so I cannot
check why it doesn't work/on what pulse it wants me which test instance
to be 1.
I do know though that 'DIVIDE_BY' is less than 16, so an overflow of my
'counter' signal should not be the problem.
In the attached screenshot, the 'valid' line stops being 1 on rising
edge 4, yet when I twisted the code so as to have 'clk_en_a' (test
instance one; the second one is 'clk_en_b') be 1 there, it didn't
change. I assumed that trying to get 'b' to be 1 there would be
pointless, as that would make 'a' be 1 much earlier, which in theory
should set the valid line to 0 much earlier.
Can someone help me figure out why it does not work?
1 | library ieee;
|
2 | use ieee.std_logic_1164.all;
|
3 | use ieee.numeric_std.all;
|
4 |
|
5 | entity ClockEnableGenerator is
|
6 |
|
7 | generic (
|
8 | DIVIDE_BY : integer
|
9 | );
|
10 |
|
11 | port (
|
12 | clk_in : in std_logic;
|
13 | clk_en_out : out std_logic;
|
14 | reset : in std_logic
|
15 | );
|
16 | end ClockEnableGenerator;
|
17 |
|
18 | architecture rtl of ClockEnableGenerator is
|
19 |
|
20 | signal counter : unsigned(3 downto 0) := (others => '0');
|
21 | signal clk_out2 : std_logic := '0';
|
22 |
|
23 | begin
|
24 | process(clk_in)
|
25 | begin
|
26 | if(rising_edge(clk_in)) then
|
27 | counter <= counter + 1;
|
28 | if (to_integer(counter) = DIVIDE_BY) then --reset the counter at 'DIVIDE_BY'
|
29 | counter <= (others => '0');
|
30 | clk_out2 <= '1'; --set the out2 signal
|
31 | else
|
32 | clk_out2 <= '0';
|
33 | end if;
|
34 | end if;
|
35 | if reset = '1' then --reset on HIGH reset input
|
36 | counter <= (others => '0');
|
37 | clk_out2 <= '0';
|
38 | end if;
|
39 | end process;
|
40 | clk_en_out <= clk_out2; --update out to out2
|
41 | end architecture rtl;
|