![]() |
|
|
|||||||
![]() |
VHDL - Error in clock divider from FAQ |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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 |
|
|
|
|
#2 |
|
Posts: n/a
|
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 |
|
|
|
#3 |
|
Posts: n/a
|
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 |
|
![]() |
| Thread Tools | Search this Thread |
|
|
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 |