source: FPGA/FTU/test_firmware/FTU_test2/FTU_test2_spi_controller.vhd@ 241

Last change on this file since 241 was 236, checked in by qweitzel, 15 years ago
second test for FTU added
File size: 2.3 KB
Line 
1--
2-- VHDL Architecture FACT_FAD_lib.spi_controller.beha
3--
4-- Created:
5-- by - Benjamin Krumm.UNKNOWN (EEPC8)
6-- at - 10:37:20 12.04.2010
7--
8-- using Mentor Graphics HDL Designer(TM) 2009.1 (Build 12)
9--
10LIBRARY ieee;
11USE ieee.std_logic_1164.all;
12USE ieee.std_logic_arith.all;
13USE ieee.std_logic_unsigned.all;
14
15ENTITY FTU_test2_spi_controller IS
16 PORT(
17 clk : IN std_logic;
18 miso : INOUT std_logic := 'Z';
19 mosi : OUT std_logic := '0';
20 dac_id : IN std_logic_vector (2 DOWNTO 0);
21 data : INOUT std_logic_vector (15 DOWNTO 0) := (others => 'Z');
22 dac_cs : OUT std_logic := '1';
23 dac_start : IN std_logic;
24 dac_ready : OUT std_logic := '0'
25 );
26END FTU_test2_spi_controller ;
27
28ARCHITECTURE beha OF FTU_test2_spi_controller IS
29
30 type TYPE_SPI_STATE is (SPI_IDLE, SPI_LOAD_DAC, SPI_LOAD_COMMAND);
31
32 signal spi_state : TYPE_SPI_STATE := SPI_IDLE;
33 signal spi_cycle_cnt : integer range 0 to 25 := 0;
34 signal shift_reg : std_logic_vector (23 downto 0) := (others => '0');
35 signal data_reg : std_logic_vector (15 downto 0) := (others => '0');
36
37BEGIN
38
39 spi_write_proc: process (clk)
40 begin
41 if falling_edge(clk) then
42 dac_cs <= '1';
43 miso <= 'Z';
44 mosi <= '0';
45 data <= (others => 'Z');
46 case spi_state is
47 when SPI_IDLE =>
48 if (dac_start = '1') then
49 dac_ready <= '0';
50 spi_state <= SPI_LOAD_COMMAND;
51 end if;
52
53 when SPI_LOAD_COMMAND =>
54 spi_cycle_cnt <= 0;
55 if (dac_start = '1') then
56 shift_reg <= "0011" & '0' & dac_id & data;
57 spi_state <= SPI_LOAD_DAC;
58 end if;
59
60 -- start loading DACs
61 when SPI_LOAD_DAC =>
62 dac_cs <= '0';
63 if (spi_cycle_cnt < 24) then
64 mosi <= shift_reg(23);
65 shift_reg <= shift_reg(22 downto 0) & shift_reg(23);
66 dac_ready <= '0';
67 spi_cycle_cnt <= spi_cycle_cnt + 1;
68 spi_state <= SPI_LOAD_DAC;
69 else
70 dac_cs <= '1';
71 dac_ready <= '1';
72 spi_state <= SPI_IDLE;
73 end if;
74 end case;
75 end if;
76 end process spi_write_proc;
77
78END ARCHITECTURE beha;
Note: See TracBrowser for help on using the repository browser.