各位高手:我用CPLD对晶振10MHz进行整数分频,输出信号为400kHz,程序用的是任意整数倍分频,程序中占空比为50%,但是在每次重新上电后,输出信号的占空比大多数次数都没达到50%,并且占空比基本上每次都在变化,偶尔能达到50%,请问有没有遇到过这种故障现象,如何解决?敬请发言以解我惑
任意整数分频出来,占空比不为50%问题

附任意整数分频vhdl代码:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity net_clk_div_n is
generic (n:integer:=20);
port(clk : in std_logic;
rst : in std_logic;
clkout :out std_logic
);
end net_clk_div_n;
architecture rtl of net_clk_div_n is
--constant n : integer range 0 to 10 := 6;
signal clk_p : std_logic;
signal clk_n : std_logic;
signal cnt_p : integer range 0 to n;
signal cnt_n : integer range 0 to n;
begin
process(clk_p, clk_n)
begin
if((n mod 2) = 0)then
clkout <= clk_p;
else
clkout <= clk_p or clk_n;
end if;
end process;
process(clk, rst)
begin
if(rst = '0') then
cnt_p <= 0;
elsif(clk'event and clk = '1') then
if(cnt_p = n-1) then
cnt_p <= 0;
else
cnt_p <= cnt_p + 1;
end if;
end if;
end process;
process(clk, rst)
begin
if(rst = '0') then
clk_p <= '0';
elsif(clk'event and clk = '1')then
if (cnt_p < (n/2)) then
clk_p <= '1';
else
clk_p <= '0';
end if ;
end if;
end process;
process(clk, rst)
begin
if(rst = '0') then
cnt_n <= 0;
elsif(clk'event and clk = '0')then
if(cnt_n = n-1) then
cnt_n <= 0;
else
cnt_n <= cnt_n + 1;
end if;
end if;
end process;
process(clk, rst)
begin
if(rst = '0') then
clk_n <= '0';
elsif(clk'event and clk = '0')then
if (cnt_n < (n/2)) then
clk_n <= '1';
else
clk_n <= '0';
end if ;
end if;
end process;
end rtl;
回复
打赏帖 | |
---|---|
分享博世的两种不同的喷射系统模式被打赏5分 | |
汽车+开路实验与短路实验被打赏10分 | |
多点式电子控制汽油喷射系统知识分享被打赏10分 | |
分享机械控制式汽油喷射系统被打赏5分 | |
汽车显示屏——第2部分:TFTLCD、OLED和micro-LED显示屏电源技术被打赏50分 | |
汽车+汽车电路板的走线规则被打赏20分 | |
五一劳动节快乐被打赏5分 | |
【分享开发笔记,赚取电动螺丝刀】s32k146适配zephyr(六)使用Ozone调试镜像被打赏29分 | |
【分享开发笔记,赚取电动螺丝刀】s32k146适配zephyr(五)添加设备树节点被打赏33分 | |
【分享开发笔记,赚取电动螺丝刀】s32k146适配zephyr(四)使用I2C总线驱动RA8900CE芯片被打赏23分 |