FPGA, SoC, And CPLD Boards And Kits
FPGA Evaluation and Development Kits
5925 Discussions

(VHDL) Help...I set the timer counter code. I want to reset the circuit by pressing it more than 2 seconds. How do I write code?

zasas
Beginner
849 Views

 

USE ieee.std_logic_unsigned.all;  

USE ieee.std_logic_unsigned.all;  

USE ieee.std_logic_unsigned.all;  

ENTITY TIMER1 IS

        digit1, digit2, digit3, clk_period: OUT STD_LOGIC_VECTOR(7 DOWNTO 0));

        digit1, digit2, digit3, clk_period: OUT STD_LOGIC_VECTOR(7 DOWNTO 0));

        digit1, digit2, digit3, clk_period: OUT STD_LOGIC_VECTOR(7 DOWNTO 0));

END TIMER1;

ARCHITECTURE TIMER1 OF TIMER1 IS

SIGNAL Hzclk : STD_LOGIC;

   SIGNAL s1: INTEGER RANGE 0 TO 10

  SIGNAL s2: INTEGER RANGE 0 TO 6;

SIGNAL minutes: INTEGER RANGE 0 TO 10;

BEGIN

PROCESS (clk)

VARIABLE count : INTEGER RANGE 0 TO fclk;

BEGIN

IF (clk'EVENT AND clk='1') THEN

count := count +1;

IF (count=fclk/2) THEN

 Hzclk <= '1';

ELSIF (count=fclk) THEN

Hzclk <= '0';

count := 0;

END IF;

END IF;

END PROCESS;

PROCESS (Hzclk, rst)

VARIABLE count1: INTEGER RANGE 0 TO 10;

VARIABLE count2: INTEGER RANGE 0 TO 6;

VARIABLE count3: INTEGER RANGE 0 TO 10;

BEGIN

IF (rst ='1'AND ) THEN

after(20ns);

count1 :=0;

count2 :=0;

count3 :=0;

ELSIF (clk'EVENT AND clk='1') THEN

IF (startstop='1' AND (count1/=9 OR count2/=5 OR count3/=9)) THEN

count1 := count1 +1 ;

IF (count1=10) THEN

count1 := 0;

 count2 := count2 + 1;

IF (count2=6) THEN

count2 := 0;

count3 := count3 +1;

END IF;

END IF;

END IF;

END IF;

s1 <= count1;

s2 <= count2;

 minutes <= count3;

END PROCESS;

 PROCESS (s1, s2, minutes)

 BEGIN

CASE s1 IS

WHEN 0 => digit1 <= "11111100";

WHEN 1 => digit1 <= "01100000";       

WHEN 2 => digit1 <= "11011010";      

WHEN 3 => digit1 <= "11110010";      

WHEN 4 => digit1 <= "01100110";

WHEN 5 => digit1 <= "10110110";     

  WHEN 6 => digit1 <= "10111110";    

  WHEN 7 => digit1 <= "11100000";      

WHEN 8 => digit1 <= "11111110";     

 WHEN 9 => digit1 <= "11110110";

WHEN OTHERS => NULL;

END CASE;      CASE s2 IS

WHEN 0 => digit2 <= "11111100";      

WHEN 1 => digit2 <= "01100000";    

  WHEN 2 => digit2 <= "11011010";    

  WHEN 3 => digit2 <= "11110010";   

   WHEN 4 => digit2 <= "01100110";    

  WHEN 5 => digit2 <= "10110110";    

   WHEN OTHERS => NULL;

END CASE;

CASE minutes IS

 WHEN 0 => digit3 <= "11111100";     

 WHEN 1 => digit3 <= "01100001";     

 WHEN 2 => digit3 <= "11011011";     

 WHEN 3 => digit3 <= "11110011";     

 WHEN 4 => digit3 <= "01100111";    

  WHEN 5 => digit3 <= "10110111";    

  WHEN 6 => digit3 <= "10111111";    

  WHEN 7 => digit3 <= "11100001";

 WHEN 8 => digit3 <= "11111111";

WHEN 9 => digit3 <= "11110111";

WHEN OTHERS => NULL;

 END CASE;

  END PROCESS;

  END TIMER1;

 

 

0 Kudos
1 Reply
AnandRaj_S_Intel
Employee
514 Views

Hi @zasas​ 

 

Okay, You have to build a counter which will count to 25 million to get 2 second events which will be used for reset.

You can refer below example and use it in you design.

 

Please note that I have not checked your code.

 

PROCESS (Clock) BEGIN IF (Clock'EVENT AND Clock = '1') THEN counter <= counter + '1'; if( counter = <NUMBER>) then --<NUMBER> =How many clocks will you need to get two second? Well it will be clearly 25 million cycles assusing clock of 50MHz. reset<= '1'; counter <= "0"; else reset<= '0'; end if; END IF; END PROCESS;

Let me know if this has helped resolve the issue you are facing or if you need any further assistance.

 

Regards

Anand

0 Kudos
Reply