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

📄 ppm.vhd.vhd

📁 ppm编码
💻 VHD
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity ppm is
  port(  clk  :in std_logic;
         RST  :in std_logic;
         din  : in std_logic;
         d_en  :out std_logic;
         f_en  :out std_logic;
        
         dout: out std_logic);
end; 

architecture behav of ppm is
 signal t:std_logic;
 signal state:std_logic_vector(2 downto 0);
 signal cnt  :std_logic_vector(2 downto 0);
 signal counter :std_logic_vector(7 downto 0);
 signal counter1:std_logic_vector(7 downto 0);
 signal counter2:std_logic_vector(7 downto 0);
 signal d1      :std_logic_vector(7 downto 0);
begin
  process(clk,RST,din) 
  begin
  if RST='0' then 
     state<="000";
     counter<="00000001";
     counter1<="00000001";
     counter2<="00000001";
    
     d_en<='0';
     f_en<='0';
     cnt<="000";
     t<='0';
     d1<="00000000";
     dout<='0';
   elsif clk'event and clk='1' then
     case state is 
     when "000" =>         
          if din='0' then
               if counter="00010000"       then state<="001"; counter<="00000001";
                 elsif counter >"00010000" then state<="000"; counter<="00000001";            
              
                 else  counter<="00000001"+counter;           
                 end if;
           else state<="000";
          end if;
     when "001" =>
            
               if din='1' then 
                  if counter="01000000" then  state<="010"; counter<="00000001";
                    elsif counter >"01000000" then state<="000"; counter<="00000001";            
                   
                    else  counter<="00000001"+counter;
                  end if;
                else state<="000"; counter<="00000001";
               end if;
             
           
 
     when "010" =>
        
               if din='0' then 
                  if counter="00010000" then state<="011"; counter<="00000001";
                     elsif counter >"00010000" then state<="000"; counter<="00000001";            
                   
                     else  counter<="00000001"+counter;  
                   end if;
               end if;
          

     when "011" =>  
        
               if din='1' and counter/="00100000" then 
                     counter<=counter+"00000001"; 
                elsif din='1' and counter="00100000" then                                          
                       state<="100";  counter<="00000001";f_en<='1';   
                 else state<="000" ;counter<="00000001";
                end if;
          
     when "100" =>  
        f_en<='0';     
         if cnt/="101" then
             if   din='1'  then  counter<=counter+"00000001";
                
                  else state<="101";                             
                      counter1<="00000001";counter2<="00000001";t<='0';
             end if;                  ------------------------ have some bug in this mode
            else state<="110"; 
          end if;  
        when "101" =>
               if  counter="00010000" then      --  one if the first low power if 16T
                                                -- do<="00";
                         if t='0' then                        
                           if  din='0' then counter1<=counter1+"00000001";state<="101";
                               elsif counter1/="00010000" then state<="000";
                               elsif counter1="00010000"  then  state<="101";counter2<="00000001"; t<='1';
                           else state<="000";
                            end if;
                         elsif t='1' then                 
                             if     din='1' and counter2/="01100000" then 
                                    counter2<=counter2+"00000001";state<="101";
                             elsif  din='1' and counter2="01100000" then  state<="100";
                                    d1<=d1(5 downto 0)&"00";
                                    cnt<=cnt+"001";t<='0';  
                                    counter1<="00000001";counter<="00000001";counter2<="00000001";
                             else  state<="000";
                          end if;
                       end if;
         elsif  counter="00110001" then          ---   two if the first low power if 48T
                                                 --  do<="10";
                         if t='0' then
                           if din='0' then  counter1<=counter1+"00000001";state<="101";
                              elsif counter1/="00010000" then state<="000";
                              elsif counter1="00010000"  then t<='1';state<="101";counter1<="00000001";
                           end if;
                         elsif t='1' then
                             if   din='1' and counter2/="01000000"  then counter2<=counter2+"00000001";state<="101";
                                elsif din='1' and counter2="01000000" then state<="100";d1<=d1(5 downto 0)&"10"; cnt<=cnt+"001";t<='0';
                                counter1<="00000001";counter<="00000001";counter2<="00000001";
                             else state<="000";
                             end if;
                         end if;
        elsif  counter="01010000" then                         ---three the80T
                                                              -- do<="01";
                     if t='0' then
                          if din='0' then  counter1<=counter1+"00000001";
                           elsif counter1/="00010000" then state<="000";
                           elsif counter1="00010000" then t<='1';counter1<="00000001";
                          end if;
                     elsif t='1' then
                         if din='1' and counter2/="00100000" then  
                             counter2<=counter2+"00000001";state<="101";
                            
                         elsif din='1' and counter2="00100000" then  
                           state<="100";d1<=d1(5 downto 0)&"01";
                           cnt<=cnt+"001";t<='0';
                           counter2<="00000001"; counter1<="00000001";  counter<="00000001";
                         else  state<="000";
                         end if;
                     end if;
            elsif counter="01110000" then                          ---112T
                                                                   -- do<="11";
                   if din='0' then  
                    counter1<=counter1+"00000001";
                    state<="101";
                     elsif counter1/="00010000" then  state<="000";
                     elsif  counter1="00010000" then
                         state<="100"; d1<=d1(5 downto 0)&"11"; cnt<=cnt+"001";t<='0';
                         counter1<="00000001";  counter<="00000001";
                    end if;
         elsif  counter="00100000" then              ---EOF
                     if t='0' then
                         if din='0' then 
                         counter1<=counter1+"00000001";
                            elsif counter1/="00010000" then state<="000";
                            elsif  counter1="00010000" then  t<='1';
                          end if;
                     elsif t='1' then
                         if   din='1' and  counter2/="00010000" then    
                           counter2<=counter2+"00000001";state<="101";
                         elsif din='1' and counter2="00010000" then   state<="100"; cnt<=cnt+"001";
                         counter1<="00000001";  counter<="00000001";counter2<="00000001"; 
                         else  state<="000";  
                         end if;
                    end if;
            else
                 state<="000";counter2<="00000001";   
                 counter1<="00000001";counter<="00000001";cnt<="000"; 
            end if; 
    when "110"=>
           d_en<='1';
           state<="111";
   when "111"=>
                 d_en<='0';
                 if counter/="00001001" then
                       dout<=d1(7);
                       d1<=d1(6 downto 0)&'0';
                       counter<=counter+"00000001"; 
                  else state<="000";dout<='0';
                 end if;
     when others =>
           state<="000";
    end case;
  end if;    
 end process;
end;

⌨️ 快捷键说明

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