Stepper-Motor-Control  v3.0.0
System on a Chip 2014 - Group 04
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
debug_key_detect.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 --! @file debug_key_detect.vhd
3 --! @author Marc Kossmann
4 --! @author Michael Riedel
5 --! @version v1.0.0
6 --! @date 05.12.2014
7 --!
8 --! @brief Debug component
9 --! @details Evaluates switches and keys and sets registers accordingly.
10 --! @par History:
11 --! @details v0.1.0 25.11.2014 Riedel & Kossmann
12 --! - first draft
13 --! @details v0.1.1 02.12.2014 Kossmann
14 --! - complete redesign because registers in register_interface
15 --! should be written only when input changes
16 --! @details v0.1.2 05.12.2014 Riedel
17 --! - added few comments to code for better findability
18 --! - corrected formatting and indention
19 --! @details v1.0.0 05.12.2014 Riedel & Kossmann
20 --! - release milestone 3b
21 -------------------------------------------------------------------------------
22 
23 --! Use Standard Library
24 LIBRARY ieee;
25 --! Use Logic Elements
26 USE ieee.std_logic_1164.all;
27 
28 --! @brief Debug-Component
30  PORT(
31  clock : IN STD_LOGIC; --! component clock
32  reset_n : IN STD_LOGIC; --! reset of component
33  switches : IN STD_LOGIC_VECTOR(9 DOWNTO 0); --! Switches to set registers in register_interface
34  key : IN STD_LOGIC; --! Run/Stop key0
35  read_data : IN STD_LOGIC_VECTOR(31 DOWNTO 0); --! data of selected register
36  ce_n : OUT STD_LOGIC; --! chip enable
37  write_n : OUT STD_LOGIC; --! write enable for register_interface
38  read_n : OUT STD_LOGIC; --! read enable for register_interface
39  addr : OUT STD_LOGIC_VECTOR(2 DOWNTO 0); --! selects the register to write
40  write_data : OUT STD_LOGIC_VECTOR(31 DOWNTO 0) --! data to write to selected register
41  );
42 END debug_key_detect;
43 
44 --! @brief Architecture of debug_key_detect
45 --! @details realized functionality:
46 --! - evaluting switches
47 --! - evaluting keys
48 --! - sets registers
49 ARCHITECTURE my_debug_key_detect of debug_key_detect is
50  --! @brief Tutorial-Component Key-Detector
51  COMPONENT key_detect_tut is
52  PORT
53  (
54  clock : IN STD_LOGIC; --! Component Clock
55  reset_n : IN STD_LOGIC; --! Component Reset
56  key_input : IN STD_LOGIC; --! Signal from key
57  key_detect : OUT STD_LOGIC --! Detect-Signal for key
58  );
59  END COMPONENT;
60 
61  SIGNAL key0_detect_wire : STD_LOGIC; --! Signal to detect key0 press
62  SIGNAL key0_reg : STD_LOGIC; --! Signal to toggle run/stop in ctrlReg(0) via key0
63  SIGNAL old_switches : STD_LOGIC_VECTOR(9 DOWNTO 0);
64  SIGNAL reg_write_stage : INTEGER;
65  SIGNAL run_bit : STD_LOGIC;
66 
67 BEGIN
68 
69  key0_inst : COMPONENT key_detect_tut
70  PORT MAP(
71  clock => clock,
72  reset_n => reset_n,
73  key_input => key,
74  key_detect => key0_detect_wire
75  );
76 
77  write_registers : PROCESS(reset_n, clock, key0_detect_wire, switches, old_switches)
78  BEGIN
79  IF(reset_n = '0') THEN
80  write_n <= '1';
81  addr <= "000";
82  run_bit <= read_data(0);
83  old_switches <= switches;
84  reg_write_stage <= 0;
85  write_data <= (others => '0'); -- unused bits to 0
86 
87  ELSIF(rising_edge(clock)) then
88  run_bit <= read_data(0);
89  IF(key0_detect_wire = '1') then
90  -- user toggled run/stop key
91  run_bit <= not run_bit;
92  old_switches <= switches;
93  reg_write_stage <= 0;
94  write_data <= (others => '0'); -- unused bits to 0
95  ELSIF(old_switches /= switches) THEN
96  -- user changed the speed via switches
97  old_switches <= switches;
98  reg_write_stage <= 0;
99  write_data <= (others => '0'); -- unused bits to 0
100  ELSIF(reg_write_stage = 0) then
101  -- read the switches-positions ...
102  addr <= "000";
103  write_data(0) <= run_bit; -- toogle R/S
104  write_data(1) <= switches(1); -- L/R
105  write_data(2) <= switches(2); -- Mode1
106  write_data(3) <= switches(3); -- Mode2
107  write_data(4) <= switches(4); -- Mode3
108  write_data(5) <= switches(5); -- Mode4
109  write_data(6) <= switches(6); -- IE
110  reg_write_stage <= 1;
111  write_n <= '0';
112  ELSIF(reg_write_stage = 1) then
113  -- ... write them to the register ...
114  addr <= "011";
115  write_data(2 downto 0) <= switches(9 downto 7);
116  reg_write_stage <= 2;
117  ELSIF(reg_write_stage = 2) then
118  -- ... reset the addr and disable the write-signal
119  addr <= "000";
120  write_n <= '1';
121  END IF;
122  END IF;
123  END PROCESS;
124 
125  read_n <= '0';
126  ce_n <= '0';
127 
128 END my_debug_key_detect;
in switchesSTD_LOGIC_VECTOR(9 DOWNTO0)
Switches to set registers in register_interface.
in reset_nSTD_LOGIC
Component Reset.
in keySTD_LOGIC
Run/Stop key0.
Debug-Component.
out addrSTD_LOGIC_VECTOR(2 DOWNTO0)
selects the register to write
out write_nSTD_LOGIC
write enable for register_interface
out write_dataSTD_LOGIC_VECTOR(31 DOWNTO0)
data to write to selected register
in key_inputSTD_LOGIC
Siggnal vom Taster.
in read_dataSTD_LOGIC_VECTOR(31 DOWNTO0)
data of selected register
out read_nSTD_LOGIC
read enable for register_interface
Tutorial-Component Key-Detector.
in clockSTD_LOGIC
component clock
out ce_nSTD_LOGIC
chip enable
in reset_nSTD_LOGIC
reset of component
in clockSTD_LOGIC
Component Clock.
_library_ ieeeieee
Use Standard Library.
Definition: counter_tb.vhd:20
out key_detectSTD_LOGIC
Detect-Signal for key.