求大师 还是CPLD分频 按键调节分频数问题

2019-03-25 10:05发布

我用CPLD进行分频   5分频和10分频  用按键调节输出5分频 或10分频  单个程序下载进去信号频率稳定   综合到一起下载进去  输出信号的频率就不稳定了   在跳动   程序如下  请大师指点    CPLD新手  
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
--**************实体定义********************
Entity div105 is
generic(duty:integer:=5);--类属参数说明语句
        --端口说明       
port(clk,key :        in        std_logic;--时钟输入
                q        :   out std_logic--分频输出          
        );
end div105;
--**************构造体定义********************



Architecture div of div105 is
  constant period : integer:=10;--常数定义,分频数
  signal count : integer range 0 to period-1;--信号定义,计数作用
  signal division1,division2,division3:std_logic:='0';
signal temp3,temp4 :integer range 0 to 10;
signal temp1:integer range 0 to 2;
  
begin
process(clk)--进程,由clk这个信号启动
  begin
        if rising_edge(clk) then --上升沿驱动,还有另一种写法,见其他例程
                if count<duty then
                        division3<='0';
                        count<=count+1;
                elsif count<period-1 then
                        division3<='1';
                        count<=count+1;
                else
                        count<=0;
                end if;
        end if;
end process;


p1:process(clk)
        --variable temp1: integer range 0 to 10;
  begin
   if rising_edge(clk) then
    temp3<=temp3+1;

    if temp3=2 then
     division1<='1';
    elsif temp3=4 then
       division1<='0';
     temp3<=0;
    end if;
      end if;
end process p1;
p2:process(clk)
        --variable temp2: integer range 0 to 10;
  begin
  if clk'event and clk='0' then
    temp4<=temp4+1;
     if temp4=2 then
  
      division2<='1';
     elsif temp4=4 then
      division2<='0';
      temp4<=0;
    end if;
    end if;
   end process p2;
   
   
process(key)
    begin
     if key='1' and key'event then
           temp1<=temp1+1;
          if temp1=2  then
           temp1<=0;
          end if;
        end if;
end process;
   
process(temp1,division1,division2,division3)
        begin
         case temp1 is
         when 0=>q<=division3;
         when 1 to 2=>q<=division1 or division2;
        end case;
end process;
end div; 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
5条回答
eeleader
1楼-- · 2019-03-25 14:46
< /

典型的新手通病。所有的设计都不是在系统时钟触发下完成的。

如果你把你的程序修改成全同步设计,估计你的问题就解决了。

还有就是需要说明一下,你描述电路的时候,一定要想到是硬件。硬件能否完成,知道了吗?

363758470
2楼-- · 2019-03-25 15:49
谢谢   受教了
spontaou
3楼-- · 2019-03-25 16:50
if count division3<='0';
count<=count+1;
elsif count division3<='1';
count<=count+1;
这几句是什么意思?
eeleader
4楼-- · 2019-03-25 18:58
 精彩回答 2  元偷偷看……
spontaou
5楼-- · 2019-03-25 20:03
楼主你好
if count division3<='0';
count<=count+1;
elsif count division3<='1';
count<=count+1;
首先count division3这个信号在代码中没发现啊,另外if 后面没有then,第三count division3<='1'这是条赋值语句,而不是条件判断语句,不吝赐教!

一周热门 更多>