OpenCores
URL https://opencores.org/ocsvn/spidac/spidac/trunk

Subversion Repositories spidac

[/] [spidac/] [trunk/] [DAC_Control.vhd] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 socrates
-----------------------------------------------------------------------------------------
2
-- Engineer: Tomas Daujotas (mailsoc@gmail.com www.scrts.net)
3
-- 
4
-- Create Date: 2010-07-21 
5
-- Design Name: Control of LTC2624 Quad 12 bit DAC on Spartan-3E Starter Kit (32bit mode)
6
-----------------------------------------------------------------------------------------
7
 
8
library IEEE;
9
use IEEE.STD_LOGIC_1164.ALL;
10
use IEEE.NUMERIC_STD.ALL;
11
 
12
entity DAC_Control is
13
    Port ( CLK : in  STD_LOGIC;
14
           RST : in  STD_LOGIC;
15
                          DAC_DATA : in STD_LOGIC_VECTOR(31 downto 0);
16
           DAC_MOSI : out  STD_LOGIC;
17
           DAC_SCK : out  STD_LOGIC;
18
           DAC_CS : out  STD_LOGIC;
19
           RDY : out  STD_LOGIC);
20
end DAC_Control;
21
 
22
architecture DAC_Control of DAC_Control is
23
 
24
type state_type is (idle,ready,send,dummy,check);
25
signal state : state_type;
26
signal DAC_SEND : std_logic_vector(31 downto 0);
27
 
28
begin
29
        process(DAC_DATA)
30
        begin
31
                for i in 31 downto 0 loop
32
                        DAC_SEND(i) <= DAC_DATA(31 - i); -- The data must be MSB first
33
                end loop;
34
        end process;
35
 
36
        process(CLK,RST)
37
 
38
        variable index : integer range 0 to 32 := 0;
39
 
40
        begin
41
                if (RST = '1') then
42
                        index := 0;
43
                elsif rising_edge(CLK) then
44
                        case state is
45
                                when idle =>
46
                                        DAC_SCK <= '0';
47
                                        DAC_CS <= '1';
48
                                        index := 0;
49
                                        DAC_MOSI <= '0';
50
                                        RDY <= '1';
51
                                        state <= ready;
52
                                when ready =>
53
                                        RDY <= '0';
54
                                        DAC_CS <= '0';
55
                                        DAC_SCK <= '0';
56
                                        DAC_MOSI <= DAC_SEND(index);
57
                                        state <= dummy;
58
                                when dummy =>
59
                                        state <= send;
60
                                when send =>
61
                                        DAC_SCK <= '1';
62
                                        state <= check;
63
                                        index := index + 1;
64
                                when check =>
65
                                        DAC_SCK <= '1';
66
                                        if (index = 32) then
67
                                                state <= idle;
68
                                        else
69
                                                state <= ready;
70
                                        end if;
71
                        end case;
72
                end if;
73
        end process;
74
 
75
end DAC_Control;
76
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.