在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 1941|回复: 4

[求助] 一个时间程序的例子里面的一个信号量的变化不能理解

[复制链接]
发表于 2015-3-9 00:19:32 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;

ENTITY clock IS
        PORT
        (
                clk                : IN        STD_LOGIC;
                keyin        : IN        STD_LOGIC_VECTOR(3 DOWNTO 0);
                diode        : OUT   STD_LOGIC_vector(5 downto 0);
                led                : out        std_logic_vector(7 downto 0);
                cs                : out        std_logic_vector(3 downto 0);
                buzz_out : OUT        STD_LOGIC
        );
END clock;
ARCHITECTURE a OF clock IS

SIGNAL q : STD_LOGIC_vector(19 downto 0);
SIGNAL second : STD_LOGIC_vector(5 downto 0);
SIGNAL minl : STD_LOGIC_vector(3 downto 0);
SIGNAL minh : STD_LOGIC_vector(2 downto 0);
SIGNAL hourl : STD_LOGIC_vector(3 downto 0);
SIGNAL hourh,scan : STD_LOGIC_vector(1 downto 0);
signal led_code,minl_code,minh_code,hourl_code,hourh_code : std_logic_vector(7 downto 0);
signal hourl_codebuf :std_logic_vector(7 downto 0);
BEGIN
        diode <= "111111";
        buzz_out <= '0';
        process(clk)
        begin
        if(clk'event and clk = '1') then
                q <= q+1;
        end if;
        end process;
       
        process(q(14))
        begin
                if(q(14)'event and q(14)='1') then
                        if second<"111011" then
                                second <= second+1;
                        else
                                second <="000000";
                                if minl < "1001" then
                                        minl <= minl+1;
                                else
                                        minl <= "0000";
                                        if minh < "101" then
                                                minh <= minh+1;
                                        else
                                                minh <="000";
                                                if hourh <"10" then
                                                        if hourl < "1001" then
                                                                hourl <= hourl+1;
                                                        else
                                                                hourl <= "0000";
                                                                hourh <= hourh+1;
                                                        end if;
                                                else if hourh = "10" then
                                                                if hourl <"0011" then
                                                                        hourl <= hourl+1;
                                                                else
                                                                        hourl <= "0000";
                                                                        hourh <= "00";
                                                                end if;
                                                        end if;
                                                end if;
                                        end if;
                                end if;
                        end if;
                end if;
        end process;
        scan <= q(7 downto 6);
        cs  <=         "0001" when scan=0 else
                        "0010" when scan=1 else
                        "0100" when scan=2 else
                        "1000" when scan=3 else
                        "0000";
        led_code  <=         minl_code  when scan=0 else
                                        minh_code  when scan=1 else
                                        hourl_codebuf when scan=2 else
                                        hourh_code when scan=3 else
                                        "00000000";
        led <=        led_code;                       
        b1: block
        begin
                minl_code <= "11000000" when minl = 0 else
                                        "11111001" when minl = 1 else
                                        "10100100" when minl = 2 else
                                        "10110000" when minl = 3 else
                                        "10011001" when minl = 4 else
                                        "10010010" when minl = 5 else
                                        "10000010" when minl = 6 else
                                        "11111000" when minl = 7 else
                                        "10000000" when minl = 8 else
                                        "10010000" when minl = 9 else
                                        "11111111";
        end block b1;
        b2: block
        begin
                minh_code <= "11000000" when minh = 0 else
                                        "11111001" when minh = 1 else
                                        "10100100" when minh = 2 else
                                        "10110000" when minh = 3 else
                                        "10011001" when minh = 4 else
                                        "10010010" when minh = 5 else
                                        "11111111";
        end block b2;
        b3: block
        begin
                hourl_code <= "01000000" when hourl = 0 else
                                        "01111001" when hourl = 1 else
                                        "00100100" when hourl = 2 else
                                        "00110000" when hourl = 3 else
                                        "00011001" when hourl = 4 else
                                        "00010010" when hourl = 5 else
                                        "00000010" when hourl = 6 else
                                        "01111000" when hourl = 7 else
                                        "00000000" when hourl = 8 else
                                        "00010000" when hourl = 9 else
                                        "11111111";
        end block b3;
        b4: block
        begin
                hourh_code <= "11000000" when hourh = 0 else
                                        "11111001" when hourh = 1 else
                                        "10100100" when hourh = 2 else
                                        "11111111";
        end block b4;
        process(q(14))
        begin
                if q(14) = '1' then
                        hourl_codebuf <= hourl_code and "01111111";
                else
                        hourl_codebuf <= hourl_code or "10000000";
                end if;
        END process;



END a;
我想问一下,这个程序中的SIGNAL q信号是根据什么变化的半天我也没看出来?
发表于 2015-3-9 22:54:59 | 显示全部楼层
q信号的变化?
这个程序做的是一个时钟,显示:时分秒。q信号,这里用作分频用,2^14分频,分频比50%。
由此可以推算出,clk的频率为:f=2^14Hz;
 楼主| 发表于 2015-3-11 15:47:31 | 显示全部楼层
回复 2# fascinate_lyd98
我想再问一下为什么它选择q(7 downto 6)这个分频来改变数码管上的时间,为什么不在q(14)这个分频段就直接修改数码管的时间?
发表于 2015-3-11 22:34:06 | 显示全部楼层
回复 3# ZHANGHUAFENG


   不知道,你的这个程序并不是不完整的,估计只是摘出来的。具体看你想要实现的功能。
发表于 2015-3-12 09:50:46 | 显示全部楼层
这个是4组8个八段数码管的显示,输入频率是2^15=32768Hz,这个是标准的时钟晶振。用q(7 downto 6)是因为做4组扫描显示输出的间隔定在15.625ms,把cs对应起来就好理解了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

×

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-1 13:28 , Processed in 0.039207 second(s), 8 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表