设计一个16位的计数器对CLK1计数,上位机通过STRB对当前的计数值进行锁存,CS为计数器的片选,RD为读选通,读取锁存后的计数值
在QUARTUS中仿真,结果正确,可下载到CPLD后,发现即使CLK1没有输入信号,计数器也在计数,即语句CLK1 'event AND CLK1='1'好像没有起作用,counter1<=counter1+'1';一直在运行
下面是程序,请帮我看看原因在哪,我用的型号是MAXII
library IEEE;
use IEEE.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity counter is
port(
CS: in std_logic;
STROBE: in std_logic;
CLK1: in std_logic;
CLR: in std_logic;
RD: in std_logic;
DATA: out std_logic_vector(15 downto 0)
);
end counter;
architecture behavior of sixcounter is
signal counter1: std_logic_vector(15 downto 0):=x"0000"; --计数值
signal counter1_temp: std_logic_vector(15 downto 0):=x"0000"; --锁存值
begin
COUNT1: process(CS,CLR,CLK1) --计数
begin
if(CLR='0' AND CS='0') then
counter1<=x"0000";
elsif(CLK1 'event AND CLK1='1') then
if(counter1=x"FFFF") then
counter1<=x"0000";
else counter1<=counter1+'1';
end if;
end if;
end process COUNT1;
STRB: process(CS,STROBE) --锁存
begin
if(STROBE 'event AND STROBE='1') then
if(CS='0') then
counter1_temp<=counter1;
end if;
end if;
end process STRB;
READDATA: process(CS,RD) --读取
begin
if(CS='0' AND RD='0') then
DATA<=counter1_temp(15 downto 0);
else DATA<="ZZZZZZZZZZZZZZZZ";
end if;
end process READDATA;
感觉你的程序应该有问题,比如
READDATA: process(CS,RD) --读取
begin
if(CS='0' AND RD='0') then
DATA<=counter1_temp(15 downto 0);
else DATA<="ZZZZZZZZZZZZZZZZ";
end if;
end process READDATA;
DATA是输出引脚,但是他的敏感信号只有CS,RD,它的触发信号CLK在哪呢?所以DATA的值不会受CLK影响。
一家之言,希望对你有帮助
STRB: process(CS,STROBE) --锁存
begin
if(STROBE 'event AND STROBE='1') then
if(CS='0') then
counter1_temp<=counter1;
end if;
end if;
end process STRB;
READDATA: process(CS,RD) --读取
begin
if(CS='0' AND RD='0') then
DATA<=counter1_temp(15 downto 0);
else DATA<="ZZZZZZZZZZZZZZZZ";
end if;
end process READDATA;
像tigerxd 说的,搂朱最好把 下面的简化下,直接用CS,RD作为三态的驱动,
READDATA: process(CS,RD) --读取
begin
if(CS= "0 " AND RD= "0 ") then
DATA <=counter1_temp(15 downto 0);
else DATA <="ZZZZZZZZZZZZZZZZ";
end if;
end process READDATA;