📄 multi_baudrate_generator.vhd
字号:
-- 库声明
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use WORK.UART_PACKAGE.ALL;
-- 实体声明
entity multi_baudrate_generator is
-- 类属参数声明
-- generic (
-- FULL_PULSE_COUNT : BD_COUNT := BD9600_FPC;
-- RISE_PULSE_COUNT : BD_COUNT := BD9600_HPC );
-- 端口声明
port (
clk : in std_logic;
reset_n : in std_logic;
ce : in std_logic;
bcr: in std_logic_vector(3 downto 0);
bcrs_n: in std_logic;
bg_out : out std_logic);
--- indicator : out std_logic );
end multi_baudrate_generator;
--}} End of automatically maintained section
-- 结构体
architecture multi_baudrate_generator of multi_baudrate_generator is
signal bcr_s:std_logic_vector(3 downto 0);
signal FULL_PULSE_COUNT:BD_COUNT;
signal RISE_PULSE_COUNT:BD_COUNT;
begin
bcr_latch_proc:process(reset_n,bcrs_n,bcr_s)
begin
if(reset_n='0') then
bcr_s<="0101";
elsif(bcrs_n='0') then
bcr_s<=bcr;
end if;
end process bcr_latch_proc;
baudrate_set_proc:process(bcr_s) -----波特率设定
begin
case bcr_s is
when "0000" =>
FULL_PULSE_COUNT<=28409;
RISE_PULSE_COUNT<=14205;
when "0001" =>
FULL_PULSE_COUNT<=10417;
RISE_PULSE_COUNT<=5208;
when "0010" =>
FULL_PULSE_COUNT<=2604;
RISE_PULSE_COUNT<=1302;
when "0011" =>
FULL_PULSE_COUNT<=1302;
RISE_PULSE_COUNT<=651;
when "0100" =>
FULL_PULSE_COUNT<=651;
RISE_PULSE_COUNT<=326;
when "0101" =>
FULL_PULSE_COUNT<=326;
RISE_PULSE_COUNT<=163;
when "0110" =>
FULL_PULSE_COUNT<=163;
RISE_PULSE_COUNT<=81;
when "0111" =>
FULL_PULSE_COUNT<=81;
RISE_PULSE_COUNT<=41;
when "1000" =>
FULL_PULSE_COUNT<=54;
RISE_PULSE_COUNT<=27;
when "1001" =>
FULL_PULSE_COUNT<=27;
RISE_PULSE_COUNT<=14;
when "1010" =>
FULL_PULSE_COUNT<=14;
RISE_PULSE_COUNT<=7;
when "1011" =>
FULL_PULSE_COUNT<=7;
RISE_PULSE_COUNT<=3;
when "1100" =>
FULL_PULSE_COUNT<=3;
RISE_PULSE_COUNT<=2;
when others =>
end case;
end process baudrate_set_proc;
-- enter your statements here --
-- 主过程
-- main process
main : process( clk, reset_n )
variable clk_count : BD_COUNT;
begin
-- 判断复位信号
if reset_n = '0' then
bg_out <= '0';
--- indicator <= '0';
clk_count := 0;
-- 在时钟信号的上升沿动作
elsif rising_edge(clk) then
-- 判断使能信号
if ce = '1' then
-- 经过了RISE_PULSE_COUNT个计数,数脉冲上升
if clk_count = RISE_PULSE_COUNT-1 then -- pulse rise
bg_out <= '1';
clk_count := clk_count+1;
-- 经过了FULL_PULSE_COUNT个计数,数脉冲下降
elsif clk_count = FULL_PULSE_COUNT-1 then -- indicator output and pulse fall
-- 输出提示信号,使其为高
---- indicator <= '1';
bg_out <= '0';
-- 重置计数器计数为0
clk_count := 0;
-- 恢复提示信号为低
elsif clk_count = 0 then
------ indicator <= '0';
clk_count := clk_count+1;
else
clk_count := clk_count+1;
end if;
end if;
end if;
end process;
end multi_baudrate_generator;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -