同一信号不能在不同进程中赋值的解决办法(程序实例)【恢复】
同一信号不能在不同得进程中赋值的解决办法下面结合具体程序说明,
源程序:library ieee;
use ieee.std_logic_1164.all;
entity counter is
port(y,clk0:in std_logic;
s1 :out std_logic);
end counter;
architecture rtl of counter is
signal en:std_logic;
begin
process(clk0)
variable i:integer;
begin
if(clk0'event and clk0='1')then
if(en='1')then
if(i=20)then
i:=0;
en<='0';
s1<=y;
else
s1<='0';
i:=i+1;
end if;
end if;
end if;
end process;
process(y)
begin
if(y'event and y='1')then
en<='1';
end if;
end process;
end rtl;
实现的功能:在输入y上升沿时计数,计数期间输出低电平,当计数到20个clk后计数结束,完后输出y的波形
出现的错误:Error (10028): Can't resolve multiple constant drivers for net "en" at test.vhd(30)
错误分析:误用Process经常会引起输出多驱动源的发生,即在两个以上的进程内对同一信号赋值操作。以下程序就出现了这类情况:
⑴ Proc_a: process(clk)
⑵ begin
⑶ if clk’event and clk=’1’ then
⑷ Dout<=Din_A;
⑸ end if
⑹ end process;;
⑺
⑻ Proc_b:process(sel_en)
⑼ begin
⑽ if sel_en=’1’ then
⑾ Dout<=Din_B;
⑿ end if;
⒀ end process;
进程Proc_a和Proc_b中都出现了对Dout的赋值语句,设计者原本的想法是,只要合理控制好clk和sel_en输入,使其不发生冲突,即 clk上升沿时sel_en不为’1’;sel_en为’1’时,不出现clk的上升沿,这样Proc_a,Proc_b两个进程就不会发生冲突。但综合时,综合工具会将所有可能情况全部罗列进去,包括第⑶行和第⑽行同时成立的情况,此时对于Dout就有Din_A和Din_B两个输入驱动,Dout不知接收哪一个,因此该程序无法综合,改正的方法是只要将两个进程合并成一个即可,也就是说想办法把赋值集中到同一个process中。
正确的程序:library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity test is
port(y,clk0: in std_logic;
s1: out std_logic;
debug_a: out std_logic);
end test;
architecture rtl of test is
signal en:std_logic;
signal i: integer range 0 to 30;--整形数据一定要指定范围,否则有意想不到的问题
signal temp:std_logic;
begin
process(clk0)
begin
if(clk0'event and clk0='1')then
if(en='1')then
if(i=20)then
i<=0;
s1<=y;
debug_a<='1';
temp<='1';
else
s1<='0';
i<=i+1;
debug_a<='0';
temp<='0';
end if;
elsif (temp='1') then
s1<=y;temp<='0';
else s1<=y;
end if;
end if;
end process;
process(y,temp)
begin
if (temp='1') then
en<='0';
elsif (y'event and y='1') then
en<='1';
end if;
end process;
上面的程序就是把en单独提出来放在了一个进程中,避免了Can't resolve multiple constant drivers的错误。
实际上,这个解决方法在其他方面可以类推 mark http://cache.amobbs.com/bbs_upload782111/files_11/ourdev_582346.jpg
正确的仿真波形图 (原文件名:33.jpg) 补充说明:这类“几个信号有牵连且同时进行”的设计,最好采用有限状态机;采用状态机的中间变量能很好且很容易地解决这类问题,过程清晰而且设计简单。
有限状态机原是图灵想法,不愧是人工智能之父 这个要学习一下
页:
[1]