Frequency.vhd
资源名称:LED8.rar [点击查看]
上传用户:sunkay99
上传日期:2022-08-09
资源大小:204k
文件大小:4k
源码类别:
VHDL/FPGA/Verilog
开发平台:
Others
- ---------------------------------------------------------------------------------------------------
- --*************************************************************************************************
- -- CreateDate : 2007-07-12
- -- ModifData : 2007-07-12
- -- Description : Frequency
- -- Author : Explorer01
- -- Version : V1.0
- --*************************************************************************************************
- ---------------------------------------------------------------------------------------------------
- -- VHDL library Declarations
- LIBRARY IEEE;
- USE IEEE.std_logic_1164.ALL;
- USE IEEE.STD_LOGIC_ARITH.ALL;
- USE IEEE.std_logic_unsigned.ALL;
- ---------------------------------------------------------------------------------------------------
- ---------------------------------------------------------------------------------------------------
- -- The Entity Declarations
- ENTITY Frequency IS
- PORT
- (
- RESET: IN STD_LOGIC;
- GCLKP1: IN STD_LOGIC;
- ClockScan: OUT STD_LOGIC;
- KeyScan: OUT STD_LOGIC
- );
- END Frequency;
- ---------------------------------------------------------------------------------------------------
- ---------------------------------------------------------------------------------------------------
- -- The Architecture of Entity Declarations
- ARCHITECTURE Frequency_arch OF Frequency IS
- --Clock:
- SIGNAL Period1uS, Period1mS, Period1S: STD_LOGIC;
- SIGNAL Frequency62: STD_LOGIC;
- BEGIN
- -------------------------------------------------
- -- GCLK: 1MHz(1uS), 1KHz(1mS), 1Hz(1S)
- CLK: PROCESS( RESET, GCLKP1, Period1uS, Period1mS, Period1S, Frequency62 )
- VARIABLE Count : STD_LOGIC_VECTOR(3 DOWNTO 0);
- VARIABLE Count1 : STD_LOGIC_VECTOR(9 DOWNTO 0);
- VARIABLE Count2 : STD_LOGIC_VECTOR(9 DOWNTO 0);
- -- VARIABLE Count3 : integer RANGE 0 TO 263;
- BEGIN
- ------------------------------------
- --Period: 1uS (Period1uS <= GCLKP1; )
- IF( GCLKP1'EVENT AND GCLKP1='1' ) THEN
- -- IF( Count>8 ) THEN Count := 0;
- -- ELSE Count := Count + 1;
- -- END IF;
- --
- -- IF( Count<5 ) THEN Period1uS <= '1';
- -- ELSE Period1uS <= '0';
- -- END IF;
- --^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- -- IF( RESET='0' ) THEN Count := "0000";
- IF( Count>"1000" ) THEN Count := "0000";
- ELSE Count := Count + 1;
- END IF;
- Period1uS <= Count(3);
- -- 1MHz
- KeyScan <= Period1uS;
- ------------------------------------
- --37.9KHz
- -- IF( Count3 > 262 ) THEN Count3 := 0;
- -- ELSE Count3 := Count3 + 1;
- -- END IF;
- --
- -- IF( Count3 < 132 ) THEN Frequency37_9K <= '1';
- -- ELSE Frequency37_9K <= '0';
- -- END IF;
- END IF;
- ------------------------------------
- --Period: 1mS
- IF( Period1uS'EVENT AND Period1uS='1' ) THEN
- -- IF( Count1>998 ) THEN Count1 := 0;
- -- ELSE Count1 := Count1 + 1;
- -- END IF;
- --
- -- IF( Count1<500 ) THEN Period1mS <= '1';
- -- ELSE Period1mS <= '0';
- -- END IF;
- --^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- IF( Count1>"1111100110" ) THEN Count1 := "0000000000";
- ELSE Count1 := Count1 + 1;
- END IF;
- Period1mS <= Count1(9);
- END IF;
- ------------------------------------
- --Period: 1S (1111100110: 998)
- IF( Period1mS'EVENT AND Period1mS='1' ) THEN
- -- IF( Count2>998 ) THEN Count2 := 0;
- -- ELSE Count2 := Count2 + 1;
- -- END IF;
- --
- -- IF( Count2<500 ) THEN Period1S <= '1';
- -- ELSE Period1S <= '0';
- -- END IF;
- --^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- IF( Count2>"1111100110" ) THEN Count2 := "0000000000";
- ELSE Count2 := Count2 + 1;
- END IF;
- Period1S <= Count2(9);
- ------------------------------------
- -- 62.5Hz
- Frequency62 <= Count2(4);
- ------------------------------------
- ClockScan <= Frequency62;
- END IF;
- END PROCESS;
- END Frequency_arch;