Advertisement
Shaco74

Sortierer Praktikum VHDL 2

Dec 9th, 2021
2,283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.50 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4.  
  5. entity sortierer is
  6.     generic (
  7.         CNT_OFL : positive := 25000000; -- Sekundentakt ofl
  8.         TIME_WEG_K : positive :=  10; -- Kunststoff-Werkstück, langer Weg
  9.         TIME_WEG_M : positive :=  8; -- Metall-Werkstück, kurzer Weg
  10.         FWD : std_logic := '0';
  11.         BCK : std_logic := '1';
  12.         RUN : std_logic := '1';
  13.         STP : std_logic := '0';
  14.         WEG_K : std_logic := '0';
  15.         WEG_M : std_logic := '1'
  16.         );
  17.  
  18.     port (
  19.         reset : in std_logic; -- Key0
  20.         clk     : in std_logic; --50 MHz
  21.         oe_in   : in std_logic; -- Switch 9
  22.         opt_sens    : in std_logic; -- optischer Sensor
  23.         ind_sens    : in std_logic; -- induktiv Sensor
  24.         oe_n_out    : out std_logic;
  25.         weiche_out  : out std_logic; -- Weg A / Weg B -Umschaltung  
  26.         motor_pwr_out : out std_logic; -- ...
  27.         motor_dir_out : out std_logic -- Motor Drehrichtung
  28.         );
  29. end entity sortierer;
  30.  
  31. architecture arch of sortierer is
  32.  
  33. -- signals
  34. signal cnt : unsigned(25 downto 0);
  35. signal time_s : unsigned(4 downto 0);
  36. signal weiche : std_logic;
  37. signal motor_pwr : std_logic;
  38. signal motor_dir : std_logic;
  39.  
  40. type main_state_t is (idle, plastik, metal);
  41. signal main_state, next_main_state : main_state_t;
  42.  
  43. begin
  44.  
  45. sort_control : process(clk, reset) is
  46. begin  
  47.     if (reset = '1') then
  48.         next_main_state <= idle;
  49.    
  50.  
  51.     elsif rising_edge(clk) then
  52.         main_state <= next_main_state; -- z_reg
  53.                
  54.         -- fast counter, overflow = 1s
  55.         if cnt = to_unsigned(CNT_OFL, cnt'length) or main_state = idle then
  56.             cnt <= (others => '0');
  57.         else
  58.             cnt <= cnt + 1;        
  59.         end if;
  60.  
  61.         -- Sekunden timer      
  62.         if main_state = idle then -- reset timer
  63.             time_s <= (others => '0'); 
  64.         elsif cnt = CNT_OFL then
  65.             time_s <= time_s + 1;
  66.         end if;
  67.  
  68.        
  69.         case main_state is
  70.        
  71.             when idle => -- warte auf opt_sens hi
  72.                 motor_pwr <= STP;
  73.                 weiche <= WEG_K;
  74.                 if(opt_sens = '1') then
  75.                     next_main_state <= plastik;
  76.                 end if;
  77.                
  78.             when plastik =>
  79.                 weiche <= WEG_K     ;      
  80.                 motor_pwr <= RUN;
  81.                 if(ind_sens = WEG_M) then
  82.                     next_main_state <= metal;
  83.                 end if;
  84.                 if(time_s >= TIME_WEG_K) then
  85.                 next_main_state <= idle;
  86.                 end if;
  87.                
  88.             when metal =>
  89.                 weiche <= WEG_M;
  90.                 motor_pwr <= RUN;
  91.                 if(time_s >= TIME_WEG_M) then
  92.                 next_main_state <= idle;
  93.                 end if;
  94.                
  95.            
  96.        
  97.        
  98.        
  99.         end case;
  100.     end if;
  101.     oe_n_out <= not oe_in; -- voltage translator active
  102.     weiche_out <= weiche;
  103.     motor_pwr_out <= motor_pwr;
  104.    motor_dir_out <= motor_dir;
  105.        
  106. end process sort_control;
  107.  
  108. end architecture arch;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement