Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Error in clock divider from FAQ

Reply
Thread Tools

Error in clock divider from FAQ

 
 
yolanda3000@freenet.de
Guest
Posts: n/a
 
      09-02-2005
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

 
Reply With Quote
 
 
 
 
charles.elias@wpafb.af.mil
Guest
Posts: n/a
 
      09-06-2005

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

 
Reply With Quote
 
 
 
 
Zara
Guest
Posts: n/a
 
      09-06-2005
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



 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clock divider? oppenheimer VHDL 2 06-08-2008 01:08 PM
clock divider FP VHDL 1 06-02-2008 08:12 PM
clock divider by 2 martstev@gmail.com VHDL 3 08-16-2006 05:06 AM
MCU clock divider vs. VHDL divider Matt Clement VHDL 3 04-28-2006 01:24 PM
Clock Divider Mohammed A khader VHDL 4 03-14-2005 11:46 AM



Advertisments
 



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 47 48 49 50 51 52 53 54 55 56 57