Stepper-Motor-Control  v3.0.0
System on a Chip 2014 - Group 04
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
motor_control_unit.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 --! @file motor_control_unit.vhd
3 --! @author Marc Kossmann
4 --! @author Michael Riedel
5 --! @version v1.0.0
6 --! @date 05.12.2014
7 --!
8 --! @brief Motor Control Unit
9 --! @details Controls the stepper motor. Communication with NIOS-Processor
10 --! is done via register_interface component.
11 --! @details Following signals are provided by register_interface:
12 --! |name |width|access| description |
13 --! |---------|-----|------|--------------------------|
14 --! |run | 1 | read | enables mcu |
15 --! |direction| 1 | read | motor dir ('0' is left) |
16 --! |IR | 1 | write| set when motor stopped |
17 --! |mode | 4 | read | use case |
18 --! |speed | 3 | read | speed of motor |
19 --! |steps | 32 | write| number of steps motor did|
20 --! |---------|-----|------|--------------------------|
21 --! @par History:
22 --! @details v0.1.0 23.11.2014 Kossmann
23 --! - first draft
24 --! @details v0.1.1 24.11.2014 Riedel
25 --! - corrected formatting
26 --! - renamed component count_5ms to counter
27 --! @details v0.1.2 27.11.2014 Riedel
28 --! - renamed the input `enable` to `prescaler` in
29 --! `signal_generator` and adapted the wires
30 --! @details v0.1.2 27.11.2014 Riedel
31 --! - added documentation for GENERIC divider
32 --! @details v0.1.3 02.11.2014 Riedel & Kossmann
33 --! - changed divider because pulse width was measure wrong
34 --! @details v1.0.0 05.12.2014 Riedel & Kossmann
35 --! - release milestone 3b
36 -------------------------------------------------------------------------------
37 
38 --! Use Standard Library
39 LIBRARY ieee;
40 --! Use Logic Elements
41 USE ieee.std_logic_1164.all;
42 
43 --! @brief Motor Control Unit
45  GENERIC
46  (
47  --! @brief Prescaler for PWM-signal.
48  --! @details For this purpose 2,5 ms are used as minimal pulse-width.
49  --! @details The prescaler is calculated with the given and desired frequency
50  --! via the following formula:
51  --! \f{equation*}{
52  --! \text{prescaler} = \frac{f_{\text{clock}} \text{Hz}}{f_{\text{prescaler}} \text{Hz}}
53  --! \f}
54  --! e.g.:
55  --! \f{equation*}{
56  --! \left.\begin{aligned}
57  --! f_{\text{prescaler}} &= \frac{5}{2}\,\text{ms} \newline
58  --! &= 400\,\text{Hz} \newline\newline
59  --! \text{prescaler} &= \frac{50\,\text{Mhz}}{400\,\text{Hz}} \newline
60  --! &= 125000 \newline
61  --! \end{aligned}
62  --! \right\}
63  --! \qquad \text{pulse-width: 2.5 ms}
64  --! \f}
65  --! @details For simulation-purpose the divider was set to 125 for faster wave generation.
66  divider : integer := 125000
67  );
68  PORT(
69  clock : IN STD_LOGIC; --! component clock
70  reset_n : IN STD_LOGIC; --! resets the component
71  run : IN STD_LOGIC; --! chip enable
72  direction : IN STD_LOGIC; --! motor direction ('0' is left)
73  mode : IN STD_LOGIC_VECTOR (3 DOWNTO 0); --! mode to run motor with
74  speed : IN STD_LOGIC_VECTOR (2 DOWNTO 0); --! speed to run moter with
75  motor_pwm : OUT STD_LOGIC_VECTOR(3 DOWNTO 0); --! signal-bus for the motor pulse-width-modulation
76  motor_en : OUT STD_LOGIC_VECTOR(1 DOWNTO 0); --! both enable signals for the motor
77  steps : OUT STD_LOGIC_VECTOR (31 DOWNTO 0); --! number of steps motor did
78  ir : OUT STD_LOGIC --! IR signal set when motor stopped
79  );
80 end motor_control_unit;
81 
82 --! @brief Architecture of motor control unit
83 --! @details used components:
84 --! - counter that counts 5 ms
85 --! - signal_generator
86 architecture my_motor_control_unit of motor_control_unit is
87 
88 COMPONENT counter is
89  GENERIC ( divider : integer );
90  PORT
91  (
92  clock : IN STD_LOGIC;
93  reset_n : IN STD_LOGIC;
94  enable : IN STD_LOGIC;
95  clk_out : OUT STD_LOGIC
96  );
97 end COMPONENT;
98 
99 COMPONENT signal_generator is
100  PORT
101  (
102  clock : IN STD_LOGIC;
103  run : IN STD_LOGIC;
104  prescaler : IN STD_LOGIC;
105  reset_n : IN STD_LOGIC;
106  mode : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
107  speed : IN STD_LOGIC_VECTOR(2 DOWNTO 0);
108  direction : IN STD_LOGIC;
109  ir : OUT STD_LOGIC;
110  steps : OUT STD_LOGIC_VECTOR(31 DOWNTO 0);
111  motor_pwm : OUT STD_LOGIC_VECTOR(3 DOWNTO 0);
112  motor_en : OUT STD_LOGIC_VECTOR(1 DOWNTO 0)
113  );
114 end COMPONENT;
115 
116  SIGNAL prescaler_wire : std_logic;
117 
118 BEGIN
119 
120  prescaler_inst : COMPONENT counter
121  GENERIC MAP ( divider => divider )
122  PORT MAP
123  (
124  clock => clock,
125  reset_n => reset_n,
126  enable => run,
127  clk_out => prescaler_wire
128  );
129 
130  signal_generator_inst : COMPONENT signal_generator
131  PORT MAP
132  (
133  clock => clock,
134  run => run,
135  prescaler => prescaler_wire,
136  reset_n => reset_n,
137  mode => mode,
138  speed => speed,
139  direction => direction,
140  ir => ir,
141  steps => steps,
142  motor_pwm => motor_pwm,
143  motor_en => motor_en
144  );
145 
146 end my_motor_control_unit;
in speedSTD_LOGIC_VECTOR(2 DOWNTO0)
speed to run moter with
in modeSTD_LOGIC_VECTOR(3 DOWNTO0)
mode to run motor with
in reset_nSTD_LOGIC
resets the component
in modeSTD_LOGIC_VECTOR(3 DOWNTO0)
mode to run motor with
out motor_enSTD_LOGIC_VECTOR(1 DOWNTO0)
both enable signals for the motor
in clockSTD_LOGIC
component clock
out irSTD_LOGIC
IR signal set when motor stopped.
out motor_pwmSTD_LOGIC_VECTOR(3 DOWNTO0)
signal-bus for the motor pulse-width-modulation
out motor_enSTD_LOGIC_VECTOR(1 DOWNTO0)
both enable signals for the motor
in clockSTD_LOGIC
component clock
in runSTD_LOGIC
run or stop the signal_generator
in enableSTD_LOGIC
enables component
Definition: counter.vhd:57
in reset_nSTD_LOGIC
global reset
Definition: counter.vhd:56
out stepsSTD_LOGIC_VECTOR(31 DOWNTO0)
number of steps motor did
dividerinteger:=125000
Prescaler for PWM-signal.
in prescalerSTD_LOGIC
input for minimum time-base
in directionSTD_LOGIC
motor direction ('0' is left)
_library_ ieeeieee
Use Standard Library.
in reset_nSTD_LOGIC
resets the component
out clk_outSTD_LOGIC
divided clock output
Definition: counter.vhd:59
Motor Control Unit.
Counter-Component.
Definition: counter.vhd:29
in runSTD_LOGIC
chip enable
in clockSTD_LOGIC
input clock
Definition: counter.vhd:55
out irSTD_LOGIC
IR signal set when motor stopped.
dividerINTEGER
Prescaler for PWM-signal.
Definition: counter.vhd:52
in directionSTD_LOGIC
motor direction ('0' is LEFT)
out motor_pwmSTD_LOGIC_VECTOR(3 DOWNTO0)
signal-bus for the motor pulse-width-modulation
Signal Generator.
in speedSTD_LOGIC_VECTOR(2 DOWNTO0)
speed to run moter with
out stepsSTD_LOGIC_VECTOR(31 DOWNTO0)
number of steps motor did