1 -------------------------------------------------------------------------------
2 --! @file milestone3.vhd
3 --! @author Marc Kossmann
4 --! @author Michael Riedel
8 --! @brief Milestone3-Component
9 --! @details Sets up all needed components for development-step milestone 3.
11 --! @details v0.1.0 23.11.2014 Kossmann
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 -------------------------------------------------------------------------------
29 --! Use Standard Library
31 --! Use Logic Elements
32 USE ieee.STD_LOGIC_1164.
all;
34 --! @brief Milestone 3
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:
43 --! \text{prescaler} = \frac{f_{\text{clock}} \text{Hz}}{f_{\text{prescaler}} \text{Hz}}
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
54 --! \qquad \text{pulse-width: 2.5 ms}
56 --! @details For simulation-purpose the divider was set to 125 for faster wave generation.
62 SW : IN (9 DOWNTO 0);
--! switch input
63 KEY : IN (3 DOWNTO 0);
--! key input
64 HSMC_RX_P : OUT (16 DOWNTO 0);
--! Motor_pwm1( bit 0 ) and Motor_pwm2( bit 1 )
65 HSMC_RX_N : OUT (16 DOWNTO 0);
--! Motor_pwm3( bit 0 ) and Motor_pwm4( bit 1 )
66 HSMC_TX_N : OUT (16 DOWNTO 0);
--! Motor_en_a( bit 2 )
67 HSMC_TX_P : OUT (16 DOWNTO 0);
--! Motor_en_b( bit 3 )
68 LEDG : OUT (7 DOWNTO 0);
--! green leds
69 LEDR : OUT (7 DOWNTO 0) --! red leds
73 --! @brief Architecture of milestone3
74 --! @details used components:
75 --! - debug_key_detect
77 --! - register_interface
78 --! - motor_control_unit
83 clock :
IN ;
--! component clock
84 reset_n :
IN ;
--! reset of component
85 switches :
IN (
9 DOWNTO 0);
--! Switches to set registers in register_interface
86 key :
IN ;
--! Run/Stop key0
87 read_data :
IN (
31 DOWNTO 0);
--! data of selected register
88 ce_n :
OUT ;
--! chip enable
89 write_n :
OUT ;
--! write enable for register_interface
90 read_n :
OUT ;
--! read enable for register_interface
91 addr :
OUT (
2 DOWNTO 0);
--! selects the register to write
92 write_data :
OUT (
31 DOWNTO 0)
--! data to write to selected register
99 clock :
IN ;
--! Avalon clock
100 reset_n :
IN ;
--! Avalon reset the component
101 ce_n :
IN ;
--! Avalon chip enable
102 read_n :
IN ;
--! Avalon set read-request
103 write_n :
IN ;
--! Avalon set write-request
104 addr :
IN (
2 DOWNTO 0);
--! Avalon address bus (selects the register)
105 write_data :
IN (
31 DOWNTO 0);
--! Avalon write data to selected register
106 read_data :
OUT (
31 DOWNTO 0);
--! Avalon read data from selected register
107 irq :
OUT ;
--! Avalon IRQ line
108 greenleds :
OUT (
7 DOWNTO 0);
--! external: green leds
109 redleds :
OUT (
7 DOWNTO 0);
--! external: red leds
110 run :
OUT ;
--! enable signal for mcu
111 direction :
OUT ;
--! direction signal for mcu
112 mode :
OUT (
3 DOWNTO 0);
--! output of mode bits for mcu
113 speed :
OUT (
2 DOWNTO 0);
--! output of `speedReg` for mcu
114 steps :
IN (
31 DOWNTO 0);
--! input for `stepsReg` for mcu
115 ir :
IN --! input request of mcu
122 clock :
IN ;
--! component clock
123 reset_n :
IN ;
--! resets the component
124 run :
IN ;
--! chip enable
125 direction :
IN ;
--! motor direction (`0` is left)
126 mode :
IN (
3 DOWNTO 0);
--! mode to run motor with
127 speed :
IN (
2 DOWNTO 0);
--! speed to run moter with
128 motor_pwm :
OUT (
3 DOWNTO 0);
--! pwm signalto control motor
129 motor_en :
OUT (
1 DOWNTO 0);
--! enables motor driver
130 steps :
OUT (
31 DOWNTO 0);
--! number of steps motor did
131 ir :
OUT --! IR signal set when motor stopped
136 SIGNAL write_n_wire : ;
137 SIGNAL addr_wire : (2 DOWNTO 0);
138 SIGNAL write_data_wire: (31 DOWNTO 0);
140 SIGNAL direction_wire : ;
141 SIGNAL mode_wire : (3 DOWNTO 0);
142 SIGNAL speed_wire : (2 DOWNTO 0);
143 SIGNAL steps_wire : (31 DOWNTO 0);
145 SIGNAL read_n_wire : ;
146 SIGNAL read_data_wire : (31 DOWNTO 0);
148 SIGNAL motor_pwm_wire : (3 DOWNTO 0);
149 SIGNAL motor_en_wire : (1 DOWNTO 0);
177 -- greenleds => LEDG,
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);
207 LEDG(5 DOWNTO 4) <= motor_en_wire;
in ce_nSTD_LOGIC
Avalon chip enable.
out HSMC_RX_PSTD_LOGIC_VECTOR(16 DOWNTO0)
Motor_pwm1( bit 0 ) and Motor_pwm2( bit 1 )
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.
Register Interface-Component.
out LEDRSTD_LOGIC_VECTOR(7 DOWNTO0)
red leds
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
dividerinteger:=125000
Prescaler for PWM-signal.
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
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
out irqSTD_LOGIC
Avalon IRQ line.
in SWSTD_LOGIC_VECTOR(9 DOWNTO0)
switch input
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 )
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
out HSMC_TX_NSTD_LOGIC_VECTOR(16 DOWNTO0)
Motor_en_a( bit 2 )
in KEYSTD_LOGIC_VECTOR(3 DOWNTO0)
key input
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 )
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