EmbDev.net

Forum: FPGA, VHDL & Verilog Variable clock with prescaler?


von Mohamed H. (Company: no) (mo7amed98)


Rate this post
useful
not useful
I wanted to make a vco to get 8 different values of frequencies 
dependent on controlfreq input and I made it successfully but for now I 
want to add another single bit input so when its value is '1' I divide 
each frequency of those by 1000 or in other words to get frequency by 
hertz instead of kilo hertz .. here's my code
1
library IEEE;
2
use IEEE.STD_LOGIC_1164.ALL;
3
use IEEE.STD_LOGIC_unsigned.ALL;
4
5
entity VCO is
6
port (
7
controlfreq: in std_logic_vector(2 downto 0);
8
clock_out: out std_logic);
9
end VCO;
10
11
architecture bhv of VCO is
12
signal clk : std_logic;
13
signal div : std_logic_vector(7 downto 0):=(others=>'0');
14
15
begin
16
17
process(clk)
18
begin
19
if(clk'event and clk='1') then
20
div <= div + '1';
21
end if;
22
end process;
23
24
process(clk)
25
begin
26
if (controlfreq <= "000") then 
27
clock_out <= div(0);
28
elsif (controlfreq <= "001") then 
29
clock_out <= div(1);
30
elsif (controlfreq <= "010") then 
31
clock_out <= div(2);
32
elsif (controlfreq <= "011") then 
33
clock_out <= div(3);
34
elsif (controlfreq <= "100") then 
35
clock_out <= div(4);
36
elsif (controlfreq <= "101") then 
37
clock_out <= div(5);
38
elsif (controlfreq <= "110") then 
39
clock_out <= div(6);
40
elsif (controlfreq <= "111") then 
41
clock_out <= div(7);
42
end if;
43
end process;
44
45
end bhv;

: Edited by Moderator
von Duke Scarring (Guest)


Rate this post
useful
not useful
Mohamed H. wrote:
> want to add another single bit input so when its value is '1' I divide
> each frequency of those by 1000 or in other words to get frequency by
> hertz instead of kilo hertz .. here's my code
I don't see a real question (mark) here.
If you need other frequencies than you need another prescaler.

> use IEEE.STD_LOGIC_unsigned.ALL;
Don't use this, use ieee.numeric_std.all instead with all proper type 
definitions.

> if(clk'event and clk='1') then
rising_edge(clk) is more reader friendly (and has some small advantages 
in simulation).

> if (controlfreq <= "000") then
> clock_out <= div(0);
> elsif (controlfreq <= "001") then
> clock_out <= div(1);
> elsif (controlfreq <= "010") then
> clock_out <= div(2);
> elsif (controlfreq <= "011") then
> clock_out <= div(3);
> elsif (controlfreq <= "100") then
> clock_out <= div(4);
> elsif (controlfreq <= "101") then
> clock_out <= div(5);
> elsif (controlfreq <= "110") then
> clock_out <= div(6);
> elsif (controlfreq <= "111") then
> clock_out <= div(7);
I suggest to use the case-construct here. See:
https://en.wikibooks.org/wiki/Programmable_Logic/VHDL_Sequential_Statement
https://en.wikibooks.org/wiki/VHDL_for_FPGA_Design/Multiplexer

Duke

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


Rate this post
useful
not useful
Mohamed H. wrote:
> for now I want to add another single bit input so when its value is '1'
> I divide each frequency of those by 1000
You will need an additional prescaler here:
1
signal prescaler : integer range 0 to 999 := 0;
2
:
3
:
4
  if(clk'event and clk='1') then
5
    if slowdown = '1' then  -- slowdown mode
6
        if prescaler = 999 then
7
           prescaler <= 0;
8
           div <= div + '1';
9
        else 
10
           prescaler <= prescaler+1;
11
        end if;           
12
    else                   -- traditional mode
13
        div <= div + '1';
14
    end if;
15
  end if;
16
:
17
:

Mohamed H. wrote:
> here's my code
Pls use the [vhdl] tags as described above every text input box.

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.