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 ------------------------------------------------------------------------------
45 -- OpenMSP430 softcore MCU module
46 ------------------------------------------------------------------------------
47 signal mclk : std_logic;
48 signal puc : std_logic;
50 signal dmem_addr : std_logic_vector (11 downto 0);
51 signal dmem_ce : std_logic;
52 signal dmem_we : std_logic;
53 signal dmem_din : std_logic_vector (15 downto 0);
54 signal dmem_dout : std_logic_vector (15 downto 0);
56 signal per_din : std_logic_vector (15 downto 0);
57 signal per_dout : std_logic_Vector (15 downto 0);
58 signal per_wen : std_logic_vector (1 downto 0);
59 signal per_wen16 : std_logic;
60 signal per_en : std_logic;
61 signal per_addr : std_logic_vector (7 downto 0);
63 ------------------------------------------------------------------------------
65 ------------------------------------------------------------------------------
67 signal GPIO_IN : std_logic_vector (15 downto 0);
68 signal GPIO_OUT : std_logic_vector (15 downto 0);
69 signal GPIO_DAT_O : std_logic_vector (15 downto 0);
70 signal GPIO_SEL : std_logic;
71 -- Qcounter MCU interface
72 signal QCNT_DAT_O : std_logic_vector (15 downto 0);
73 signal QCNT_SEL : std_logic;
75 ------------------------------------------------------------------------------
76 -- Dual-port shared memory
77 ------------------------------------------------------------------------------
78 -- These signals of A-port (MCU) enables creation of external data encoder and
79 -- multiplexer in a case of multiple devices connected to the external data
80 -- bus. Otherwise useless.
81 signal DPA_DAT_O : std_logic_vector (15 downto 0);
82 signal DPA_SEL : std_logic;
83 signal DPA_STB : std_logic;
84 -- Auxiliary register used to generate IRF_ACK
85 signal IRF_ACK_REG : std_logic;
86 -- Auxiliary signal used to form B-port address
87 signal DPB_ADR : std_logic_vector (9 downto 0);
89 ------------------------------------------------------------------------------
90 -- Motion Control Chain
91 ------------------------------------------------------------------------------
93 constant PWM_W : integer := 10;
94 constant LUT_ADR_W : integer := 11;
95 constant LUT_INIT : string := "sin1000.lut";
97 -- Bus interface to the shared memory
98 signal IRF_ACK : std_logic;
99 signal IRF_ADR : std_logic_vector (4 downto 0);
100 signal IRF_DAT_I : std_logic_vector (15 downto 0);
101 signal IRF_DAT_O : std_logic_vector (15 downto 0);
102 signal IRF_STB : std_logic;
103 signal IRF_WE : std_logic;
104 -- Wave look-up table
105 signal LUT_ADR : std_logic_vector (LUT_ADR_W-1 downto 0);
106 signal LUT_DAT_O : std_logic_vector (PWM_W-1 downto 0);
107 signal LUT_STB : std_logic;
108 -- MCC execution control
109 signal MCC_ACK : std_logic;
110 signal MCC_STB : std_logic;
112 ------------------------------------------------------------------------------
114 ------------------------------------------------------------------------------
115 signal PWM_CNT : std_logic_vector (PWM_W-1 downto 0);
116 signal PWM_OW : std_logic; -- PWM counter overflow
117 -- PWM interface to the MCC
118 signal PWM_DAT : std_logic_vector (PWM_W-1 downto 0);
119 signal PWM1_STB : std_logic;
120 signal PWM2_STB : std_logic;
121 signal PWM3_STB : std_logic;
123 signal PWM1_OUT : std_logic;
124 signal PWM2_OUT : std_logic;
125 signal PWM3_OUT : std_logic;
127 signal QCNT : std_logic_vector (31 downto 0);
129 --------------------------------------------------------------------------------
133 ------------------------------------------------------------------------------
134 -- OpenMSP430 softcore MCU module
135 ------------------------------------------------------------------------------
136 openMSP430_1 : entity work.openMSP430_8_32_mul_dbus
138 dco_clk => CLK_24MHz,
143 per_addr => per_addr,
145 per_dout => per_dout,
149 irq => (others => '0'),
155 dmem_addr => dmem_addr,
158 dmem_din => dmem_din,
159 dmem_dout => dmem_dout);
161 -- External data bus address decoder and data multiplexer.
162 ------------------------------------------------------------------------------
163 -- This statement leads to priority encoder (which should be avoided), but for
164 -- a small mux it doesn't matter and it's better readable.
165 dmem_dout <= DPA_DAT_O when DPA_SEL = '1' else
168 DPA_SEL <= '1' when dmem_addr (11 downto 10) = "00" else '0';
169 DPA_STB <= dmem_ce and DPA_SEL;
171 -- Peripheral bus address decoder and data multiplexer.
172 ------------------------------------------------------------------------------
173 per_dout <= GPIO_DAT_O when GPIO_SEL = '1' else
174 QCNT_DAT_O when QCNT_SEL = '1' else
175 (others => '0'); -- MUST be 0 when nothing is addressed
177 GPIO_SEL <= '1' when per_addr(7 downto 2) = 16#0140#/2/4 else '0';
178 QCNT_SEL <= '1' when per_addr(7 downto 1) = 16#0148#/2/2 else '0';
181 ------------------------------------------------------------------------------
183 ------------------------------------------------------------------------------
187 GPIO_IN(3) <= IRC_INDEX;
189 gpio_0 : entity work.gpio
194 ADR_I => per_addr (1 downto 0),
205 qcounter_mcu16_0 : entity work.qcounter_mcu16
208 ADR_I => per_addr (0),
216 ------------------------------------------------------------------------------
217 -- Dual-port shared memory
218 ------------------------------------------------------------------------------
219 -- Shared memory between MCU and MCC (size: 16+2 bits x 1k).
220 -- Port A (MCU side) has a priority of writing.
221 shared_mem : RAMB16_S18_S18
223 WRITE_MODE_A => "READ_FIRST",
224 WRITE_MODE_B => "WRITE_FIRST")
227 ADDRA => dmem_addr (9 downto 0),
247 -- B-Port address (10 bits) constructed from IRF_ADR (5 bits). Upper addr bits
248 -- are forced to '0', but in a case of several axes these can be used to
249 -- address memory space of the appropriate one.
250 DPB_ADR (9 downto 5) <= (others => '0');
251 DPB_ADR (4 downto 0) <= IRF_ADR;
253 -- Generation of IRF acknowledge signal for MCC.
254 IRF_ACK <= IRF_STB and (IRF_WE or IRF_ACK_REG);
256 -- IRF_ACK_REG signalizes that data is present on IRF_DAT_O when reading.
257 irf_read : process (mclk, puc) is
259 if rising_edge(mclk) then
263 IRF_ACK_REG <= IRF_STB and not IRF_WE;
269 ------------------------------------------------------------------------------
270 -- Motion Control Chain
271 ------------------------------------------------------------------------------
272 mcc_exec_1 : entity work.mcc_exec
277 MCC_EXEC_I => PWM_OW,
279 MCC_ACK_I => MCC_ACK,
280 MCC_STB_O => MCC_STB);
282 mcc_1 : entity work.mcc
285 LUT_ADR_W => LUT_ADR_W)
291 LUT_STB_O => LUT_STB,
292 LUT_ADR_O => LUT_ADR,
293 LUT_DAT_I => LUT_DAT_O,
294 IRC_DAT_I => QCNT (15 downto 0),
295 PWM_DAT_O => PWM_DAT,
296 PWM1_STB_O => PWM1_STB,
297 PWM2_STB_O => PWM2_STB,
298 PWM3_STB_O => PWM3_STB,
299 IRF_ACK_I => IRF_ACK,
300 IRF_ADR_O => IRF_ADR,
301 IRF_DAT_I => IRF_DAT_O,
302 IRF_DAT_O => IRF_DAT_I,
303 IRF_STB_O => IRF_STB,
306 wave_table_1 : entity work.wave_table
310 INIT_FILE => LUT_INIT)
315 DAT_I => conv_std_logic_vector(0, PWM_W),
321 ------------------------------------------------------------------------------
323 ------------------------------------------------------------------------------
324 -- PWM counter is shared by all PWM generators. Generator contains only
325 -- comparator and desired value.
326 counter_1 : entity work.counter
337 pwm_1 : entity work.pwm
349 pwm_2 : entity work.pwm
361 pwm_3 : entity work.pwm
373 -- PWM signals mapped to FPGA outputs, EN forced to '1'
380 -- PWM is signalized on LEDs
385 qcounter_1 : entity work.qcounter