TEST_EN<='0';
ELSECNT:
=0;TEST_EN<='0';
ENDIF;
ENDIF;
ENDPROCESS;
PROCESS(TEST_EN)
BEGIN
IF(TEST_EN'EVENTANDTEST_EN='1')THEN
DIV2CLK<=NOTDIV2CLK;
ENDIF;
ENDPROCESS;
PROCESS(TEST_EN,DIV2CLK,C)--产生清0信号---
BEGIN
IF((TEST_EN='0'ANDDIV2CLK='0')ORC='0')THEN
RST_EN<='0';
ELSERST_EN<='1';
ENDIF;
ENDPROCESS;
LOAD<=NOTDIV2CLK;C_EN<=DIV2CLK;
ENDBEHAVIOR;
锁存器设计
当系统正常工作时,脉冲发生器提供的1Hz的输入信号,通过测频操纵信号发生器进行信号的变换,产生计数信号,被测信号通过信号整形电路产生同频率的矩形波,送入计数模块,计数模块对输入的矩形波进行计数,将计数结果送入锁存器中,保证系统能够稳固显示数据。
LIBRARYIEEE;
USEUSEUSEENTITYREG32BIS
PORT(
LOAD:
INSTD_LOGIC;
DIN:
INSTD_LOGIC_VECTOR(31DOWNTO0);
DOUT:
OUTSTD_LOGIC_VECTOR(31DOWNTO0)
);
ENDREG32B;
ARCHITECTUREBEHAVIOROFREG32BIS
BEGIN
PROCESS(LOAD,DIN)
BEGIN
IF(LOAD'EVENTANDLOAD='1')THEN
DOUT<=DIN;
ENDIF;
ENDPROCESS;
ENDBEHAVIOR;
除法器模块程序
LIBRARYieee;
USElpm;
USE;
ENTITYdiv32bIS
PORT
(
denom:
INSTD_LOGIC_VECTOR(31DOWNTO0);
numer:
INSTD_LOGIC_VECTOR(31DOWNTO0);
quotient:
OUTSTD_LOGIC_VECTOR(31DOWNTO0);
remain:
OUTSTD_LOGIC_VECTOR(31DOWNTO0)
);
ENDdiv32b;
ARCHITECTURESYNOFdiv32bIS
SIGNALsub_wire0:
STD_LOGIC_VECTOR(31DOWNTO0);
SIGNALsub_wire1:
STD_LOGIC_VECTOR(31DOWNTO0);
COMPONENTlpm_divide
GENERIC(
lpm_drepresentation:
STRING;
lpm_hint:
STRING;
lpm_nrepresentation:
STRING;
lpm_type:
STRING;
lpm_widthd:
NATURAL;
lpm_widthn:
NATURAL
);
PORT(
denom:
INSTD_LOGIC_VECTOR(31DOWNTO0);
quotient:
OUTSTD_LOGIC_VECTOR(31DOWNTO0);
remain:
OUTSTD_LOGIC_VECTOR(31DOWNTO0);
numer:
INSTD_LOGIC_VECTOR(31DOWNTO0)
);
ENDCOMPONENT;
BEGIN
quotient<=sub_wire0(31DOWNTO0);
remain<=sub_wire1(31DOWNTO0);
lpm_divide_component:
lpm_divide
GENERICMAP(
lpm_drepresentation=>"UNSIGNED",
lpm_hint=>"LPM_REMAINDERPOSITIVE=TRUE",
lpm_nrepresentation=>"UNSIGNED",
lpm_type=>"LPM_DIVIDE",
lpm_widthd=>32,
lpm_widthn=>32
)
PORTMAP(
denom=>denom,
numer=>numer,
quotient=>sub_wire0,
remain=>sub_wire1
);
ENDSYN;
动态扫描信号输出
显示译码驱动电路将二进制表示的计数结果转换成相应的能够在七段数码显示管上能够显示的十进制结果。
在数码显示管上能够看到计数结果。
LIBRARYIEEE;
USESCAN8IS
PORT(
CLK:
INSTD_LOGIC;
NO1_BCD:
INSTD_LOGIC_VECTOR(3DOWNTO0);
NO2_BCD:
INSTD_LOGIC_VECTOR(3DOWNTO0);
NO3_BCD:
INSTD_LOGIC_VECTOR(3DOWNTO0);
NO4_BCD:
INSTD_LOGIC_VECTOR(3DOWNTO0);
NO5_BCD:
INSTD_LOGIC_VECTOR(3DOWNTO0);
NO6_BCD:
INSTD_LOGIC_VECTOR(3DOWNTO0);
NO7_BCD:
INSTD_LOGIC_VECTOR(3DOWNTO0);
NO8_BCD:
INSTD_LOGIC_VECTOR(3DOWNTO0);
IED_CS:
OUTSTD_LOGIC_VECTOR(7DOWNTO0);
IED_DATA:
OUTSTD_LOGIC_VECTOR(7DOWNTO0)
);
ENDSCAN8;
ARCHITECTUREBEHAVIOROFSCAN8IS
SIGNALS1:
STD_LOGIC_VECTOR(2DOWNTO0);
SIGNALBCD_OUT:
STD_LOGIC_VECTOR(3DOWNTO0);
SIGNALTEST_EN:
STD_LOGIC;
BEGIN
PROCESS(CLK)
VARIABLECNT:
INTEGERRANGE0TO2000;
BEGIN
IF(CLK'EVENTANDCLK='1')THEN
CNT:
=CNT+1;
IFCNT<1000THEN
TEST_EN<='1';
ELSIFCNT<2000THEN
TEST_EN<='0';
ELSECNT:
=0;TEST_EN<='0';
ENDIF;
ENDIF;
ENDPROCESS;
PROCESS(TEST_EN)
BEGIN
IF(TEST_EN'EVENTANDTEST_EN='0')THEN
IFS1="111"THENS1<="000";
ELSES1<=S1+1;
ENDIF;
ENDIF;
ENDPROCESS;
PROCESS(S1)
BEGIN
CASES1IS
WHEN"000"=>BCD_OUT<=NO1_BCD;IED_CS<="00000001";
WHEN"001"=>BCD_OUT<=NO2_BCD;IED_CS<="00000010";
WHEN"010"=>BCD_OUT<=NO3_BCD;IED_CS<="00000100";
WHEN"011"=>BCD_OUT<=NO4_BCD;IED_CS<="00001000";
WHEN"100"=>BCD_OUT<=NO5_BCD;IED_CS<="00010000";
WHEN"101"=>BCD_OUT<=NO6_BCD;IED_CS<="00100000";
WHEN"110"=>BCD_OUT<=NO7_BCD;IED_CS<="01000000";
WHEN"111"=>BCD_OUT<=NO8_BCD;IED_CS<="";
ENDCASE;
ENDPROCESS;
PROCESS(BCD_OUT)
BEGIN
CASEBCD_OUTIS
WHEN"0000"=>IED_DATA<="";--0
WHEN"0001"=>IED_DATA<="";--1
WHEN"0010"=>IED_DATA<="";--2
WHEN"0011"=>IED_DATA<="";--3
WHEN"0100"=>IED_DATA<="";--4
WHEN"0101"=>IED_DATA<="";--5
WHEN"0110"=>IED_DATA<="";--6
WHEN"0111"=>IED_DATA<="";--7
WHEN"1000"=>IED_DATA<="";--8
WHEN"1001"=>IED_DATA<="";--9
WHENOTHERS=>NULL;
ENDCASE;
ENDPROCESS;
ENDBEHAVIOR;
频率计
LIBRARYIEEE;
USEfreqIS
PORT(
C:
INSTD_LOGIC;
CLK:
INSTD_LOGIC;
TEST_CLK:
INSTD_LOGIC;
IED_CS:
OUTSTD_LOGIC_VECTOR(7DOWNTO0);
IED_DATA:
OUTSTD_LOGIC_VECTOR(7DOWNTO0)
);
ENDfreq;
ARCHITECTUREBEHAVIOROFfreqIS
COMPONENTCNT10IS--计数器的例化--
PORT(
C:
INSTD_LOGIC;
CLK:
INSTD_LOGIC;
C_EN:
INSTD_LOGIC;
CARRY_OUT:
OUTSTD_LOGIC;
Q_OUT:
OUTSTD_LOGIC_VECTOR(3DOWNTO0)
);
ENDCOMPONENTCNT10;
COMPONENTTESTCTLIS--测频部份例化--
PORT(
C:
INSTD_LOGIC;
CLK:
INSTD_LOGIC;
C_EN:
OUTSTD_LOGIC;
RST_EN:
OUTSTD_LOGIC;
LOAD:
OUTSTD_LOGIC
);
ENDCOMPONENTTESTCTL;
COMPONENTREG32BIS--锁存器例化---
PORT(
LOAD:
INSTD_LOGIC;
DIN:
INSTD_LOGIC_VECTOR(31DOWNTO0);
DOUT:
OUTSTD_LOGIC_VECTOR(31DOWNTO0)
);
ENDCOMPONENTREG32B;
COMPONENTSCAN8IS--扫描部份例化---
PORT(
CLK:
INSTD_LOGIC;
NO1_BCD:
INSTD_LOGIC_VECTOR(3DOWNTO0);
NO2_BCD:
INSTD_LOGIC_VECTOR(3DOWNTO0);
NO3_BCD:
INSTD_LOGIC_VECTOR(3DOWNTO0);
NO4_BCD:
INSTD_LOGIC_VECTOR(3DOWNTO0);
NO5_BCD:
INSTD_LOGIC_VECTOR(3DOWNTO0);
NO6_BCD:
INSTD_LOGIC_VECTOR(3DOWNTO0);
NO7_BCD:
INSTD_LOGIC_VECTOR(3DOWNTO0);
NO8_BCD:
INSTD_LOGIC_VECTOR(3DOWNTO0);
IED_CS:
OUTSTD_LOGIC_VECTOR(7DOWNTO0);
IED_DATA:
OUTSTD_LOGIC_VECTOR(7DOWNTO0)
);
ENDCOMPONENTSCAN8;
SIGNALSE,SC,SL:
STD_LOGIC;
SIGNALS1,S2,S3,S4,S5,S6,S7,S8:
STD_LOGIC;
SIGNALSD:
STD_LOGI