source: FPGA/FAD/FACT_FAD_lib/hdl/spi_controller_beha.vhd@ 228

Last change on this file since 228 was 215, checked in by dneise, 14 years ago
initial commit (2nd part): only VHDL and UCF files were commited.
  • Property svn:executable set to *
File size: 3.7 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 spi_controller IS
16 PORT(
17 clk : IN std_logic;
18 sio : INOUT std_logic := 'Z';
19 mosi : OUT std_logic := '0';
20 dac_id : IN std_logic_vector (2 DOWNTO 0);
21 sensor_id : IN std_logic_vector (1 downto 0);
22 data : INOUT std_logic_vector (15 DOWNTO 0) := (others => 'Z');
23 dac_cs : OUT std_logic := '1';
24 sensor_cs : OUT std_logic_vector (3 DOWNTO 0) := (others => '1');
25 dac_start : IN std_logic;
26 dac_ready : OUT std_logic := '0';
27 sensor_start : IN std_logic;
28 sensor_valid : OUT std_logic := '0'
29 );
30END spi_controller ;
31
32ARCHITECTURE beha OF spi_controller IS
33
34 type TYPE_SPI_STATE is (SPI_IDLE, SPI_LOAD_DAC, SPI_LOAD_COMMAND, SPI_GET_TEMP);
35
36 signal spi_state : TYPE_SPI_STATE := SPI_IDLE;
37 signal spi_cycle_cnt : integer range 0 to 25 := 0;
38 signal shift_reg : std_logic_vector (23 downto 0) := (others => '0');
39 signal data_reg : std_logic_vector (15 downto 0) := (others => '0');
40
41BEGIN
42
43 spi_write_proc: process (clk)
44 begin
45 if falling_edge(clk) then
46 dac_cs <= '1';
47 sensor_cs <= (others => '1');
48 sio <= 'Z';
49 mosi <= '0';
50 data <= (others => 'Z');
51 case spi_state is
52 when SPI_IDLE =>
53 if (dac_start = '1') then
54 dac_ready <= '0';
55 spi_state <= SPI_LOAD_COMMAND;
56 elsif (sensor_start = '1') then
57 sensor_valid <= '0';
58 spi_state <= SPI_LOAD_COMMAND;
59 end if;
60
61 when SPI_LOAD_COMMAND =>
62 spi_cycle_cnt <= 0;
63 if (sensor_start = '1') then
64 shift_reg <= X"C1" & X"0000"; -- command: Temperature register read
65 spi_state <= SPI_GET_TEMP;
66 elsif (dac_start = '1') then
67 shift_reg <= "0011" & '0' & dac_id & data;
68 spi_state <= SPI_LOAD_DAC;
69 end if;
70
71 -- start temperature sensor read
72 when SPI_GET_TEMP =>
73 if (spi_cycle_cnt < 24) then -- must be on more cause MAX6662 provides data on falling edge
74 sensor_cs(conv_integer(sensor_id)) <= '0';
75 sensor_valid <= '0';
76 spi_cycle_cnt <= spi_cycle_cnt + 1;
77 if (spi_cycle_cnt < 9) then -- send data
78 sio <= shift_reg(23);
79 shift_reg <= shift_reg(22 downto 0) & shift_reg(23);
80 end if;
81 else
82 data <= data_reg;
83 sensor_valid <= '1';
84 spi_state <= SPI_IDLE;
85 end if;
86
87 -- start loading DACs
88 when SPI_LOAD_DAC =>
89 dac_cs <= '0';
90 if (spi_cycle_cnt < 24) then
91 mosi <= shift_reg(23);
92 shift_reg <= shift_reg(22 downto 0) & shift_reg(23);
93 dac_ready <= '0';
94 spi_cycle_cnt <= spi_cycle_cnt + 1;
95 spi_state <= SPI_LOAD_DAC;
96 else
97 dac_cs <= '1';
98 dac_ready <= '1';
99 spi_state <= SPI_IDLE;
100 end if;
101 end case;
102 end if;
103 end process spi_write_proc;
104
105 -- MAX6662 input must be read with rising edge
106 spi_read_proc: process (clk)
107 begin
108 if rising_edge(clk) then
109 if (spi_state = SPI_GET_TEMP and spi_cycle_cnt >= 9) then
110 data_reg(0) <= sio;
111 data_reg(15 downto 1) <= data_reg(14 downto 0);
112 end if;
113 end if;
114 end process spi_read_proc;
115
116END ARCHITECTURE beha;
117
Note: See TracBrowser for help on using the repository browser.