mrflibble
Advanced Member level 5
- Joined
- Apr 19, 2010
- Messages
- 2,720
- Helped
- 679
- Reputation
- 1,360
- Reaction score
- 652
- Trophy points
- 1,393
- Activity points
- 19,551
32_bit_entity <= {adc_value[3], adc_value[2], adc_value[1], adc_value[0]};
32_bit_entity <= {adc_value[2], adc_value[1], adc_value[0], adc_value[3]};
32_bit_entity <= {adc_value[1], adc_value[0], adc_value[3], adc_value[2]};
reg [31:0] 32_bit_entity;
reg [7:0] ADC_DATA = 0; // Continuously coming ADC DATA at 100 MHz Clock
reg [7:0] adc_value [0:3];
reg [1:0] idx = 0; // this will init the register to 2'b00, it also ensures the simulation is non-X
always @ (posedge 100_mhz_clk)
begin
ADC_DATA <= ADC_DATA + 1;
if (ADC_DATA == 8'b00001010)
begin
ADC_DATA <= 0;
end
end
always @ (posedge 100_mhz_clk) begin
idx <= idx + 1;
end
always @ (posedge 100_mhz_clk) begin
if (idx == 2'b00) begin
adc_value[0] <= ADC_DATA;
end
if (idx == 2'b01) begin
adc_value[1] <= ADC_DATA;
end
if (idx == 2'b10) begin
adc_value[2] <= ADC_DATA;
end
if (idx == 2'b11) begin
adc_value[3] <= ADC_DATA;
end
end
always @ (posedge 25_mhz_clk)
begin
32_bit_entity <= {adc_value[3], adc_value[2], adc_value[1], adc_value[0]};
end
Code SystemVerilog - [expand] 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 module tb_adc_and_counter; reg clk_100_mhz = 0; reg clk_25_mhz = 0; always begin # 5 clk_100_mhz <= ~clk_100_mhz; end always @* begin repeat(4) @clk_100_mhz; clk_25_mhz <= ~clk_25_mhz; end adc_and_counter DUT (.*); endmodule // tb_adc_and_counter module adc_and_counter ( input clk_100_mhz, input clk_25_mhz ); reg [31:0] entity_32_bit; reg [7:0] ADC_DATA = 0; // Continuously coming ADC DATA at 100 MHz Clock reg [7:0] adc_value [0:3]; reg [1:0] idx = 0; // This will init the register to 2'b00, it also ensures the simulation is non-X always @ (posedge clk_100_mhz) begin // ADC_DATA goes through 0 .. 84 in increments of 7, for a total of 13 steps. // The reason we pick an increment like 7 (instead of 1) is to make it // easier to see where numbers are coming from. Same thing goes for // the loop count of 13 (instead of 10). if (ADC_DATA == (12*7)) begin ADC_DATA <= 0; end else begin ADC_DATA <= ADC_DATA + (1*7); end idx <= idx + 1; case (idx) 2'b00: adc_value[0] <= ADC_DATA; 2'b01: adc_value[1] <= ADC_DATA; 2'b10: adc_value[2] <= ADC_DATA; 2'b11: adc_value[3] <= ADC_DATA; endcase end // TODO: replace this with a block clocked by clk_100_mhz, and use a Clock Enable. always @ (posedge clk_25_mhz) begin entity_32_bit <= {adc_value[3], adc_value[2], adc_value[1], adc_value[0]}; end endmodule // adc_and_counter
Code Verilog - [expand] 1 2 3 4 5 always @ (posedge 100_mhz_clk) begin if (idx == 0) begin 32_bit_entity <= {adc_value[3], adc_value[2], adc_value[1], adc_value[0]}; end end
Now you spoiled the exercise for the reader.// TODO: replace this with a block clocked by clk_100_mhz, and use a Clock Enable.
Now you spoiled the exercise for the reader.
But yes, this is a perfect example of why you want to use clock enables.
Hi, Thanks this works fine.Try that instead of the code you're using, this code should only update the 32_bit_entity when all 4 indices have been updated.
Code Verilog - [expand] 1 2 3 4 5 6 7 always @ (posedge 100_mhz_clk) begin if (idx == 0) begin fifo_write <= 1; input_to_fifo <= {adc_value[3], adc_value[2], adc_value[1], adc_value[0]}; end end
Code Verilog - [expand] 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 dcfifo #( .intended_device_family ("Cyclone IV"), .lpm_numwords(4096), .lpm_showahead("OFF"), .lpm_type("dcfifo"), .lpm_width(32), .lpm_widthu(12), .overflow_checking("ON"), .rdsync_delaypipe(4), .read_aclr_synch("ON"), .underflow_checking("ON"), .use_eab("ON"), .write_aclr_synch("ON"), .wrsync_delaypipe(4) ) Inst_FIFO ( .aclr(reset_n), .wrclk(test_100_mhz), .wrreq(fifo_write), .wrfull(fifo_full), .data(input_to_fifo), .rdclk(test_25_mhz), .rdreq(fifo_read), .rdempty(fifo_empty), .q(output_from_fifo) );
Code Verilog - [expand] 1 2 3 4 5 always @ (posedge 25_mhz_clk) begin fifo_read <= 1; GPIO <= output_from_fifo; end end
and read it at 25 MHz at output as:
Code Verilog - [expand] 1 2 3 4 5 always @ (posedge 25_mhz_clk) begin fifo_read <= 1; GPIO <= output_from_fifo; end end
and put signal tap at GPIO pin. but unfortunately I don't have expected output. and yes I am missing the concept of controlling fifo_full and fifo_empty signal in this continuous data flow.
Regards
Hi, here is the complete code:Also saying you don't have expected output is not going to help us help you. Explain exactly what is wrong with the output, include input and output data if possible.
Code Verilog - [expand] 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 module test( //////////// CLOCK ////////// CLOCK_50, CLOCK2_50, CLOCK3_50, //////////// LED ////////// LEDG, LEDR, //////////// KEY ////////// KEY, //////////// SW ////////// SW, //////////// GPIO, GPIO connect to GPIO Default ////////// GPIO ); //////////// CLOCK ////////// input CLOCK_50; input CLOCK2_50; input CLOCK3_50; //////////// LED ////////// output [8:0] LEDG; output [17:0] LEDR; //////////// KEY ////////// input [3:0] KEY; //////////// SW ////////// input [17:0] SW; //////////// GPIO, GPIO connect to GPIO Default ////////// inout reg [31:0] GPIO; wire fifo_rclk; wire fifo_empty; reg fifo_read; reg fifo_write; wire fifo_full; wire test_250_mhz, test_125_mhz, test_100_mhz, test_25_mhz, test_12p5_mhz; reg [31:0] output_from_fifo; reg [31:0] input_to_fifo; reg [7:0] ADC_DATA = 0; // Continuously coming ADC DATA at 100 MHz Clock reg [7:0] adc_value [0:3]; // To store 4 values of ADC DATA. reg [1:0] idx = 0; // this will init the register to 2'b00, it also ensures the simulation is non-X always @ (posedge test_100_mhz) begin ADC_DATA <= ADC_DATA + 1; if (ADC_DATA == 8'b00011111) begin ADC_DATA <= 0; end end always @ (posedge test_100_mhz) begin idx <= idx + 1; adc_value[idx] <= ADC_DATA; end always @ (posedge test_100_mhz) begin if (idx == 0) begin if(fifo_full == 1) begin fifo_write <= 0; end else begin fifo_write <= 1; input_to_fifo <= {adc_value[0], adc_value[1], adc_value[2], adc_value[3]}; end end end pll_test pll_test ( .inclk0(CLOCK3_50), .c0(test_100_mhz), .c1(test_25_mhz), .c2(test_12p5_mhz), .c3(test_250_mhz), .c4(test_125_mhz) ); dcfifo #( .intended_device_family ("Cyclone IV"), .lpm_numwords(4096), .lpm_showahead("OFF"), .lpm_type("dcfifo"), .lpm_width(32), .lpm_widthu(12), .overflow_checking("ON"), .rdsync_delaypipe(4), .read_aclr_synch("ON"), .underflow_checking("ON"), .use_eab("ON"), .write_aclr_synch("ON"), .wrsync_delaypipe(4) ) Inst_RxFIFO ( .aclr(global_reset_n), .wrclk(test_100_mhz), .wrreq(fifo_write), .wrfull(fifo_full), .data(input_to_fifo), .rdclk(test_100_mhz), .rdreq(fifo_read), .rdempty(fifo_empty), .q(output_from_fifo) ); always @ (posedge test_25_mhz) begin if (fifo_empty == 1) begin fifo_read <= 0; end else begin fifo_read <= 1; GPIO <= output_from_fifo; end end endmodule
and in attachment, screenshot of signal tap at 25 MHz and 100 MHz.
What I didn't understand in signal tap are:
1. Although I am running signal tap at 25 MHZ, why value in GPIO comes after 3 clock cycles compared to input_to_fifo/data pin of FIFO and why rdclk and wrclk is always high.
2. while running signal tap at 100 MHz, why value in GPIO comes after 2 clock cycles compared to input_to_fifo/data pin of FIFO. and again rdclk and wrclk is always high.
3. How to control wrfull and rdempty of Dual Clock FIFO in case there is continuous flow of data and don't want to loose any data provided input and output running at different clock.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?