⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 image_convert.vhd

📁 机器状态机。控制工作方式。用vhdl写的。很不错哦
💻 VHD
字号:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity image_convert is
       Port (clk,reset,int,data_valid,ligne1:in std_logic;
             pixel_from_ir:in std_logic_vector(13 downto 0);     --BAI:pixel_from_ir是从AD转换器送出来的每个像素的数据。
             video_out:out std_logic_vector(13 downto 0);
             video_en:out std_logic;
             video_clk:out std_logic;
             reset_DSP:out std_logic;
             sram_addr:out std_logic_vector(19 downto 0);       --BAI:sram是20位的地址线。
             sram_data:inout std_logic_vector(13 downto 0);
             sram_ce,sram_oe,sram_we:inout std_logic
             --mc:out std_logic             
              );
end image_convert;

    
architecture Behavioral of image_convert is 
signal read_write_toggle:std_logic :='1';                  --BAI:读写标志,初值为1。 
signal ram_toggle:std_logic;
signal ligne_en,write_en,read_en:std_logic;
signal line_count:std_logic_vector(9 downto 0);
signal read_pixel_count,write_pixel_count:std_logic_vector(23 downto 0);    --BAI:像素为320*240=72800个25位,ram分成两块交叉进行读写,所以对读写计数时只需24位,最高位指明是高位部分还是低位部分。 
begin
   reset_DSP<='1';
process(reset)
begin
if(reset'event and reset='1') then
    ram_toggle<=not ram_toggle;              --BAI:ram_toggle的频率是reset的一半
end if;
end process;

--process(clk)
--begin
--if(clk'event and clk='1') then
--   read_write_toggle<=not read_write_toggle;
--end if;
--end process;



process(clk)
begin
if(clk'event and clk='1') then

   read_write_toggle<=not read_write_toggle;

   if(read_write_toggle='0' and read_en='1') then   --BAI:用读标志和读使能控制ce、oe、we三个信号。
     sram_ce<='0';    --BAI:片选有效
     sram_oe<='0';    --BAI:输出有效
     sram_we<='1';    --写无效。
     sram_addr<=ram_toggle&read_pixel_count(18 downto 0);   --BAI:一共20位地址线,此处用了后19位,最高位表明对高半部分还是低半部分进行操作。 
   elsif(read_write_toggle='1' and write_en='1') then       --当ram-toggle为1的时候才对sram进行读操作。
     sram_ce<='0';
     sram_oe<='1';
     sram_we<='0';
     sram_addr<=(not ram_toggle)&write_pixel_count(18 downto 0);
  -- elsif(read_write_toggle='1' and write_en2='1') then
  --   sram_ce<='0';
  --   sram_oe<='1';
  --   sram_we<='0';
  --   sram_addr<=(not ram_toggle)&write_pixel_count(18 downto 0);
   else
     sram_ce<='1';
     sram_oe<='1';
     sram_we<='1';
   end if;
end if;
end process;             --?BAI:read和write-en由谁控制?后面定义了。
--sram_we<='1';
process(clk)
begin
if(clk'event and clk='1') then       --BAI:保证以clk的频率工作
   if(read_write_toggle='1') then 
     video_out<=sram_data(13 downto 0);
   end if;
end if;
end process;
--sram_data(9 downto 0)<=pixel_from_ir(9 downto 0) when sram_we='0' else
--      (others=>'Z');
--sram_data(13 downto 0)<=line_count(9 downto 0)&"0000" when sram_we='0' and ligne_en='1' else

sram_data(13 downto 0)<=pixel_from_ir when sram_we='0' else     --BAI:pixel_from_ir为输入信号。
                       -- pixel_from_ir when sram_we='0' and write_en2<='1' else
                      -- "0000000000" when sram_we='0' and sram_addr>="100000000000000000" else
                       (others=>'Z');      --BAI:不读的时候要送入高阻。
process(data_valid,reset)
begin
if(reset='1') then
    line_count<=(others=>'0');
elsif(data_valid'event and data_valid='1') then
    line_count<=line_count+'1';    --BAI:有效数据来的时候开始计数
end if;
end process;

process(ligne1,reset)       --??BAI?: ligne1的作用是什么???
begin                       --?ligne_en的作用是什么?ligne1的作用是给ligne_en赋值用到的。
if(reset='1') then
   ligne_en<='0';
elsif(ligne1'event and ligne1='1') then
   ligne_en<='1';
   --ligne_en<=not ligne_en;          --BAI:ligne_en 是行可读信号。
end if;
end process;

write_en<='1' when ligne_en='1' and data_valid='1' and line_count<=250 else        --白:????为什么是250而不是240?
          '0';
--write_en1<='1' when ligne_en='1' and data_valid='1' and line_count<200 else
 --         '0';
--write_en2<='1' when ligne_en='1' and data_valid='1' and line_count>=200 and  line_count<240 else
 --         '0';


process(clk)
begin
if(reset='1') then
   write_pixel_count<=(others=>'0');
elsif(clk'event and clk='1') then
   --if(ligne_en='1' and data_valid='1' and line_count<=240) then
   if(ligne_en='1' and data_valid='1' and line_count<240) then
     if(read_write_toggle='1') then           --BAI:为1的时候写?    --????/???BAI:两个if的条件是并列的吧???
       write_pixel_count<=write_pixel_count+'1';
     end if;
   end if;
end if;
end process;

process(clk)
begin
if(reset='1') then
   read_pixel_count<=(others=>'0');
elsif(clk'event and clk='1') then
   if(read_write_toggle='0') then
     read_pixel_count<=read_pixel_count+'1';
   end if;
end if;
end process;

read_en<='1' when read_pixel_count>=1 and read_pixel_count<=76800 else
         '0';
--read_en2<='1' when read_pixel_count>=64001 and read_pixel_count<=76800 else
 --        '0';

video_en<=read_en;
end Behavioral;


--BAI: write_en是看行数,而read_en确是看像素数?为什么?见142和109行。

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -