集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 1501|回复: 1

请有空闲的伸出下援手

[复制链接]
新手的梦 发表于 2011-5-16 16:07:22 | 显示全部楼层 |阅读模式
要做一个0到256赫兹的频率计数器,然后要将频率转换成BCD1 BCD2 BCD3三个输出。举个列子,假如频率是256,就是将256能分开2 5 6 然后将2 5 6分别在三个数码管上显示。求指教如何将256准换分开。
wangjinzeng 发表于 2011-6-4 10:41:40 | 显示全部楼层
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity test is
generic(N:integer:=255);
port(clk:in std_logic;
data:in integer range 0 to N;--需要分频的数据,
data_en:in std_logic;--要求与需要分频的数据,即data同步,高电平有效
q_hundredut integer range 0 to 2;
q_tenut integer range 0 to 9;
q_aut integer range 0 to 9;
q_enut std_logic--输出使能,高电平有效,此时输出百十个位数。即q_hundred,q_ten,q_a
);
end;
architecture behav of test is
signal data_p:integer range 0 to N;
signal data_en1,data_en2:std_logic;
signal data_en_p:std_logic;
signal step:std_logic_vector(4 downto 0);
begin
process(clk)
        begin
                if(clk'event and clk='1')then
                        data_en1<=data_en;
                end if;
        end process;
process(clk)
        begin
                if(clk'event and clk='1')then
                        data_en2<=data_en1;
                end if;
        end process;

data_en_p<=data_en1 and(not data_en2);
process(clk)
        begin
                if(clk'event and clk='1')then
                        data_p<=data;
                end if;
        end process;

process(clk)
       
        constant idle:       std_logic_vector(4 downto 0):="00001";
        constant ready:      std_logic_vector(4 downto 0):="00010";
        constant count_ten:  std_logic_vector(4 downto 0):="00100";
        constant count_a:    std_logic_vector(4 downto 0):="01000";
        constant result_out: std_logic_vector(4 downto 0):="10000";
       
        constant data_h:integer:=100;
        constant data_t:integer:=10;
        constant data_a:integer:=1;
        variable d:integer range 0 to N;
        variable i_h:integer range 0 to 2;
        variable i_t:integer range 0 to 9;
        variable i_a:integer range 0 to 9;

        begin
                if(clk'event and clk='1')then
                        case step is
                                when idle=>
                                        i_h:=0;
                                        i_t:=0;
                                        i_a:=0;
                                        q_en<='0';
                                        if(data_en_p='1')then
                                                step<=ready;
                                                d:=data_p;
                                        else
                                                step<=idle;
                                                d:=0;
                                        end if;
                                when ready=>
                                        if(d>=data_h)then
                                                d:=d-data_h;
                                                i_h:=i_h+1;
                                                step<=ready;
                                        else
                                                step<=count_ten;
                                        end if;
                                when count_ten=>
                                        if(d>=data_t)then
                                                d:=d-data_t;
                                                i_t:=i_t+1;
                                                step<=count_ten;
                                        else
                                                step<=count_a;
                                        end if;
                                when count_a=>
                                        if(d>=data_a)then
                                                d:=d-data_a;
                                                i_a:=i_a+1;
                                                step<=count_a;
                                        else
                                                step<=result_out;
                                        end if;
                                when result_out=>
                                        q_hundred<=i_h;
                                        q_ten<=i_t;
                                        q_a<=i_a;
                                        q_en<='1';
                                        i_h:=0;
                                        i_t:=0;
                                        i_a:=0;
                                        d:=0;
                                        step<=idle;
                                when others=>
                                        q_hundred<=0;
                                        q_ten<=0;
                                        q_a<=0;
                                        q_en<='0';
                                        i_h:=0;
                                        i_t:=0;
                                        i_a:=0;
                                        d:=0;
                                        step<=idle;
                        end case;
                end if;
        end process;


end;
256给你分开了,数码管就自己悟吧
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

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

QQ|小黑屋|手机版|Archiver|fpga论坛|fpga设计论坛 ( 京ICP备20003123号-1 )

GMT+8, 2025-6-23 11:27 , Processed in 0.062719 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表