FGPA_Verilog_VHDL

DE-70 보드를 이용한 P161-MAN LED Dot Matrix Module 테스트

LonleyEngineer 2008. 3. 28. 19:17
반응형

어제 밤에 VHDL 문법에도 익숙해지고 state Machine에도 익숙해지기 위해서

FPGA로 LDM 구동 모듈을 만들어 보았다.

코드가 엉망이다.

 

처음에는 state Machine을 어떻게 구현해야 할지 몰라서 삽질했는데

while 문으로 구현하니 잘되었다.

 

역시 맨땅에 헤딩해봐야 하나씩 배우는 것 같다.

 

엉망인 코드지만 한번 올려본다.

 

===================================================================

-- Title : P161-MAN LED Dot Matrix Test
-- File: ldm.vhd
-- Author : OH JOO YEOL(http://blog.naver.com/jesusace)
-- Organization : Lonely Engeneer(It is My nick, Not Corp)
-- Created : March 27, 2008
-- Last update : Marh 27, 2008
-- Platform : Altera EP2C70F896C6 Based TerasIC DE2-70 Board
--    WinXP Sp2, QuartusII 7.2 Web-Edition
--  Simulator : QuartusII 7.2 Default Simulator
--  Synthesizers : QuartusII 7.2 Default Synthesizer
--  Target : None(It is practice)
--  Descriptions : This code is my VHDL coding practice object.
-- Revision Number : 34
--  Version : 0.1.34
--  Date of Change : March 27, 2008
--  Modifier : OH JOO YEOL
--  Description of change : xxxxxxxxxxxxxxx
-- Notice : xxxxxxx


Library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.all;
use ieee.std_logic_arith.all;

entity LDM is
 port( red_n : out std_logic :='1'; -- Red Data pin, Active low
  green_n : out std_logic :='1'; -- Green Data pin, Active low
  ldm_clock : out std_logic :='0'; -- Dot Matrix Module's clock
  ldm_oe  : out std_logic:='0'; -- out_enable pin
  ldm_latch : out std_logic:='1'; -- Latch pin
  gnd   : out std_logic:='0'; -- Ground Pin, Always Low  
  line_addr : out std_logic_vector(3 downto 0); -- Line Data pin. 0~15(16 lines)   
  
  clock_50 : in std_logic -- 50MHz Colck input pin  
 );
 type states is (init, dot_data, oe_high, latch_low, latch_high, oe_low);
end LDM;


architecture LDM_rtl of LDM is
    
signal current_state : states :=init;
signal count : integer range 0 to 1000 :=0;
signal line_count : std_logic_vector(3 downto 0) :="0000";

begin
 process(clock_50) 
 variable line_dot_num : integer range 0 to 1000 :=192; 
 variable count_temp : integer range 0 to 1000;
 
 begin
  if clock_50' event and clock_50='1' then  
   case current_state is
   when init=>
   
    green_n<='1';
    red_n <= '1';
    ldm_clock<='0';
    ldm_latch <='1';
    ldm_oe <='0';
    gnd<='0';
    line_addr <="0000"; 
    line_count<="0000"; 
    count<=0;            
    current_state<=dot_data;
    
    
    
   when dot_data=>  
    if count<line_dot_num then
     red_n<='0';    
    
     if (count mod 2)=0 then
      ldm_clock<='1';     
     else
      ldm_clock<='0';     
     end if;    
     count <=count+1;    
        
     if count=191 then
      count<=0;
      current_state<=oe_high;     
     end if;
    end if;
   
   
   when oe_high=>
   
    ldm_oe<='1';        
    count<=0;
    count_temp:=1;
    current_state<=latch_low;
   
   
   when latch_low=>
    if count<305 then --about 3us     
     count<=count+1;    
    else
     ldm_latch<='0';    
     count<=0;       
     current_state<=latch_high;    
    end if;
   
   
   when latch_high=>
    if count<2 then
     count<=count+1;
     --ldm_clock<='1';
    else 
     ldm_latch<='1';     
     if line_count="1111" then
      line_addr<="0000";      
     else
      line_addr<=line_count+"0001";      
     end if;              
     count<=0;
     current_state<=oe_low;
    end if;
   
   
   when oe_low=>
    if count<155 then --about 1.5us     
     count<=count+1;
     --ldm_clock<='0';    
    else
     line_count<=line_count+"0001";
     ldm_oe<='0';    
     count<=0;           
     current_state<=dot_data;
    end if;
   
   when others =>
    current_state<=init;
   
   end case;
  
  end if;  
 
 end process;
end LDM_rtl;

 

----------------------------------------------------------

 

P161-MAN의 datasheet 는 아쉽게도 없다.

KLM-163CAN Module의 데이터시트에서 RED, GREEN의 Pin이 Active low라는 점만 다르고 같다.

 

 

글자도 찍고 이것저것 해봐야 하는데

H/W 지식이 없으니 갈길이 멀어서 일단 좀 더 실력을 쌓고 구현해야겠다.

 

구동시키면 온통 빨간색 천지가 된다. ㅎㅎ

반응형