【常用电路】线性反馈移位寄存器(LFSR)
读华为技术文档《FIFO经验谈》看到的这个电路:
FIFO的读写地址产生比较简单,当读使能有效时,在时钟作用下,读地址加1;当写使能有效时,写地址加1。
当FIFO深度较大时,同时FIFO的速度要求较高时,可以采用线性反馈移位计数器 (LFSR)。它的速度非常快,但是要牺牲一个地址。
针对同步的大FIFO,它们的读写地址完全可以使用线性反馈移位寄存器 LFSR 产生,而不 是简单的加1操作,极大的提高了速度,如果对FIFO的利用率没有很高要求的时候,推荐使用该方法。使用LFSR的优点是在XILINX的FPGA中布线,可以使用LUT直接完成。
1 /************************************************************\ 2 * * 3 * Generation of Read and Write address pointers. They use * 4 * LFSR counters, which are very fast. Because of the * 5 * nature of LFSR, one address is sacrificed. * 6 * * 7 \************************************************************/ 8 wire read_linearfeedback, write_linearfeedback; 9 10 assign read_linearfeedback = ! (read_addr[8] ^ read_addr[4]); 11 assign write_linearfeedback = ! (write_addr[8] ^ write_addr[4]); 12 13 always @(posedge clock or posedge fifo_gsr) 14 if (fifo_gsr) read_addr <= 9'h0; 15 else if (read_allow) 16 read_addr <= { read_addr[7], read_addr[6], read_addr[5], 17 read_addr[4], read_addr[3], read_addr[2], 18 read_addr[1], read_addr[0], read_linearfeedback }; 19 20 always @(posedge clock or posedge fifo_gsr) 21 if (fifo_gsr) write_addr <= 9'h0 22 else if (write_allow) 23 write_addr <= { write_addr[7], write_addr[6], write_addr[5], 24 write_addr[4], write_addr[3], write_addr[2], 25 write_addr[1], write_addr[0], write_linearfeedback };