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

Subversion Repositories pmodda4driver

[/] [pmodda4driver/] [trunk/] [hw/] [sources/] [Top_PmodDA4Driver.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ldalmasso
------------------------------------------------------------------------
2
-- Engineer:    Dalmasso Loic
3
-- Create Date: 05/02/2025
4
-- Module Name: Top_PmodDA4Driver
5
-- Description:
6
--      Top Module including Pmod DA4 Driver for the 8 Channels 12-bit Digital-to-Analog Converter AD5628.
7
--
8
-- Ports
9
--              Input   -       i_sys_clock: System Input Clock
10
--              Input   -       i_reset: Module Reset ('0': No Reset, '1': Reset)
11
--              Input   -       i_enable: Module Enable ('0': Disable, '1': Enable)
12
--              Input   -       i_addr: DAC Address Register (4 bits)
13
--              Output  -       o_sclk: SPI Serial Clock
14
--              Output  -       o_mosi: SPI Master Output Slave Input Data line
15
--              Output  -       o_ss: SPI Slave Select Line ('0': Enable, '1': Disable)
16
------------------------------------------------------------------------
17
 
18
LIBRARY IEEE;
19
USE IEEE.STD_LOGIC_1164.ALL;
20
USE IEEE.NUMERIC_STD.ALL;
21
 
22
ENTITY Top_PmodDA4Driver is
23
 
24
PORT(
25
        i_sys_clock: IN STD_LOGIC;
26
    i_reset: IN STD_LOGIC;
27
    i_enable: IN STD_LOGIC;
28
    i_addr: IN UNSIGNED(3 downto 0);
29
        o_sclk: OUT STD_LOGIC;
30
    o_mosi: OUT STD_LOGIC;
31
        o_ss: OUT STD_LOGIC
32
);
33
 
34
END Top_PmodDA4Driver;
35
 
36
ARCHITECTURE Behavioral of Top_PmodDA4Driver is
37
 
38
------------------------------------------------------------------------
39
-- Component Declarations
40
------------------------------------------------------------------------
41
COMPONENT PmodDA4Driver is
42
 
43
    GENERIC(
44
        sys_clock: INTEGER := 100_000_000;
45
        spi_clock: INTEGER range 1 to 50_000_000 := 1_000_000
46
    );
47
 
48
    PORT(
49
        i_sys_clock: IN STD_LOGIC;
50
        i_enable: IN STD_LOGIC;
51
        i_command: IN UNSIGNED(3 downto 0);
52
        i_addr: IN UNSIGNED(3 downto 0);
53
        i_digital_value: IN UNSIGNED(11 downto 0);
54
        i_config: IN UNSIGNED(7 downto 0);
55
        o_ready: OUT STD_LOGIC;
56
        o_sclk: OUT STD_LOGIC;
57
        o_mosi: OUT STD_LOGIC;
58
        o_ss: OUT STD_LOGIC
59
    );
60
 
61
END COMPONENT;
62
 
63
------------------------------------------------------------------------
64
-- Signal Declarations
65
------------------------------------------------------------------------
66
-- Pmod DA4 Configuration Init
67
signal pmodda4_init_end: STD_LOGIC := '0';
68
 
69
-- Pmod DA4 Ready Handler
70
signal pmodda4_ready: STD_LOGIC := '0';
71
signal pmodda4_ready_reg: STD_LOGIC := '0';
72
signal pmodda4_ready_rising: STD_LOGIC := '0';
73
 
74
-- Pmod DA4 Input Register
75
signal command_reg: UNSIGNED(3 downto 0) := (others => '0');
76
signal address_reg: UNSIGNED(3 downto 0) := (others => '0');
77
signal digital_value_reg: UNSIGNED(11 downto 0) := (others => '0');
78
signal config_reg: UNSIGNED(7 downto 0) := (others => '0');
79
 
80
------------------------------------------------------------------------
81
-- Module Implementation
82
------------------------------------------------------------------------
83
begin
84
 
85
    ----------------------------
86
        -- Pmod DA4 Ready Handler --
87
        ----------------------------
88
        process(i_sys_clock)
89
        begin
90
 
91
                if rising_edge(i_sys_clock) then
92
            pmodda4_ready_reg <= pmodda4_ready;
93
        end if;
94
    end process;
95
    pmodda4_ready_rising <= pmodda4_ready and not(pmodda4_ready_reg);
96
 
97
    -------------------
98
        -- Pmod DA4 Mode --
99
        -------------------
100
        process(i_sys_clock)
101
        begin
102
 
103
                if rising_edge(i_sys_clock) then
104
 
105
            -- Reset
106
            if (i_reset = '1') then
107
                pmodda4_init_end <= '0';
108
 
109
            -- Config Mode
110
            elsif (pmodda4_ready_rising = '1') then
111
                pmodda4_init_end <= '1';
112
            end if;
113
        end if;
114
    end process;
115
 
116
        ------------------------------
117
        -- Digital Value Simulation --
118
        ------------------------------
119
        process(i_sys_clock)
120
        begin
121
 
122
                if rising_edge(i_sys_clock) then
123
 
124
            -- Reset Digital Value
125
            if (i_reset = '1') then
126
                command_reg <= x"0";
127
                address_reg <= x"0";
128
                digital_value_reg <= x"000";
129
                config_reg <= x"00";
130
 
131
            -- Config Mode
132
            elsif (pmodda4_init_end = '0') then
133
                command_reg <= x"8";
134
                address_reg <= x"0";
135
                digital_value_reg <= x"000";
136
                config_reg <= x"01";
137
 
138
            -- Signal Mode
139
            else
140
                command_reg <= x"3";
141
                address_reg <= i_addr;
142
                digital_value_reg <= digital_value_reg;
143
                config_reg <= x"00";
144
            end if;
145
 
146
            -- Increment Digital Value
147
            if (pmodda4_ready_rising = '1') then
148
                digital_value_reg <= digital_value_reg +1;
149
            end if;
150
 
151
        end if;
152
    end process;
153
 
154
    ---------------------
155
        -- Pmod DA4 Driver --
156
        ---------------------
157
    inst_PmodDA4Driver: PmodDA4Driver
158
    generic map (
159
        sys_clock => 100_000_000,
160
        spi_clock => 1_000_000)
161
 
162
    port map (
163
        i_sys_clock => i_sys_clock,
164
        i_enable => i_enable,
165
        i_command => command_reg,
166
        i_addr => address_reg,
167
        i_digital_value => digital_value_reg,
168
        i_config => config_reg,
169
        o_ready => pmodda4_ready,
170
        o_sclk => o_sclk,
171
        o_mosi => o_mosi,
172
        o_ss => o_ss);
173
 
174
end Behavioral;

powered by: WebSVN 2.1.0

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