我需要多少个进程来监视两个信号?

2023-12-14

我是一名 vhdl 初学者,需要帮助解决我的问题。 我有两个需要监控的信号。一个是 CHECK,另一个是 OK。 每次我要求检查时,我都应该得到好的结果(高或低)。 我需要连续监测6个连续的CHECK脉冲,并计数OK。 如果我有 6 OK(低),那么我需要产生输出(高),任何其他情况输出(低)。 我编写了一些代码,但无法产生上面想要的输出。但我首先有一个基本问题。 这可以在一个过程中完成吗?

--one process
if ...
  reset clauses
elsif
  count pulses and set a variable to 6
else  
  if variable = 6, produce output
end if;

或者我需要更多吗?

--first process
start counter on rising_edge of CHECK

-- second process
count pulses and set a signal some value (6)

-- third process 
monitor signal and if =6, produce output

编辑: 这是我尝试过的代码,但失败了...将研究 FSM...

counter_operation:process (RESETn, CHECK, OK)
variable counter : unsigned (2 downto 0);
variable lost_count : unsigned (2 downto 0);
begin
-- if reset it asserted ensure counter is not running
if ( RESETn = '0') then
    trip_signal <= '0';
    lost_count := to_unsigned (0,3);
    counter := to_unsigned (0,3);

-- run counter and perform actions
elsif (rising_edge(CHECK)) then
        -- increment counter and limit maximum value
        counter := counter+1;   
        if (counter > to_unsigned(6,3) ) then
            counter := to_unsigned (0,3);
            lost_count := to_unsigned (0,3);
        end if;

        -- check for first OK(LOW)
        if (counter = to_unsigned(1,3))  then
            if (OK = '0') then
                lost_count := lost_count + to_unsigned (1,3);
            else
                lost_count := lost_count;   
            end if; 
        end if;
        -- check for second consecutive OK(LOW)
        if (counter = to_unsigned(2,3))  then
            if (OK = '0') then
                lost_count := lost_count + to_unsigned (1,3);
            else
                lost_count := lost_count;   
            end if; 
        end if;
        -- check for third consecutive OK(LOW)
        if (counter = to_unsigned(3,3))  then
            if (OK = '0') then
                lost_count := lost_count + to_unsigned (1,3);
            else
                lost_count := lost_count;   
            end if; 
        end if;
        -- check for fourth consecutive OK(LOW)
        if (counter = to_unsigned(4,3))  then
            if (OK = '0') then
                lost_count := lost_count + to_unsigned (1,3);
            else
                lost_count := lost_count;   
            end if; 
        end if;
        -- check for fifth consecutive OK(LOW)
        if (counter = to_unsigned(5,3))  then
            if (OK = '0') then
                lost_count := lost_count + to_unsigned (1,3);
            else
                lost_count := lost_count;   
            end if; 
        end if;
        -- check for sixth consecutive OK(LOW)
        if (counter = to_unsigned(6,3))  then
            if (OK = '0') then
                lost_count := lost_count + to_unsigned (1,3);
            else
                lost_count := lost_count;   
            end if; 
        end if;
        -- check if we lost 6 consecutive 
        if (lost_count = to_unsigned (6,3)) then
            trip_signal <= '1';
        else
            trip_signal <= '0'; 
        end if; 
    end if;
end process counter_operation;

我这里肯定有问题,因为模拟前和模拟后不会产生相同的结果。 Pre-sim 似乎有效,但 post-sim 则无效。

编辑(2): 对于FSM来说,是这样的吗?

library IEEE;
use IEEE.std_logic_1164.all;

entity FSM_1 is
port (
    CHECK : in std_logic;
    CRC :in std_logic;
    CLK : in std_logic; 
    RESETn :in std_logic;
    OUT_SIG : out std_logic

);
end FSM_1;

architecture arch of FSM_1 is


-- signal, component etc. declarations
type TargetSeqStates is (IDLE, FIRST_CHECK, SECOND_CHECK, THIRD_CHECK, FOURTH_CHECK, FIFTH_CHECK, SIXTH_CHECK);
signal curr_st, next_st : TargetSeqStates;

begin
--------------------------------------------------------------------------------
-- Using the current state of the counter and the input signals, decide what the next state should be
--------------------------------------------------------------------------------
NxStDecode:process (CHECK, OK, curr_st)
begin
-- default next-state condition
next_st <= IDLE;
-- TODO...

-- TODO...
end process NxStDecode;
--------------------------------------------------------------------------------
-- At the desired clock edge, load the next state of the counter (from 1.) into the counter
-- create the current-state variables 
--------------------------------------------------------------------------------
CurStDecode:process (CLK, RESETn)
begin
-- Clear FSM to start state 
if (RESETn = '0') then
    curr_st <= IDLE;
elsif (rising_edge(CLK)) then
    curr_st <= next_st;
end if;
end process CurStDecode;

--------------------------------------------------------------------------------
-- Using the current state of the counter and the input signals, decide what the values of all output signals should be
--------------------------------------------------------------------------------
DecOutputs;process (curr_st)
begin
-- TODO....

-- TODO...

end process DecOutputs;

end arch;

我猜 TODO 部分依赖于状态图? 另外,我需要CLK吗?看来我需要改变状态, 在 CHECK 的上升沿,而不是 CLK。

最终编辑:

counter_operation:process (RESETn, CHECK, OK, CLK)
variable lost_counter : integer := 0;
variable last_CHECK : std_logic;

begin
    if ( RESETn = '0') then
    D_TRIP <= '0';
    lost_counter := 0;

else 
    if (rising_edge(CLK)) then
        if (CHECK /= last_CHECK) then
            if (OK = '0') then
            lost_counter := lost_counter + 1;
            else
            lost_counter := 0;  
            end if; 
            D_TRIP <= '0';
            if (lost_counter = 6) then
            D_TRIP <= '1';
            lost_counter := 0;
            end if;   
        end if;
        last_CHECK := CHECK;
    end if;
end if;
end process counter_operation;

这是一个非常标准的状态机,大多数设计人员都会为状态机使用一到三个进程。如果您刚刚开始,那么使用三个流程可能会让您的事情变得更容易。这些过程将是:

  1. 使用计数器的当前状态和输入信号,决定下一个状态应该是什么。
  2. 使用计数器的当前状态和输入信号,确定所有输出信号的值应该是什么。
  3. 在所需的时钟沿,将计数器的下一个状态(从 1 开始)加载到计数器中。

请注意,前两个过程纯粹是组合逻辑,而第三个过程是时钟顺序过程。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

我需要多少个进程来监视两个信号? 的相关文章

  • 是否有理由在 VHDL 和 Verilog 中初始化(而不是重置)信号?

    我从未初始化过信号 这样 任何缺少重置或分配的信号都将是未知的或已初始化 在一些参考代码中它们有初始化 这违背了我的愿望 此外 由于初始化不可综合 因此可能会出现模拟 综合不匹配的情况 在这种情况下有什么理由初始化信号吗 编辑 2011 年
  • VHDL:使用输入端口是不好的做法吗?

    我有一个程序 我按照以下方式使用 inout 端口 port inout unsigned 9 downto 0 if port gt 10 then port lt port 1 end if 我正在使用 inout 端口 这样我就可以读
  • 子状态机

    我有一个有 5 个州的 FSM 其中3个是通过子FSM UML模式 设计的 对于 VHDL 中的实现 恕我直言 有两种方法可以做到这一点 将它们总结为一个 这样我就有了一份包含子 FSM 的文档和一个包含一个大 FSM 的产品 与所有州建立
  • 在变量类型VHDL中添加2个std_logic_vector

    我正在参与这个学校项目 我有两个 std logic vector 31 downto 0 A 和 B 并且我有一个变量类型 std logic vector 32 downto 0 我想添加 A B 并将结果放入 32 位的 std lo
  • 在vhdl中生成随机整数

    我需要在 vhdl 中生成 0 1023 之间的随机整数 但是我在互联网上找不到这方面的好资源 请问有人帮我吗 下面是生成范围 0 1023 内均匀 均匀 分布的整数的示例 请注意 floor必须在与最大值 1 相乘之后使用运算 在本例中为
  • VHDL——连接开关和LED

    我有 Xilinx Spartan6 和下一个 VHDL 代码 library ieee use ieee std logic 1164 all use ieee numeric std all entity Switches Leds i
  • 在VHDL中初始化记录数组

    我有一条记录定义如下 type ifx t is record data std logic vector 127 downto 0 address std logic vector 19 downto 0 WrReq std logic
  • “警告 C0007:架构具有未绑定的实例”问题!

    我从 数字设计基础 一书随附的 CD 中获取了以下源代码 当我尝试运行该程序时 出现以下错误 Compiling Fig17 13 vhd C Users SPIDER Desktop EE460 The Final Project Fig
  • VHDL 上的反转位顺序

    我在做类似的事情时遇到困难 b 0 to 7 lt a 7 downto 0 当我用ghdl编译它时 出现顺序错误 我发现使我的电路工作的唯一方法如下 library ieee use ieee std logic 1164 all ent
  • 模拟器和合成器之间初始化状态机的差异

    我的问题是关于合成状态机中使用的第一个状态 我正在使用莱迪思 iCE40 FPGA 用于仿真的 EDA Playground 和用于综合的莱迪思 Diamond Programmer 在下面的示例中 我生成一系列信号 该示例仅显示引用状态机
  • Quartus初始化RAM

    我制作了一个实体 其中 quartus 成功识别 RAM 并为其实例化 RAM 宏功能 如果我可以从文件初始化 RAM 那就太好了 我找到了制作此类文件 mif 文件 的教程 现在我已经创建了该文件 我不知道如何让 quartus 初始化该
  • 将库添加到 Vivado 2014.4

    我对 Vivado 和 VHDL 还很陌生 我想要一些关于基本问题的指导 我猜我可以创建自己的库并在我的项目中使用它们 就像使用默认库和基本库一样 eg library IEEE use IEEE std logic 1164 ALL us
  • VHDL 中的 BRAM_INIT

    我正在模拟基于处理器的设计 其中程序存储器内容保存在 BRAM 中 我正在使用 VHDL 推断 BRAM 实现程序存储器 我试图避免使用 CoreGen 因为我想保持设计的可移植性 最终该设计将进入 FPGA 我想看看是否有一种方法可以使用
  • VHDL - 分配默认值

    我有以下架构 architecture datapath of DE2 TOP is begin U1 entity work lab1 port map error on this line clock gt clock 50 key g
  • 全8位加法器,非逻辑输出

    我创建了一个带全加器的 8 位加法器 正如您所看到的 我开始从右到左添加相应的位 对于 cin 信号 t1 和 t2 并按顺序 cout t2 和 t1 第一个 cin 设置为加法器输入 cin 我在实现中没有看到任何问题 但是当我运行它时
  • VHDL 中的进程是可重入的吗?

    一个进程是否可以连续运行两次或多次VHDL 如果在进程的顺序执行未完成的情况下发生另一个事件 在敏感信号列表上 会发生什么 有可能还是我的VHDL流程中的模型完全错误 进程运行时不会发生任何事件 当进程被事件唤醒时 它会运行到完成 结束进程
  • 如何从 Spartan 6 写入 Nexys 3 FPGA 板上的 Micron 外部蜂窝 RAM?

    我到处都查过了 数据表 Xilinx 网站 digilent 等等 但什么也没找到 我能够使用 Adept 工具来验证我的蜂窝 RAM 是否正常运行 但我找不到任何库存 VHDL 代码作为控制器来写入数据和从中读取数据 帮助 找到了此链接
  • VHDL 计数器错误 (vcom-1576)

    伙计们 我试图用 VHDL 编写一个简单的计数器 但我总是收到此错误 Error C Users usrname dir1 dir2 dir3 counter vhd 22 near rising edge vcom 1576 expect
  • Simulink/HDL Coder 中的反馈循环

    我有一个 Simulink HDL 编码器系统 请参见下图 我有 3 个输出和 3 个输入 我希望我的系统运行 10 次 每次迭代后 它应该选择输出并将它们用作输入 我怎样才能做到这一点 使用存储器和每个信号的初始值块构建一个循环 内存块允
  • 使用 if 语句更改进程内的信号 - VHDL

    我有这个 VHDL 代码 我想要的是在 sw event 时首先上升 然后 首先自行下降 但当我模拟这个时 首先永远不会跌倒 process rst clk sw begin if clk EVENT and clk 1 then if r

随机推荐