VHDL 中的过程

Process in VHDL

我是 VHDL 的初学者,这里有一些关于我的代码的问题。

process(clock_50)
begin
if(clock_50'event and clock_50='1') 
    if(prescaler<500000) then --prescaler to slow down and initialized by 0
       prescaler<=prescaler+1;
    else
       prescaler<=0;
    end if;

    if(prescaler=0) then
        case key(0) is --key representing button 
            when '0' =>  
                if(result<1023) then --result is a signal counter for 10 bit led value
                                     --and initialized by 0

                    result<=result+1;
                else
                    result<=0;
                end if;
            when '1' =>       
                if(result>0) then
                    result<=result-1; 
                else
                    result<=1023;
                end if;
       end case;
    end if;
end if; 
end process;

关于那些代码;

问题 1:预分频器已用值 0 初始化,在第 4 行中,有 'if' 条件,但表现得像一个循环,我说的对吗?我的意思是它按 500000 计数。是真的吗?如果是真的,为什么?感谢'process'或并行编码?

Q2:实际上,当按键被释放时,LED 从 9 倒数到 0。但是在代码中,我们声明 case key(0) 是当 '0' 结果向上计数时。我缺少什么? 在此先感谢并原谅我的不足。

Q1:第 4 行的 if 条件在 clock_50 信号的每个上升沿运行(由于前三行代码)。预分频器初始化为零后,第 4-9 行的 if 语句将每个时钟将预分频器值递增 1,直到它等于 500000,此时它被重置回零。这会将时钟信号的 50 MHz 周期(假设基于信号名称)变为 50,000,000 / 500,000 或 100 Hz。一个更明智的时间框架来检查开关,特别是如果你没有做任何其他的去抖动。

Q2:当预分频器=0(每 500000 个时钟中有一个)时,结果值将增加 1 或减少 1,在 0 和 1023(即:10 位二进制值)处回绕,具体取决于key(0) 值是“0”(递增)还是“1”(递减)。

没有足够的信息来回答您的 "But on code, we state that case key(0) is when '0' result is counting up. What I'm missing?" 问题,但是将开关 "inverted" 与上拉电阻和开关短路接地(所以一个打开的开关读取“1”,一个闭合的开关读取“0”),但是在没有看到其余逻辑的情况下,我无法告诉你在 key(0) 的值之外应该发生什么。查看其余的逻辑(和原理图!)以查看键(0)信号的来源,以及当您实际按下按钮时该值应该是“0”还是“1”。