来自不同进程的VHDL驱动信号
我对以下 VHDL 代码有一个小问题:
process (zbroji)
begin
if rising_edge(zbroji) then
oduzima <= '0';
ucitanPrvi <= '1';
broj1 <= ulaz_broj;
end if;
end process;
process (oduzmi)
begin
if rising_edge(oduzmi) then
oduzima <= '1';
ucitanPrvi <= '1';
broj1 <= ulaz_broj;
end if;
end process;
问题是信号 ucitanPrvi 始终具有值 X。如果我不尝试在两个进程中设置它的值,那么我就没有任何问题......所以我知道我不能从多个进程驱动一个信号,但我不知道如何以不同的方式编写它...... 有谁知道我如何解决这个问题?
谢谢 !
编辑:谢谢大家的回复:)现在我明白为什么我不能从多个进程驱动一个信号(至少以我希望它工作的方式)。
I have a little problem with following VHDL code:
process (zbroji)
begin
if rising_edge(zbroji) then
oduzima <= '0';
ucitanPrvi <= '1';
broj1 <= ulaz_broj;
end if;
end process;
process (oduzmi)
begin
if rising_edge(oduzmi) then
oduzima <= '1';
ucitanPrvi <= '1';
broj1 <= ulaz_broj;
end if;
end process;
The problem is that signal ucitanPrvi always has value X. If I don't try to set it's value in two processes, then I don't have any problems ... So I know that I mustn't drive one signal from multiple processes, but I don't know how to write this differently ...
Does anyone have an idea how I could resolve this problem ?
Thanks !
EDIT: Thank you all guys for replying :) Now I understand why I can't drive one signal from multiple processes (at least in the way I wanted it to work).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您想综合真实 FPGA 或 ASIC 的设计,则必须从真实硬件(线路、触发器、门等)角度考虑 VHDL。此外,如果您想在硬件中执行真正的上升沿检测,您将需要一个驱动触发器的系统时钟。鉴于您的原始代码示例, zbroji 或 oduzmi 似乎不是系统时钟,而只是 std_logic 信号。我编写了这个代码示例,假设您的示例具有基本功能,希望您可以采用我的代码和注释并完成您需要的功能。
前面的代码假设您有一个系统时钟。在像 ModelSim(免费学生版)这样的模拟器中,您可以使用不可综合的测试平台代码生成 100 MHz 时钟,如下所示...
在实际的 FPGA/ASIC 实现中,您可能需要使用遇到的外部振荡器您的芯片,将信号驱动到 DCM(数字时钟管理器),它将向您的所有 VHDL 逻辑输出非常干净的时钟信号,这样您就可以获得无故障设计。
最后,这是关于rising_edge和rising_edge之间差异的一个很好的解释
(clk'事件和 clk='1')
http:// vhdlguru.blogspot.com/2010/04/difference- Between-risingedgeclk-and.html
希望有帮助。
If you want to synthesize your design for a real FPGA or ASIC, you are going to have to think of VHDL in terms of real hardware (wires, flip flops, gates, etc.). Also, if you want to perform a real rising edge detect in hardware, you will need a system clock that drives a flip flop. Given your original code sample, it doesn't seem that zbroji or oduzmi are system clocks, but just std_logic signals. I wrote this code example assuming basic functionality from your example, hopefully, you can take my code and comments and accomplish what you need.
The previous code assumes you have a system clock. In a simulator like ModelSim (free student edition), you can generate a 100 MHz clock with non-synthesizable testbench code like this...
In an actual FPGA/ASIC implementation, you will probably want to use an external oscillator that you run into your chip, drive the signal into a DCM (Digital clock manager), which will output a very clean clock signal to all of your VHDL logic, so you can have a glitch free design.
And finally, here is a great explanation on the differences between rising_edge and
(clk'event and clk='1')
http://vhdlguru.blogspot.com/2010/04/difference-between-risingedgeclk-and.html
Hope that helps.
如果您从多个进程驱动一个
std_logic
信号(请记住,进程外部的连续赋值也会创建一个隐含进程!),那么除了其中一个之外,所有进程都必须驱动Z< /code> 到信号上。对于第一个近似,解析函数(决定最终值应该是什么)将产生
X
,除非发生这种情况。我不确定如何最好地更改您的代码 - 您需要决定特定进程何时不应驱动信号并让它在此时驱动 Z。
多个驱动程序如何解析的完整定义在 ieee.std_logic_1164 包中定义,涵盖了所有可能性,例如
1
和L
驱动等。 IEEE get由于版权问题,我不会在这里发布任何摘录,但您可以在模拟器的源库中找到它。If you drive a
std_logic
signal from more than one process (and remember that a continuous assignment outside of a process also creates an implied process!) then all but one of them must be drivingZ
onto the signal. To a first approximation, the resolution function (that decides what the final value should be) will produceX
s unless this happens.I'm not sure how best to change your code - you need to decide when a particular process should not drive the signal and have it drive a
Z
at that point.The full definition of how the multiple drivers are resolved is defined in the ieee.std_logic_1164 package and covers all possibilities, such as a
1
and anL
driving etc. The IEEE get shirty about copyright, so I'm not going to post even an excerpt here, but you'll be able to find it in the source libraries of your simulator.从多个进程驱动信号是一个坏主意,除非您真正知道自己在做什么。您可以像这样在单个进程中重写此代码。
请注意,如果执行此操作,
zbroji
和zbroji
上都会出现上升沿。oduzmi
然后oduzima
将获得值1
,因为它在该过程中最后发生。之前您会尝试同时将其设置为0
和1
。这将模拟X
,并且可能不会合成。如果它确实合成,您将在 CMOS 设计中将电源和接地连接在一起。另一种方法是让每个进程驱动它自己的信号版本,然后使用您喜欢的函数(或另一个进程)在外部解析它们。在本例中我使用了
或
:Driving signals from multiple processes is a bad idea unless you really know what you're doing. You can re-write this code in a single process like this.
Note that if you do this, and you get a rising edge on both
zbroji
&oduzmi
thenoduzima
will get the value1
as it happens last in the process. Before you'd have been trying to set it to0
and1
at the same time. That would simulate toX
, and probably wouldn't synthesize. If it did synthesize you'd be connecting power and ground together in a CMOS design.An alternative method is to have each process drive it's own version of the signal, and then resolve them externally with what ever function you like (or another process). In this case I used
or
:除非 zbroji 和 oduzmi 是单独的时钟,否则这是我推荐的实现。
它注册 zbroji 和 oduzmi 并检查寄存器中的值是否与原始信号相反。仅当 zbroji/oduzmi 从 0 变为 1 并且寄存器尚未更新信号变化时才会发生这种情况。
而且 ucitanPrvi 和 broj1 似乎总是同一件事。信号要么是无用的,这本来就是一个拼写错误,要么您正在创建“更新”脉冲,在这种情况下您需要
if(rising_edge(clk) 语句后面的语句
Unless zbroji and oduzmi are seperate clocks this is my recommended implementation
This registers the zbroji and oduzmi and checks if the value in the register is the opposite of the original signal. This should only occur when zbroji/oduzmi go from 0 to 1 and the register has not yet updated the change in signal.
Also it appears that ucitanPrvi and broj1 are always the same thing. Either the signals are useless, this was orignally a typo or you are creating "update" pulses in which case you need the statement
following the if(rising_edge(clk) statement
当您从多个进程更改相同的信号值时,模拟器将为此创建多个信号驱动程序。它们的输出基本上是悬而未决的。将其视为连接在一起的多个门的输出,您期望什么?
为了克服这个问题,您需要实现一个解析函数,驱动输出信号。
http://www.csee.umbc.edu/portal/help /VHDL/misc.html#resf
如果您有任何疑问,请告诉我。
When you're changing same signal value from multiple process, the simulator will be creating multiple signal drivers for this. The output of them will essentially will be unresolved. Think of it as the output of multiple gates connected together, what do you expect?
To overcome this, what you need to implement is, a resolution function, that drivers the output to signal.
http://www.csee.umbc.edu/portal/help/VHDL/misc.html#resf
If you have any doubts, let me know.