source: firmware/FTU/dac_spi/FTU_spi_controller.vhd@ 16339

Last change on this file since 16339 was 9939, checked in by weitzel, 14 years ago
FTU RS485 interface is now connected to main control
File size: 2.1 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
38BEGIN
39
40 spi_write_proc: process (clk)
41 begin
42 if falling_edge(clk) then
43 dac_cs <= '1';
44 mosi <= '0';
45 case spi_state is
46 when SPI_IDLE =>
47 if (dac_start = '1') then
48 dac_ready <= '0';
49 spi_state <= SPI_LOAD_COMMAND;
50 end if;
51
52 when SPI_LOAD_COMMAND =>
53 spi_cycle_cnt <= 0;
54 if (dac_start = '1') then
55 shift_reg <= "0011" & '0' & dac_id & data(11 downto 0) & "0000";
56 spi_state <= SPI_LOAD_DAC;
57 end if;
58
59 -- start loading DACs
60 when SPI_LOAD_DAC =>
61 dac_cs <= '0';
62 if (spi_cycle_cnt < 24) then
63 mosi <= shift_reg(23);
64 shift_reg <= shift_reg(22 downto 0) & shift_reg(23);
65 dac_ready <= '0';
66 spi_cycle_cnt <= spi_cycle_cnt + 1;
67 spi_state <= SPI_LOAD_DAC;
68 else
69 dac_cs <= '1';
70 dac_ready <= '1';
71 spi_state <= SPI_IDLE;
72 end if;
73 end case;
74 end if;
75 end process spi_write_proc;
76
77END ARCHITECTURE beha;
Note: See TracBrowser for help on using the repository browser.