Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - Error in clock divider from FAQ

 
Thread Tools Search this Thread
Old 09-02-2005, 12:15 PM   #1
Default Error in clock divider from FAQ


Hello,

the clock divider from the FAQ is:

architecture Behavior of ClockDivider is
begin
process (ClkIn, Reset)
variable Count: Natural range 0 to Modulus-1;
begin
if Reset = '1' then
Count := 0;
ClkOut <= '0';
elsif ClkIn = '1' and ClkIn'event then
if Count = Modulus-1 then
Count := 0;
else
Count := Count + 1;
end if;
if Count >= Modulus/2 then
ClkOut <= '0';
else
ClkOut <= '1';
end if;
end if;
end process;
end Behavior;

In my simulation (ModelSim) the first '1' cycle of ClkOut is too short
by one ClkIn cycle.
Fixes for that:
- Initialize count with Modulus-1 in reset OR
- Count up _after_ ClkOut is set

I wonder why nobody came accross this problem. It's there quite
a long time.
I don't have information who is maintaining the FAQ and who could
fix this.

Bye,
Y



yolanda3000@freenet.de
  Reply With Quote
Old 09-06-2005, 12:12 PM   #2
charles.elias@wpafb.af.mil
 
Posts: n/a
Default Re: Error in clock divider from FAQ

wrote:
> Hello,
>
> the clock divider from the FAQ is:
>
> architecture Behavior of ClockDivider is
> begin
> process (ClkIn, Reset)
> variable Count: Natural range 0 to Modulus-1;
> begin
> if Reset = '1' then
> Count := 0;
> ClkOut <= '0';
> elsif ClkIn = '1' and ClkIn'event then
> if Count = Modulus-1 then
> Count := 0;
> else
> Count := Count + 1;
> end if;
> if Count >= Modulus/2 then
> ClkOut <= '0';
> else
> ClkOut <= '1';
> end if;
> end if;
> end process;
> end Behavior;
>
> In my simulation (ModelSim) the first '1' cycle of ClkOut is too short
> by one ClkIn cycle.
> Fixes for that:
> - Initialize count with Modulus-1 in reset OR
> - Count up _after_ ClkOut is set
>
> I wonder why nobody came accross this problem. It's there quite
> a long time.
> I don't have information who is maintaining the FAQ and who could
> fix this.
>
> Bye,
> Y


I just simulated the divider using Active-HDL and got the same result
that you did. You are very observant! I have used this divider a
number of time and never noticed the problem.

Charles



charles.elias@wpafb.af.mil
  Reply With Quote
Old 09-06-2005, 02:16 PM   #3
Zara
 
Posts: n/a
Default Re: Error in clock divider from FAQ
wrote:
> wrote:
>
>>Hello,
>>
>>the clock divider from the FAQ is:
>>
>>architecture Behavior of ClockDivider is
>> begin
>> process (ClkIn, Reset)
>> variable Count: Natural range 0 to Modulus-1;
>> begin
>> if Reset = '1' then
>> Count := 0;
>> ClkOut <= '0';
>> elsif ClkIn = '1' and ClkIn'event then
>> if Count = Modulus-1 then
>> Count := 0;
>> else
>> Count := Count + 1;
>> end if;
>> if Count >= Modulus/2 then
>> ClkOut <= '0';
>> else
>> ClkOut <= '1';
>> end if;
>> end if;
>> end process;
>> end Behavior;
>>
>>In my simulation (ModelSim) the first '1' cycle of ClkOut is too short
>>by one ClkIn cycle.
>>Fixes for that:
>>- Initialize count with Modulus-1 in reset OR
>>- Count up _after_ ClkOut is set
>>
>>I wonder why nobody came accross this problem. It's there quite
>>a long time.
>>I don't have information who is maintaining the FAQ and who could
>>fix this.
>>
>>Bye,
>>Y

>
>
> I just simulated the divider using Active-HDL and got the same result
> that you did. You are very observant! I have used this divider a
> number of time and never noticed the problem.
>
> Charles
>


The reason is pretty simple: In normal cycles, ClkOut changes from '0'
to '1' when Count changes from Modulus/2 to Modulus/2+1, and the other
way round when Count changes from '0' to '1'. So, simlutaneously with
Count=1, ClkOut='1'.

But on reset, Count is given the value '0' and ClkOut too, not
corresponding to the rest of the time.
Solutions:

a) Either initialize ClkOut on reset with the value '1'
b) Or change ths sign of both ClkOut transitions





Zara
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Clock Modelling using VHDL rtl.engineer Hardware 0 07-31-2008 11:50 AM
Computer Clock GoneBeforeMyTime A+ Certification 5 04-21-2007 05:31 PM
Post-Route Simulation does not give output for the first clock cycle Options velocityreviews Software 0 04-17-2007 05:47 PM
New Releases: Revelations, The Librarian & My Left Foot: Updated complete downloadable R1 DVD DB & Info lists Doug MacLean DVD Video 0 05-17-2005 06:57 AM
Hollywood Detective - The Buried Clock David Marsh DVD Video 1 09-27-2004 11:26 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46