介绍
这几天突然就不知道要使用FPGA实现什么样的功能了,然后就跑去学习数电了,学的也是晕晕的。正好之前写了一个使用FPGA发送伪随机序列的代码,然后因为需要使用曼彻斯特编码,所以又加了一个模块吧,使得最后输出的波形经过曼彻斯特编码。
曼彻斯特编码
首先,曼彻斯特编码是一种常见的数字编码方式。在曼彻斯特编码中,每个数据位都有两位数据来表示,下面我写给出对应关系。

设计文件
因为这次的文件比较多,所以就只列举一下,曼彻斯特编码的代码,其余的代码都在压缩包里了。因为我是对FPGA内部的时钟进行了10000分频,所以在这个文件中我设置的计数器为5000,当计满5000个数据时,信号实现反转。
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity rz is
Port (
clk : in STD_LOGIC;
rst_n : in STD_LOGIC;
input_data : in STD_LOGIC;
output_pwm : out STD_LOGIC
);
end entity;
architecture Behavioral of rz is
signal pwm_counter : integer := 0;
signal half_period : integer := 5000; -- 占空比为50%,方波周期为20个时钟周期
signal manchester_data : std_logic := '0';
begin
process (clk, rst_n)
begin
if rst_n = '0' then
pwm_counter <= 0;
manchester_data <= '0';
output_pwm <= '0';
elsif rising_edge(clk) then
if pwm_counter < half_period then
pwm_counter <= pwm_counter + 1;
else
pwm_counter <= 0;
manchester_data <= not manchester_data;
end if;
if manchester_data = '1' then
output_pwm <= not input_data;
else
output_pwm <= input_data;
end if;
end if;
end process;
end Behavioral;
仿真文件
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity tb_manchester is
end tb_manchester;
architecture behaval of tb_manchester is
component manchester is
port(clk,rst_n:in std_logic;
outp:out std_logic);
end component;
signal clk : std_logic;
signal rst_n : std_logic ;
signal outp : std_logic;
begin
dut : manchester
port map(clk => clk,
rst_n => rst_n,
outp => outp);
gen_clk : process
begin
rst_n <= '1';
clk <= '0';
wait for 10ns;
clk <= '1';
wait for 10ns;
end process;
end architecture;
RTL视图

从这个RTL视图中可以很清楚的看到,整个系统分了三个模块,分别是分频模块,伪随机序列产生模块和曼彻斯特编码模块。
仿真结果
这个仿真结果应该还是比较清晰的哈。

结语
我对比了伪随机序列和经过rz模块后的数据,应该是没有什么问题吧,如果有什么问题,欢迎留言。
另外,伪随机序列模块可以根据自己的需要进行设置。下次给大家更新伪随机序列的生成吧。
本文介绍了如何使用FPGA发送经过曼彻斯特编码的伪随机序列。通过详细的设计文件、仿真过程,展示了从编码到输出的完整流程,并提供了RTL视图和仿真结果。最后,作者鼓励读者对结果进行验证并分享可能的问题。

504

被折叠的 条评论
为什么被折叠?



