打印

请指教:vhdl语言编写的蜂鸣器发生模块。仿真结果不正确。

[复制链接]
3744|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
f4335089|  楼主 | 2009-7-9 22:07 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
正个程序是想通过对时钟分频,再预置控制信号tone1来达到使spks输出频率信号,让蜂鸣器发出不同的声音。
 程序:
library ieee;
use ieee.std_logic_1164.all;
entity speaker is 
 port(clk1:in std_logic;
      tone1: in integer range 0 to 16#7ff#;
      spks:out std_logic); 
end;
 architecture one of speaker is
 signal preclk:std_logic;
 signal fullspks: std_logic;

 begin
  divedeclk:process(clk1)   
   variable count4:integer range 0 to 15; 
 begin
  preclk<='0';
  if count4>11 then preclk<='1';count4:=0;
  elsif clk1'event and clk1='1'then count4:=count4+1;
  end if;
  end process;
  genspks:process(preclk,tone1)
    variable count11:integer range 0 to 16#7ff#;
    begin
    if preclk'event and preclk='1' then
     if count11=16#7ff# then
        count11:=tone1; fullspks<='1';
      else count11:=count11+1;fullspks<='0';
      end if;
     end if;
   end process;
   delayspks:process(fullspks)
    variable count2:std_logic;
    begin
    if fullspks'event and fullspks='1' then count2:=not count2;
     if count2='1' then spks<='1';
     else spks<='0';
     end if;
    end if;
  end process;
  end;

 现在程序编译正确但是结果不符合设计。 
1. 求教这个设计中divedeclk这个过程中输出的结果不对 为什么?
 2. count4到八就跳到零了,而且还不是执行的加一。
3.  spks始终是0,无法实现要求 。 
    求高手指点,不胜感激。 现在在做全国电子设计大赛,希望有专业人士能指点。qq:250318261 

相关帖子

沙发
jinfengmusic| | 2009-7-19 20:04 | 只看该作者

没有看明白!

老兄,我们的程序风格很重要啊!咱们一起学习吧!

使用特权

评论回复
板凳
patrick007| | 2009-7-19 20:32 | 只看该作者

re

基本全部需要改写。

找本好书,重点看看,
计数器的写法。
信号,变量在不同位置赋值产生的隐含dff。
用process实现 时序,组合逻辑器件时, 敏感列表 的差别。


网上也有**,这三个问题看明白了,你这个东西就做好了(第二行或许可以先不考虑,你这个东西可能对时序不是太敏感)。

使用特权

评论回复
地板
jinfengmusic| | 2009-7-19 20:35 | 只看该作者

一起学习

以下是楼主修改后的程序,在下稍微编辑了一下,大家共享。
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity speaker is 
 port(clk1:in std_logic;
      tone1: in std_logic_vector(10 downto 0);
      spks:out std_logic
      ); 
end speaker;

architecture one of speaker is
signal preclk:std_logic;
signal fullspks: std_logic;
begin

  divedeclk:process(clk1)   
  variable count4:std_logic_vector(3 downto 0);
  begin
       if (clk1'event and clk1='1') then
         if count4="1111" then
            preclk<='0';
            count4:=count4+1;
         elsif count4>"0111" then 
            preclk<='1';
            count4:=count4+1;
         else  
            count4:=count4+1;
         end if;
       end if;
  end process;

  genspks:process(preclk,tone1)
  variable count11:std_logic_vector(10 downto 0);
  begin
    if (preclk'event and preclk='1') then
       if count11="11111111111" then
          count11:=tone1; 
          fullspks<='1';
       else 
          count11:=count11+1;
          fullspks<='0';
       end if;
    end if;
  end process;

  delayspks:process(fullspks)
  variable count2:std_logic;
  begin
    if (fullspks'event and fullspks='1') then
       count2:=not count2;
       if count2='1' then 
          spks<='1';
       else 
          spks<='0';
       end if;
    end if;
  end process;
end one;


还有很多不完美的地方,望大家共同讨论,共同进步!

使用特权

评论回复
5
f4335089|  楼主 | 2009-7-19 20:41 | 只看该作者

已解决

谢谢大家关注  经检查是由于第一个过程中程序代码与设想不一致导致,以后我会注意程序的写法 , 给帮我的人说句谢谢!!

使用特权

评论回复
6
patrick007| | 2009-7-20 09:35 | 只看该作者

re

目前的这个可能比你需要的东西“大”一点点。。。。。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

4

主题

26

帖子

1

粉丝