source: FPGA/FTU/dac_spi/FTU_spi_controller.vhd@ 4882

Last change on this file since 4882 was 273, checked in by qweitzel, 14 years ago
new structure for FTU firmware, not yet finished
File size: 2.2 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--
12
13LIBRARY ieee;
14USE ieee.std_logic_1164.all;
15USE ieee.std_logic_arith.all;
16USE ieee.std_logic_unsigned.all;
17
18ENTITY FTU_spi_controller IS
19 PORT(
20 clk : IN std_logic;
21 mosi : OUT std_logic := '0';
22 dac_id : IN std_logic_vector (2 DOWNTO 0);
23 data : IN std_logic_vector (15 DOWNTO 0) := (others => '0');
24 dac_cs : OUT std_logic := '1';
25 dac_start : IN std_logic;
26 dac_ready : OUT std_logic := '0'
27 );
28END FTU_spi_controller ;
29
30ARCHITECTURE beha OF FTU_spi_controller IS
31
32 type TYPE_SPI_STATE is (SPI_IDLE, SPI_LOAD_DAC, SPI_LOAD_COMMAND);
33
34 signal spi_state : TYPE_SPI_STATE := SPI_IDLE;
35 signal spi_cycle_cnt : integer range 0 to 25 := 0;
36 signal shift_reg : std_logic_vector (23 downto 0) := (others => '0');
37 signal data_reg : std_logic_vector (15 downto 0) := (others => '0');
38
39BEGIN
40
41 spi_write_proc: process (clk)
42 begin
43 if falling_edge(clk) then
44 dac_cs <= '1';
45 mosi <= '0';
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(11 downto 0) & "0000";
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.