1
0
mirror of git://projects.qi-hardware.com/nn-usb-fpga.git synced 2025-01-10 13:50:14 +02:00
nn-usb-fpga/Examples/ADC/logic/ADC.v

113 lines
3.0 KiB
Coq
Raw Normal View History

2010-04-03 05:44:09 +03:00
`timescale 1ns / 1ps
module ADC(clk, sram_data, addr, nwe, ncs, noe, reset, led, ADC_EOC,
ADC_SCLK, ADC_SDIN, ADC_SDOUT, ADC_CS, ADC_CSTART, irq_pin, OD1, OD2, OD3);
2010-04-03 05:44:09 +03:00
parameter B = (7);
2010-04-03 05:44:09 +03:00
input clk, addr, nwe, ncs, noe, reset, ADC_EOC;
inout [B:0] sram_data;
output led, ADC_CS, ADC_CSTART, ADC_SCLK;
output OD1, OD2, OD3;
inout ADC_SDIN, ADC_SDOUT;
input irq_pin;
2010-04-03 05:44:09 +03:00
// Internal conection
reg led;
reg OD1, OD2, OD3;
2010-04-03 05:44:09 +03:00
// synchronize signals
reg sncs, snwe;
2010-04-04 21:58:41 +03:00
reg [12:0] buffer_addr;
2010-04-03 05:44:09 +03:00
reg [B:0] buffer_data;
// bram interfaz signals
reg we;
reg w_st=0;
reg [B:0] wrBus;
wire [B:0] rdBus;
2010-04-03 07:30:52 +03:00
// interfaz fpga signals
2010-04-04 21:58:41 +03:00
wire [12:0] addr;
2010-04-03 07:30:52 +03:00
2010-04-03 05:44:09 +03:00
reg [25:0] counter;
// Test : LED blinking
always @(posedge clk) begin
if (~reset)
2010-04-03 07:30:52 +03:00
counter <= {25{1'b0}};
else
counter <= counter + 1;
led <= counter[25];
OD1 <= counter[25];
OD2 <= counter[16];
OD3 <= counter[15];
2010-04-03 05:44:09 +03:00
end
// interefaz signals assignments
wire T = ~noe | ncs;
assign sram_data = T?8'bZ:rdBus;
// synchronize assignment
always @(negedge clk)
begin
2010-04-03 07:30:52 +03:00
sncs <= ncs;
snwe <= nwe;
buffer_data <= sram_data;
buffer_addr <= addr;
2010-04-03 05:44:09 +03:00
end
// write access cpu to bram
always @(posedge clk)
if(~reset) {w_st, we, wrBus} <= 0;
2010-04-03 05:44:09 +03:00
else begin
wrBus <= buffer_data;
case (w_st)
0: begin
we <= 0;
if(sncs | snwe) w_st <= 1;
end
1: begin
if(~(sncs | snwe)) begin
we <= 1;
w_st <= 0;
end
else we <= 0;
end
endcase
end
2010-04-03 07:30:52 +03:00
// Peripherals control
wire [3:0] csN;
wire [7:0] rdBus0, rdBus1, rdBus2, rdBus3;
2010-04-04 21:58:41 +03:00
assign csN = buffer_addr[12]? (buffer_addr[11]? 4'b1000:
4'b0100)
2010-04-04 21:58:41 +03:00
: (buffer_addr[11]? 4'b0010:
4'b0001);
2010-04-03 07:30:52 +03:00
2010-04-04 21:58:41 +03:00
assign rdBus = buffer_addr[12]? (buffer_addr[11]? rdBus3:
rdBus2)
2010-04-04 21:58:41 +03:00
: (buffer_addr[11]? rdBus1:
rdBus0);
2010-04-03 05:44:09 +03:00
// Peripheral instantiation
2010-04-03 07:30:52 +03:00
ADC_peripheral P1(
.clk(clk),
.reset(~reset),
2010-04-03 07:30:52 +03:00
.cs(csN[0]),
.ADC_EOC(ADC_EOC),
.ADC_CS(ADC_CS),
.ADC_CSTART(ADC_CSTART),
.ADC_SCLK(ADC_SCLK),
.ADC_SDIN(ADC_SDIN),
.ADC_SDOUT(ADC_SDOUT),
2010-04-04 21:58:41 +03:00
.addr(buffer_addr[10:0]),
2010-04-03 07:30:52 +03:00
.rdBus(rdBus0),
.wrBus(wrBus),
.we(we));
2010-04-03 05:44:09 +03:00
endmodule