huanben 发表于 2011-6-29 10:36:58

类似定时开关的小模块,自己试着写了一段。

START 和 CLK 为输入 EN 为输出
工作流程如下:
START一个上升沿(按一次开关),使得EN低,并且同时对CLK的上升沿敏感进行计数,经过四个上升沿后,EN升高,并停止计数(CLK一直是脉冲输入)。 再一次START上升沿。。。。以此类推。。。

计数器需要START的下降沿,计数满后是EN升高并自动停止计数。
http://cache.amobbs.com/bbs_upload782111/files_42/ourdev_653178MQTSBZ.jpg
(原文件名:shixu.jpg)

huanben 发表于 2011-6-29 10:38:12

菜鸟请求指教。

huanben 发表于 2011-6-29 11:34:41

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;

-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity MODULE is
    Port ( START : inSTD_LOGIC;
         CLK : inSTD_LOGIC;
         EN : outSTD_LOGIC);
end MODULE;

architecture Behavioral of MODULE is
signal E12,E21: std_logic;
signal count: std_logic_vector(2 downto 0);

begin
   PROCESS(START,E21)
        BEGIN
                IF RISING_EDGE(START)THEN
                        COUNT<="000";
                        ELSE IF E21'EVENT THEN
                        E12<='1';
               END IF;
        END process;
       
        PROCESS(CLK,E12)
        BEGIN
                IF E12='0' THEN
                        IF RISING_EDGE(CLK)THEN
                                IF COUNT="011"; THEN
                                E21<=NOT E21;
                                        ELSE
                                                COUNT<=COUNT+1;
                           END IF;
                       END IF;
               END IF;
               
        END process;
       
        EN<=E12;
                               





end Behavioral;

自己试着写了一段,编译说 IF和PROCESS结尾有错误

40130064 发表于 2011-6-29 15:19:45

回复【2楼】huanben
-----------------------------------------------------------------------
因为某种原因,不能上代码,只能上图片。

http://cache.amobbs.com/bbs_upload782111/files_42/ourdev_653274NHSVGE.jpg
(原文件名:IMG0063A.jpg)

http://cache.amobbs.com/bbs_upload782111/files_42/ourdev_653275RKG4EB.jpg
(原文件名:IMG0064A.jpg)

http://cache.amobbs.com/bbs_upload782111/files_42/ourdev_653276DF7B5Z.jpg
(原文件名:IMG0065A.jpg)

huanben 发表于 2011-6-29 17:09:53

谢谢 楼上师兄我仔细看看!!

huanben 发表于 2011-6-29 23:17:34

楼上师兄 这段代码有仿真过吗?

40130064 发表于 2011-7-2 15:22:06

http://cache.amobbs.com/bbs_upload782111/files_42/ourdev_654103SZNSZZ.jpg
(原文件名:IMG0070A.jpg)

把countmax 改成3
count 改成 1 to countmax+1 就是上图

输入和输出不可能在同时变。
页: [1]
查看完整版本: 类似定时开关的小模块,自己试着写了一段。