Motion FPGA
Motion FPGA for the MachX02-7000HE Breakout Board
top.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 --! @file
3 --! @brief MotionFpga top-level 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 MachX02 library
13 LIBRARY machxo2;
14 
15 --! Using MachX02 library components (for oscj)
16 USE machxo2.ALL;
17 
18 --! @brief MotionFpga top-level entity
19 ENTITY top IS
20  GENERIC (
21  version : std_logic_vector(31 DOWNTO 0) := X"00000000" --! Version number
22  );
23  PORT (
24  rst_in : IN std_logic; --! FPGA reset input line
25  spi_cs_in : IN std_logic; --! SPI chip-select input line
26  spi_sclk_in : IN std_logic; --! SPI clock input line
27  spi_mosi_in : IN std_logic; --! SPI MOSI input line
28  spi_miso_out : OUT std_logic; --! SPI MISO output line
29  spi_ver_en_in : IN std_logic; --! SPI Version Enable input line
30  led_out : OUT std_logic_vector(7 DOWNTO 0) --! LED outputs
31  );
32 END ENTITY top;
33 
34 --! Architecture rtl of top entity
35 ARCHITECTURE rtl OF top IS
36 
37  SIGNAL osc : std_logic; --! Internal oscillator (11.08MHz)
38  SIGNAL lock : std_logic; --! PLL Lock
39  SIGNAL clk : std_logic; --! Main clock (99.72MHz)
40  SIGNAL rst_ms : std_logic; --! Reset (possibly metastable)
41  SIGNAL rst : std_logic; --! Reset
42  SIGNAL spi_cs_ms : std_logic; --! SPI chip-select input (metastable)
43  SIGNAL spi_sclk_ms : std_logic; --! SPI clock input (metastable)
44  SIGNAL spi_mosi_ms : std_logic; --! SPI MOSI input (metastable)
45  SIGNAL spi_ver_en_ms : std_logic; --! SPI Version Enable (metastable)
46  SIGNAL spi_cs_s : std_logic; --! SPI chip-select input (stable)
47  SIGNAL spi_sclk_s : std_logic; --! SPI clock input (stable)
48  SIGNAL spi_mosi_s : std_logic; --! SPI MOSI input (stable)
49  SIGNAL spi_ver_en_s : std_logic; --! SPI Version Enable input (stable)
50  SIGNAL pwm_adv : std_logic; --! PWM advance signal
51 
52  -- SPI slave output signals
53  SIGNAL spi_miso_out_device : std_logic; --! SPI MISO output for devices
54  SIGNAL spi_miso_out_version : std_logic; --! SPI MISO output for version
55 
56  -- SPI slave signals
57  SIGNAL dat_rd_reg : std_logic_vector(95 DOWNTO 0); --! SPI read data (response)
58  SIGNAL dat_wr_reg : std_logic_vector(95 DOWNTO 0); --! SPI write data (command)
59  SIGNAL dat_wr_done : std_logic; --! SPI write done pulse
60 
61  -- PWM lines
62  SIGNAL pwm_lines : std_logic_vector(3 DOWNTO 0); --! PWM outputs
63 
64  -- SDM lines
65  SIGNAL sdm_lines : std_logic_vector(3 DOWNTO 0); --! SDM outputs
66 
67  -- GPIO lines
68  SIGNAL gpio_in_lines : std_logic_vector(31 DOWNTO 0); --! GPIO inputs
69  SIGNAL gpio_out_lines : std_logic_vector(31 DOWNTO 0); --! GPIO outputs
70 
71  --! Component declaration for the MachX02 internal oscillator
72  COMPONENT osch IS
73  GENERIC (
74  nom_freq : string := "11.08"
75  );
76  PORT (
77  stdby : IN std_logic;
78  osc : OUT std_logic;
79  sedstdby : OUT std_logic
80  );
81  END COMPONENT osch;
82 
83  --! Component delcaration for the PLL
84  COMPONENT pll IS
85  PORT (
86  clki : IN std_logic;
87  clkop : OUT std_logic;
88  lock : OUT std_logic
89  );
90  END COMPONENT pll;
91 
92 BEGIN
93 
94  --! Instantiate the internal oscillator for 11.08MHz
95  i_osch : osch
96  GENERIC MAP (
97  nom_freq => "11.08"
98  )
99  PORT MAP (
100  stdby => '0',
101  osc => osc,
102  sedstdby => OPEN
103  );
104 
105  --! Instantiate the PLL (11.08MHz -> 99.72MHz)
106  i_pll : pll
107  PORT MAP (
108  clki => osc,
109  clkop => clk,
110  lock => lock
111  );
112 
113  --! Instantiate the clock divider for PWM advance
114  i_pwm_clk : ENTITY work.clk_div_n
115  GENERIC MAP (
116  clk_div => 4
117  )
118  PORT MAP (
119  clk_in => clk,
120  rst_in => rst,
121  div_clr_in => '0',
122  div_adv_in => '1',
123  div_end_out => OPEN,
125  );
126 
127  --! Instantiate SPI slave device bus
128  i_spi_slave_device : ENTITY work.spi_slave
129  GENERIC MAP (
130  size => 96
131  )
132  PORT MAP (
133  clk_in => clk,
134  rst_in => rst,
135  spi_cs_in => spi_cs_s,
142  );
143 
144  --! Instantiate SPI slave version bus
145  i_spi_slave_version : ENTITY work.spi_slave
146  GENERIC MAP (
147  size => 32
148  )
149  PORT MAP (
150  clk_in => clk,
151  rst_in => rst,
152  spi_cs_in => spi_cs_s,
154  spi_mosi_in => '0',
157  dat_wr_reg_out => OPEN,
158  dat_wr_done_out => OPEN
159  );
160 
161  --! Instantiate the PWM device
162  i_pwm_device : ENTITY work.pwm_device
163  PORT MAP (
164  clk_in => clk,
165  rst_in => rst,
167  dat_wr_reg_in => dat_wr_reg(31 DOWNTO 0),
168  dat_rd_reg_out => dat_rd_reg(31 DOWNTO 0),
169  pwm_adv_in => pwm_adv,
170  pwm_out => pwm_lines
171  );
172 
173  --! Instantiate the PWM device
174  i_sdm_device : ENTITY work.sdm_device
175  PORT MAP (
176  clk_in => clk,
177  rst_in => rst,
179  dat_wr_reg_in => dat_wr_reg(63 DOWNTO 32),
180  dat_rd_reg_out => dat_rd_reg(63 DOWNTO 32),
181  sdm_out => sdm_lines
182  );
183 
184  --! Instantiate the GPIO device
185  i_gpio_device : ENTITY work.gpio_device
186  PORT MAP (
187  clk_in => clk,
188  rst_in => rst,
190  dat_wr_reg_in => dat_wr_reg(95 DOWNTO 64),
191  dat_rd_reg_out => dat_rd_reg(95 DOWNTO 64),
194  );
195 
196  --! @brief Reset process
197  --!
198  --! This process provides a synchronous reset signal where possible. Before
199  --! the PLL has locked, it asserts reset; and after the PLL has locked it
200  --! uses the resynchronized reset input pin.
201  pr_reset : PROCESS (clk, lock) IS
202  BEGIN
203 
204  IF (lock = '0') THEN
205  rst_ms <= '1';
206  rst <= '1';
207  ELSIF (rising_edge(clk)) THEN
208  rst_ms <= rst_in;
209  rst <= rst_ms;
210  END IF;
211 
212  END PROCESS pr_reset;
213 
214  --! @brief SPI input double-flop resynchronizer
215  --!
216  --! This process double-flops the SPI inputs to resolve metastability and
217  --! ensure the signals are stable for SPI processing
218  pr_spi_input : PROCESS (clk, rst) IS
219  BEGIN
220 
221  IF (rst = '1') THEN
222  spi_cs_ms <= '0';
223  spi_sclk_ms <= '0';
224  spi_mosi_ms <= '0';
225  spi_ver_en_ms <= '0';
226  spi_cs_s <= '0';
227  spi_sclk_s <= '0';
228  spi_mosi_s <= '0';
229  spi_ver_en_s <= '0';
230  ELSIF (rising_edge(clk)) THEN
231  spi_cs_ms <= spi_cs_in;
235  spi_cs_s <= spi_cs_ms;
239  END IF;
240 
241  END PROCESS pr_spi_input;
242 
243  -- Output the version (if enabled) or the device
246 
247  led_out(7) <= pwm_lines(0);
248  led_out(6) <= pwm_lines(1);
249  led_out(5) <= sdm_lines(0);
250  led_out(4) <= sdm_lines(1);
251  led_out(3) <= gpio_out_lines(3);
252  led_out(2) <= gpio_out_lines(2);
253  led_out(1) <= gpio_out_lines(1);
254  led_out(0) <= gpio_out_lines(0);
255 
256  gpio_in_lines(31) <= gpio_out_lines(31);
257  gpio_in_lines(30) <= gpio_out_lines(30);
258  gpio_in_lines(29 DOWNTO 0) <= (OTHERS => '0');
259 
260 END ARCHITECTURE rtl;
std_logic rst
Reset.
Definition: top.vhd:41
out led_outstd_logic_vector( 7 DOWNTO 0)
LED outputs.
Definition: top.vhd:31
out div_pls_outstd_logic
Divider pulse flag.
Definition: clk_div_n.vhd:30
in clk_instd_logic
Clock.
Definition: pwm_device.vhd:24
in spi_sclk_instd_logic
SPI clock input line.
Definition: top.vhd:26
std_logic spi_miso_out_device
SPI MISO output for devices.
Definition: top.vhd:53
in rst_instd_logic
Asynchronous reset.
Definition: pwm_device.vhd:25
pll i_plli_pll
Instantiate the PLL (11.08MHz -> 99.72MHz)
Definition: top.vhd:111
in spi_ver_en_instd_logic
SPI Version Enable input line.
Definition: top.vhd:29
out dat_rd_reg_outstd_logic_vector( 31 DOWNTO 0)
Device Read Register value.
Definition: gpio_device.vhd:18
MotionFpga top-level entity.
Definition: top.vhd:19
in spi_mosi_instd_logic
SPI MOSI.
Definition: spi_slave.vhd:34
std_logic_vector( 31 DOWNTO 0) gpio_out_lines
GPIO outputs.
Definition: top.vhd:69
out div_end_outstd_logic
Divider end flag.
Definition: clk_div_n.vhd:28
osch
Component declaration for the MachX02 internal oscillator.
Definition: top.vhd:72
osch i_oschi_osch
Instantiate the internal oscillator for 11.08MHz.
Definition: top.vhd:103
std_logic spi_mosi_ms
SPI MOSI input (metastable)
Definition: top.vhd:44
std_logic spi_ver_en_s
SPI Version Enable input (stable)
Definition: top.vhd:49
in dat_wr_reg_instd_logic_vector( 31 DOWNTO 0)
Device Write Register value.
Definition: pwm_device.vhd:27
in clk_instd_logic
Clock.
Definition: gpio_device.vhd:14
out gpio_bus_outstd_logic_vector( 31 DOWNTO 0)
GPIO outputs.
Definition: gpio_device.vhd:21
in clk_instd_logic
Clock.
Definition: clk_div_n.vhd:24
in rst_instd_logic
Asynchronous reset.
Definition: gpio_device.vhd:15
std_logic dat_wr_done
SPI write done pulse.
Definition: top.vhd:59
out spi_miso_outstd_logic
SPI MISO.
Definition: spi_slave.vhd:35
std_logic spi_cs_ms
SPI chip-select input (metastable)
Definition: top.vhd:42
in clk_instd_logic
Clock.
Definition: spi_slave.vhd:30
out spi_miso_outstd_logic
SPI MISO output line.
Definition: top.vhd:28
std_logic spi_sclk_ms
SPI clock input (metastable)
Definition: top.vhd:43
std_logic pwm_adv
PWM advance signal.
Definition: top.vhd:50
in clk_instd_logic
Clock.
Definition: sdm_device.vhd:22
out dat_rd_reg_outstd_logic_vector( 31 DOWNTO 0)
Device Read Register value.
Definition: pwm_device.vhd:28
in dat_wr_done_instd_logic
Device Write Done flag.
Definition: gpio_device.vhd:16
in dat_wr_done_instd_logic
Device Write Done flag.
Definition: sdm_device.vhd:24
in spi_sclk_instd_logic
SPI Clock.
Definition: spi_slave.vhd:33
in dat_rd_reg_instd_logic_vector( size- 1 DOWNTO 0)
Data Read Register value.
Definition: spi_slave.vhd:36
versionstd_logic_vector( 31 DOWNTO 0) := X"00000000"
Version number.
Definition: top.vhd:22
SPI Slave module.
Definition: spi_slave.vhd:25
in spi_mosi_instd_logic
SPI MOSI input line.
Definition: top.vhd:27
in pwm_adv_instd_logic
PWM Advance flag.
Definition: pwm_device.vhd:29
std_logic_vector( 3 DOWNTO 0) sdm_lines
SDM outputs.
Definition: top.vhd:65
out sdm_outstd_logic_vector( 3 DOWNTO 0)
Modulator outputs.
Definition: sdm_device.vhd:28
in div_adv_instd_logic
Divider advance flag.
Definition: clk_div_n.vhd:27
clk_divinteger range 2 TO integer'high:= 4
Divider amount.
Definition: clk_div_n.vhd:22
std_logic spi_sclk_s
SPI clock input (stable)
Definition: top.vhd:47
in spi_cs_instd_logic
SPI chip-select input line.
Definition: top.vhd:25
std_logic spi_miso_out_version
SPI MISO output for version.
Definition: top.vhd:54
sizenatural range 1 TO natural'high
Size of the SPI data.
Definition: spi_slave.vhd:28
std_logic_vector( 95 DOWNTO 0) dat_wr_reg
SPI write data (command)
Definition: top.vhd:58
in div_clr_instd_logic
Divider clear flag.
Definition: clk_div_n.vhd:26
std_logic_vector( 3 DOWNTO 0) pwm_lines
PWM outputs.
Definition: top.vhd:62
out dat_wr_done_outstd_logic
Data Write Done flag.
Definition: spi_slave.vhd:39
pll
Component delcaration for the PLL.
Definition: top.vhd:84
in rst_instd_logic
Asynchronous reset.
Definition: sdm_device.vhd:23
std_logic lock
PLL Lock.
Definition: top.vhd:38
in dat_wr_reg_instd_logic_vector( 31 DOWNTO 0)
Device Write Register value.
Definition: gpio_device.vhd:17
std_logic osc
Internal oscillator (11.08MHz)
Definition: top.vhd:37
in rst_instd_logic
Asynchronous reset.
Definition: spi_slave.vhd:31
Clock divider entity.
Definition: clk_div_n.vhd:19
std_logic spi_mosi_s
SPI MOSI input (stable)
Definition: top.vhd:48
in rst_instd_logic
FPGA reset input line.
Definition: top.vhd:24
Sigma-Delta modulator device entity.
Definition: sdm_device.vhd:20
std_logic spi_ver_en_ms
SPI Version Enable (metastable)
Definition: top.vhd:45
in gpio_bus_instd_logic_vector( 31 DOWNTO 0)
GPIO inputs.
Definition: gpio_device.vhd:19
std_logic rst_ms
Reset (possibly metastable)
Definition: top.vhd:40
std_logic_vector( 31 DOWNTO 0) gpio_in_lines
GPIO inputs.
Definition: top.vhd:68
std_logic spi_cs_s
SPI chip-select input (stable)
Definition: top.vhd:46
in spi_cs_instd_logic
SPI Chip-select.
Definition: spi_slave.vhd:32
_library_ ieeeieee
Using IEEE library.
PWM device entity.
Definition: pwm_device.vhd:22
std_logic clk
Main clock (99.72MHz)
Definition: top.vhd:39
in dat_wr_reg_instd_logic_vector( 31 DOWNTO 0)
Device Write Register value.
Definition: sdm_device.vhd:25
out pwm_outstd_logic_vector( 3 DOWNTO 0)
PWM outputs.
Definition: pwm_device.vhd:31
std_logic_vector( 95 DOWNTO 0) dat_rd_reg
SPI read data (response)
Definition: top.vhd:57
in rst_instd_logic
Asynchronous reset.
Definition: clk_div_n.vhd:25
in dat_wr_done_instd_logic
Device Write Done flag.
Definition: pwm_device.vhd:26
out dat_wr_reg_outstd_logic_vector( size- 1 DOWNTO 0)
Data Write Register value.
Definition: spi_slave.vhd:37
out dat_rd_reg_outstd_logic_vector( 31 DOWNTO 0)
Device Read Register value.
Definition: sdm_device.vhd:26