@@ -33,7 +33,7 @@ reg [4:0] in_hold_reg = 5'b0; // shift reg for signal hold time checks
3333reg [3 :0 ] sample_count = 4'b0 ; // count ticks for 16x oversample
3434reg [4 :0 ] out_hold_count = 5'b0 ; // count ticks before clearing output data
3535reg [2 :0 ] bit_index = 3'b0 ; // index for 8-bit data
36- reg [7 :0 ] received_data = 8'b0 ; // storage for the deserialized data
36+ reg [7 :0 ] received_data = 8'b0 ; // shift reg for the deserialized data
3737wire in_sample;
3838wire [3 :0 ] in_prior_hold_reg;
3939wire [3 :0 ] in_current_hold_reg;
@@ -155,7 +155,7 @@ always @(posedge clk) begin
155155 if (& sample_count) begin // reached 15
156156 // sample_count wraps around to zero
157157 bit_index <= 3'b1 ;
158- received_data <= { 7'b0 , in_sample };
158+ received_data <= { in_sample, 7'b0 };
159159 out <= 8'b0 ;
160160 state <= `DATA_BITS;
161161 end
@@ -165,14 +165,18 @@ always @(posedge clk) begin
165165 /*
166166 * Take 8 baud intervals to receive serial data
167167 */
168- sample_count <= sample_count + 4'b1 ;
168+ sample_count <= sample_count + 4'b1 ;
169169 if (& sample_count) begin // reached 15 - save one more bit of data
170- received_data[bit_index] <= in_sample;
171- bit_index <= bit_index + 3'b1 ;
170+ // store the bit using a shift register: the hardware
171+ // realization is simple compared to routing the bit
172+ // dynamically, i.e. using received_data[bit_index]
173+ received_data <= { in_sample, received_data[7 :1 ] };
174+ // manage the state transition
175+ bit_index <= bit_index + 3'b1 ;
172176 if (& bit_index) begin
173177 // bit_index wraps around to zero
174178 // sample_count wraps around to zero
175- state <= `STOP_BIT;
179+ state <= `STOP_BIT;
176180 end
177181 end
178182 end
0 commit comments