1 |
2 |
ldalmasso |
------------------------------------------------------------------------
|
2 |
|
|
-- Engineer: Dalmasso Loic
|
3 |
|
|
-- Create Date: 19/02/2025
|
4 |
|
|
-- Module Name: PmodSF3SPIFrequencyGenerator
|
5 |
|
|
-- Description:
|
6 |
|
|
-- Pmod SF3 SPI Frequency Generator for the 32 MB NOR Flash Memory MT25QL256ABA.
|
7 |
|
|
-- From the System Input Clock, this module generate valid SPI Serial Clock Frequency according to the actual Dummy Cycles and SPI Mode (Single, Dual, Quad).
|
8 |
|
|
-- If the wanted SPI Serial Clock Frequency cannot be generated (i.e., Specified SPI Flash Frequency > System Input Clock Frequency), the System Input Clock Frequency is used.
|
9 |
|
|
-- When the System Input Clock Frequency is used, the 'o_using_sys_freq' signal is set.
|
10 |
|
|
--
|
11 |
|
|
-- SPI Frequency References (in MHz):
|
12 |
|
|
-- | Dummy Cycles | Single SPI | Dual SPI | Quad SPI |
|
13 |
|
|
-- | 0 | 133 | 94 | 133 |
|
14 |
|
|
-- | 1 | 94 | 79 | 44 |
|
15 |
|
|
-- | 2 | 112 | 97 | 61 |
|
16 |
|
|
-- | 3 | 129 | 106 | 78 |
|
17 |
|
|
-- | 4 | 133 | 115 | 97 |
|
18 |
|
|
-- | 5 | 133 | 125 | 106 |
|
19 |
|
|
-- | 6 | 133 | 133 | 115 |
|
20 |
|
|
-- | 7 | 133 | 94 | 125 |
|
21 |
|
|
-- | 8 | 133 | 94 | 133 |
|
22 |
|
|
-- | 9 | 133 | 94 | 133 |
|
23 |
|
|
-- | 10 | 133 | 94 | 133 |
|
24 |
|
|
-- | 11 | 133 | 94 | 133 |
|
25 |
|
|
-- | 12 | 133 | 94 | 133 |
|
26 |
|
|
-- | 13 | 133 | 94 | 133 |
|
27 |
|
|
-- | 14 | 133 | 94 | 133 |
|
28 |
|
|
--
|
29 |
|
|
-- Generics
|
30 |
|
|
-- sys_clock: System Input Clock Frequency (Hz)
|
31 |
|
|
--
|
32 |
|
|
-- Ports
|
33 |
|
|
-- Input - i_sys_clock: System Input Clock
|
34 |
|
|
-- Input - i_reset: System Input Reset ('0': No Reset, '1': Reset)
|
35 |
|
|
-- Input - i_spi_single_enable: Enable SPI Single Mode ('0': Disable, '1': Enable)
|
36 |
|
|
-- Input - i_spi_dual_enable: Enable SPI Dual Mode ('0': Disable, '1': Enable)
|
37 |
|
|
-- Input - i_dummy_cycles: Number of Dummy Cycles (0 to 14 cycles)
|
38 |
|
|
-- Output - o_spi_freq: SPI Serial Clock Frequency
|
39 |
|
|
-- Output - o_using_sys_freq: System Input Clock as SPI Serial Clock Frequency ('0': Disable, '1': Enable)
|
40 |
|
|
------------------------------------------------------------------------
|
41 |
|
|
|
42 |
|
|
LIBRARY IEEE;
|
43 |
|
|
USE IEEE.STD_LOGIC_1164.ALL;
|
44 |
|
|
USE IEEE.NUMERIC_STD.ALL;
|
45 |
|
|
|
46 |
|
|
ENTITY Testbench_PmodSF3SPIFrequencyGenerator is
|
47 |
|
|
END Testbench_PmodSF3SPIFrequencyGenerator;
|
48 |
|
|
|
49 |
|
|
ARCHITECTURE Behavioral of Testbench_PmodSF3SPIFrequencyGenerator is
|
50 |
|
|
|
51 |
|
|
COMPONENT PmodSF3SPIFrequencyGenerator is
|
52 |
|
|
|
53 |
|
|
GENERIC(
|
54 |
|
|
sys_clock: INTEGER := 100_000_000
|
55 |
|
|
);
|
56 |
|
|
|
57 |
|
|
PORT(
|
58 |
|
|
i_sys_clock: IN STD_LOGIC;
|
59 |
|
|
i_reset: IN STD_LOGIC;
|
60 |
|
|
i_spi_single_enable: IN STD_LOGIC;
|
61 |
|
|
i_spi_dual_enable: IN STD_LOGIC;
|
62 |
|
|
i_dummy_cycles: IN INTEGER range 0 to 14;
|
63 |
|
|
o_spi_freq: OUT STD_LOGIC;
|
64 |
|
|
o_using_sys_freq: OUT STD_LOGIC
|
65 |
|
|
);
|
66 |
|
|
|
67 |
|
|
END COMPONENT;
|
68 |
|
|
|
69 |
|
|
signal sys_clock: STD_LOGIC := '0';
|
70 |
|
|
signal reset: STD_LOGIC := '0';
|
71 |
|
|
signal spi_single_enable: STD_LOGIC := '0';
|
72 |
|
|
signal spi_dual_enable: STD_LOGIC := '0';
|
73 |
|
|
signal dummy_cycle_clock: STD_LOGIC := '0';
|
74 |
|
|
signal dummy_cycles: INTEGER range 0 to 14 := 0;
|
75 |
|
|
signal spi_freq: STD_LOGIC := '0';
|
76 |
|
|
signal using_sys_freq: STD_LOGIC := '0';
|
77 |
|
|
|
78 |
|
|
begin
|
79 |
|
|
|
80 |
|
|
-- Clock 100 MHz
|
81 |
|
|
sys_clock <= not(sys_clock) after 5 ns;
|
82 |
|
|
|
83 |
|
|
-- Reset
|
84 |
|
|
reset <= '1', '0' after 145 ns;
|
85 |
|
|
|
86 |
|
|
-- SPI Modes (Single, then Dual, then Quad)
|
87 |
|
|
spi_single_enable <= '1', '0' after 4950 ns, '0' after 7950 ns;
|
88 |
|
|
spi_dual_enable <= '0', '1' after 4950 ns, '0' after 7950 ns;
|
89 |
|
|
|
90 |
|
|
-- Dummy Cycles
|
91 |
|
|
dummy_cycle_clock <= not(dummy_cycle_clock) after 20 ns;
|
92 |
|
|
process(dummy_cycle_clock)
|
93 |
|
|
begin
|
94 |
|
|
if rising_edge(dummy_cycle_clock) then
|
95 |
|
|
|
96 |
|
|
-- Reset Dummy Cycles
|
97 |
|
|
if (reset = '1') or (dummy_cycles = 14) then
|
98 |
|
|
dummy_cycles <= 0;
|
99 |
|
|
|
100 |
|
|
-- New Dummy Cycles
|
101 |
|
|
else
|
102 |
|
|
dummy_cycles <= dummy_cycles +1;
|
103 |
|
|
end if;
|
104 |
|
|
end if;
|
105 |
|
|
end process;
|
106 |
|
|
|
107 |
|
|
uut: PmodSF3SPIFrequencyGenerator
|
108 |
|
|
|
109 |
|
|
GENERIC map(
|
110 |
|
|
sys_clock => 100_000_000)
|
111 |
|
|
|
112 |
|
|
PORT map(
|
113 |
|
|
i_sys_clock => sys_clock,
|
114 |
|
|
i_reset => reset,
|
115 |
|
|
i_spi_single_enable => spi_single_enable,
|
116 |
|
|
i_spi_dual_enable => spi_dual_enable,
|
117 |
|
|
i_dummy_cycles => dummy_cycles,
|
118 |
|
|
o_spi_freq => spi_freq,
|
119 |
|
|
o_using_sys_freq => using_sys_freq);
|
120 |
|
|
|
121 |
|
|
end Behavioral;
|