VHDL我的代码在FPGA上工作吗?
我最近几乎完成了我的项目(我需要创建分频器(50MHZ->1HZ(1s))并完成7段显示解码器)。我的项目包含一个计时器(倒计时到00:00触发报警,如果当前状态为00:00则倒计时)。该项目在活动HDL模拟器上运行良好,但我不知道它是否在FPGA上工作。我使用1进程的行为方法编写代码。我的问题是:如果我完成了分频器,我的代码在FPGA上工作吗?如果没有,我如何修改代码才能工作 我的代码:VHDL我的代码在FPGA上工作吗?,vhdl,fpga,hardware-programming,Vhdl,Fpga,Hardware Programming,我最近几乎完成了我的项目(我需要创建分频器(50MHZ->1HZ(1s))并完成7段显示解码器)。我的项目包含一个计时器(倒计时到00:00触发报警,如果当前状态为00:00则倒计时)。该项目在活动HDL模拟器上运行良好,但我不知道它是否在FPGA上工作。我使用1进程的行为方法编写代码。我的问题是:如果我完成了分频器,我的代码在FPGA上工作吗?如果没有,我如何修改代码才能工作 我的代码: library IEEE; use IEEE.STD_LOGIC_1164.all; use IEEE.S
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_unsigned.all;
use IEEE.STD_LOGIC_arith.all;
entity Timer is
port(start_stop,M,S : in std_logic; --Start/Stop , Minutes,Seconds
clk : in std_logic; -- clock 1 MHz
alarm : out std_logic; -- alarm/buzzer
s1,s2,m1,m2 : inout std_logic_vector(6 downto 0)); --BCD to 7segment display representation for seconds and minutes
end Timer;
--}} End of automatically maintained section
architecture Timer of Timer is
signal sec1,sec2,min1,min2 : std_logic_vector(3 downto 0);
signal T : std_logic := '0';
signal done : std_logic;
signal cu : std_logic;
component seg7 is
port(bcd : in std_logic_vector(3 downto 0);
output : out std_logic_vector(6 downto 0)
);
end component;
begin
P0 : process(clk,start_stop,M,S)
variable temp1,temp2,temp3,temp4 : std_logic_vector(3 downto 0);
variable carry_s,carry_m : std_logic;
variable alarm_counter : std_logic_vector(3 downto 0) := "1111"; -- buzzer/alarm counter
begin
if(M = '1'and S = '1' and start_stop = '0')
then
temp1 := "0000";
temp2 := "0000";
temp3 := "0000";
temp4 := "0000";
sec1 <= temp1;
sec2 <= temp2;
min1 <= temp3;
min2 <= temp4;
alarm <= '0';
done <= '0';
T <= '0';--RESET when you press M and S
elsif(M = '0' and S = '1' and start_stop = '0')
then
temp1 := temp1 + "0001";
if(temp1 = "1010")
then
temp1 := "0000";
carry_s := '1';
else
carry_s := '0';
end if;
if(carry_s = '1')
then
temp2 := temp2 + "0001";
if(temp2 = "0110")
then
temp2 := "0000";
carry_s := '0';
end if;
end if;
sec1 <= temp1;
sec2 <= temp2;-- Increment seconds when you press M
elsif(M = '1' and S = '0' and start_stop = '0')
then
temp3 := temp3 + "0001";
if(temp3 = "1010")
then
temp3 := "0000";
carry_m := '1';
else
carry_m := '0';
end if;
if(carry_m = '1')
then
temp4 := temp4 + "0001";
if(temp4 = "1010")
then
temp4 := "0000";
carry_m := '0';
end if;
end if;
min1 <= temp3;
min2 <= temp4;-- Increment minutes when you press M
elsif(S = '0' and M = '0' and start_stop = '1')
then
alarm <= '0';
T <= T xor '1';-- T Flip Flop behaviour
if(sec1 /= "0000" or sec2 /= "0000" or min1 /= "0000" or min2 /= "0000")
then
cu <= '0';
else
cu <= '1';
end if; -- counting directions
elsif(T = '1' and RISING_EDGE(clk))
then
if(cu = '0')
then
done <= '0';
temp1 := temp1 - "0001";
if(temp1 = "1111")
then
temp2 := temp2 - "0001";
temp1 := "1001";
end if;
if(temp2 = "1111")
then
temp2 := "0101";
carry_s := '1';
else
carry_s := '0';
end if;
if(carry_s = '1')
then
temp3 := temp3 - "0001";
if(temp3 = "1111")
then
temp4 := temp4 - "0001";
temp3 := "1001";
end if;
end if;
if(temp1 = "0000" and temp2 = "0000" and temp3 = "0000" and temp4 = "0000")
then
done <= '1';
end if;
sec1 <= temp1;
sec2 <= temp2;
min1 <= temp3;
min2 <= temp4;-- counting down
else
temp1 := temp1 + "0001";
if(temp1 = "1010")
then
temp1 := "0000";
temp2 := temp2 + "0001";
end if;
if(temp2 = "0110")
then
temp2 := "0000";
carry_s := '1';
else
carry_s := '0';
end if;
if(carry_s = '1')
then
temp3 := temp3 + "0001";
if(temp3 = "1010")
then
temp3 := "0000";
temp4 := temp4 + "0001";
if(temp4 = "1010")
then
temp4 := "0000";
T <= '0';
end if;
end if;
end if;
sec1 <= temp1;
sec2 <= temp2;
min1 <= temp3;
min2 <= temp4;-- counting up
end if;
end if;
if(done = '1')
then
T <= '0';
alarm_counter := alarm_counter - "0001";
alarm <= '1';
if(alarm_counter = "0000")
then
done <= '0';
alarm <= '0';
end if;
else
alarm_counter := "1111";
alarm <= '0';
end if;-- when the alarm starts
end process P0;
C1 : seg7 port map (sec1,s1);
C2 : seg7 port map (sec2,s2);
C3 : seg7 port map (min1,m1);
C4 : seg7 port map (min2,m2);
-- seven segment display port mapping
end Timer;
IEEE库;
使用IEEE.STD_LOGIC_1164.all;
使用IEEE.STD_LOGIC_unsigned.all;
使用IEEE.STD_LOGIC_arith.all;
实体计时器为
端口(启动/停止,M,S:在标准逻辑中;--启动/停止,分钟,秒
时钟:标准逻辑中——时钟频率1MHz
报警:输出标准逻辑;--报警/蜂鸣器
s1,s2,m1,m2:inout标准逻辑向量(6到0)--BCD至7段显示模式(秒和分钟)
结束计时器;
--}}自动维护区段的结束
定时器的结构是定时器
信号sec1、sec2、min1、min2:std_逻辑_向量(3到0);
信号T:std_逻辑:='0';
信号完成:标准逻辑;
信号cu:std_逻辑;
组件seg7是
端口(bcd:标准逻辑向量(3到0);
输出:输出标准逻辑向量(6到0)
);
端部元件;
开始
P0:过程(时钟、启动和停止、M、S)
变量temp1、temp2、temp3、temp4:std_逻辑_向量(3到0);
变量进位,进位:标准逻辑;
可变报警计数器:标准逻辑向量(3到0):=“1111”——蜂鸣器/报警计数器
开始
如果(M='1'和S='1'和start\u stop='0')
然后
temp1:=“0000”;
temp2:=“0000”;
temp3:=“0000”;
temp4:=“0000”;
sec1不,这种设计是不可合成的
特别是,这里有异步反馈:
if(M = '0' and S = '1')
then
temp1 := temp1 + "0001";
所有计数逻辑必须计时。在模拟器中,进程上的灵敏度列表可防止反馈失控,但在实际硬件中,异步周期将失控
请尝试改用此结构:
if (M = '1' and S = '1') then
-- async reset
elsif RISING_EDGE(clk) then
--all other logic for setting modes, counting, limits goes here
endif
上升沿功能与clk='1'和clk'event
大致相同,只是它对于查看代码的人来说更有意义,并且具有。不,这种设计是不可合成的
特别是,这里有异步反馈:
if(M = '0' and S = '1')
then
temp1 := temp1 + "0001";
所有计数逻辑必须计时。在模拟器中,进程上的灵敏度列表可防止反馈失控,但在实际硬件中,异步周期将失控
请尝试改用此结构:
if (M = '1' and S = '1') then
-- async reset
elsif RISING_EDGE(clk) then
--all other logic for setting modes, counting, limits goes here
endif
RISING_EDGE
函数与clk='1'和clk'event
大致相同,只是它对于查看代码的人来说更有意义,而且已经实现了。如果我修复了这个问题,可以在FPGA上实现吗?在FPGA中构建如此复杂的闹钟是完全可行的,是的。我不会对此感到满意:如果(M='1'和S='1')然后
。根据我通过简单阅读代码所能理解的,M
和S
是功能输入(“分钟”和“秒”)。功能逻辑不应控制异步复位;驱动异步复位的唯一信号是专用复位信号,其唯一功能是将芯片置于已知状态。使用任何其他信号驱动异步复位不是同步设计。如果同时按下M和S,计时器将重置为00:00.我是否需要一个信号reset
,当M=1和S=1时,它将重置为'1'并将重置计时器?@CălinCalin:VHDL分析器足够智能,可以创建一个中间信号areset=(M和S)
,您不需要显式地这样做。如果我解决了这个问题,它可以在FPGA上实现吗?在FPGA中构建如此复杂的闹钟是完全可行的,是的。如果(M='1'和s='1',我会不高兴的:然后
。通过简单阅读代码,我可以理解,M
和S
是功能输入(“分钟”和“秒”)。功能逻辑不应控制异步复位;驱动异步复位的唯一信号是专用复位信号,其唯一功能是将芯片置于已知状态。使用任何其他信号驱动异步复位不是同步设计。如果同时按下M和S,计时器将重置为00:00.我是否需要一个信号reset
,当M=1和S=1时,它将重置为'1'并将重置计时器?@CălinCalin:VHDL分析器足够智能,可以创建一个中间信号areset=(M和S)
,您不需要明确地这样做。@playmough的可能重复:这个问题与另一个问的端口映射无关。是的,它们是由同一个作者编写的,大约是相同的代码,但这并不意味着它们重复。@BenVoigt我不同意。另一个确实提到了端口映射,但最终还是这个问题与此无关,因为a)它从来没有问过关于端口映射的任何具体问题(只是一个模糊的“[h]如何使用端口映射”)和b)它最终遇到了一个关于它是否具有功能性和可合成性的问题。这个问题本质上是同一个问题。@playmough的可能重复:这个问题与另一个问的端口映射无关。是的,它们是由同一作者编写的,代码大致相同,但这并不意味着它们是重复的。@BenVoigt我不同意。另一个确实提到了端口映射,但最终这个问题与之无关,因为a)它从来没有问过关于端口映射的任何具体问题(只是一个模糊的“[h]如何使用端口映射”)和b)它最后问了一个关于它是否具有功能性和可合成性的问题。这个问题本质上是同一个问题。