【发布时间】:2016-05-22 10:19:10
【问题描述】:
我现在正在学习 VHDL,我尝试实现 UART(1 个起始位、8 个数据位、1 个停止位)以定期发送硬编码字符串。
一切都按预期工作 - 我每 1 秒收到一次字符串。但是,没有第二个字符。
不管字符串有多长,它是哪个字符。我在示波器上检查了这个事实,没有这个特定字符的波形。 1 个起始位,第一个字符 8 位,停止位,起始位和第三个字符 8 位,而不是第二个。
以下代码将 10 MHz 时钟分频以每秒约 38 400 位发送,我也尝试以每秒 9600 位发送,两者都是同样的问题。
我正在使用 Altera MAX10 开发板:http://maximator-fpga.org/
工作原理短视频: https://gfycat.com/JoyousIlliterateGuillemot
UART.vhd:
LIBRARY ieee;
USE ieee.std_logic_1164.all;
use ieee.numeric_std.ALL;
use ieee.std_logic_arith.all;
entity UART is
port (
clk_10mhz: in STD_LOGIC;
txPin: out STD_LOGIC
);
end entity;
architecture Test of UART is
signal txStart: STD_LOGIC;
signal txIdle: STD_LOGIC;
signal txData: STD_LOGIC_VECTOR(7 downto 0);
component TX is
port (
clk_in: in STD_LOGIC;
start: in STD_LOGIC;
data: in STD_LOGIC_VECTOR(7 downto 0);
tx: out STD_LOGIC;
txIdle: out STD_LOGIC
);
end component TX;
begin
process (clk_10mhz, txIdle)
variable clkDividerCounter : integer range 0 to 10000000;
variable textToSend : string(1 to 31) := "Hello darkness my old friend!" & CR & LF;
variable currentCharacterIndex : integer range 0 to 31;
begin
if (rising_edge(clk_10mhz)) then
if (clkDividerCounter < 10000000) then
clkDividerCounter := clkDividerCounter + 1;
else
clkDividerCounter := 0;
currentCharacterIndex := 1;
end if;
if (txIdle = '1' and currentCharacterIndex > 0) then
txData <= CONV_STD_LOGIC_VECTOR(character'pos(textToSend(currentCharacterIndex)),8);
txStart <= '1';
if (currentCharacterIndex < 31) then
currentCharacterIndex := currentCharacterIndex + 1;
else
currentCharacterIndex := 0;
txStart <= '0';
end if;
end if;
end if;
end process;
u1: TX port map (clk_10mhz, txStart, txData, txPin, txIdle);
end Test;
TX.vhd:
LIBRARY ieee;
USE ieee.std_logic_1164.all;
use ieee.numeric_std.ALL;
entity TX is
port (
clk_in: in STD_LOGIC;
start: in STD_LOGIC;
data: in STD_LOGIC_VECTOR(7 downto 0);
tx: out STD_LOGIC;
txIdle: out STD_LOGIC
);
end entity;
architecture Test of TX is
signal idle: STD_LOGIC;
begin
process (clk_in)
variable bitIndex : integer range 0 to 9;
variable clkDividerCounter : integer range 0 to 260;
variable dataFrame : STD_LOGIC_VECTOR(9 downto 0);
variable dataFrameCurrentIndex : integer range 0 to 9;
begin
if (rising_edge(clk_in)) then
if (start = '1' and idle = '1') then
dataFrame(0) := '0';
dataFrame(8 downto 1) := data;
dataFrame(9) := '1';
dataFrameCurrentIndex := 0;
idle <= '0';
end if;
if (idle = '0') then
if (clkDividerCounter < 260) then
clkDividerCounter := clkDividerCounter + 1;
else
if (dataFrameCurrentIndex <= 9) then
tx <= dataFrame(dataFrameCurrentIndex);
dataFrameCurrentIndex := dataFrameCurrentIndex + 1;
else
idle <= '1';
end if;
clkDividerCounter := 0;
end if;
end if;
txIdle <= idle;
end if;
end process;
end Test;
【问题讨论】:
-
你的模拟测试台呢?
-
我尝试使用 ModelSim,但 tx_pin 始终未初始化,即使经过数百万个时钟周期(我还将 1s 延迟更改为几分之一秒)。我正在寻找另一个问题的解决方案。您所说的模拟测试台到底是什么意思?
-
在提供输入信号(clk 等)并监控其输出(理想情况下,报告错误但可以等待)的测试台(没有端口的 VHDL 实体)中实例化您的 UART。在此处发布该文件。没有测试平台的模拟是一种艰难的方式。直接在硬件中调试是真的困难的方法。哦,还有
std_logic_arith库。
标签: vhdl fpga intel-fpga