搜索
bottom↓
回复: 4

同一信号不能在不同进程中赋值的解决办法(程序实例)【恢复】

[复制链接]

出0入0汤圆

发表于 2009-1-11 20:09:29 | 显示全部楼层 |阅读模式
同一信号不能在不同得进程中赋值的解决办法

下面结合具体程序说明,

源程序: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的错误。

实际上,这个解决方法在其他方面可以类推

阿莫论坛20周年了!感谢大家的支持与爱护!!

知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)

出0入0汤圆

发表于 2009-1-13 22:25:35 | 显示全部楼层
mark

出0入0汤圆

 楼主| 发表于 2009-1-11 20:10:01 | 显示全部楼层


正确的仿真波形图 (原文件名:33.jpg) 

出0入0汤圆

 楼主| 发表于 2009-8-28 15:09:45 | 显示全部楼层
补充说明:这类“几个信号有牵连且同时进行”的设计,最好采用有限状态机;采用状态机的中间变量能很好且很容易地解决这类问题,过程清晰而且设计简单。   


   有限状态机原是图灵想法,不愧是人工智能之父

出0入70汤圆

发表于 2009-8-29 20:42:16 | 显示全部楼层
这个要学习一下
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-7-24 19:26

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表