Hello,
I am a newbie to VHDL programming and want to test my FPGA board with
a code which lights a LED every second. To do this I need a VHDL code
for 1 Hz signal generator. Unfortunately, I cannot find such in Web.
Also I am not experienced in VHDL programming and not sure how to
write such a code. If you have any similar code could you put it in
this thread, please or give me some idea how to write this. I also
wonder - is it necessary to use a clock for such signal generator?
|
|
0
|
|
|
|
Reply
|
vladimir.v.korostelev (17)
|
1/8/2008 7:31:59 PM |
|
Vagant schrieb:
> I am a newbie to VHDL programming and want to test my FPGA board with
> a code which lights a LED every second. To do this I need a VHDL code
> for 1 Hz signal generator. Unfortunately, I cannot find such in Web.
Take your clock (which is running at X MHz) and divide it by X.
process(reset_n,clk)
variable cnt : integer;
begin
if (reset_n='0') then
clk_out<='0';
cnt:=0;
elsif rising_edge(clk) then
if (cnt=divider_half-1) then
clk_out<=NOT(clk_out);
cnt:=0;
else
cnt:=cnt+1;
end if;
end if;
end process;
Note that divider_half is X/2.
The code is not tested - just written in the mail program.
Ralf
|
|
0
|
|
|
|
Reply
|
Ralf
|
1/8/2008 8:22:30 PM
|
|
On Jan 8, 10:22=A0pm, Ralf Hildebrandt <Ralf-Hildebra...@gmx.de> wrote:
> Vagant schrieb:
>
> > I am a newbie to VHDL programming and want to test my FPGA board with
> > a code which lights a LED every second. To do this I need a VHDL code
> > for 1 Hz signal generator. Unfortunately, I cannot find such in Web.
>
> Take your clock (which is running at X MHz) and divide it by X.
>
> process(reset_n,clk)
> variable =A0 cnt =A0 : integer;
> begin
> if (reset_n=3D'0') then
> =A0 =A0 =A0 =A0 clk_out<=3D'0';
> =A0 =A0 =A0 =A0 cnt:=3D0;
> elsif rising_edge(clk) then
> =A0 =A0 =A0 =A0 if (cnt=3Ddivider_half-1) then
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 clk_out<=3DNOT(clk_out);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 cnt:=3D0;
> =A0 =A0 =A0 =A0 else
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 cnt:=3Dcnt+1;
> =A0 =A0 =A0 =A0 end if;
> end if;
> end process;
>
> Note that divider_half is X/2.
>
> The code is not tested - just written in the mail program.
>
> Ralf
Thank you. I just wonder where I could get a complete listing (which
includes 'entity' part)?
|
|
0
|
|
|
|
Reply
|
Vagant
|
1/8/2008 8:36:46 PM
|
|
Vagant wrote:
> Thank you. I just wonder where I could get a complete listing (which
> includes 'entity' part)?
Do you have a text editor?
Didn't the board come with some examples?
Here's a related example including an entity:
http://home.comcast.net/~mike_treseler/count_enable.vhd
-- Mike Treseler
|
|
0
|
|
|
|
Reply
|
Mike
|
1/8/2008 9:12:10 PM
|
|
On Jan 8, 10:22=A0pm, Ralf Hildebrandt <Ralf-Hildebra...@gmx.de> wrote:
>
> Take your clock (which is running at X MHz) and divide it by X.
>
I guess it should be divided by X*10^6 to get 1 Hz, isn't it?
|
|
0
|
|
|
|
Reply
|
Vagant
|
1/8/2008 9:57:05 PM
|
|
On Jan 8, 11:12=A0pm, Mike Treseler <mike_trese...@comcast.net> wrote:
> Vagant wrote:
> > Thank you. I just wonder where I could get a complete listing (which
> > includes 'entity' part)?
>
> Do you have a text editor?
> Didn't the board come with some examples?
>
> Here's a related example including an entity:http://home.comcast.net/~mike=
_treseler/count_enable.vhd
>
> =A0 =A0 =A0 =A0 -- Mike Treseler
No, it's not what I am asking about.
|
|
0
|
|
|
|
Reply
|
Vagant
|
1/9/2008 5:53:02 AM
|
|
On Jan 8, 10:22=A0pm, Ralf Hildebrandt <Ralf-Hildebra...@gmx.de> wrote:
> Vagant schrieb:
>
> > I am a newbie to VHDL programming and want to test my FPGA board with
> > a code which lights a LED every second. To do this I need a VHDL code
> > for 1 Hz signal generator. Unfortunately, I cannot find such in Web.
>
> Take your clock (which is running at X MHz) and divide it by X.
>
> process(reset_n,clk)
> variable =A0 cnt =A0 : integer;
> begin
> if (reset_n=3D'0') then
> =A0 =A0 =A0 =A0 clk_out<=3D'0';
> =A0 =A0 =A0 =A0 cnt:=3D0;
> elsif rising_edge(clk) then
> =A0 =A0 =A0 =A0 if (cnt=3Ddivider_half-1) then
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 clk_out<=3DNOT(clk_out);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 cnt:=3D0;
> =A0 =A0 =A0 =A0 else
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 cnt:=3Dcnt+1;
> =A0 =A0 =A0 =A0 end if;
> end if;
> end process;
>
> Note that divider_half is X/2.
>
> The code is not tested - just written in the mail program.
>
> Ralf
However the syntax check gives an error message:
Parameter clk_out of mode out can not be associated with a formal
parameter of mode in.
for the line:
clk_out<=3DNOT(clk_out);
|
|
0
|
|
|
|
Reply
|
Vagant
|
1/9/2008 6:23:30 AM
|
|
On Jan 9, 2:57 am, Vagant <vladimir.v.koroste...@rambler.ru> wrote:
> On Jan 8, 10:22 pm, Ralf Hildebrandt <Ralf-Hildebra...@gmx.de> wrote:
>
> > Take your clock (which is running at X MHz) and divide it by X.
>
> I guess it should be divided by X*10^6 to get 1 Hz, isn't it?
Not really. You're already using your clk to increment cnt. You just
need to divide it by X.
For instance, if you had a clock running at 50 MHz, cnt would
increment 50,000 times a second. Divide it by 50 and you're left with
a cnt that increments a thousand times a second - a 1 MHz clock.
|
|
0
|
|
|
|
Reply
|
neeraj2608
|
1/9/2008 6:23:38 AM
|
|
On Jan 9, 8:23=A0am, neeraj2...@gmail.com wrote:
> On Jan 9, 2:57 am, Vagant <vladimir.v.koroste...@rambler.ru> wrote:
>
> > On Jan 8, 10:22 pm, Ralf Hildebrandt <Ralf-Hildebra...@gmx.de> wrote:
>
> > > Take your clock (which is running at X MHz) and divide it by X.
>
> > I guess it should be divided by X*10^6 to get 1 Hz, isn't it?
>
> Not really. You're already using your clk to increment cnt. You just
> need to divide it by X.
>
> For instance, if you had a clock running at 50 MHz, cnt would
> increment 50,000 times a second. Divide it by 50 and you're left with
> a cnt that increments a thousand times a second - a 1 MHz clock.
Well, but I need 1 Hz clock not 1 MHz.
|
|
0
|
|
|
|
Reply
|
Vagant
|
1/9/2008 6:25:12 AM
|
|
On Jan 9, 11:23=A0am, Vagant <vladimir.v.koroste...@rambler.ru> wrote:
> On Jan 8, 10:22=A0pm, Ralf Hildebrandt <Ralf-Hildebra...@gmx.de> wrote:
>
>
>
>
>
> > Vagant schrieb:
>
> > > I am a newbie to VHDL programming and want to test my FPGA board with
> > > a code which lights a LED every second. To do this I need a VHDL code
> > > for 1 Hz signal generator. Unfortunately, I cannot find such in Web.
>
> > Take your clock (which is running at X MHz) and divide it by X.
>
> > process(reset_n,clk)
> > variable =A0 cnt =A0 : integer;
> > begin
> > if (reset_n=3D'0') then
> > =A0 =A0 =A0 =A0 clk_out<=3D'0';
> > =A0 =A0 =A0 =A0 cnt:=3D0;
> > elsif rising_edge(clk) then
> > =A0 =A0 =A0 =A0 if (cnt=3Ddivider_half-1) then
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 clk_out<=3DNOT(clk_out);
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 cnt:=3D0;
> > =A0 =A0 =A0 =A0 else
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 cnt:=3Dcnt+1;
> > =A0 =A0 =A0 =A0 end if;
> > end if;
> > end process;
>
> > Note that divider_half is X/2.
>
> > The code is not tested - just written in the mail program.
>
> > Ralf
>
> However the syntax check gives an error message:
>
> Parameter clk_out of mode out can not be associated with a formal
> parameter of mode in.
>
> for the line:
> clk_out<=3DNOT(clk_out);- Hide quoted text -
>
> - Show quoted text -
You can not have a port of mode "out" being assigned to another
signal. That makes sense if you think in terms of hardware, doesn't
it? :)
I can give you two solutions:
1. Change the mode of clk_out to "inout."
2. A better solution would be to declare an internal signal and assign
it to clk_out after the process. For example,
signal clk_sig : std_logic;
process(reset_n,clk)
variable cnt : integer;
begin
if (reset_n=3D'0') then
clk_sig<=3D'0';
cnt:=3D0;
elsif rising_edge(clk) then
if (cnt=3Ddivider_half-1) then
clk_sig<=3DNOT(clk_sig);
cnt:=3D0;
else
cnt:=3Dcnt+1;
end if;
end if;
end process;
clk_out <=3D clk_sig;
|
|
0
|
|
|
|
Reply
|
neeraj2608
|
1/9/2008 6:29:16 AM
|
|
On Jan 9, 11:25=A0am, Vagant <vladimir.v.koroste...@rambler.ru> wrote:
> On Jan 9, 8:23=A0am, neeraj2...@gmail.com wrote:
>
> > On Jan 9, 2:57 am, Vagant <vladimir.v.koroste...@rambler.ru> wrote:
>
> > > On Jan 8, 10:22 pm, Ralf Hildebrandt <Ralf-Hildebra...@gmx.de> wrote:
>
> > > > Take your clock (which is running at X MHz) and divide it by X.
>
> > > I guess it should be divided by X*10^6 to get 1 Hz, isn't it?
>
> > Not really. You're already using your clk to increment cnt. You just
> > need to divide it by X.
>
> > For instance, if you had a clock running at 50 MHz, cnt would
> > increment 50,000 times a second. Divide it by 50 and you're left with
> > a cnt that increments a thousand times a second - a 1 MHz clock.
>
> Well, but I need 1 Hz clock not 1 MHz.
Whoops, my mistake. The line should have been:
Divide it by 50 and you're left with
a cnt that increments a thousand times a second - a 1 Hz clock.
Sorry.
|
|
0
|
|
|
|
Reply
|
neeraj2608
|
1/9/2008 6:30:32 AM
|
|
On Jan 9, 11:30=A0am, neeraj2...@gmail.com wrote:
> On Jan 9, 11:25=A0am, Vagant <vladimir.v.koroste...@rambler.ru> wrote:
>
>
>
>
>
> > On Jan 9, 8:23=A0am, neeraj2...@gmail.com wrote:
>
> > > On Jan 9, 2:57 am, Vagant <vladimir.v.koroste...@rambler.ru> wrote:
>
> > > > On Jan 8, 10:22 pm, Ralf Hildebrandt <Ralf-Hildebra...@gmx.de> wrote=
:
>
> > > > > Take your clock (which is running at X MHz) and divide it by X.
>
> > > > I guess it should be divided by X*10^6 to get 1 Hz, isn't it?
>
> > > Not really. You're already using your clk to increment cnt. You just
> > > need to divide it by X.
>
> > > For instance, if you had a clock running at 50 MHz, cnt would
> > > increment 50,000 times a second. Divide it by 50 and you're left with
> > > a cnt that increments a thousand times a second - a 1 MHz clock.
>
> > Well, but I need 1 Hz clock not 1 MHz.
>
> Whoops, my mistake. The line should have been:
> Divide it by 50 and you're left with
> a cnt that increments a thousand times a second - a 1 Hz clock.
>
> Sorry.- Hide quoted text -
>
> - Show quoted text -
No, on second thought, you're right. For a 50 MHz clock, you would
count to 24999 before toggling clk_out.
|
|
0
|
|
|
|
Reply
|
neeraj2608
|
1/9/2008 6:32:48 AM
|
|
On Jan 9, 8:32=A0am, neeraj2...@gmail.com wrote:
> On Jan 9, 11:30=A0am, neeraj2...@gmail.com wrote:
>
>
>
>
>
> > On Jan 9, 11:25=A0am, Vagant <vladimir.v.koroste...@rambler.ru> wrote:
>
> > > On Jan 9, 8:23=A0am, neeraj2...@gmail.com wrote:
>
> > > > On Jan 9, 2:57 am, Vagant <vladimir.v.koroste...@rambler.ru> wrote:
>
> > > > > On Jan 8, 10:22 pm, Ralf Hildebrandt <Ralf-Hildebra...@gmx.de> wro=
te:
>
> > > > > > Take your clock (which is running at X MHz) and divide it by X.
>
> > > > > I guess it should be divided by X*10^6 to get 1 Hz, isn't it?
>
> > > > Not really. You're already using your clk to increment cnt. You just=
> > > > need to divide it by X.
>
> > > > For instance, if you had a clock running at 50 MHz, cnt would
> > > > increment 50,000 times a second. Divide it by 50 and you're left wit=
h
> > > > a cnt that increments a thousand times a second - a 1 MHz clock.
>
> > > Well, but I need 1 Hz clock not 1 MHz.
>
> > Whoops, my mistake. The line should have been:
> > Divide it by 50 and you're left with
> > a cnt that increments a thousand times a second - a 1 Hz clock.
>
> > Sorry.- Hide quoted text -
>
> > - Show quoted text -
>
> No, on second thought, you're right. For a 50 MHz clock, you would
> count to 24999 before toggling clk_out.- Hide quoted text -
>
> - Show quoted text -
Thank you. I have corrected the code and now it looks like this (is
this correct?):
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity sig_gen is
Port (clk : in STD_LOGIC;
reset_n : in STD_LOGIC;
clk_out : out STD_LOGIC);
end entity sig_gen;
architecture Behavioral of sig_gen is
signal clk_sig : std_logic;
begin
process(reset_n,clk)
variable cnt : integer;
begin
if (reset_n=3D'0') then
clk_sig<=3D'0';
cnt:=3D0;
elsif rising_edge(clk) then
if (cnt=3D2499-1) then
clk_sig<=3DNOT(clk_sig);
cnt:=3D0;
else
cnt:=3Dcnt+1;
end if;
end if;
end process;
clk_out <=3D clk_sig;
end Behavioral;
|
|
0
|
|
|
|
Reply
|
Vagant
|
1/9/2008 10:43:32 AM
|
|
On Jan 9, 3:43 pm, Vagant <vladimir.v.koroste...@rambler.ru> wrote:
> On Jan 9, 8:32 am, neeraj2...@gmail.com wrote:
>
>
>
> > On Jan 9, 11:30 am, neeraj2...@gmail.com wrote:
>
> > > On Jan 9, 11:25 am, Vagant <vladimir.v.koroste...@rambler.ru> wrote:
>
> > > > On Jan 9, 8:23 am, neeraj2...@gmail.com wrote:
>
> > > > > On Jan 9, 2:57 am, Vagant <vladimir.v.koroste...@rambler.ru> wrote:
>
> > > > > > On Jan 8, 10:22 pm, Ralf Hildebrandt <Ralf-Hildebra...@gmx.de> wrote:
>
> > > > > > > Take your clock (which is running at X MHz) and divide it by X.
>
> > > > > > I guess it should be divided by X*10^6 to get 1 Hz, isn't it?
>
> > > > > Not really. You're already using your clk to increment cnt. You just
> > > > > need to divide it by X.
>
> > > > > For instance, if you had a clock running at 50 MHz, cnt would
> > > > > increment 50,000 times a second. Divide it by 50 and you're left with
> > > > > a cnt that increments a thousand times a second - a 1 MHz clock.
>
> > > > Well, but I need 1 Hz clock not 1 MHz.
>
> > > Whoops, my mistake. The line should have been:
> > > Divide it by 50 and you're left with
> > > a cnt that increments a thousand times a second - a 1 Hz clock.
>
> > > Sorry.- Hide quoted text -
>
> > > - Show quoted text -
>
> > No, on second thought, you're right. For a 50 MHz clock, you would
> > count to 24999 before toggling clk_out.- Hide quoted text -
>
> > - Show quoted text -
>
> Thank you. I have corrected the code and now it looks like this (is
> this correct?):
>
> library IEEE;
> use IEEE.STD_LOGIC_1164.ALL;
> use IEEE.STD_LOGIC_ARITH.ALL;
> use IEEE.STD_LOGIC_UNSIGNED.ALL;
>
> entity sig_gen is
> Port (clk : in STD_LOGIC;
> reset_n : in STD_LOGIC;
> clk_out : out STD_LOGIC);
> end entity sig_gen;
>
> architecture Behavioral of sig_gen is
> signal clk_sig : std_logic;
> begin
> process(reset_n,clk)
> variable cnt : integer;
> begin
> if (reset_n='0') then
> clk_sig<='0';
> cnt:=0;
> elsif rising_edge(clk) then
> if (cnt=2499-1) then
> clk_sig<=NOT(clk_sig);
> cnt:=0;
> else
> cnt:=cnt+1;
> end if;
> end if;
> end process;
>
> clk_out <= clk_sig;
>
> end Behavioral;
Have you checked that your board provides you with a 50 MHz clock? I
quoted 50 just as an example. :)
If yes, then you should count from 0 to 24999 (i.e., 25000 50 MHz
clocks or half a second) and toggle clk_sig. Then you reset the count
to 0 and start again. At the end of the next 25000 50 MHz clocks (or
another half a second) you toggle clk_sig again and so on.
So, your code should be:
> if (cnt=25000-1) then
Of course, (25000 - 1) is 24999. So you could also write:
> if (cnt=24999) then
I hope the calculation is clear. To give another example, for a 10 MHz
clock, you count from 0 to 4999 (5000 10 MHz clocks).
While coding, you could also declare the count limit as a constant.
constant HALF_FREQ : INTEGER := 25000;
So,
> if (cnt=HALF_FREQ-1) then
That way, if you decided to change the clock later on, you would only
have to change the constant at one place. This could be helpful if you
write a really large piece of code.
|
|
0
|
|
|
|
Reply
|
Ponceludon
|
1/9/2008 11:25:31 AM
|
|
Vagant a �crit :
> On Jan 8, 11:12 pm, Mike Treseler <mike_trese...@comcast.net> wrote:
>> Vagant wrote:
>>> Thank you. I just wonder where I could get a complete listing (which
>>> includes 'entity' part)?
>> Do you have a text editor?
>> Didn't the board come with some examples?
>>
>> Here's a related example including an entity:http://home.comcast.net/~mike_treseler/count_enable.vhd
>>
>> -- Mike Treseler
>
> No, it's not what I am asking about.
The response of Mike, if I understood it rightly, means that a so simple
question can be answered by yourself if you take the time to read the notice of
your board, or if any of a VHDL book for beginner.
Do not expect the forum's guys to do your project at your place : it will not
learn you anything.
That I read below let me out of mind...
50Mhz is 50 000 000 period per second. So you have to divide it by 50 000 000 go
get 1Hz, or to count two times from 0 to 24 999 999.
I hope the error was to see if someone follows ?
:-)
Pascal
|
|
0
|
|
|
|
Reply
|
Pascal
|
1/9/2008 2:14:29 PM
|
|
On Jan 9, 4:14=A0pm, Pascal Peyremorte
<p.peyremorte.remove_t...@free.fr> wrote:
>
> The response of Mike, if I understood it rightly, means that a so simple
> question can be answered by yourself if you take the time to read the noti=
ce of
> your board, or if any of a VHDL book for beginner.
>
> Do not expect the forum's guys to do your project at your place : it will =
not
> learn you anything.
>
>
> Pascal
Well, a reply with a long code which was not asked would not be
helpful either and if one does not like question then just reply
nothing.
|
|
0
|
|
|
|
Reply
|
Vagant
|
1/9/2008 2:26:40 PM
|
|
>Well, a reply with a long code which was not asked would not be
>helpful either and if one does not like question then just reply
>nothing.
As I understand it, you have a PhD in nuclear magnetic resonance
(Manchester 2004), so FPGAs and the associated HDLs are not beyond
your abilities.
But, as I said earlier, you need to learn some basic electronics and
logic before you can handle these more recent developments, because
most of those working with HDLs have that experience of older
technologies and what you read will almost always assume that.
Did you think it was going to be easy?
Mike
|
|
0
|
|
|
|
Reply
|
MikeShepherd564
|
1/9/2008 2:38:23 PM
|
|
>Well, a reply with a long code which was not asked would not be
>helpful either and if one does not like question then just reply
>nothing.
off-topic : Esli Vy esche v Manchestere, u nas vecherinka russkaya v
gorode Bolton v subotu (12.01.2008) ot 18:00 na pabe "Balmoral" (v
tsentre). Stoit vsego 60 funtov, tak, esli pridut N chelovek, prosyat
c kazhdogo 60/N funtov. Mike
|
|
0
|
|
|
|
Reply
|
MikeShepherd564
|
1/9/2008 2:56:36 PM
|
|
On Jan 9, 4:56=A0pm, MikeShepherd...@btinternet.com wrote:
> >Well, a reply with a long code which was not asked would not be
> >helpful either and if one does not like question then just reply
> >nothing.
>
> off-topic : =A0Esli Vy esche v Manchestere, u nas vecherinka russkaya v
> gorode Bolton v subotu (12.01.2008) ot 18:00 na pabe "Balmoral" (v
> tsentre). =A0Stoit vsego 60 funtov, tak, esli pridut N chelovek, prosyat
> c kazhdogo 60/N funtov. =A0Mike
Spasibo :), no ia ne v manchestere uje s 2004
|
|
0
|
|
|
|
Reply
|
Vagant
|
1/9/2008 3:27:31 PM
|
|
On Jan 9, 4:38=A0pm, MikeShepherd...@btinternet.com wrote:
> >Well, a reply with a long code which was not asked would not be
> >helpful either and if one does not like question then just reply
> >nothing.
>
> As I understand it, you have a PhD in nuclear magnetic resonance
> (Manchester 2004), so FPGAs and the associated HDLs are not beyond
> your abilities.
>
> But, as I said earlier, you need to learn some basic electronics and
> logic before you can handle these more recent developments, because
> most of those working with HDLs have that experience of older
> technologies and what you read will almost always assume that.
>
> Did you think it was going to be easy?
>
> Mike
It goes allright with me and I am familiar with electronics. I got
Diploma in radiophysics and electronics (undegraduate study) but FPGA
and VHDL are something really new. So sometimes I get stuck and then i
ask questions here.
|
|
0
|
|
|
|
Reply
|
Vagant
|
1/9/2008 3:32:26 PM
|
|
Hurrah! It works! I have used 50MHz clock as input and my 1Hz output
signal was connected to a LED. So it flashes every second now! Thanks
to all for encouragement, criticism, real help and suggestions!
P.S. Final version of the VHDL code used is:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity sig_gen is
Port (clk : in STD_LOGIC;
reset_n : in STD_LOGIC;
clk_out : out STD_LOGIC);
end entity sig_gen;
architecture Behavioral of sig_gen is
signal clk_sig : std_logic;
begin
process(reset_n,clk)
variable cnt : integer;
begin
if (reset_n='0') then
clk_sig<='0';
cnt:=0;
elsif rising_edge(clk) then
if (cnt=24999999) then
clk_sig<=NOT(clk_sig);
cnt:=0;
else
cnt:=cnt+1;
end if;
end if;
end process;
clk_out <= clk_sig;
end Behavioral;
|
|
0
|
|
|
|
Reply
|
Vagant
|
1/9/2008 5:38:28 PM
|
|
Vagant a �crit :
> Hurrah! It works! I have used 50MHz clock as input and my 1Hz output
> signal was connected to a LED. So it flashes every second now! Thanks
> to all for encouragement, criticism, real help and suggestions!
>
> P.S. Final version of the VHDL code used is:
>
> library IEEE;
> use IEEE.STD_LOGIC_1164.ALL;
> use IEEE.STD_LOGIC_ARITH.ALL;
> use IEEE.STD_LOGIC_UNSIGNED.ALL;
Drop these last two non-standard libraries and use ieee.numeric_std instead.
The code you posted doesn't even need it anyway.
Nicolas
|
|
0
|
|
|
|
Reply
|
Nicolas
|
1/9/2008 7:28:51 PM
|
|
> 50Mhz is 50 000 000 period per second. So you have to divide it by 50 000 000 go
> get 1Hz, or to count two times from 0 to 24 999 999.
> I hope the error was to see if someone follows ?
> :-)
>
> Pascal
Correct. My mistake, sorry. :(
|
|
0
|
|
|
|
Reply
|
Ponceludon
|
1/10/2008 4:41:32 AM
|
|
neeraj2608@gmail.com schrieb:
> On Jan 9, 11:30 am, neeraj2...@gmail.com wrote:
>> On Jan 9, 11:25 am, Vagant <vladimir.v.koroste...@rambler.ru> wrote:
>>
>>
>>
>>
>>
>>> On Jan 9, 8:23 am, neeraj2...@gmail.com wrote:
>>>> On Jan 9, 2:57 am, Vagant <vladimir.v.koroste...@rambler.ru> wrote:
>>>>> On Jan 8, 10:22 pm, Ralf Hildebrandt <Ralf-Hildebra...@gmx.de> wrote:
>>>>>> Take your clock (which is running at X MHz) and divide it by X.
>>>>> I guess it should be divided by X*10^6 to get 1 Hz, isn't it?
>>>> Not really. You're already using your clk to increment cnt. You just
>>>> need to divide it by X.
>>>> For instance, if you had a clock running at 50 MHz, cnt would
>>>> increment 50,000 times a second. Divide it by 50 and you're left with
>>>> a cnt that increments a thousand times a second - a 1 MHz clock.
>>> Well, but I need 1 Hz clock not 1 MHz.
>> Whoops, my mistake. The line should have been:
>> Divide it by 50 and you're left with
>> a cnt that increments a thousand times a second - a 1 Hz clock.
>>
>> Sorry.- Hide quoted text -
>>
>> - Show quoted text -
>
> No, on second thought, you're right. For a 50 MHz clock, you would
> count to 24999 before toggling clk_out.
Well, not quitre right yet. 50MHz is 50 MILLION Hz, so for 1 Hz output
clock you're a factor of a thousand off track...
HTH,
Florian
|
|
0
|
|
|
|
Reply
|
Florian
|
1/10/2008 8:42:24 AM
|
|
On Jan 10, 10:42=A0am, Florian Teply <onlinef...@usenet.cnntp.org>
wrote:
> neeraj2...@gmail.com schrieb:
>
>
>
>
>
> > On Jan 9, 11:30 am, neeraj2...@gmail.com wrote:
> >> On Jan 9, 11:25 am, Vagant <vladimir.v.koroste...@rambler.ru> wrote:
>
> >>> On Jan 9, 8:23 am, neeraj2...@gmail.com wrote:
> >>>> On Jan 9, 2:57 am, Vagant <vladimir.v.koroste...@rambler.ru> wrote:
> >>>>> On Jan 8, 10:22 pm, Ralf Hildebrandt <Ralf-Hildebra...@gmx.de> wrote=
:
> >>>>>> Take your clock (which is running at X MHz) and divide it by X.
> >>>>> I guess it should be divided by X*10^6 to get 1 Hz, isn't it?
> >>>> Not really. You're already using your clk to increment cnt. You just
> >>>> need to divide it by X.
> >>>> For instance, if you had a clock running at 50 MHz, cnt would
> >>>> increment 50,000 times a second. Divide it by 50 and you're left with=
> >>>> a cnt that increments a thousand times a second - a 1 MHz clock.
> >>> Well, but I need 1 Hz clock not 1 MHz.
> >> Whoops, my mistake. The line should have been:
> >> Divide it by 50 and you're left with
> >> a cnt that increments a thousand times a second - a 1 Hz clock.
>
> >> Sorry.- Hide quoted text -
>
> >> - Show quoted text -
>
> > No, on second thought, you're right. For a 50 MHz clock, you would
> > count to 24999 before toggling clk_out.
>
> Well, not quitre right yet. 50MHz is 50 MILLION Hz, so for 1 Hz output
> clock you're a factor of a thousand off track...
>
> HTH,
> Florian- Hide quoted text -
>
> - Show quoted text -
I used 24999999 (which is 50 millions divided by 2 minus 1) and it
really produces 1 Hz signal. :)
|
|
0
|
|
|
|
Reply
|
Vagant
|
1/10/2008 6:53:08 PM
|
|
On Jan 10, 1:53 pm, Vagant <vladimir.v.koroste...@rambler.ru> wrote:
>
> I used 24999999 (which is 50 millions divided by 2 minus 1) and it
> really produces 1 Hz signal. :)
Actually, the difference between 25e6 and 25e6-1 is well under 1 part
per million. You're unlikely to be generating 1 Hz with either
divisor; I'll go out on a limb and guess you're not using a calibrated
(atomic, GPS) 50 MHz oscillator and are probably lucky to be within 10
ppm to begin with. Using N-1 is clearly the theoretically correct
solution (for a piece of code in an appropriate style), as well as
being necessary system-wide in a lot of other ways, but don't expect
your output to be any better in a practical sense, nor to be correct
in an absolute sense :-(
- Kenn
|
|
0
|
|
|
|
Reply
|
kennheinrich
|
1/10/2008 7:16:42 PM
|
|
|
25 Replies
694 Views
(page loaded in 0.132 seconds)
Similiar Articles: How to write a VHDL code for 1Hz signal? - comp.lang.vhdl ...Hello, I am a newbie to VHDL programming and want to test my FPGA board with a code which lights a LED every second. To do this I need a VHDL code for 1 Hz signal ... change a clock to pulse in vhdl - comp.lang.vhdlHow to write a VHDL code for 1Hz signal? - comp.lang.vhdl ... change a clock to pulse in vhdl - comp.lang.vhdl How to write a VHDL code for 1Hz signal? - comp.lang.vhdl ... AMS simulation error - comp.cad.cadencedata_wr : OUT STD_LOGIC_DATA; -- data bus for writing ... ncvhdl_p: *E,IDENTU (../spi_digi/spislave14/entity/vhdl ... simulation and modeling for analog, RF, and mixed-signal ... VHDL code for 2's complement - comp.lang.vhdlinteger BCD converter in VHDL - comp.lang.vhdl How to write a VHDL code for 1Hz signal? - comp.lang.vhdl ... integer BCD ... comp.soft-sys.matlab ... integer BCD converter ... how to do a 1 to 4 demultiplexer in vhdl? - comp.lang.vhdl ...How to write a VHDL code for 1Hz signal? - comp.lang.vhdl ... Hello, I am a newbie to VHDL programming and want to test my FPGA board with a code which lights a LED every ... how to write a constraint function for optimtool??? - comp.soft ...Purpose of a string variable in a FSM process - comp.lang.vhdl ... How to write a VHDL code for 1Hz signal? - comp.lang.vhdl ... how to write a constraint function for ... stupid newbie: how to write to standard error? - comp.lang.awk ...How to write a VHDL code for 1Hz signal? - comp.lang.vhdl ... Hello, I am a newbie to VHDL programming and ... ALL; Drop these last two non-standard ... Convert from std_logic_vector to real - comp.lang.vhdlHow to write a VHDL code for 1Hz signal? - comp.lang.vhdl ... Thanks > to all for encouragement, criticism, real ... integer BCD converter in VHDL - comp.lang.vhdl How to ... How to write a code for iteration process - comp.soft-sys.matlab ...How to write a VHDL code for 1Hz signal? - comp.lang.vhdl ... How to write a code for iteration process - comp.soft-sys.matlab ... How to write a VHDL code for 1Hz signal ... cycle count for divide - comp.lang.asm.x86How to write a VHDL code for 1Hz signal? - comp.lang.vhdl ... cycle count for divide - comp.lang.asm.x86 How to write a VHDL code for 1Hz signal? - comp.lang.vhdl ... A code generator written in AWK - comp.lang.awkA code generator written in AWK - comp.lang.awk How to write a VHDL code for 1Hz signal? - comp.lang.vhdl ... Hello, I am a ... How can I read line input in an interactive ... Purpose of a string variable in a FSM process - comp.lang.vhdl ...Purpose of a string variable in a FSM process - comp.lang.vhdl ... Purpose of a string variable in a FSM process - comp.lang.vhdl ... How to write a VHDL code for 1Hz ... Multipliers, dividers, adders etc.... - comp.lang.verilog ...... count for divide - comp.lang.asm.x86 Multipliers, dividers, adders etc.... - comp.lang.verilog ... cycle count for divide ... How to write a VHDL code for 1Hz signal ... ModelSim & tcl testbench - comp.lang.vhdlI'm reasonably OK at writing VHDL code & testbenches, but I now need to write ... likely to be far better to write the detailed time-dependent signal-wiggling stuff in a VHDL ... Re: how to insrt a line at the end of every page in rtf - comp ...How to write a VHDL code for 1Hz signal? - comp.lang.vhdl ..... board with a code which lights a LED every ... you have any similar code could you put ... How to write a VHDL code for 1Hz signal? - Page 3How to write a VHDL code for 1Hz signal? - vhdl . This is a discussion on How to write a VHDL code for 1Hz signal? - vhdl; Hurrah! It works! I have used 50MHz clock ... How to write a VHDL code for 1Hz signal? - Application Forum at ...How to write a VHDL code for 1Hz signal? - vhdl . This is a discussion on How to write a VHDL code for 1Hz signal? - vhdl; Hello, I am a newbie to VHDL programming ... 7/23/2012 5:24:12 PM
|