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

Subversion Repositories pmodda4driver

[/] [pmodda4driver/] [trunk/] [hw/] [simulations/] [Testbench_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: PmodDA4Driver
5
-- Description:
6
--      Pmod DA4 Driver for the 8 Channels 12-bit Digital-to-Analog Converter AD5628. The communication with the DAC uses the SPI protocol (Write only)
7
--      User can specifies the SPI Serial Clock Frequency (up to 50 MHz).
8
--
9
-- Usage:
10
--              The o_ready signal (set to '1') indicates the PmodDA4Driver is ready to receive new data (command, address and digital value).
11
--              Once data are set, the i_enable signal can be triggered (set to '1') to begin transmission.
12
--              The o_ready signal is set to '0' to acknowledge the receipt and the application of the new data.
13
--              When the transmission is complete, the o_ready is set to '1' and the PmodDA4Driver is ready for new transmission.
14
--
15
--      Commands
16
--      | C3 | C2 | C1 | C0 | Description
17
--      |  0 |  0 |  0 |  0 | Write to Input Register n
18
--      |  0 |  0 |  0 |  1 | Update DAC Register n
19
--      |  0 |  0 |  1 |  0 | Write to Input Register n, update all (software /LDAC)
20
--      |  0 |  0 |  1 |  1 | Write to and update DAC Channel n
21
--      |  0 |  1 |  0 |  0 | Power down/power up DAC
22
--      |  0 |  1 |  0 |  1 | Load clear code register
23
--      |  0 |  1 |  1 |  0 | Load /LDAC register
24
--      |  0 |  1 |  1 |  1 | Reset (power-on reset)
25
--      |  1 |  0 |  0 |  0 | Set up internal REF register
26
--      |  - |  - |  - |  - | Reserved
27
--
28
--      Address
29
--      | A3 | A2 | A1 | A0 | Description
30
--      |  0 |  0 |  0 |  0 | DAC Channel A
31
--      |  0 |  0 |  0 |  1 | DAC Channel B
32
--      |  0 |  0 |  1 |  0 | DAC Channel C
33
--      |  0 |  0 |  1 |  1 | DAC Channel D
34
--      |  0 |  1 |  0 |  0 | DAC Channel E
35
--      |  0 |  1 |  0 |  1 | DAC Channel F
36
--      |  0 |  1 |  1 |  0 | DAC Channel G
37
--      |  0 |  1 |  1 |  1 | DAC Channel H
38
--      |  1 |  1 |  1 |  1 | DAC All Channels
39
--
40
-- Generics
41
--              sys_clock: System Input Clock Frequency (Hz)
42
--      spi_clock: SPI Serial Clock Frequency (up to 50 MHz)
43
-- Ports
44
--              Input   -       i_sys_clock: System Input Clock
45
--              Input   -       i_enable: Module Enable ('0': Disable, '1': Enable)
46
--              Input   -       i_command: DAC Command (4 bits)
47
--              Input   -       i_addr: DAC Address Register (4 bits)
48
--              Input   -       i_digital_value: Digital Value to convert (12 bits)
49
--              Input   -       i_config: DAC Configuration Bits (8 bits)
50
--              Output  -       o_ready: Ready to convert Next Digital Value ('0': NOT Ready, '1': Ready)
51
--              Output  -       o_sclk: SPI Serial Clock
52
--              Output  -       o_mosi: SPI Master Output Slave Input Data line
53
--              Output  -       o_ss: SPI Slave Select Line ('0': Enable, '1': Disable)
54
------------------------------------------------------------------------
55
 
56
LIBRARY IEEE;
57
USE IEEE.STD_LOGIC_1164.ALL;
58
USE IEEE.NUMERIC_STD.ALL;
59
 
60
ENTITY Testbench_PmodDA4Driver is
61
--  Port ( );
62
END Testbench_PmodDA4Driver;
63
 
64
ARCHITECTURE Behavioral of Testbench_PmodDA4Driver is
65
 
66
COMPONENT PmodDA4Driver is
67
 
68
GENERIC(
69
        sys_clock: INTEGER := 100_000_000;
70
        spi_clock: INTEGER range 1 to 50_000_000 := 1_000_000
71
);
72
 
73
PORT(
74
        i_sys_clock: IN STD_LOGIC;
75
    i_enable: IN STD_LOGIC;
76
    i_command: IN UNSIGNED(3 downto 0);
77
    i_addr: IN UNSIGNED(3 downto 0);
78
        i_digital_value: IN UNSIGNED(11 downto 0);
79
        i_config: IN UNSIGNED(7 downto 0);
80
    o_ready: OUT STD_LOGIC;
81
        o_sclk: OUT STD_LOGIC;
82
    o_mosi: OUT STD_LOGIC;
83
        o_ss: OUT STD_LOGIC
84
);
85
 
86
END COMPONENT;
87
 
88
signal sys_clock: STD_LOGIC := '0';
89
signal enable: STD_LOGIC := '0';
90
signal command: UNSIGNED(3 downto 0):= (others => '0');
91
signal addr: UNSIGNED(3 downto 0):= (others => '0');
92
signal digital_value: UNSIGNED(11 downto 0):= (others => '0');
93
signal config: UNSIGNED(7 downto 0):= (others => '0');
94
signal ready: STD_LOGIC := '0';
95
signal sclk: STD_LOGIC := '0';
96
signal mosi: STD_LOGIC := '0';
97
signal ss: STD_LOGIC := '0';
98
 
99
begin
100
 
101
-- Clock 100 MHz
102
sys_clock <= not(sys_clock) after 5 ns;
103
 
104
-- Enable
105
enable <= '0', '1' after 111 us, '0' after 114 us, '1' after 150 us, '0' after 153 us, '1' after 178 us, '0' after 237 us;
106
 
107
-- Inputs Sequence
108
process
109
begin
110
    -- Init
111
    command <= x"0";
112
    addr <= x"0";
113
    digital_value <= x"000";
114
    config <= x"00";
115
    wait for 111 us;
116
 
117
    -- Config Internal REF Register
118
    command <= x"8";
119
    addr <= x"0";
120
    digital_value <= x"000";
121
    config <= x"01";
122
    wait until ready = '0';
123
 
124
    -- Digital Value 1
125
    command <= x"F";
126
    addr <= x"2";
127
    digital_value <= x"123";
128
    config <= x"00";
129
    wait until ready = '0';
130
 
131
    -- Digital Value 2
132
    command <= x"9";
133
    addr <= x"8";
134
    digital_value <= x"765";
135
    config <= x"00";
136
    wait;
137
end process;
138
 
139
uut: PmodDA4Driver
140
    GENERIC map(
141
        sys_clock => 100_000_000,
142
        spi_clock => 1_000_000
143
    )
144
 
145
    PORT map(
146
        i_sys_clock => sys_clock,
147
        i_enable => enable,
148
        i_command => command,
149
        i_addr => addr,
150
        i_digital_value => digital_value,
151
        i_config => config,
152
        o_ready => ready,
153
        o_sclk => sclk,
154
        o_mosi => mosi,
155
        o_ss => ss);
156
 
157
end Behavioral;

powered by: WebSVN 2.1.0

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