各位高手:我用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;
回复
打赏帖 | |
---|---|
【S32K146】S32DS watchdog 配置使用被打赏20分 | |
【Zephyr】使用 IAR 调试 Zephyr 镜像被打赏20分 | |
【Zephyr】MCXN947 Zephyr 开发入门适配shell被打赏20分 | |
【我要开发板】6.联合MATLAB记录数据被打赏50分 | |
【瑞萨RA2E1开发板】:使用ADC功能实现位移传感器采集方案被打赏20分 | |
【nRF7002DK】基于sht30的温湿度计被打赏20分 | |
【nRF7002DK】日志打印被打赏20分 | |
【换取手持示波器】RGB屏幕移植ARM-2D库被打赏35分 | |
【分享开发笔记,赚取电动螺丝刀】分享一下如何解决瑞萨RA2E1使用printf编译报错问题被打赏27分 | |
rtthread硬件加密-5hash加密分析被打赏10分 |