1 -------------------------------------------------------------------------------
2 --! @file motor_control_unit.vhd
3 --! @author Marc Kossmann
4 --! @author Michael Riedel
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 --! |---------|-----|------|--------------------------|
22 --! @details v0.1.0 23.11.2014 Kossmann
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 -------------------------------------------------------------------------------
38 --! Use Standard Library
40 --! Use Logic Elements
41 USE ieee.std_logic_1164.
all;
43 --! @brief Motor Control Unit
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:
52 --! \text{prescaler} = \frac{f_{\text{clock}} \text{Hz}}{f_{\text{prescaler}} \text{Hz}}
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
63 --! \qquad \text{pulse-width: 2.5 ms}
65 --! @details For simulation-purpose the divider was set to 125 for faster wave generation.
69 clock : IN ;
--! component clock
71 run : IN ;
--! chip enable
73 mode : IN (3 DOWNTO 0);
--! mode to run motor with
74 speed : IN (2 DOWNTO 0);
--! speed to run moter with
75 motor_pwm : OUT (3 DOWNTO 0);
--! signal-bus for the motor pulse-width-modulation
76 motor_en : OUT (1 DOWNTO 0);
--! both enable signals for the motor
77 steps : OUT (31 DOWNTO 0);
--! number of steps motor did
78 ir : OUT --! IR signal set when motor stopped
80 end motor_control_unit;
82 --! @brief Architecture of motor control unit
83 --! @details used components:
84 --! - counter that counts 5 ms
85 --! - signal_generator
106 mode :
IN (
3 DOWNTO 0);
107 speed :
IN (
2 DOWNTO 0);
110 steps :
OUT (
31 DOWNTO 0);
116 SIGNAL prescaler_wire : ;
120 prescaler_inst :
COMPONENT counter
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
in reset_nSTD_LOGIC
global reset
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
in runSTD_LOGIC
chip enable
in clockSTD_LOGIC
input clock
out irSTD_LOGIC
IR signal set when motor stopped.
dividerINTEGER
Prescaler for PWM-signal.
in directionSTD_LOGIC
motor direction ('0' is LEFT)
out motor_pwmSTD_LOGIC_VECTOR(3 DOWNTO0)
signal-bus for the motor pulse-width-modulation
in speedSTD_LOGIC_VECTOR(2 DOWNTO0)
speed to run moter with
out stepsSTD_LOGIC_VECTOR(31 DOWNTO0)
number of steps motor did