Add tests Makefile

This commit is contained in:
Kelvin Ly 2020-01-07 20:04:58 -05:00
parent 0e67bfc6dc
commit 008783cc40
4 changed files with 38 additions and 28 deletions

View File

@ -2,13 +2,13 @@ module adc_driver(
input clk, input clk,
input rstn, input rstn,
input adc_so, input so,
output adc_si, output si,
output adc_ss, output ss,
output adc_sck, output sck,
output [1:0] channel, output [1:0] channel,
output [11:0] adc_val, output [11:0] val,
output vld, output vld,
input ack input ack
); );
@ -18,7 +18,7 @@ reg [11:0] adc_val_ff = 0;
reg vld_ff = 0; reg vld_ff = 0;
assign channel = channel_ff; assign channel = channel_ff;
assign adc_val = adc_val_ff; assign val = adc_val_ff;
assign vld = vld_ff; assign vld = vld_ff;
reg [2:0] sck_strobe = 0; reg [2:0] sck_strobe = 0;
@ -47,12 +47,12 @@ reg sck_next;
reg ss_next; reg ss_next;
reg si_next; reg si_next;
reg adc_si_ff = 1; reg si_ff = 1;
reg adc_ss_ff = 1; reg ss_ff = 1;
reg adc_sck_ff = 1; reg sck_ff = 1;
assign adc_si = adc_si_ff; assign si = si_ff;
assign adc_ss = adc_ss_ff; assign ss = ss_ff;
assign adc_sck = adc_sck_ff; assign sck = sck_ff;
wire [15:0] config_word; wire [15:0] config_word;
wire config_bit; wire config_bit;
@ -79,14 +79,14 @@ always @* begin
if (rstn) begin if (rstn) begin
// latch sck and ss state until the strobe happens // latch sck and ss state until the strobe happens
si_next = adc_si; si_next = si;
ss_next = adc_ss; ss_next = ss;
sck_next = adc_sck; sck_next = sck;
if (strobe2) begin if (strobe2) begin
if (state == CONFIG || state == ADC) begin if (state == CONFIG || state == ADC) begin
// deassert slave select so it can be triggered on the next frame // deassert slave select so it can be triggered on the next frame
if (bit_pos == 31 & ~ss_next & ~adc_sck) begin if (bit_pos == 31 & ~ss_next & ~sck) begin
ss_next = 1; ss_next = 1;
//bit_pos_next = 0; // don't need this because it's going to //bit_pos_next = 0; // don't need this because it's going to
// overflow // overflow
@ -107,12 +107,12 @@ always @* begin
bit_pos_next = bit_pos + 1; bit_pos_next = bit_pos + 1;
// update on the falling edge // update on the falling edge
if (adc_sck) begin if (sck) begin
si_next = config_bit; si_next = config_bit;
end end
// switch state on the rising edge after the overflow // switch state on the rising edge after the overflow
// and reassert ss to start the next frame // and reassert ss to start the next frame
if (~adc_sck & (bit_pos == 31)) begin if (~sck & (bit_pos == 31)) begin
//ss_next = 0; //ss_next = 0;
state_next = ADC; state_next = ADC;
end end
@ -125,8 +125,8 @@ always @* begin
// update bit pos state on the rising edge // update bit pos state on the rising edge
// shift in data as well // shift in data as well
if (~adc_sck) begin if (~sck) begin
so_ff_next = {so_ff[14:0], adc_so}; so_ff_next = {so_ff[14:0], so};
// after reading the last bit // after reading the last bit
// deassert ss so it can be reasserted on the next rising edge // deassert ss so it can be reasserted on the next rising edge
@ -150,9 +150,9 @@ always @(posedge clk) begin
state <= state_next; state <= state_next;
bit_pos <= bit_pos_next; bit_pos <= bit_pos_next;
adc_sck_ff <= sck_next; sck_ff <= sck_next;
adc_ss_ff <= ss_next; ss_ff <= ss_next;
adc_si_ff <= si_next; si_ff <= si_next;
so_ff <= so_ff_next; so_ff <= so_ff_next;
// write the data out when write_out is asserted // write the data out when write_out is asserted

1
rtl/tb/.gitignore vendored
View File

@ -1,2 +1,3 @@
a.out a.out
*.vcd *.vcd
*_tb

9
rtl/tb/Makefile Normal file
View File

@ -0,0 +1,9 @@
tests: test_adc
test_adc: adc_driver_tb.vcd
adc_driver_tb.vcd: ./adc_driver_tb
./adc_driver_tb
adc_driver_tb: adc_driver_tb.v ../library/adc_driver.v
iverilog adc_driver_tb.v ../library/adc_driver.v -o adc_driver_tb

View File

@ -21,13 +21,13 @@ reg ack = 0;
adc_driver dut( adc_driver dut(
.clk(clk), .clk(clk),
.rstn(rstn), .rstn(rstn),
.adc_so(adc_so), .so(adc_so),
.adc_si(adc_si), .si(adc_si),
.adc_ss(adc_ss), .ss(adc_ss),
.adc_sck(adc_sck), .sck(adc_sck),
.channel(channel), .channel(channel),
.adc_val(adc_val), .val(adc_val),
.vld(vld), .vld(vld),
.ack(ack) .ack(ack)
); );