S
SneakerNet
Guest
Hi All
I have a Nios Development Board that has a crystal osciallating at 50MHz.
This is correct as I have seen the waveform and measured the frequency on an
osilloscope.
I am trying to implement USB Prototcol, for which I need a clock speed of
48MHz. How can I reduce the clock speed from 50 to 48. I have written a code
that reduces a given speed to any speed, however it has its limitations.
The code is presented below. This code is fully generic, thus user only has
to give the current clock speed and the wanted clock speed. This code works
fine as I am using this code to reduce the clock speed to 12.5MHz and 25Mhz.
However it does not work for 30Mhz and 48Mhz as the result is a fraction and
my code can't handle it.
How can i fix this. How can I generate a clock of 48Mhz given that the
crystal is 50Mhz.
Pls Advice (Aplogoies in advance as the code does not have any comments, but
it is very self-explanatory..)
Regards
=======================================================
LIBRARY IEEE;
USE IEEE.std_logic_1164.all;
USE IEEE.std_logic_arith.all;
entity slow_clk is
generic (
Clock_Speed : integer := 50000000;
New_ClkSpeed: integer := 50000000
);
port (
clock : in std_logic;
slow_clock : out std_logic
);
end entity slow_clk;
architecture behavioural of slow_clk is
constant con_StopCnt : integer := ((Clock_Speed / New_ClkSpeed) / 2);
signal main_cnt : integer range 1 to ((Clock_Speed / New_ClkSpeed) / 2);
signal sig_TmpClk : std_logic;
begin
slow_clock <= sig_TmpClk;
process is
begin
wait until rising_edge (clock);
if main_cnt = con_StopCnt then
sig_TmpClk <= not sig_TmpClk;
main_cnt <= 1;
end if;
else
main_cnt <= main_cnt + 1;
end if;
end process;
end architecture behavioural;
=======================================================
I have a Nios Development Board that has a crystal osciallating at 50MHz.
This is correct as I have seen the waveform and measured the frequency on an
osilloscope.
I am trying to implement USB Prototcol, for which I need a clock speed of
48MHz. How can I reduce the clock speed from 50 to 48. I have written a code
that reduces a given speed to any speed, however it has its limitations.
The code is presented below. This code is fully generic, thus user only has
to give the current clock speed and the wanted clock speed. This code works
fine as I am using this code to reduce the clock speed to 12.5MHz and 25Mhz.
However it does not work for 30Mhz and 48Mhz as the result is a fraction and
my code can't handle it.
How can i fix this. How can I generate a clock of 48Mhz given that the
crystal is 50Mhz.
Pls Advice (Aplogoies in advance as the code does not have any comments, but
it is very self-explanatory..)
Regards
=======================================================
LIBRARY IEEE;
USE IEEE.std_logic_1164.all;
USE IEEE.std_logic_arith.all;
entity slow_clk is
generic (
Clock_Speed : integer := 50000000;
New_ClkSpeed: integer := 50000000
);
port (
clock : in std_logic;
slow_clock : out std_logic
);
end entity slow_clk;
architecture behavioural of slow_clk is
constant con_StopCnt : integer := ((Clock_Speed / New_ClkSpeed) / 2);
signal main_cnt : integer range 1 to ((Clock_Speed / New_ClkSpeed) / 2);
signal sig_TmpClk : std_logic;
begin
slow_clock <= sig_TmpClk;
process is
begin
wait until rising_edge (clock);
if main_cnt = con_StopCnt then
sig_TmpClk <= not sig_TmpClk;
main_cnt <= 1;
end if;
else
main_cnt <= main_cnt + 1;
end if;
end process;
end architecture behavioural;
=======================================================