各位高手:我用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;
回复
打赏帖 | |
---|---|
C语言函数宏的三种封装方式被打赏50分 | |
【STM32F769】记一次由于开启D-Cache之后DMA数据传输出错的问题查找与解决被打赏35分 | |
嵌入式LinuxC语言程序调试和宏使用技巧被打赏50分 | |
让代码中包含最新的编译时间信息被打赏50分 | |
【分享开发笔记,赚取电动螺丝刀】STM32F769LVGL优化显示被打赏26分 | |
rtthread硬件加密--2crc加密分析被打赏10分 | |
【分享开发笔记,赚取电动螺丝刀】STM32F769驱动ST7789以及显示优化被打赏36分 | |
【分享开发笔记,赚取电动螺丝刀】S32K146 PAL模拟I2C驱动适配被打赏23分 | |
我想要一部加热台+电源硬件设计规范被打赏16分 | |
我想要一部加热台+LED背光驱动芯片RT9293知识被打赏18分 |