|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
本人用fpga和51单片机分别对同一脉冲信号测量占空比,结果单片机测的正确,fpga测量一直不对,求大神们指点一下,fpga程序如下:library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity zhankong is
port( clk10m,datain: in std_logic;
dataout: out integer
);
end entity zhankong;
architecture run of zhankong is
signal x1,y1:integer range 0 to 50000000;
begin
q:process(clk10m)
variable y: integer range 0 to 50000000;
begin
if(clk10m'event and clk10m='1') then
if(datain='0') then
y:=y+1;
elsif (y>0) then
y1<=y;
y:=0;
end if;
end if;
end process;
q1:process(clk10m)
variable x: integer range 0 to 50000000;
begin
if(clk10m'event and clk10m='1') then
if(datain='1') then
x:=x+1;
elsif (x>0) then
x1<=x;
x:=0;
end if;
end if;
end process;
q2:process(x1,y1)
begin
if(clk10m'event and clk10m='1') then
dataout<=x1/(x1+y1); --dataout记为占空比
end if;
end process;
end architecture run; |
|