Input VHDL:计算输入值而不注册最终输入
我正在研究一个vhdl模块 我想总结6个时钟周期的输入值,然后根据是否达到阈值将输出设置为高或低 我遇到的问题是,在最后一个时钟周期,总和值没有添加最终输入值。我需要将输出置于时钟上升沿的高位 代码如下:Input VHDL:计算输入值而不注册最终输入,input,sum,vhdl,Input,Sum,Vhdl,我正在研究一个vhdl模块 我想总结6个时钟周期的输入值,然后根据是否达到阈值将输出设置为高或低 我遇到的问题是,在最后一个时钟周期,总和值没有添加最终输入值。我需要将输出置于时钟上升沿的高位 代码如下: architecture Behavioral of inputCounter is signal totalBitWidth : integer := 6; -- This signal is specified by the user to determine the majo
architecture Behavioral of inputCounter is
signal totalBitWidth : integer := 6;
-- This signal is specified by the user to determine the majority value
-- for the output.
signal majorityValue : integer := 4;
signal Sum : integer := 0;
process(clk, input)
variable clkCount : integer := 0;
begin
if input = '1' then
Sum <= Sum + 1;
else
Sum <= Sum + 0;
end if;
clkCount := clkCount + 1;
if clkCount >= (totalBitWidth) then
-- Determine if the majoritySum variable has met the
-- threshold for a 1 value
if Sum >= majorityValue then
output <= '1';
else
output <= '0';
end if;
if Sum = totalBitWidth Or Sum = 0 then
countError <= '0';
else
countError <= '1';
end if;
-- Reset the clock counter, sum value and majority vector
clkCount := 0;
Sum <= 0;
-- Set the bit counter high to alert other midules that a new bit
-- has been received
bitReady <= '1';
end process;
end behavioral;
inputCounter的行为架构是
信号总比特宽度:整数:=6;
--该信号由用户指定以确定多数值
--对于输出。
信号多数值:整数=4;
信号和:整数:=0;
过程(时钟,输入)
变量clkCount:整数:=0;
开始
如果输入='1',则
求和=多数值
输出解决方法是在这个过程中将我的信号变成一个变量 这是我的密码:
architecture Behavioral of inputCounter is
signal totalBitWidth : integer := 6;
signal majorityValue : integer := 4;
-- This signal is to trace the variable sum
signal SumS : integer := 0;
begin
-- Process for recognizing a single input value from a 6 clock cycle
-- wide input signal
majority_proc: process(clk, input)
variable clkCount : integer := 0;
variable Sum : integer := 0;
begin
if rising_edge(clk) And enable = '1' then
-- Reset bitReady after one clock cycle
bitReady <= '0';
-- Check the input value and add it to the Sum variable
if input = '1' then
Sum := Sum + 1;
else
Sum := Sum + 0;
end if;
-- Increment the clock counter variable
clkCount := clkCount + 1;
-- Check if the clock count has reached the specified number of cycles
if clkCount >= totalBitWidth then
-- Determine if the Sum variable has met the threshold for
-- value of 1, set the output accordingly
if Sum >= majorityValue then
output <= '1';
else
output <= '0';
end if;
-- This checks if the value for all clock cycles was the same and
-- sets an error flag if not
if Sum = totalBitWidth Or Sum = 0 then
countError <= '0';
else
countError <= '1';
end if;
-- Reset the clock counter and sum value
clkCount := 0;
Sum := 0;
-- Set the bit counter high to alert other midules that a new bit
-- has been received
bitReady <= '1';
end if;
end if;
-- Assign the variable Sum to the signal SumS
SumS <= Sum;
end process;
end Behavioral;
inputCounter的行为架构是
信号总比特宽度:整数:=6;
信号多数值:整数=4;
--此信号用于跟踪变量和
信号和:整数:=0;
开始
--从6个时钟周期识别单个输入值的过程
--宽输入信号
多数程序:过程(时钟,输入)
变量clkCount:整数:=0;
变量和:整数:=0;
开始
如果上升沿(clk)和启用='1',则
--一个时钟周期后复位位就绪
bitReady=totalBitWidth然后
--确定Sum变量是否满足的阈值
--值为1时,相应地设置输出
如果总和>=多数值,则
输出如果必须在最后一次输入的同一时钟周期结束时更改输出,则需要分离累加器寄存器和加法器。将累加器寄存器和输出比较逻辑放入进程中,并将加法器拉入异步逻辑。缩写示例代码:
process (clk)
if rising_edge(clk) and enable='1' then
accumulator <= sum;
if sum >= majorityValue then
output <= '1';
else
output <= '0';
end if;
end if;
end process;
sum <= accumulator + 1 when input='1' else accumulator;
过程(clk)
如果上升沿(clk)并启用='1',则
累加器=多数值
输出您始终可以将变量复制到一个信号中,作为流程的最后一行。@BrianDrummond-我可以使用变量,但我确实像您所说的那样将其分配到一个信号中,这样我就可以跟踪该值,但它与以前一样。信号更新速度不够快,因为我的Sum变量正在增加到6的值,然后根据阈值进行检查,然后在时钟上升沿重置所有。不过谢谢你的帮助。我的意思是,把它复制成一个信号,以便进行监控。如果在同一周期内需要更新的值,则需要比较variable=threshold。这是信号允许进程间同步的基本方式。@BrianDrummond-OK。这就是我最终改变的。我更改了实际值,该值随着变量的输入而更新,然后将信号设置为与您所说的变量相等。我能够看到正确的输出和结果。再次感谢。