在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 2384|回复: 4

[求助] pwm,大神帮忙解释一下这段程序

[复制链接]
发表于 2014-8-27 11:14:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
程序中英文缩写都代表什么意思呢?这段程序实现什么功能呢?

LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;

entity fcounter is
        generic
        (   
                f_len:natural:=9;         
                f_delta:natural:=10
        );
        port(
                rst,clk,di:in std_logic;
                f,fiut std_logic_vector(f_len-1 downto 0);
                tmut std_logic
        );
end entity fcounter ;

architecture bhv of fcounter is
        type f_reg_type is array (natural range<>) of std_logic_vector(f_len-1 downto 0);
        signal f_reg:f_reg_type(2+2 downto 0);
        signal fsum:std_logic_vector(f_len-1+2 downto 0);
        signal di_reg:std_logic_vector(3 downto 0);
        signal di_rise,di_fall:std_logic;
        signal cnt:std_logic_vector(f_len-1 downto 0);
begin
        fsum<="00"&f_reg(0)+f_reg(1)+f_reg(2)+f_reg(2);
        f<=fsum(f_len-1+2 downto 2);
        fi<=cnt;
        
        count:process(clk,rst)
        begin
                if rst='0' then
                        di_reg<=(others=>'0');
                        f_reg<=(others=>(others=>'0'));
                        cnt<=(others=>'0');
                        tm<='0';
                elsif clk'event and clk='1' then
                                cnt<=cnt+'1';
                                di_reg<=di_reg(2 downto 0)&di;
                                if di_rise='1' then
                                        f_reg(4)<=cnt;
                                        cnt<=(others=>'0');
                                        tm<='1';
                                end if;
                                if di_fall='1' then
                                        f_reg(3)<=cnt;
                                        cnt<=(others=>'0');
                                        tm<='0';
                                end if;
                                if (f_reg(3)>f_reg(4) and f_reg(3)-f_delta<f_reg(4))
                                        or (f_reg(3)<f_reg(4) and f_reg(3)+f_delta>f_reg(4)) then
                                        f_reg(2 downto 0)<=f_reg(1 downto 0)&(f_reg(3)+f_reg(4));
                                end if;
                end if;        
        end process;
               
        di_rise<= '1' when (di_reg(2)='0' and di_reg(1)='0'and di_reg(0)='1' and di='1') else '0';
        di_fall<= '1' when (di_reg(2)='1' and di_reg(1)='1'and di_reg(0)='0' and di='0') else '0';
        
end bhv;
发表于 2014-8-27 16:33:31 | 显示全部楼层
di_rise:di信号的上升沿
di_fall:di信号的下降沿
f_reg(0):di信号一个周期时间计数
f_reg(1):di信号一个周期时间计数
f_reg(2):di信号一个周期时间计数
f_reg(3):di信号的高电平时间计数
f_reg(4):di信号的低电平时间计数
if (f_reg(3)>f_reg(4) and f_reg(3)-f_delta<f_reg(4))
or (f_reg(3)<f_reg(4) and f_reg(3)+f_delta>f_reg(4)):判断di信号高低电平的时间差是否在f_delta偏差内
fsum:4次和
f:4次平均
发表于 2014-8-28 09:57:08 | 显示全部楼层
学习学习,谢谢
 楼主| 发表于 2014-8-28 13:44:11 | 显示全部楼层
回复 2# pmdddd

好像明白点了,再请你看看这段程序吧,跟上面的程序是一个整体
   LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;


ENTITY pwmgen IS

generic

(   

f_len:natural:=9;  

delay_len:natural:=9;

dead:natural:=5

);



port(

rst,clk:in std_logic;

feedin:in std_logic;
        di:in std_logic;

--delay:in std_logic_vector(f_len-1 downto 0);

pwm1,pwm3,pwm2,pwm4ut std_logic

);
end entity pwmgen ;


architecture bhv of pwmgen is

signal tm,pwm10,pwm20,pwm30,pwm40:std_logic;

signal delay_r:std_logic_vector(delay_len+f_len-1 downto 0);

signal cmp,cmp_dead:std_logic_vector(f_len-1 downto 0);

signal f,fi:std_logic_vector(f_len-1 downto 0);

signal delay:std_logic_vector(f_len-1 downto 0):="011001100";

signal feedcount:std_logic_vector(11 downto 0):="000000000000";
signal close:std_logic:='0';
signal dis: std_logic;

component fcounter

generic

(   

f_len:natural:=9;  


f_delta:natural:=10

);

port(

rst,clk,di:in std_logic;

f,fiut std_logic_vector(f_len-1 downto 0);

tmut std_logic

);

end component;


begin
d1:process(clk,close)
    begin

if close='0' then

if clk'event and clk='1' then

   

    if feedcount<"111111111100" then
        feedcount<=feedcount+'1';
        dis<=di;
--        di1<=dis;

  else
          close<='1';

  dis<=feedin;
--
  di1<=dis;
        end if;


end if;

        else

  dis<=feedin;
--
  di1<=dis;
end if;
  
end process;

fc1:fcounter generic map(9,10) port map(rst,clk,dis,f,fi,tm);

delay_r<=delay*f;

cmp<=delay_r(delay_len+f_len-1 downto delay_len);

cmp_dead<="0"&f(f'length-1 downto 1)-dead;

--adad


d:process(clk,rst)

begin


if rst='0' then

pwm10<='0';

pwm20<='0';

pwm30<='0';

pwm40<='0';


elsif clk'event and clk='1' then

if (fi>=0 and fi<cmp ) then

if tm='1' then pwm10<='1';end if;

if tm='0' then pwm20<='1';end if;

else

pwm10<='0';

pwm20<='0';

end if;



if (fi>dead and fi<cmp_dead) then

if tm='1' then pwm30<='1';end if;

if tm='0' then pwm40<='1';end if;

else

pwm30<='0';

pwm40<='0';

end if;

end if;

end process;



pwm1<=pwm10 and pwm30;

pwm3<=pwm20 and pwm40;
   pwm2<=not dis;
   pwm4<=dis;


end bhv;
 楼主| 发表于 2015-1-21 09:28:42 | 显示全部楼层
回复 2# pmdddd


   大神,我给你发了一个短消息,帮忙看一下程序吧
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

×

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-9 18:40 , Processed in 0.034325 second(s), 8 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表