Advertisement
Guest User

Untitled

a guest
May 22nd, 2013
771
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 8.34 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date:    08:51:34 05/02/2013
  6. -- Design Name:
  7. -- Module Name:    adc_lcd - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22. use IEEE.std_logic_unsigned.all;
  23.  
  24. -- Uncomment the following library declaration if using
  25. -- arithmetic functions with Signed or Unsigned values
  26. use IEEE.NUMERIC_STD.ALL;
  27.  
  28. -- Uncomment the following library declaration if instantiating
  29. -- any Xilinx primitives in this code.
  30. --library UNISIM;
  31. --use UNISIM.VComponents.all;
  32.  
  33. entity adc_lcd is
  34.     Port ( RST : in  STD_LOGIC;
  35.            CLK : in  STD_LOGIC;
  36.            WR : out  STD_LOGIC := '1';
  37.            RD : out  STD_LOGIC := '1';
  38.            CS : out  STD_LOGIC := '1';
  39.            DATA : in  STD_LOGIC_VECTOR (7 downto 0);
  40.            INTR : in  STD_LOGIC;
  41.            DATA_SHIFT : out  STD_LOGIC := '1';
  42.            CK_SHIFT : out  STD_LOGIC := '1';
  43.            STROBE : out  STD_LOGIC := '1';
  44.            LCD_BP : out  STD_LOGIC := '1');
  45. end adc_lcd;
  46.  
  47. architecture Behavioral of adc_lcd is
  48.  
  49. signal time_base : STD_LOGIC := '0';
  50. signal sample : STD_LOGIC := '1';
  51. signal polarity : STD_LOGIC := '0';
  52. signal t1 : STD_LOGIC_VECTOR (7 downto 0) := x"00";
  53.  
  54. signal data_adc: STD_LOGIC_VECTOR (7 downto 0) := x"00";
  55. signal bcd: STD_LOGIC_VECTOR (9 downto 0);
  56.  
  57. signal seven_segment: STD_LOGIC_VECTOR (23 downto 0) := x"000000";
  58. signal i : integer range 0 to 25 := 0;
  59. signal event_counter : integer range 0 to 4096 := 0;
  60. signal zobraz_time : integer range 0 to 128 := 0;
  61.  
  62. type stav is (INIT_ADC,CAKAJ_INTR, READ_ADC, SPRACUJ, ZOBRAZ, CAKAJ);
  63. signal AKT_STAV,NASL_STAV: stav;
  64.  
  65. begin
  66.  
  67.  
  68.  
  69. --generovanie signalu periody 500ns
  70. process(CLK,RST)
  71.     begin
  72.         if(RST = '1') then
  73.             t1 <= x"00";
  74.        
  75.         else
  76.                 if rising_edge(CLK) then
  77.                    
  78.                     t1 <= t1 + 1;
  79.                     if(t1 = x"1F") then
  80.                         time_base <= not(time_base);
  81.                         t1 <= x"00";
  82.                     end if;
  83.                 end if;
  84.            
  85.         end if;
  86.  
  87. end process;
  88.  
  89.  
  90.  
  91. --stavovy automat
  92. process(time_base,RST)
  93.    
  94.     variable z: STD_LOGIC_VECTOR (17 downto 0);
  95.    
  96.     begin  
  97.         if(RST = '1') then
  98.             AKT_STAV <= INIT_ADC;
  99.             NASL_STAV <= INIT_ADC;
  100.             event_counter <= 0;
  101.             i <= 0;
  102.             zobraz_time <= 0;
  103.         else
  104.             if rising_edge(time_base) then
  105.                     AKT_STAV <= NASL_STAV;
  106.                    
  107.                     if(AKT_STAV = NASL_STAV) then
  108.                         event_counter <= event_counter + 1;
  109.                     else
  110.                         event_counter <= 0;
  111.                     end if;
  112.                    
  113.            
  114.                     -- zaciatok stavoveho automatiu
  115.                     case AKT_STAV is
  116.                         -- stav init_adc
  117.                         when INIT_ADC =>
  118.                             if(event_counter = 0) then
  119.                                 CS <= '0';
  120.                             elsif(event_counter = 1) then
  121.                                 WR <= '0';                     
  122.                             elsif(event_counter = 2) then
  123.                                 WR <= '1';         
  124.                             else
  125.                                 WR <= '1';
  126.                                 CS <= '1';
  127.                                 NASL_STAV <= CAKAJ_INTR;
  128.                             end if;
  129.                            
  130.                         -- cakaj na INTR s AD prevodnika
  131.                         when CAKAJ_INTR =>
  132.                             if(INTR = '0') then
  133.                               NASL_STAV <= READ_ADC;
  134.                             end if;    
  135.  
  136.                         -- citaj data s AD prevodnika
  137.                         when READ_ADC =>
  138.                             if(event_counter = 0) then
  139.                                 CS <= '0';     
  140.                             elsif(event_counter = 1) then
  141.                                 RD <= '0';
  142.                             elsif(event_counter = 2) then
  143.                                 data_adc <= DATA;  
  144.                             elsif(event_counter = 3) then
  145.                                 RD <= '1';
  146.                             else
  147.                                 RD <= '1';
  148.                                 CS <= '1';
  149.                                 NASL_STAV <= SPRACUJ;
  150.                             end if;
  151.                         -- spracuj ADC na data pre LCD
  152.                         when SPRACUJ =>
  153.                             -- data_adc = vstup
  154.                             -- seven_segment = vystup
  155.                            
  156.                             -- spracuj vysledok ADC do BCD kodu
  157.                             for i in 0 to 17 loop
  158.                                 z(i) := '0';
  159.                             end loop;
  160.                             z(10 downto 3) := data_Adc;
  161.  
  162.                             for i in 0 to 4 loop
  163.                             if z(11 downto 8) > 4 then 
  164.                                     z(11 downto 8) := z(11 downto 8) + 3;
  165.                             end if;
  166.                             if z(15 downto 12) > 4 then
  167.                                     z(15 downto 12) := z(15 downto 12) + 3;
  168.                             end if;
  169.                             z(17 downto 1) := z(16 downto 0);
  170.                             end loop;
  171.                            
  172.                             bcd <= z(17 downto 8); 
  173.                            
  174.                             -- mame BCD teraz skonvertuj do 7segmentovky
  175.                             case  bcd(3 downto 0) is
  176.                                 when "0000"=> seven_segment(6 downto 0) <="0111111";  -- '0'
  177.                                 when "0001"=> seven_segment(6 downto 0) <="0000110";  -- '1'
  178.                                 when "0010"=> seven_segment(6 downto 0) <="1011011";  -- '2'
  179.                                 when "0011"=> seven_segment(6 downto 0) <="1001111";  -- '3'
  180.                                 when "0100"=> seven_segment(6 downto 0) <="1100110";  -- '4'
  181.                                 when "0101"=> seven_segment(6 downto 0) <="1101101";  -- '5'
  182.                                 when "0110"=> seven_segment(6 downto 0) <="1111101";  -- '6'
  183.                                 when "0111"=> seven_segment(6 downto 0) <="0000111";  -- '7'
  184.                                 when "1000"=> seven_segment(6 downto 0) <="1111111";  -- '8'
  185.                                 when "1001"=> seven_segment(6 downto 0) <="1101111";  -- '9'
  186.                                  --nothing is displayed when a number more than 9 is given as input.
  187.                                 when others=> seven_segment(6 downto 0) <="0000000";
  188.                             end case;  
  189.                            
  190.                             -- preskoc bodku
  191.                            
  192.                             case  bcd(7 downto 4) is
  193.                                 when "0000"=> seven_segment(14 downto 8) <="0111111";  -- '0'
  194.                                 when "0001"=> seven_segment(14 downto 8) <="0000110";  -- '1'
  195.                                 when "0010"=> seven_segment(14 downto 8) <="1011011";  -- '2'
  196.                                 when "0011"=> seven_segment(14 downto 8) <="1001111";  -- '3'
  197.                                 when "0100"=> seven_segment(14 downto 8) <="1100110";  -- '4'
  198.                                 when "0101"=> seven_segment(14 downto 8) <="1101101";  -- '5'
  199.                                 when "0110"=> seven_segment(14 downto 8) <="1111101";  -- '6'
  200.                                 when "0111"=> seven_segment(14 downto 8) <="0000111";  -- '7'
  201.                                 when "1000"=> seven_segment(14 downto 8) <="1111111";  -- '8'
  202.                                 when "1001"=> seven_segment(14 downto 8) <="1101111";  -- '9'
  203.                                  --nothing is displayed when a number more than 9 is given as input.
  204.                                 when others=> seven_segment(14 downto 8) <="0000000";
  205.                             end case;  
  206.                            
  207.                             -- preskoc bodku
  208.                            
  209.                             case  bcd(9 downto 8) is
  210.                                 when "00"=> seven_segment(22 downto 16) <="0111111";  -- '0'
  211.                                 when "01"=> seven_segment(22 downto 16) <="0000110";  -- '1'
  212.                                 when "10"=> seven_segment(22 downto 16) <="1011011";  -- '2'
  213.                            
  214.                                  --nothing is displayed when a number more than 9 is given as input.
  215.                                 when others=> seven_segment(22 downto 16) <="0000000";
  216.                             end case;  
  217.                            
  218.                             --seven_segment <= bcd;
  219.                            
  220.                             zobraz_time <= 0;
  221.                             NASL_STAV <= ZOBRAZ;
  222.                                                                    
  223.                         when ZOBRAZ =>
  224.                         -- nasip data do shift registra
  225.                             if(event_counter < 47) then
  226.                                 -- vypni strobe
  227.                                 STROBE <= '1';
  228.                                 -- dobezna hrana
  229.                                 if(sample = '1') then
  230.                                     -- polarita dat
  231.                                     if(polarity = '1') then
  232.                                         DATA_SHIFT <=  not(seven_segment(i));
  233.                                     else
  234.                                         DATA_SHIFT <=  seven_segment(i);
  235.                                     end if;
  236.                                    
  237.                                     CK_SHIFT <= '0';
  238.                                     i <= i + 1;
  239.                                 --nabezna hrana
  240.                                 else
  241.                                     CK_SHIFT <= '1';
  242.                                 end if;
  243.                                 -- rozhoduje ci ma vlozit novu vzorku
  244.                                 sample <= not(sample);
  245.                            
  246.                             -- data su nahrane zobraz ich na LCD
  247.                             else   
  248.                                 -- neguj polaritu                              
  249.                                 i <= 0;
  250.                                 CK_SHIFT <= '1';
  251.                                
  252.                                 -- vyber polaritu spolocnej elektrody
  253.                                 if(polarity = '1') then
  254.                                     LCD_BP <= '1';
  255.                                 else
  256.                                     LCD_BP <= '0';
  257.                                 end if;
  258.                                
  259.                                 -- zapni strobe
  260.                                 STROBE <= '0';
  261.                                
  262.                                 --inkrementuj pocet zobrazeni do dalsieho merania
  263.                                 zobraz_time <= zobraz_time + 1;
  264.                                
  265.                                 -- cakaj x ms
  266.                                 NASL_STAV <= CAKAJ;                        
  267.                             end if;    
  268.  
  269.                     when CAKAJ =>
  270.                         -- ak sa zobrazovalo urcity cas zacni odznova
  271.                         -- zobrazuj hodnotu 0,5sec
  272.                         if(zobraz_time = 100) then
  273.                             NASL_STAV <= INIT_ADC;
  274.                         else
  275.                             -- 2ms to je 50Hz
  276.                             if (event_counter = 4000) then
  277.                                     NASL_STAV <= ZOBRAZ;
  278.                                     polarity <= not(polarity);
  279.                             end if;
  280.                         end if;
  281.  
  282.                     end case;
  283.                    
  284.                     -- spracovanie event_countera ku jednotlivym uloham
  285.            
  286.                    
  287.                                        
  288.             end if;
  289.         end if;
  290.  
  291. end process;
  292.  
  293.  
  294. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement