Stepper-Motor-Control  v3.0.0
System on a Chip 2014 - Group 04
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
register_interface.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 --! @file register_interface.vhd
3 --! @author Marc Kossmann
4 --! @author Michael Riedel
5 --! @version v2.0.0
6 --! @date 05.12.2014
7 --!
8 --! @brief Register component
9 --! @details Provides the `ctrlReg`, `speedReg`, `stepsReg` registers.
10 --! The `ctrlReg` can be set and cleared bitwise with the
11 --! `ctrlSetReg` and `ctrlClrReg`.
12 --! @details Addresses for register-access:
13 --! | address | register |
14 --! |:-------:|:-----------|
15 --! | `000` | `ctrlReg` |
16 --! | `001` |`ctrlSetReg`|
17 --! | `010` |`ctrlClrReg`|
18 --! | `011` |`speedReg` |
19 --! | `100` |`stepsReg` |
20 --! @par History:
21 --! @details v0.1.0 06.11.2014 Kossmann
22 --! - first draft
23 --! @details v0.1.1 07.11.2014 Kossmann
24 --! - finished reset_n task
25 --! @details v0.1.2 17.11.2014 Riedel
26 --! - corrected formatting
27 --! - improved documentation
28 --! @details v1.0.0 18.11.2014 Riedel & Kossmann
29 --! - verified functionality -> release MS2
30 --! @details v1.0.1 19.11.2014 Kossmann
31 --! - changed register write implementation to more save version
32 --! @details v1.0.2 21.11.2014 Riedel & Kossmann
33 --! - removed ctrlSetReg and ctrlClrReg signals
34 --! - added register access for mcu
35 --! @details v1.0.3 01.12.2014 Kossmann
36 --! - reacting to rising edge of ir signal
37 --! @details v1.0.4 05.12.2014 Riedel
38 --! - corrected formatting and indention
39 --! @details v2.0.0 05.12.2014 Riedel & Kossmann
40 --! - release milestone 3b
41 -------------------------------------------------------------------------------
42 
43 --! Use Standard Library
44 LIBRARY ieee;
45 --! Use Logic Elements
46 USE ieee.STD_LOGIC_1164.all;
47 --! Use Conversion Functions
48 USE ieee.STD_LOGIC_signed.all;
49 
50 --! @brief Register Interface-Component
52  PORT
53  (
54  clock : IN STD_LOGIC; --! Avalon clock
55  reset_n : IN STD_LOGIC; --! Avalon reset the component
56  ce_n : IN STD_LOGIC; --! Avalon chip enable
57  read_n : IN STD_LOGIC; --! Avalon set read-request
58  write_n : IN STD_LOGIC; --! Avalon set write-request
59  addr : IN STD_LOGIC_VECTOR (2 DOWNTO 0); --! Avalon address bus (selects the register)
60  write_data : IN STD_LOGIC_VECTOR (31 DOWNTO 0); --! Avalon write data to selected register
61  read_data : OUT STD_LOGIC_VECTOR (31 DOWNTO 0); --! Avalon read data from selected register
62  irq : OUT STD_LOGIC; --! Avalon IRQ line
63  greenleds : OUT STD_LOGIC_VECTOR (7 DOWNTO 0); --! external: green leds
64  redleds : OUT STD_LOGIC_VECTOR (7 DOWNTO 0); --! external: red leds
65  run : OUT STD_LOGIC; --! enable signal for mcu
66  direction : OUT STD_LOGIC; --! direction signal for mcu
67  mode : OUT STD_LOGIC_VECTOR(3 DOWNTO 0); --! output of Mode bits for mcu
68  speed : OUT STD_LOGIC_VECTOR(2 DOWNTO 0); --! output of speedReg for mcu
69  steps : IN STD_LOGIC_VECTOR(31 DOWNTO 0); --! input for stepsReg for mcu
70  ir : IN STD_LOGIC --! input request of mcu
71  );
72 END register_interface;
73 
74 --! @brief Architecture of register_interface
75 --! @details realized components:
76 --! - all five registers
77 --! - 3 green LEDs showing speedReg with 0 .. 2
78 --! - 8 red LEDs showing ctrlReg
79 --! - generating motor interrupt
80 ARCHITECTURE my_register_interface OF register_interface IS
81 
82  --! internal signal representing the registers
83  SIGNAL ctrlReg : STD_LOGIC_VECTOR(7 DOWNTO 0);
84  SIGNAL speedReg : STD_LOGIC_VECTOR(2 DOWNTO 0);
85  SIGNAL stepsReg : STD_LOGIC_VECTOR(31 DOWNTO 0);
86 
87 BEGIN
88  --! @brief processing the tasks:
89  --! - interface to NIOS-processor
90  --! - writing registers
91  --! - reading registers
92  --! - implementing set and clear functionality
93  processing : PROCESS(clock, reset_n, ce_n, read_n, write_n, addr, ir)
94  BEGIN
95  -- ctrlReg Register Write
96  IF (reset_n = '0') THEN
97  ctrlReg <= (others => '0');
98  ELSIF (rising_edge(clock)) THEN
99  ctrlReg <= ctrlReg;
100 
101  IF(ir = '1') THEN -- set IR-bit in ctrlReg
102  ctrlReg(7) <= '1';
103  END IF;
104 
105  IF (addr = B"000" AND write_n = '0' AND ce_n = '0') THEN
106  ctrlReg <= write_data(7 DOWNTO 0); -- overwrite complete ctrlReg
107  ELSIF(addr = B"001" AND write_n = '0' AND ce_n = '0') THEN
108  ctrlReg <= ctrlReg or write_data(7 DOWNTO 0); -- set ctrlReg bitwise
109  ELSIF(addr = B"010" AND write_n = '0' AND ce_n = '0') THEN
110  ctrlReg <= ctrlReg and (not write_data(7 DOWNTO 0)); -- clr ctrlReg
111  END IF;
112  END IF;
113 
114  -- speedReg Register Write
115  IF (reset_n = '0') THEN
116  speedReg <= (others => '0');
117  ELSIF (rising_edge(clock)) THEN
118  IF (addr = B"011" AND write_n = '0' AND ce_n = '0') THEN
119  speedReg <= write_data(2 DOWNTO 0);
120  else
121  speedReg <= speedReg;
122  END IF;
123  END IF;
124 
125  -- stepsReg Register Write
126  IF (reset_n = '0') THEN
127  stepsReg <= (others => '0');
128  ELSIF (rising_edge(clock)) THEN
129  stepsReg <= stepsReg;
130  IF(CONV_INTEGER(steps) /= 0) THEN -- write stepsReg from mcu when mcu input is not '0'
131  stepsReg <= steps;
132  END IF;
133  IF (addr = B"100" AND write_n = '0' AND ce_n = '0') THEN
134  stepsReg <= write_data(31 DOWNTO 0);
135  END IF;
136  END IF;
137 
138  -- Processor reads from Register
139  read_data <= (others => '0'); -- unused bits to 0
140  IF (read_n = '0' AND ce_n = '0') THEN
141  CASE addr is
142  WHEN B"000" =>
143  read_data(7 DOWNTO 0) <= ctrlReg;
144  WHEN B"011" =>
145  read_data(2 DOWNTO 0) <= speedReg;
146  WHEN B"100" =>
147  read_data(31 DOWNTO 0) <= stepsReg;
148  WHEN others =>
149  read_data(31 DOWNTO 0) <= (others => '0');
150  END CASE;
151  END IF;
152 
153  END PROCESS;
154 
155  -- set interrupt
156  irq <= ctrlReg(6) and ctrlReg(7);
157 
158  -- clone ctrlReg to red leds
159  redleds <= ctrlReg;
160 
161  -- clone speedReg to green leds
162  greenleds(2 DOWNTO 0) <= speedReg;
163  greenleds(7 DOWNTO 3) <= (others => '0');
164 
165  -- extra mcu outputs
166  run <= ctrlReg(0);
167  direction <= ctrlReg(1);
168  mode <= ctrlReg(5 DOWNTO 2);
169  speed <= speedReg;
170 
171 END my_register_interface;
in ce_nSTD_LOGIC
Avalon chip enable.
in read_nSTD_LOGIC
Avalon set read-request.
out redledsSTD_LOGIC_VECTOR(7 DOWNTO0)
external: red leds
Register Interface-Component.
_library_ ieeeieee
Use Standard Library.
in write_nSTD_LOGIC
Avalon set write-request.
out runSTD_LOGIC
enable signal for mcu
out speedSTD_LOGIC_VECTOR(2 DOWNTO0)
output of speedReg for mcu
in addrSTD_LOGIC_VECTOR(2 DOWNTO0)
Avalon address bus (selects the register)
out irqSTD_LOGIC
Avalon IRQ line.
out read_dataSTD_LOGIC_VECTOR(31 DOWNTO0)
Avalon read data from selected register.
in reset_nSTD_LOGIC
Avalon reset the component.
out greenledsSTD_LOGIC_VECTOR(7 DOWNTO0)
external: green leds
in write_dataSTD_LOGIC_VECTOR(31 DOWNTO0)
Avalon write data to selected register.
in clockSTD_LOGIC
Avalon clock.
in stepsSTD_LOGIC_VECTOR(31 DOWNTO0)
input for stepsReg for mcu
out directionSTD_LOGIC
direction signal for mcu
in irSTD_LOGIC
input request of mcu
out modeSTD_LOGIC_VECTOR(3 DOWNTO0)
output of Mode bits for mcu