@@ -21,34 +21,34 | |||||
21 | ------------------------------------------------------------------------------ |
|
21 | ------------------------------------------------------------------------------ | |
22 |
|
22 | |||
23 |
|
23 | |||
24 | library IEEE; |
|
24 | LIBRARY IEEE; | |
25 |
|
|
25 | USE IEEE.STD_LOGIC_1164.ALL; | |
26 |
|
|
26 | USE IEEE.NUMERIC_STD.ALL; | |
27 |
|
27 | |||
28 |
|
|
28 | ENTITY SPI_DAC_DRIVER IS | |
29 | Generic( |
|
29 | GENERIC( | |
30 |
|
|
30 | datawidth : INTEGER := 16; | |
31 |
|
|
31 | MSBFIRST : INTEGER := 1 | |
32 | ); |
|
32 | ); | |
33 | Port ( |
|
33 | PORT ( | |
34 |
|
|
34 | clk : IN STD_LOGIC; | |
35 |
|
|
35 | rstn : IN STD_LOGIC; | |
36 |
|
|
36 | DATA : IN STD_LOGIC_VECTOR(datawidth-1 DOWNTO 0); | |
37 |
|
|
37 | SMP_CLK : IN STD_LOGIC; | |
38 |
|
|
38 | SYNC : OUT STD_LOGIC; | |
39 |
|
|
39 | DOUT : OUT STD_LOGIC; | |
40 |
|
|
40 | SCLK : OUT STD_LOGIC | |
41 |
|
|
41 | ); | |
42 |
|
|
42 | END ENTITY SPI_DAC_DRIVER; | |
43 |
|
43 | |||
44 | architecture behav of SPI_DAC_DRIVER is |
|
44 | ARCHITECTURE behav OF SPI_DAC_DRIVER IS | |
45 |
|
|
45 | SIGNAL SHIFTREG : STD_LOGIC_VECTOR(datawidth-1 DOWNTO 0) := (OTHERS => '0'); | |
46 |
|
|
46 | SIGNAL INPUTREG : STD_LOGIC_VECTOR(datawidth-1 DOWNTO 0) := (OTHERS => '0'); | |
47 | signal SMP_CLK_R : STD_LOGIC:='0'; |
|
47 | SIGNAL SMP_CLK_R : STD_LOGIC := '0'; | |
48 | signal shiftcnt : INTEGER:=0; |
|
48 | SIGNAL shiftcnt : INTEGER := 0; | |
49 | signal shifting : STD_LOGIC:='0'; |
|
49 | SIGNAL shifting : STD_LOGIC := '0'; | |
50 | signal shifting_R : STD_LOGIC:='0'; |
|
50 | SIGNAL shifting_R : STD_LOGIC := '0'; | |
51 | begin |
|
51 | BEGIN | |
52 |
|
52 | |||
53 | DOUT <= SHIFTREG(datawidth-1); |
|
53 | DOUT <= SHIFTREG(datawidth-1); | |
54 |
|
54 | |||
@@ -57,49 +57,49 MSB:IF MSBFIRST=1 GENERATE | |||||
57 | END GENERATE; |
|
57 | END GENERATE; | |
58 |
|
58 | |||
59 | LSB:IF MSBFIRST=0 GENERATE |
|
59 | LSB : IF MSBFIRST = 0 GENERATE | |
60 |
INPUTREG(datawidth-1 |
|
60 | INPUTREG(datawidth-1 DOWNTO 0) <= DATA(0 TO datawidth-1); | |
61 | END GENERATE; |
|
61 | END GENERATE; | |
62 |
|
62 | |||
63 |
SCLK |
|
63 | SCLK <= clk; | |
64 |
|
64 | |||
65 | process(clk,rstn) |
|
65 | PROCESS(clk, rstn) | |
66 | begin |
|
66 | BEGIN | |
67 |
|
|
67 | IF rstn = '0' then | |
68 |
|
|
68 | shifting_R <= '0'; | |
69 |
|
|
69 | SMP_CLK_R <= '0'; | |
70 |
|
|
70 | ELSIF clk'EVENT AND clk = '1' then | |
71 |
|
|
71 | SMP_CLK_R <= SMP_CLK; | |
72 |
|
|
72 | shifting_R <= shifting; | |
73 | end if; |
|
73 | END IF; | |
74 | end process; |
|
74 | END PROCESS; | |
75 |
|
75 | |||
76 | process(clk,rstn) |
|
76 | PROCESS(clk, rstn) | |
77 | begin |
|
77 | BEGIN | |
78 |
|
|
78 | IF rstn = '0' then | |
79 |
|
|
79 | shifting <= '0'; | |
80 |
|
|
80 | SHIFTREG <= (OTHERS => '0'); | |
81 |
|
|
81 | SYNC <= '0'; | |
82 |
|
|
82 | shiftcnt <= 0; | |
83 |
|
|
83 | ELSIF clk'EVENT AND clk = '1' then | |
84 |
|
|
84 | IF(SMP_CLK = '1' and SMP_CLK_R = '0') THEN | |
85 |
|
|
85 | SYNC <= '1'; | |
86 |
|
|
86 | shifting <= '1'; | |
87 | else |
|
87 | ELSE | |
88 |
|
|
88 | SYNC <= '0'; | |
89 |
|
|
89 | IF shiftcnt = datawidth-1 THEN | |
90 |
|
|
90 | shifting <= '0'; | |
91 | end if; |
|
91 | END IF; | |
92 | end if; |
|
92 | END IF; | |
93 |
|
|
93 | IF shifting = '1' then | |
94 |
|
|
94 | shiftcnt <= shiftcnt + 1; | |
95 |
|
|
95 | SHIFTREG <= SHIFTREG (datawidth-2 DOWNTO 0) & '0'; | |
96 | else |
|
96 | ELSE | |
97 |
|
|
97 | SHIFTREG <= INPUTREG; | |
98 |
|
|
98 | shiftcnt <= 0; | |
99 | end if; |
|
99 | END IF; | |
100 | end if; |
|
100 | END IF; | |
101 | end process; |
|
101 | END PROCESS; | |
102 |
|
102 | |||
103 | end architecture behav; |
|
103 | END ARCHITECTURE behav; | |
104 |
|
104 | |||
105 |
|
105 |
General Comments 0
You need to be logged in to leave comments.
Login now