微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > FPGA,CPLD和ASIC > 关于fpga测占空比的问题

关于fpga测占空比的问题

时间:10-02 整理:3721RD 点击:
本人用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;

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top