EmbDev.net

Forum: FPGA, VHDL & Verilog Signal clock generator


von Filip (laugher)


Attached files:

Rate this post
useful
not useful
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;

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
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.

: Edited by Moderator
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.