source: firmware/FTU/test_firmware/FTU_test2/FTU_test2_spi_controller.vhd@ 20115

Last change on this file since 20115 was 243, checked in by qweitzel, 14 years ago
FTU_test2 is now working
File size: 2.4 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--
10-- modified by Q. Weitzel
11--
12LIBRARY ieee;
13USE ieee.std_logic_1164.all;
14USE ieee.std_logic_arith.all;
15USE ieee.std_logic_unsigned.all;
16
17ENTITY FTU_test2_spi_controller IS
18 PORT(
19 clk : IN std_logic;
20 miso : INOUT std_logic := 'Z';
21 mosi : OUT std_logic := '0';
22 dac_id : IN std_logic_vector (2 DOWNTO 0);
23 --data : INOUT std_logic_vector (15 DOWNTO 0) := (others => 'Z');
24 data : IN std_logic_vector (15 DOWNTO 0) := (others => '0');
25 dac_cs : OUT std_logic := '1';
26 dac_start : IN std_logic;
27 dac_ready : OUT std_logic := '0'
28 );
29END FTU_test2_spi_controller ;
30
31ARCHITECTURE beha OF FTU_test2_spi_controller IS
32
33 type TYPE_SPI_STATE is (SPI_IDLE, SPI_LOAD_DAC, SPI_LOAD_COMMAND);
34
35 signal spi_state : TYPE_SPI_STATE := SPI_IDLE;
36 signal spi_cycle_cnt : integer range 0 to 25 := 0;
37 signal shift_reg : std_logic_vector (23 downto 0) := (others => '0');
38 signal data_reg : std_logic_vector (15 downto 0) := (others => '0');
39
40BEGIN
41
42 spi_write_proc: process (clk)
43 begin
44 if falling_edge(clk) then
45 dac_cs <= '1';
46 miso <= 'Z';
47 mosi <= '0';
48 --data <= (others => 'Z');
49 case spi_state is
50 when SPI_IDLE =>
51 if (dac_start = '1') then
52 dac_ready <= '0';
53 spi_state <= SPI_LOAD_COMMAND;
54 end if;
55
56 when SPI_LOAD_COMMAND =>
57 spi_cycle_cnt <= 0;
58 if (dac_start = '1') then
59 shift_reg <= "0011" & '0' & dac_id & data(11 downto 0) & "0000";
60 spi_state <= SPI_LOAD_DAC;
61 end if;
62
63 -- start loading DACs
64 when SPI_LOAD_DAC =>
65 dac_cs <= '0';
66 if (spi_cycle_cnt < 24) then
67 mosi <= shift_reg(23);
68 shift_reg <= shift_reg(22 downto 0) & shift_reg(23);
69 dac_ready <= '0';
70 spi_cycle_cnt <= spi_cycle_cnt + 1;
71 spi_state <= SPI_LOAD_DAC;
72 else
73 dac_cs <= '1';
74 dac_ready <= '1';
75 spi_state <= SPI_IDLE;
76 end if;
77 end case;
78 end if;
79 end process spi_write_proc;
80
81END ARCHITECTURE beha;
Note: See TracBrowser for help on using the repository browser.