-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.sv
More file actions
209 lines (176 loc) · 5.21 KB
/
Copy pathmain.sv
File metadata and controls
209 lines (176 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// This file contains serial to parallel converter which is designed
// to control multiple Digital to Analog Converters (DAC) from AD53xx series.
// however it can be used in other applications.
// Data received from the computer via the UART interface are
// collected in the FIFO buffers. Then when sertain comand is received module
// simultaneously transmit data to the DACs.
// Parametrisation of the module allows to change clock frequency for
// UART and the rest part of the control logic independently. Frequency of the
// UART module should be less or equal to the frequency of the control logic.
// Parameters:
// - CLKS_PER_BIT is used by the UART modules.
// Set parameter CLKS_PER_BIT as follows:
// CLKS_PER_BIT = round((Frequency of clock)/(UART baud rate))
// Example: 1 MHz Clock, 115200 baud UART
// round((1000000)/(115200)) = 9
// - DACN is the number of used DACs in the project.
// Equal to the number of devices conected to the FPGA chip.
// - TESTBENCH if high configure module for testbench.
module main #(
parameter DACN = 2,
parameter CLKS_PER_BIT = 9,
parameter TESTBENCH = 0
) (
// General purpose ports
input clk_50,
input reset_button,
// Debugging outputs
output on_led,
output fifo_empty_led_and,
output fifo_empty_led_or,
// UART ports
input uart_rx,
output uart_tx,
// DACs ports
input [DACN-1:0] dac_busy_n,
output [DACN-1:0] dac_sdo,
dac_sclk,
dac_sync_n,
dac_reset_n,
dac_clr_n,
dac_ldac_n
);
logic reset;
logic clk_1;
logic pll_locked;
logic pll_locked_q;
logic reset_user;
logic reset_button_pressed;
logic reset_button_pressed_q;
genvar geni;
// Connections between uart and control
logic [7:0] uart_rx_data;
logic uart_byte_ready;
logic [7:0] uart_tx_data;
// Connetions between control and spi
wire [DACN-1:0] spi_busy;
wire [DACN-1:0] spi_start_transmit;
// Connections between control and fifo
wire [23:0] fifo_data_in[0:DACN-1];
wire [DACN-1:0] fifo_write_data;
wire [DACN-1:0] fifo_full;
wire [DACN-1:0] fifo_empty;
// Connections between fifo and spi
wire [23:0] fifo_data_out[0:DACN-1];
wire [DACN-1:0] fifo_read_data;
// Debugging interface
assign on_led = 0;
assign fifo_empty_led_and = &fifo_empty;
assign fifo_empty_led_or = |fifo_empty;
// Pll is used in design only. When it's testbench
// clock should be driven manualy.
generate
if (TESTBENCH == 0) begin
pll pll_1_MHz_m (
.inclk0 (clk_50),
.c0 (clk_1),
.locked (pll_locked)
);
end
endgenerate
// Reset button
button button_m (
.button_in (~reset_button),
.clock (clk_50),
.out (reset_button_pressed)
);
// Reset processing
always @(posedge clk_1) begin
pll_locked_q <= pll_locked;
reset_button_pressed_q <= reset_button_pressed;
end
assign pll_reset = pll_locked & ~pll_locked_q;
assign reset_user = reset_button_pressed & ~reset_button_pressed_q;
assign reset = reset_user | pll_reset;
// UART modules
uart_receiver #(
.CLKS_PER_BIT(CLKS_PER_BIT)
) uart_receiver_m (
.rx (uart_rx),
.clock (clk_1),
.reset (reset),
.rx_byte_ready (uart_byte_ready),
.rx_data (uart_rx_data)
);
uart_transmitter #(
.CLKS_PER_BIT(CLKS_PER_BIT)
) uart_transmitter_m (
.clock (clk_1),
.reset (reset),
.data (uart_tx_data),
.start_transmit (uart_start_transmit),
.tx (uart_tx),
.tx_busy (uart_tx_busy)
);
// SPI modules
generate
for (geni=0; geni<DACN; geni=geni+1) begin : generate_spi_modules
spi_transmitter spi_transmitter_m (
.clock (clk_1),
.reset (reset),
// FIFO connection
.data (fifo_data_out[geni]),
.fifo_read (fifo_read_data[geni]),
.fifo_empty (fifo_empty[geni]),
// Control module
.start_transmit (spi_start_transmit[geni]),
.spi_busy (spi_busy[geni]),
// DAC connetcion
.sdo (dac_sdo[geni]),
.sclk (dac_sclk[geni]),
.sync_n (dac_sync_n[geni])
);
end
endgenerate
// FIFO modules
generate
for (geni=0; geni<DACN; geni=geni+1) begin : generate_fifo_modules
fifo_buffer fifo_buffer_m (
.clock (clk_1),
.reset (reset),
// Write and read data ports
.write_data (fifo_write_data[geni]),
.data_in (fifo_data_in[geni]),
.read_data (fifo_read_data[geni]),
.data_out (fifo_data_out[geni]),
// Status outputs
.full (fifo_full[geni]),
.empty (fifo_empty[geni])
);
end
endgenerate
// Main control module
control #(.DACN(DACN)) control_m (
.clock (clk_1),
.reset (reset),
// UART ports
.uart_rx_data (uart_rx_data),
.uart_rx_byte_ready (uart_byte_ready),
.uart_tx_data (uart_tx_data),
.uart_tx_transmit (uart_start_transmit),
.uart_tx_busy (uart_tx_busy),
// FIFO memory ports
.fifo_data (fifo_data_in),
.fifo_write (fifo_write_data),
.fifo_full (fifo_full),
.fifo_empty (fifo_empty),
// SPI control ports
.spi_busy (spi_busy),
.spi_start_transmit (spi_start_transmit),
// Direct to DACs
.dac_clr_n (dac_clr_n),
.dac_reset_n (dac_reset_n),
.dac_ldac_n (dac_ldac_n),
.dac_busy_n (dac_busy_n)
);
endmodule