Signal clock generator

OP #7320909

Hello everyone, I am new to VHDL so basically I need help with vhdl code that I have to do till friday for college. I'm working in Xilinx ISE (dev sys is E2LP)

"Design a clock signal generator circuit. Using switches on the development system, the frequency of the clock signal should be able to be selected as: 3 Hz, 6 Hz, 12 Hz, 24 Hz, 100 Hz, 1000 Hz and 2000 Hz."

So I have been working on solution but I'm not sure if it is going to work on E2LP. Any help is going to be appreciated

1
library IEEE;
2
use IEEE.STD_LOGIC_1164.ALL;
3

4
entity clock_generator is
5
    Port ( clk_sel : in STD_LOGIC_VECTOR(3 downto 0);
6
           clk : out STD_LOGIC);
7
end clock_generator;
8

9
architecture Behavioral of clock_generator is
10
    signal clk_int : std_logic := '0';
11
    signal clk_freq : integer := 3;
12
begin
13
    clk_gen: process(clk_sel)
14
    begin
15
        case clk_sel is
16
            when "0000" => clk_freq := 3;
17
            when "0001" => clk_freq := 6;
18
            when "0010" => clk_freq := 12;
19
            when "0011" => clk_freq := 24;
20
            when "0100" => clk_freq := 100;
21
            when "0101" => clk_freq := 1000;
22
            when "0110" => clk_freq := 2000;
23
            when others => null;
24
        end case;
25
    end process;
26

27
    clk <= not clk_int;
28
    clk_int_gen: process(clk)
29
    begin
30
        clk_int <= not clk_int after (1000000/clk_freq) ns;
31
    end process;
32
end Behavioral;
Attached files:
Moderator (Company: Titel) #7321982

Filip wrote:

not sure if it is going to work on E2LP

Give it a try. Start the synthesizer and look what happens.

But to go into future: it won't work. Simply because inside the FPGA isn't anything like a "variable drlay" like that you want to get with "after (1000000/clk_freq) ns;"

In your FPGA you will have to use flip-flops and logic (in the LUTs) to create a counter that counts some clock-cycles and toggles a flag after reaching a desired prescaler value.

With other words: why reenventing the wheel? Simply look how others did the job and try to understand what they did.

Reply

A question of your own? This thread is over 3 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.