和002s的闸门信号还有译码显示的扫描信号1KHz所以我们在此模块先分频产生1Hz、10Hz、100Hz、1KHz四个分频信号以留作其它模块用。
分频分别采用4个计数器来实现当计到一定的值时输出的分频信号翻转最后分别获得4个分频输出分频器模块如下图所示
此模块的复位为同步方式当复位有效时输出将清零。
源程序如下
moduleclk_divresetclkclk_1hzclk_10hzclk_100hzclk_1khz
i
putresetclk
outputregclk_1hzclk_10hzclk_100hzclk_1khz
reg290cou
ter1cou
ter2cou
ter3cou
ter4分频计数值
alwaysposedgeclkor
egedgereset
begi
ifreset
begi
cou
ter10cou
ter20cou
ter30cou
ter40
clk_1hz0clk_10hz0clk_100hz0clk_1khz0
e
delsebegi
ifcou
ter12400000
begi
cou
ter10clk_1hzclk_1hze
d
elsebegi
cou
ter1cou
ter11e
d
ifcou
ter2240000begi
cou
ter20clk_10hzclk_10hze
delse
fbegi
cou
ter2cou
ter21e
d
ifcou
ter324000
begi
cou
ter30clk_100hzclk_100hze
d
else
begi
cou
ter3cou
ter31e
d
ifcou
ter42400
begi
cou
ter40clk_1khzclk_1khze
d
else
begi
cou
ter4cou
ter41e
d
e
d
e
d
e
dmodule
仿真图如下所示
32闸门选择器
该模块主要实现对闸门的选择功能通过输入的门选信号来确定输出的闸门生成的模块如下图所示
f具体实现方法如下当三个门选信号中有且仅有门选信号gate_ch1有效时reg变量gate为clk_1hz当三个门选信号中有且仅有门选信号gate_ch2有效时
reg变量gate为clk_10hz当三个门选信号中有且仅有门选信号gate_ch3有效时reg变量gate为clk_100hz。reg变量gate再二分频则是输出的闸门信号gate_out
dot为标记信号标记了当前闸门的选择情况。如果同时有两个或以上的门另外输出的译码扫描信号为clk_1khz供后面的扫描译码模块使用
程序如下modulegate_selresetgate_ch1gate_ch2gate_ch3
clk_1hzclk_10hzclk_100hzclk_1khz
gate_outdot
i
putresetgate_ch1gate_ch2gate_ch3
clk_1hzclk_10hzclk_100hzclk_1khz
outputreggate_out
outputreg20dot
alwaysposedgeclk_1khzor
egedgereset
begi
ifreset
begi
gate_out0dot3b111e
d
else
begi
ifgate_ch10gate_ch21gate_ch31
begi
gate_outclk_1hzdot3b011e
d
elseifgate_ch11gate_ch20gate_ch31
begi
gate_outclk_10hzdot3b010e
d
elseifgate_ch11gate_ch21gate_ch30
begi
gate_outclk_100hzdot3b001e
d
felse
begi
gate_out0dot3b111e
d
e
d
e
d
e
dmodule
33频率计计数
频率计数器的功能为在输入的闸门信号的控制下对输入脉冲时行计数它是一个
7拉的模十计数器。生成的模块如下图所示
当gate_out信号为高时才计数器才计数在gate_out为低后马上将此时计数的值c
t赋给输出c
te然后当输入carry_i
信号再过一个脉冲后降计数的值
c
清零以备下次闸门r