2 use ieee.std_logic_1164.all;
3 use ieee.std_logic_arith.all;
4 use ieee.std_logic_unsigned.all;
7 use unisim.vcomponents.all;
9 --------------------------------------------------------------------------------
14 CLK_24MHz : in std_logic;
25 PWM0_EN : out std_logic;
27 PWM1_EN : out std_logic;
29 PWM2_EN : out std_logic;
31 IRC_INDEX : in std_logic;
40 --------------------------------------------------------------------------------
42 architecture rtl of msp_motion is
44 signal reset_p : std_logic;
46 ------------------------------------------------------------------------------
47 -- OpenMSP430 softcore MCU module
48 ------------------------------------------------------------------------------
49 signal mclk : std_logic;
50 signal puc : std_logic;
52 signal dmem_addr : std_logic_vector (11 downto 0);
53 signal dmem_ce : std_logic;
54 signal dmem_we : std_logic;
55 signal dmem_din : std_logic_vector (15 downto 0);
56 signal dmem_dout : std_logic_vector (15 downto 0);
58 signal per_din : std_logic_vector (15 downto 0);
59 signal per_dout : std_logic_Vector (15 downto 0);
60 signal per_wen : std_logic_vector (1 downto 0);
61 signal per_wen16 : std_logic;
62 signal per_en : std_logic;
63 signal per_addr : std_logic_vector (7 downto 0);
65 signal irq : std_logic_vector (13 downto 0);
66 signal irq_acc : std_logic_vector (13 downto 0);
68 ------------------------------------------------------------------------------
70 ------------------------------------------------------------------------------
72 signal GPIO_IN : std_logic_vector (15 downto 0);
73 signal GPIO_OUT : std_logic_vector (15 downto 0);
74 signal GPIO_DAT_O : std_logic_vector (15 downto 0);
75 signal GPIO_SEL : std_logic;
76 -- Qcounter MCU interface
77 signal QCNT_DAT_O : std_logic_vector (15 downto 0);
78 signal QCNT_SEL : std_logic;
79 -- Motor feedback IRQ generator
80 signal MOTOR_IRQ : std_logic;
82 ------------------------------------------------------------------------------
83 -- Dual-port shared memory
84 ------------------------------------------------------------------------------
85 -- These signals of A-port (MCU) enables creation of external data encoder and
86 -- multiplexer in a case of multiple devices connected to the external data
87 -- bus. Otherwise useless.
88 signal DPA_DAT_O : std_logic_vector (15 downto 0);
89 signal DPA_SEL : std_logic;
90 signal DPA_STB : std_logic;
91 -- Auxiliary register used to generate IRF_ACK
92 signal IRF_ACK_REG : std_logic;
93 -- Auxiliary signal used to form B-port address
94 signal DPB_ADR : std_logic_vector (9 downto 0);
96 ------------------------------------------------------------------------------
97 -- Motion Control Chain
98 ------------------------------------------------------------------------------
100 constant PWM_W : integer := 10;
101 constant LUT_ADR_W : integer := 11;
102 constant LUT_INIT : string := "sin1000.lut";
104 -- Bus interface to the shared memory
105 signal IRF_ACK : std_logic;
106 signal IRF_ADR : std_logic_vector (4 downto 0);
107 signal IRF_DAT_I : std_logic_vector (15 downto 0);
108 signal IRF_DAT_O : std_logic_vector (15 downto 0);
109 signal IRF_STB : std_logic;
110 signal IRF_WE : std_logic;
111 -- Wave look-up table
112 signal LUT_ADR : std_logic_vector (LUT_ADR_W-1 downto 0);
113 signal LUT_DAT_O : std_logic_vector (PWM_W-1 downto 0);
114 signal LUT_STB : std_logic;
115 -- MCC execution control
116 signal MCC_ACK : std_logic;
117 signal MCC_STB : std_logic;
119 ------------------------------------------------------------------------------
121 ------------------------------------------------------------------------------
122 signal PWM_CNT : std_logic_vector (PWM_W-1 downto 0);
123 signal PWM_OW : std_logic; -- PWM counter overflow
124 -- PWM interface to the MCC
125 signal PWM_DAT : std_logic_vector (PWM_W-1 downto 0);
126 signal PWM1_STB : std_logic;
127 signal PWM2_STB : std_logic;
128 signal PWM3_STB : std_logic;
130 signal PWM1_OUT : std_logic;
131 signal PWM2_OUT : std_logic;
132 signal PWM3_OUT : std_logic;
134 signal QCNT : std_logic_vector (31 downto 0);
136 --------------------------------------------------------------------------------
140 ------------------------------------------------------------------------------
141 -- OpenMSP430 softcore MCU module
142 ------------------------------------------------------------------------------
143 openMSP430_1 : entity work.openMSP430_8_32_mul_dbus
145 dco_clk => CLK_24MHz,
150 per_addr => per_addr,
152 per_dout => per_dout,
162 dmem_addr => dmem_addr,
165 dmem_din => dmem_din,
166 dmem_dout => dmem_dout);
169 reset_p <= not RESET;
171 STARTUP_VIRTEX2_inst : STARTUP_VIRTEX2
174 -- Clock input for start-up sequence
175 GSR => reset_p, -- Global Set/Reset input (GSR cannot be used for the port name)
176 GTS => open); -- Global 3-state input (GTS cannot be used for the port name)
179 -- External data bus address decoder and data multiplexer.
180 ------------------------------------------------------------------------------
181 -- When connection more memories, be aware that 'dmem_dout' can vary only when
182 -- reading cycle is performed. I.e. mux variable must be registered.
183 dmem_dout <= DPA_DAT_O;
185 DPA_SEL <= '1' when dmem_addr (11 downto 10) = "00" else '0';
186 DPA_STB <= dmem_ce and DPA_SEL;
188 -- Peripheral bus address decoder and data multiplexer.
189 ------------------------------------------------------------------------------
190 per_dout <= GPIO_DAT_O when GPIO_SEL = '1' else
191 QCNT_DAT_O when QCNT_SEL = '1' else
192 (others => '0'); -- MUST be 0 when nothing is addressed
194 GPIO_SEL <= '1' when per_addr(7 downto 2) = 16#0140#/2/4 else '0';
195 QCNT_SEL <= '1' when per_addr(7 downto 1) = 16#0148#/2/2 else '0';
198 ------------------------------------------------------------------------------
199 irq (13 downto 1) <= (others => '0');
201 motor_irq_ff : process (mclk, puc) is
203 if rising_edge (mclk) then
204 if puc = '1' or irq_acc (0) = '1' then
206 elsif MOTOR_IRQ = '1' then
213 ------------------------------------------------------------------------------
215 ------------------------------------------------------------------------------
219 GPIO_IN(3) <= IRC_INDEX;
221 gpio_0 : entity work.gpio
226 ADR_I => per_addr (1 downto 0),
237 qcounter_mcu16_0 : entity work.qcounter_mcu16
240 ADR_I => per_addr (0),
247 -- Motor feedback IRQ generator
248 -- f_motor_irq approx. 1 kHz
249 mcc_irq_counter_1 : entity work.counter
258 event_ow => MOTOR_IRQ);
261 ------------------------------------------------------------------------------
262 -- Dual-port shared memory
263 ------------------------------------------------------------------------------
264 -- Shared memory between MCU and MCC (size: 16+2 bits x 1k).
265 -- Port A (MCU side) has a priority of writing.
266 shared_mem : RAMB16_S18_S18
268 WRITE_MODE_A => "READ_FIRST",
269 WRITE_MODE_B => "WRITE_FIRST")
272 ADDRA => dmem_addr (9 downto 0),
292 -- B-Port address (10 bits) constructed from IRF_ADR (5 bits). Upper addr bits
293 -- are forced to '0', but in a case of several axes these can be used to
294 -- address memory space of the appropriate one.
295 DPB_ADR (9 downto 5) <= (others => '0');
296 DPB_ADR (4 downto 0) <= IRF_ADR;
298 -- Generation of IRF acknowledge signal for MCC.
299 IRF_ACK <= IRF_STB and (IRF_WE or IRF_ACK_REG);
301 -- IRF_ACK_REG signalizes that data is present on IRF_DAT_O when reading.
302 irf_read : process (mclk, puc) is
304 if rising_edge(mclk) then
308 IRF_ACK_REG <= IRF_STB and not IRF_WE;
314 ------------------------------------------------------------------------------
315 -- Motion Control Chain
316 ------------------------------------------------------------------------------
317 mcc_exec_1 : entity work.mcc_exec
322 MCC_EXEC_I => PWM_OW,
324 MCC_ACK_I => MCC_ACK,
325 MCC_STB_O => MCC_STB);
327 mcc_1 : entity work.mcc
330 LUT_ADR_W => LUT_ADR_W)
336 LUT_STB_O => LUT_STB,
337 LUT_ADR_O => LUT_ADR,
338 LUT_DAT_I => LUT_DAT_O,
339 IRC_DAT_I => QCNT (15 downto 0),
340 PWM_DAT_O => PWM_DAT,
341 PWM1_STB_O => PWM1_STB,
342 PWM2_STB_O => PWM2_STB,
343 PWM3_STB_O => PWM3_STB,
344 IRF_ACK_I => IRF_ACK,
345 IRF_ADR_O => IRF_ADR,
346 IRF_DAT_I => IRF_DAT_O,
347 IRF_DAT_O => IRF_DAT_I,
348 IRF_STB_O => IRF_STB,
351 wave_table_1 : entity work.wave_table
355 INIT_FILE => LUT_INIT)
360 DAT_I => conv_std_logic_vector(0, PWM_W),
366 ------------------------------------------------------------------------------
368 ------------------------------------------------------------------------------
369 -- PWM counter is shared by all PWM generators. Generator contains only
370 -- comparator and desired value.
371 counter_1 : entity work.counter
382 pwm_1 : entity work.pwm
394 pwm_2 : entity work.pwm
406 pwm_3 : entity work.pwm
418 -- PWM signals mapped to FPGA outputs, EN forced to '1'
425 -- PWM is signalized on LEDs
430 qcounter_1 : entity work.qcounter