Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Checking to see if one second has passed

Reply
Thread Tools

Checking to see if one second has passed

 
 
johnnyjohn2009 johnnyjohn2009 is offline
Junior Member
Join Date: Dec 2009
Posts: 8
 
      12-06-2009
Hello,

This is probably so simple to achieve, but I am unsure how to code this effciently. At the moment I have tried while Clock < 1000 ms. I have also tried .. if the clock is less than 1000 ms..

I would like to increment a counter while the clock is less than 1 second. Once a second has passed pass the count value to a signal which then goes to the entity output. Then repeat the process.

If anyone has any ideas i'd be most grateful
 
Reply With Quote
 
 
 
 
jeppe jeppe is offline
Senior Member
Join Date: Mar 2008
Location: Denmark
Posts: 348
 
      12-06-2009
VHDL code with statements like "while Clock < 1000 ms" will only be useful for simulation - not for synthesizing to hardware.

What's your goal with the code?
 
Reply With Quote
 
 
 
 
johnnyjohn2009 johnnyjohn2009 is offline
Junior Member
Join Date: Dec 2009
Posts: 8
 
      12-06-2009
Hi, many thanks for your reply with this and my other post.

Just to let you know this is part of my final year project at university so help should be limited!

My goal is to count pulses 0 -> 1 within a 1 second window repeatedly. Once one second has passed the process should be repeated. My attempt is shown below:

Process(clock) begin
timer <= '1', '0' after 1000 ms;

if timer = '0' then
FreqCount <= "0000";
timer <= '1';
end if;

if timer = '0' then
if rising_edge(Clock) then
if Datain = '1' then
FreqCount <= FreqCount + "1";
end if;

else -- clock event is falling edge 1 -> 0
if Datain = '1' then
FreqCount <= FreqCount + "1";
end if;

end if;
TempCount <= FreqCount;
end if;


end process;

FreqOut <= TempCount;
end Behavioral;
 

Last edited by johnnyjohn2009; 12-06-2009 at 12:22 PM..
Reply With Quote
 
jeppe jeppe is offline
Senior Member
Join Date: Mar 2008
Location: Denmark
Posts: 348
 
      12-06-2009
Do you have some kind of hardware / FPGA-kit which your planning to use or do you "just" want to make a simulation of the solution.

Important to know becourse the VHDL code you can use depend on this.

Take a look at this code - not the solution to your problem - only inspiration.

Code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity Freq_counter1 is
end Freq_counter1;

architecture Behavioral of Freq_counter1 is
   signal FreqCount, TempCount: std_logic_vector( 3 downto 0) := "0000";
   signal Timer: integer range 0 to 1023;
   signal Clk:   std_logic := '0';
   signal Datain: std_logic := '0';
begin
 
   clk <= not clk after 500 us; -- This code NOT for synthesizing - only simulation
   -- simulates a frequency of 1kHz which used for the 1 second generation.
   
   Datain <= not Datain after 60 ms; -- This code NOT for synthesizing - only simulation
   -- simulation of input data.
  
   process( clk, Datain)
   begin
      -- This construction only for simulation - can't be synthesized
      if rising_edge( Datain) then
         TempCount <= TempCount +1;   -- Count the frequency.
      end if;

      -- one second timer functionality 
      if rising_edge( clk) then
         timer <= timer+1;
         if timer>999 then          -- Now 1 Second gone
            timer <= 0;             -- Init timer to next second count
            FreqCount <= TempCount; -- Remember the count 
            TempCount <= "0000";    -- Init for next count
         end if;
      end if;
   end process;        
   
end Behavioral;
 

Last edited by jeppe; 12-07-2009 at 08:12 AM.. Reason: Code added
Reply With Quote
 
johnnyjohn2009 johnnyjohn2009 is offline
Junior Member
Join Date: Dec 2009
Posts: 8
 
      12-08-2009
Hi Jeppe,

The code you posted is extremely interesting.. it has certainly given me some ideas to go away and experiment.

There have been many discussions in VHDL books regarding unsynthesisable code for hardware implementation. However no author has explaining exactly why..

I do plan to implement this on a Xilinx Spartan 3E board if I have time so I should make sure my code is synthesisable and not just for simulation.

John
 
Reply With Quote
 
jeppe jeppe is offline
Senior Member
Join Date: Mar 2008
Location: Denmark
Posts: 348
 
      12-09-2009
Hi John

Its not that difficult to spot code which can't be synthesized.
All VHDL code which depend on delays like Y <= Not AFTER ... or WAIT FOR xx NS will fail to synthesize.
Your allowed to use FOR and WHILE loops if they generates COMBINATORIAL logic, but if you write "normal program code" which wait for something to happen will the synthesize process fail as well.

In my code example must the 1 kHz come from an external source (and will proberly be 50 MHz)
You must realize that a process normally only will allow one signal which depend on a rising_edge and hence must you "create" an extra rising edge detection for the Datain signal.
This can be done with a two bit shiftregister which remember the actual and former value of the Datain signal - hence will "10" indicate a rising edge.

Jeppe
 
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
strip all but second second line from bottom and then strip that!!!! yelipolok Perl Misc 4 01-27-2010 08:14 AM
May output the char one after one every other second? liking C lang. C Programming 16 02-17-2007 12:47 AM
How to change data displayed in one GridView depending on selection made in the second one? (ASP.NET 2.0) misiek ASP .Net 7 02-28-2006 09:40 AM
Checking One Box when I check a second checkbox Rich Javascript 2 05-18-2004 06:12 PM
IBM JVM: loading two native libraries in JNI, second one has problems Alex Hunsley Java 4 11-14-2003 10:08 AM



Advertisments