Stepper-Motor-Control  v3.0.0
System on a Chip 2014 - Group 04
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
milestone3.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 --! @file milestone3.vhd
3 --! @author Marc Kossmann
4 --! @author Michael Riedel
5 --! @version v1.0.0
6 --! @date 05.12.2014
7 --!
8 --! @brief Milestone3-Component
9 --! @details Sets up all needed components for development-step milestone 3.
10 --! @par History:
11 --! @details v0.1.0 23.11.2014 Kossmann
12 --! - first draft
13 --! @details v0.1.1 24.11.2014 Riedel
14 --! - corrected formatting
15 --! - corrected directions for `debug_key_detect`-component
16 --! - added signals and connected the three components
17 --! @details v0.1.2 25.11.2014 Riedel & Kossmann
18 --! - changed entitiy according to pin-assignments
19 --! @details v0.1.3 28.11.2014 Kossmann
20 --! - improved documemtation
21 --! @details v0.1.4 02.12.2014 Riedel & Kossmann
22 --! - fix wrong green leds output
23 --! @details v0.1.5 02.12.2014 Kossmann
24 --! - adjustments to work with new debug_key_detect design
25 --! @details v1.0.0 05.12.2014 Riedel & Kossmann
26 --! - release milestone 3b
27 -------------------------------------------------------------------------------
28 
29 --! Use Standard Library
30 LIBRARY ieee;
31 --! Use Logic Elements
32 USE ieee.STD_LOGIC_1164.all;
33 
34 --! @brief Milestone 3
35 ENTITY milestone3 is
36  GENERIC
37  (
38  --! @brief Prescaler for PWM-signal.
39  --! @details For this purpose 2,5 ms are used as minimal pulse-width.
40  --! @details The prescaler is calculated with the given and desired frequency
41  --! via the following formula:
42  --! \f{equation*}{
43  --! \text{prescaler} = \frac{f_{\text{clock}} \text{Hz}}{f_{\text{prescaler}} \text{Hz}}
44  --! \f}
45  --! e.g.:
46  --! \f{equation*}{
47  --! \left.\begin{aligned}
48  --! f_{\text{prescaler}} &= \frac{5}{2}\,\text{ms} \newline
49  --! &= 400\,\text{Hz} \newline\newline
50  --! \text{prescaler} &= \frac{50\,\text{Mhz}}{400\,\text{Hz}} \newline
51  --! &= 125000 \newline
52  --! \end{aligned}
53  --! \right\}
54  --! \qquad \text{pulse-width: 2.5 ms}
55  --! \f}
56  --! @details For simulation-purpose the divider was set to 125 for faster wave generation.
57  divider : integer := 125000
58  );
59  port(
60  CLOCK_50_B5B : IN STD_LOGIC; --! component clock
61  CPU_RESET_n : IN STD_LOGIC; --! resets the component
62  SW : IN STD_LOGIC_VECTOR(9 DOWNTO 0); --! switch input
63  KEY : IN STD_LOGIC_VECTOR(3 DOWNTO 0); --! key input
64  HSMC_RX_P : OUT STD_LOGIC_VECTOR(16 DOWNTO 0); --! Motor_pwm1( bit 0 ) and Motor_pwm2( bit 1 )
65  HSMC_RX_N : OUT STD_LOGIC_VECTOR(16 DOWNTO 0); --! Motor_pwm3( bit 0 ) and Motor_pwm4( bit 1 )
66  HSMC_TX_N : OUT STD_LOGIC_VECTOR(16 DOWNTO 0); --! Motor_en_a( bit 2 )
67  HSMC_TX_P : OUT STD_LOGIC_VECTOR(16 DOWNTO 0); --! Motor_en_b( bit 3 )
68  LEDG : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); --! green leds
69  LEDR : OUT STD_LOGIC_VECTOR(7 DOWNTO 0) --! red leds
70  );
71 END milestone3;
72 
73 --! @brief Architecture of milestone3
74 --! @details used components:
75 --! - debug_key_detect
76 --! - count_5ms
77 --! - register_interface
78 --! - motor_control_unit
79 architecture my_milestone3 of milestone3 is
80 
81 COMPONENT debug_key_detect is
82  PORT(
83  clock : IN STD_LOGIC; --! component clock
84  reset_n : IN STD_LOGIC; --! reset of component
85  switches : IN STD_LOGIC_VECTOR(9 DOWNTO 0); --! Switches to set registers in register_interface
86  key : IN STD_LOGIC; --! Run/Stop key0
87  read_data : IN STD_LOGIC_VECTOR(31 DOWNTO 0); --! data of selected register
88  ce_n : OUT STD_LOGIC; --! chip enable
89  write_n : OUT STD_LOGIC; --! write enable for register_interface
90  read_n : OUT STD_LOGIC; --! read enable for register_interface
91  addr : OUT STD_LOGIC_VECTOR(2 DOWNTO 0); --! selects the register to write
92  write_data : OUT STD_LOGIC_VECTOR(31 DOWNTO 0) --! data to write to selected register
93  );
94 END COMPONENT;
95 
96 COMPONENT register_interface is
97  PORT
98  (
99  clock : IN STD_LOGIC; --! Avalon clock
100  reset_n : IN STD_LOGIC; --! Avalon reset the component
101  ce_n : IN STD_LOGIC; --! Avalon chip enable
102  read_n : IN STD_LOGIC; --! Avalon set read-request
103  write_n : IN STD_LOGIC; --! Avalon set write-request
104  addr : IN STD_LOGIC_VECTOR(2 DOWNTO 0); --! Avalon address bus (selects the register)
105  write_data : IN STD_LOGIC_VECTOR(31 DOWNTO 0); --! Avalon write data to selected register
106  read_data : OUT STD_LOGIC_VECTOR(31 DOWNTO 0); --! Avalon read data from selected register
107  irq : OUT STD_LOGIC; --! Avalon IRQ line
108  greenleds : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); --! external: green leds
109  redleds : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); --! external: red leds
110  run : OUT STD_LOGIC; --! enable signal for mcu
111  direction : OUT STD_LOGIC; --! direction signal for mcu
112  mode : OUT STD_LOGIC_VECTOR(3 DOWNTO 0); --! output of mode bits for mcu
113  speed : OUT STD_LOGIC_VECTOR(2 DOWNTO 0); --! output of `speedReg` for mcu
114  steps : IN STD_LOGIC_VECTOR(31 DOWNTO 0); --! input for `stepsReg` for mcu
115  ir : IN STD_LOGIC --! input request of mcu
116  );
117 END COMPONENT;
118 
119 COMPONENT motor_control_unit is
120  GENERIC ( divider : integer );
121  PORT(
122  clock : IN STD_LOGIC; --! component clock
123  reset_n : IN STD_LOGIC; --! resets the component
124  run : IN STD_LOGIC; --! chip enable
125  direction : IN STD_LOGIC; --! motor direction (`0` is left)
126  mode : IN STD_LOGIC_VECTOR(3 DOWNTO 0); --! mode to run motor with
127  speed : IN STD_LOGIC_VECTOR(2 DOWNTO 0); --! speed to run moter with
128  motor_pwm : OUT STD_LOGIC_VECTOR(3 DOWNTO 0); --! pwm signalto control motor
129  motor_en : OUT STD_LOGIC_VECTOR(1 DOWNTO 0); --! enables motor driver
130  steps : OUT STD_LOGIC_VECTOR(31 DOWNTO 0); --! number of steps motor did
131  ir : OUT STD_LOGIC --! IR signal set when motor stopped
132  );
133 END COMPONENT;
134 
135 SIGNAL ce_n_wire : STD_LOGIC;
136 SIGNAL write_n_wire : STD_LOGIC;
137 SIGNAL addr_wire : STD_LOGIC_VECTOR(2 DOWNTO 0);
138 SIGNAL write_data_wire: STD_LOGIC_VECTOR(31 DOWNTO 0);
139 SIGNAL run_wire : STD_LOGIC;
140 SIGNAL direction_wire : STD_LOGIC;
141 SIGNAL mode_wire : STD_LOGIC_VECTOR(3 DOWNTO 0);
142 SIGNAL speed_wire : STD_LOGIC_VECTOR(2 DOWNTO 0);
143 SIGNAL steps_wire : STD_LOGIC_VECTOR(31 DOWNTO 0);
144 SIGNAL ir_wire : STD_LOGIC;
145 SIGNAL read_n_wire : STD_LOGIC;
146 SIGNAL read_data_wire : STD_LOGIC_VECTOR(31 DOWNTO 0);
147 
148 SIGNAL motor_pwm_wire : STD_LOGIC_VECTOR(3 DOWNTO 0);
149 SIGNAL motor_en_wire : STD_LOGIC_VECTOR(1 DOWNTO 0);
150 
151 BEGIN
152  debug_inst : COMPONENT debug_key_detect
153  PORT MAP (
154  clock => CLOCK_50_B5B,
155  reset_n => CPU_RESET_n,
156  switches => SW,
157  key => KEY(0),
158  ce_n => ce_n_wire,
159  write_n => write_n_wire,
160  read_n => read_n_wire,
161  addr => addr_wire,
162  write_data => write_data_wire ,
163  read_data => read_data_wire
164  );
165 
166  register_interface_inst : COMPONENT register_interface
167  PORT MAP (
168  clock => CLOCK_50_B5B,
169  reset_n => CPU_RESET_n,
170  ce_n => ce_n_wire,
171  read_n => read_n_wire,
172  write_n => write_n_wire,
173  addr => addr_wire,
174  write_data => write_data_wire ,
175  read_data => read_data_wire,
176 -- irq => irq_wire,
177 -- greenleds => LEDG,
178  redleds => LEDR,
179  run => run_wire,
180  direction => direction_wire ,
181  mode => mode_wire,
182  speed => speed_wire,
183  steps => steps_wire,
184  ir => ir_wire
185  );
186 
187  motor_control_unit_inst : COMPONENT motor_control_unit
188  GENERIC MAP ( divider => divider )
189  PORT MAP(
190  clock => CLOCK_50_B5B,
191  reset_n => CPU_RESET_n,
192  run => run_wire,
193  direction => direction_wire,
194  mode => mode_wire,
195  speed => speed_wire,
196  motor_pwm => motor_pwm_wire,
197  motor_en => motor_en_wire,
198  steps => steps_wire,
199  ir => ir_wire
200  );
201 
202  LEDG(3) <= motor_pwm_wire(3);
203  LEDG(2) <= motor_pwm_wire(1);
204  LEDG(1) <= motor_pwm_wire(2);
205  LEDG(0) <= motor_pwm_wire(0);
206 
207  LEDG(5 DOWNTO 4) <= motor_en_wire;
208 
209  HSMC_RX_P(0) <= motor_pwm_wire(0);
210  HSMC_RX_P(1) <= motor_pwm_wire(1);
211  HSMC_RX_N(0) <= motor_pwm_wire(2);
212  HSMC_RX_N(1) <= motor_pwm_wire(3);
213  HSMC_TX_N(2) <= motor_en_wire(0);
214  HSMC_TX_P(3) <= motor_en_wire(1);
215 
216 END my_milestone3;
in ce_nSTD_LOGIC
Avalon chip enable.
out HSMC_RX_PSTD_LOGIC_VECTOR(16 DOWNTO0)
Motor_pwm1( bit 0 ) and Motor_pwm2( bit 1 )
Definition: milestone3.vhd:64
in switchesSTD_LOGIC_VECTOR(9 DOWNTO0)
Switches to set registers in register_interface.
in read_nSTD_LOGIC
Avalon set read-request.
in modeSTD_LOGIC_VECTOR(3 DOWNTO0)
mode to run motor with
out redledsSTD_LOGIC_VECTOR(7 DOWNTO0)
external: red leds
in clockSTD_LOGIC
component clock
in keySTD_LOGIC
Run/Stop key0.
Debug-Component.
Register Interface-Component.
out LEDRSTD_LOGIC_VECTOR(7 DOWNTO0)
red leds
Definition: milestone3.vhd:70
out addrSTD_LOGIC_VECTOR(2 DOWNTO0)
selects the register to write
in write_nSTD_LOGIC
Avalon set write-request.
out write_nSTD_LOGIC
write enable for register_interface
out motor_enSTD_LOGIC_VECTOR(1 DOWNTO0)
both enable signals for the motor
out write_dataSTD_LOGIC_VECTOR(31 DOWNTO0)
data to write to selected register
Milestone 3.
Definition: milestone3.vhd:35
dividerinteger:=125000
Prescaler for PWM-signal.
Definition: milestone3.vhd:58
out runSTD_LOGIC
enable signal for mcu
out speedSTD_LOGIC_VECTOR(2 DOWNTO0)
output of speedReg for mcu
dividerinteger:=125000
Prescaler for PWM-signal.
in addrSTD_LOGIC_VECTOR(2 DOWNTO0)
Avalon address bus (selects the register)
in CPU_RESET_nSTD_LOGIC
resets the component
Definition: milestone3.vhd:61
in directionSTD_LOGIC
motor direction ('0' is left)
in reset_nSTD_LOGIC
resets the component
in read_dataSTD_LOGIC_VECTOR(31 DOWNTO0)
data of selected register
out read_nSTD_LOGIC
read enable for register_interface
out LEDGSTD_LOGIC_VECTOR(7 DOWNTO0)
green leds
Definition: milestone3.vhd:68
out irqSTD_LOGIC
Avalon IRQ line.
Motor Control Unit.
in SWSTD_LOGIC_VECTOR(9 DOWNTO0)
switch input
Definition: milestone3.vhd:62
out read_dataSTD_LOGIC_VECTOR(31 DOWNTO0)
Avalon read data from selected register.
in clockSTD_LOGIC
component clock
in reset_nSTD_LOGIC
Avalon reset the component.
out HSMC_TX_PSTD_LOGIC_VECTOR(16 DOWNTO0)
Motor_en_b( bit 3 )
Definition: milestone3.vhd:67
out greenledsSTD_LOGIC_VECTOR(7 DOWNTO0)
external: green leds
out ce_nSTD_LOGIC
chip enable
in reset_nSTD_LOGIC
reset of component
in runSTD_LOGIC
chip enable
out irSTD_LOGIC
IR signal set when motor stopped.
in write_dataSTD_LOGIC_VECTOR(31 DOWNTO0)
Avalon write data to selected register.
in CLOCK_50_B5BSTD_LOGIC
component clock
Definition: milestone3.vhd:60
out HSMC_TX_NSTD_LOGIC_VECTOR(16 DOWNTO0)
Motor_en_a( bit 2 )
Definition: milestone3.vhd:66
in KEYSTD_LOGIC_VECTOR(3 DOWNTO0)
key input
Definition: milestone3.vhd:63
out motor_pwmSTD_LOGIC_VECTOR(3 DOWNTO0)
signal-bus for the motor pulse-width-modulation
in clockSTD_LOGIC
Avalon clock.
out HSMC_RX_NSTD_LOGIC_VECTOR(16 DOWNTO0)
Motor_pwm3( bit 0 ) and Motor_pwm4( bit 1 )
Definition: milestone3.vhd:65
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
_library_ ieeeieee
Use Standard Library.
out modeSTD_LOGIC_VECTOR(3 DOWNTO0)
output of Mode bits for mcu
in speedSTD_LOGIC_VECTOR(2 DOWNTO0)
speed to run moter with
out stepsSTD_LOGIC_VECTOR(31 DOWNTO0)
number of steps motor did