📄 freq.vhd
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity freq is
port(fsin:in std_logic;--被测信号
clk:in std_logic;--基准时间,1Hz
reset : in std_logic;
show:out std_logic_vector(7 downto 0);--数码管段码输出
row:out std_logic_vector(2 downto 0));--数码管选择信号
end freq;
architecture one of freq is
signal test_en:std_logic;
signal clear:std_logic;--复位信号
signal data:std_logic_vector(23 downto 0);--bcd
signal buf:std_logic_vector(23 downto 0);
signal data_in:std_logic_vector(3 downto 0);--单个数码管显示
signal row_in:std_logic_vector(2 downto 0);--数码管的选择
signal cnt:std_logic_vector(3 downto 0);
signal flag:bit;
begin
--分频,得到0.5Hz信号test_en
process(clk)
begin
if clk'event and clk='1' then
test_en<=not test_en;
end if;
end process;
clear<=not clk and not test_en;--定义clear信号
process(test_en,reset)
begin
if(reset='0') then
cnt<="0000";
elsif test_en'event and test_en='0' then
if (cnt="1111") then
cnt<="0000";
else
cnt<=cnt+'1';
end if;
end if;
end process;
process(fsin)
begin
if reset= '0' then
row_in<= "000";
--flag<='0';
elsif fsin'event and fsin='1' then
if row_in="000" then row_in<="001";
elsif row_in="001" then row_in<="010";
elsif row_in="010" then row_in<="011";
elsif row_in="011" then row_in<="100";
elsif row_in="100" then row_in<="101";
elsif row_in="101" then row_in<="110";
elsif row_in="110" then row_in<="111";
elsif row_in="111" then row_in<="000";
end if;
end if;
end process;
--在1秒钟时间内对被测脉冲信号计数
process(fsin,test_en)
begin
buf<=data(23 downto 0);
if cnt="0000" then
data(23 downto 0)<="0000000000000000";
elsif fsin'event and fsin='1' then
if test_en='1' and cnt="0001" then
if data(23 downto 0)="100110011001100110011001"then data<=data+"011001100110011001100111";
--999999->1000000
elsif data(19 downto 0)="10011001100110011001" then data<=data+"01100110011001100111";
--99999->100000
elsif data(15 downto 0)="1001100110011001" then data<=data+"0110011001100111";
--9999->10000
elsif data(11 downto 0)="100110011001" then data<=data+"011001100111";
--999->1000
elsif data(7 downto 0)="10011001" then data<=data+"01100111";
--99->100
elsif data(3 downto 0)="1001" then data<=data+"0111";
--9->10
else data<=data+'1';
end if;
end if;
end if;
end process;
--根据所选数码管显示数据
process(row_in)
begin
row(2 downto 0)<=row_in(2 downto 0);
if (buf(23 downto 0) and "111111111111000000000000")="000000000000000000000000" then
flag<='0';
case row_in is
when "111"=>data_in<="1011";
when "110"=>data_in<="1010";
when "101"=>data_in<=buf(3 downto 0);
when "100"=>data_in<=buf(7 downto 4);
when "011"=>data_in<=buf(11 downto 8);
when "010"=>data_in<=buf(15 downto 12);
when "001"=>data_in<=buf(19 downto 16);
when "000"=>data_in<=buf(23 downto 20);
when others=>data_in<="XXXX";
end case;
else
--if row_in="010" then
--show<=show(7 downto 0) or "10000000";
flag<='1';
case row_in is
when "111"=>data_in<="1010";
when "110"=>data_in<="1100";
when "101"=>data_in<=buf(3 downto 0);
when "100"=>data_in<=buf(7 downto 4);
when "011"=>data_in<=buf(11 downto 8);
when "010"=>data_in<=buf(15 downto 12);
when "001"=>data_in<=buf(19 downto 16);
when "000"=>data_in<=buf(23 downto 20);
when others=>data_in<="XXXX";
end case;
end if;
end process;
--根据欲显示的数据配置数码管
process(data_in,flag,row_in)
begin
case data_in is
when "0000"=>show(6 downto 0)<="0111111";--0
when "0001"=>show(6 downto 0)<="0000110";--1
when "0010"=>show(6 downto 0)<="1011011";--2
when "0011"=>show(6 downto 0)<="1001111";--3
when "0100"=>show(6 downto 0)<="1100110";--4
when "0101"=>show(6 downto 0)<="1101101";--5
when "0110"=>show(6 downto 0)<="1111101";--6
when "0111"=>show(6 downto 0)<="0000111";--7
when "1000"=>show(6 downto 0)<="1111111";--8
when "1001"=>show(6 downto 0)<="1101111";--9
when "1010"=>show(6 downto 0)<="1110110";--H
when "1011"=>show(6 downto 0)<="1011011";--Z
when "1100"=>show(6 downto 0)<="1110111";--A
when others=>show(6 downto 0)<="1000110";---1
end case;
if row_in="010" and flag='1' then
show(7)<='1';
else
show(7)<='0';
end if;
end process;
end one;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -