Motion FPGA
Motion FPGA for the MachX02-7000HE Breakout Board
step_generator.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 --! @file
3 --! @brief Step Generator module
4 -------------------------------------------------------------------------------
5 
6 --! Using IEEE library
7 LIBRARY ieee;
8 
9 --! Using IEEE standard logic components
10 USE ieee.std_logic_1164.ALL;
11 
12 --! Using IEE standard numeric components
13 USE ieee.numeric_std.ALL;
14 
15 --! @brief Step Generator entity
16 --!
17 --! This step-generator entity produces a number of step-pulses. This is
18 --! commonly used for devices such as stepper motor driver chips.
19 --!
20 --! When the user asserts the enable_in signal the step-generation begins. The
21 --! user can de-assert enable_in to cancel step-generation.
22 --!
23 --! The advance_in flag should be pulsed at the basic step-generation rate.
24 --! This rate is divided down by the delay_in count to produce the stepping
25 --! rate.
26 ENTITY step_generator IS
27  GENERIC (
28  count_wid : integer RANGE 1 TO integer'high := 4; --! Width of count
29  delay_wid : integer RANGE 1 TO integer'high := 6 --! Width of delay
30  );
31  PORT (
32  clk_in : IN std_logic; --! Clock
33  rst_in : IN std_logic; --! Asynchronous reset
34  enable_in : IN std_logic; --! Generator enable flag
35  advance_in : IN std_logic; --! Advance flag
36  count_in : IN std_logic_vector(count_wid - 1 DOWNTO 0); --! Count of steps
37  delay_in : IN std_logic_vector(delay_wid - 1 DOWNTO 0); --! Delay between steps
38  step_out : OUT std_logic --! Step output
39  );
40 END ENTITY step_generator;
41 
42 --! Architecture rtl of step_generator entity
43 ARCHITECTURE rtl OF step_generator IS
44 
45  --! Current step counter
46  SIGNAL count : unsigned(count_wid - 1 DOWNTO 0);
47 
48  --! Current delay counter
49  SIGNAL delay : unsigned(delay_wid - 1 DOWNTO 0);
50 
51  --! Step state
52  SIGNAL step : std_logic;
53 
54 BEGIN
55 
56  --! @brief Process to generate steps
57  pr_step : PROCESS (clk_in, rst_in) IS
58  BEGIN
59 
60  IF (rst_in = '1') THEN
61  -- Reset
62  count <= (OTHERS => '0');
63  delay <= (OTHERS => '0');
64  step <= '0';
65  ELSIF (rising_edge(clk_in)) THEN
66  IF (enable_in = '0') THEN
67  -- Reset (disabled)
68  count <= (OTHERS => '0');
69  delay <= (OTHERS => '0');
70  step <= '0';
71  ELSIF (advance_in = '1') THEN
72  -- Check for step-generator delay
73  IF (delay = 0) THEN
74  -- Delay expired, reset
75  delay <= unsigned(delay_in);
76 
77  -- Check for more steps to generate
78  IF (count /= unsigned(count_in)) THEN
79  -- Check for end of step ('1' going to '0')
80  IF (step = '1') THEN
81  -- Advance step count
82  count <= count + 1;
83  END IF;
84 
85  -- Toggle step-line
86  step <= NOT step;
87  END IF;
88  ELSE
89  -- More delay
90  delay <= delay - 1;
91  END IF;
92  END IF;
93  END IF;
94 
95  END PROCESS pr_step;
96 
97  -- Output step signal
98  step_out <= step;
99 
100 END ARCHITECTURE rtl;
out step_outstd_logic
Step output.
in clk_instd_logic
Clock.
unsigned( delay_wid- 1 DOWNTO 0) delay
Current delay counter.
count_widinteger range 1 TO integer'high:= 4
Width of count.
in rst_instd_logic
Asynchronous reset.
in count_instd_logic_vector( count_wid- 1 DOWNTO 0)
Count of steps.
in delay_instd_logic_vector( delay_wid- 1 DOWNTO 0)
Delay between steps.
in advance_instd_logic
Advance flag.
unsigned( count_wid- 1 DOWNTO 0) count
Current step counter.
in enable_instd_logic
Generator enable flag.
std_logic step
Step state.
delay_widinteger range 1 TO integer'high:= 6
Width of delay.
_library_ ieeeieee
Drive quadrature output.
Definition: sdm.vhd:7
Step Generator entity.