📄 一个vhdl实现的测频计.vhd
字号:
--BCD Counter
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
USE ieee.std_logic_unsigned.all;
ENTITY freq IS
PORT( Fsignal : IN std_logic;
-- Rst : IN std_logic;
Gate : IN std_logic;
Ready : OUT std_logic;
Data_out : OUT std_logic_vector(31 downto 0);
overflow : OUT std_logic
);
END freq;
ARCHITECTURE freq_counter OF freq IS
CONSTANT HIGH : std_logic := '1';
CONSTANT LOW : std_logic := '0';
--SIGNAL Rst : std_logic;
SIGNAL one : std_logic_vector (3 downto 0);
SIGNAL ten : std_logic_vector (3 downto 0);
SIGNAL hun : std_logic_vector (3 downto 0);
SIGNAL thou : std_logic_vector (3 downto 0);
SIGNAL mill : std_logic_vector (3 downto 0);
SIGNAL ten_mill : std_logic_vector (3 downto 0);
SIGNAL hun_mill : std_logic_vector (3 downto 0);
SIGNAL thou_mill : std_logic_vector (3 downto 0);
SIGNAL state : std_logic_vector (1 downto 0);
SIGNAL enable_cnt : std_logic;
--SIGNAL Temp_data : std_logic_vector(31 downto 0);
BEGIN
-- Data_out <= thou_mill & hun_mill & ten_mill & mill & thou & hun & ten & one;
-- Temp_data := thou_mill & hun_mill & ten_mill & mill & thou & hun & ten & one;
-- Data_out <= Temp_data;
Ready <= NOT enable_cnt;
PROCESS (Gate)
BEGIN
IF (Gate = LOW and Gate'EVENT) then
Data_out <= thou_mill & hun_mill & ten_mill & mill & thou & hun & ten & one;
END IF;
END PROCESS;
-- Rst := Gate;
-- enable_cnt := Gate;
-- *******************************************************************************************
-- FREQUENCY COUNTER
-- Counts from 00000000 to 99999999 (BCD) only when the GATE is high
-- *******************************************************************************************
PROCESS (Fsignal, Gate)
BEGIN
IF (Gate = LOW) THEN
state <= "00";
ELSIF (Fsignal= HIGH and Fsignal'EVENT) THEN
state <= "11";
END IF;
END PROCESS;
STAT: PROCESS (state)
BEGIN
IF (state = "11") THEN
--IF (Gate=HIGH)
-- THEN
enable_cnt <= HIGH;
--END IF;
ELSIF (state = "00") --THEN
--ELSIF (Gate=LOW)
THEN enable_cnt <= LOW;
--END IF;
END IF;
END PROCESS STAT;
-- OVERFLOW DETECT
OVERFLOW_DET: PROCESS (Gate, Fsignal)
BEGIN
IF (Gate=LOW) THEN
overflow <= LOW;
ELSIF (Fsignal=HIGH and Fsignal'EVENT) THEN
IF (thou_mill="1001" and hun_mill="1001" and ten_mill="1001" and mill="1001"
and thou="1001" and hun="1001" and ten="1001" and one="1001")
THEN overflow <= HIGH;
END IF;
END IF;
END PROCESS OVERFLOW_DET;
--**********************************
-- COUNTERS
-- ONES BCD COUNTERS
ONE_CNTER: PROCESS (Fsignal, Gate)
BEGIN
IF (Gate=LOW ) THEN
one <= "0000";
ELSIF (Fsignal=HIGH and Fsignal'EVENT) THEN
IF (enable_cnt=HIGH) THEN
IF (one="1001") THEN
one <= "0000";
ELSE one <= one + 1;
END IF;
END IF;
END IF;
END PROCESS ONE_CNTER;
-- TENS BCD COUNTERS
TEN_CNTER: PROCESS (Fsignal, Gate)
BEGIN
IF (Gate=LOW ) THEN
ten <= "0000";
ELSIF (Fsignal=HIGH and Fsignal'EVENT) THEN
IF (enable_cnt=HIGH) THEN
IF (ten="1001" and one="1001") THEN
ten <= "0000";
ELSIF (one="1001") THEN
ten <= ten + 1;
END IF;
END IF;
END IF;
END PROCESS TEN_CNTER;
-- HUNDREDS BCD COUNTERS
HUND_CNTER: PROCESS (Fsignal, Gate)
BEGIN
IF (Gate=LOW ) THEN
hun <= "0000";
ELSIF (Fsignal=HIGH and Fsignal'EVENT) THEN
IF (enable_cnt=HIGH) THEN
IF (hun="1001" and ten="1001" and one="1001") THEN
hun <= "0000";
ELSIF (ten="1001" and one="1001") THEN
hun <= hun + 1;
END IF;
END IF;
END IF;
END PROCESS HUND_CNTER;
-- THOUSANDS BCD COUNTERS
THOU_CNTER: PROCESS (Fsignal, Gate)
BEGIN
IF (Gate=LOW ) THEN
thou <= "0000";
ELSIF (Fsignal=HIGH and Fsignal'EVENT) THEN
IF (enable_cnt=HIGH) THEN
IF (thou="1001" and hun="1001" and ten="1001" and one="1001") THEN
thou <= "0000";
ELSIF (hun="1001" and ten="1001" and one="1001") THEN
thou <= thou + 1;
END IF;
END IF;
END IF;
END PROCESS THOU_CNTER;
-- MILLIONS BCD COUNTERS
MILL_CNTER: PROCESS (Fsignal, Gate)
BEGIN
IF (Gate=LOW ) THEN
mill <= "0000";
ELSIF (Fsignal=HIGH and Fsignal'EVENT) THEN
IF (enable_cnt=HIGH) THEN
IF (mill="1001" and thou="1001" and hun="1001" and ten="1001" and one="1001") THEN
mill <= "0000";
ELSIF (thou="1001" and hun="1001" and ten="1001" and one="1001") THEN
mill <= mill + 1;
END IF;
END IF;
END IF;
END PROCESS MILL_CNTER;
-- TEN_MILLIONS BCD COUNTERS
TEN_MILL_CNTER: PROCESS (Fsignal, Gate)
BEGIN
IF (Gate=LOW ) THEN
ten_mill <= "0000";
ELSIF (Fsignal=HIGH and Fsignal'EVENT) THEN
IF (enable_cnt=HIGH) THEN
IF (ten_mill="1001" and mill="1001" and thou="1001" and hun="1001" and ten="1001" and one="1001") THEN
ten_mill <= "0000";
ELSIF (mill="1001" and thou="1001" and hun="1001" and ten="1001" and one="1001") THEN
ten_mill <= ten_mill + 1;
END IF;
END IF;
END IF;
END PROCESS TEN_MILL_CNTER;
-- HUND_MILLIONS BCD COUNTERS
HUN_MILL_CNTER: PROCESS (Fsignal, Gate)
BEGIN
IF (Gate=LOW ) THEN
hun_mill <= "0000";
ELSIF (Fsignal=HIGH and Fsignal'EVENT) THEN
IF (enable_cnt=HIGH) THEN
IF (hun_mill="1001" and ten_mill="1001" and mill="1001" and thou="1001" and hun="1001" and ten="1001" and one="1001") THEN
hun_mill <= "0000";
ELSIF (ten_mill="1001" and mill="1001" and thou="1001" and hun="1001" and ten="1001" and one="1001") THEN
hun_mill <= hun_mill + 1;
END IF;
END IF;
END IF;
END PROCESS HUN_MILL_CNTER;
-- THOU_MILLIONS BCD COUNTERS
THOU_MILL_CNTER: PROCESS (Fsignal, Gate)
BEGIN
IF (Gate=LOW ) THEN
thou_mill <= "0000";
ELSIF (Fsignal=HIGH and Fsignal'EVENT) THEN
IF (enable_cnt=HIGH) THEN
IF (thou="1001" and hun_mill="1001" and ten_mill="1001" and mill="1001" and thou="1001" and hun="1001" and ten="1001" and one="1001") THEN
thou_mill <= "0000";
ELSIF (hun_mill="1001" and ten_mill="1001" and mill="1001" and thou="1001" and hun="1001" and ten="1001" and one="1001") THEN
thou_mill <= thou_mill + 1;
END IF;
END IF;
END IF;
END PROCESS THOU_MILL_CNTER;
END freq_counter;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -