初学FPGA,在写一个UART的接收代码,用的是3段式写法;遇到一个奇怪的现象:明明使用了default语句,可状态机一直停留在非法的状态。试着把状态机输出到FPGA引脚观测它的状态,UART居然又正常了! 另:用的是xilinx spartan2 , ISE6.3 各位熟悉FPGA的兄弟指点一下!
module uart(Rxd,ledout,clk,monitor); input Rxd; output [7:0] ledout; input clk; output [10:0] monitor;
... ...
always@(posedge clk) if(Baud16Tick) begin CS <= NS; pulse <= ~pulse; end
always@(CS or ...) begin case(CS) RX_IDLE: ... NS = RX_START: ... NS = RX_BIT0: ... NS = RX_BIT1: ... NS = RX_BIT2: ... NS = RX_BIT3: ... NS = RX_BIT4: ... NS = RX_BIT5: ... NS = RX_BIT6: ... NS = RX_BIT7: ... NS = RX_STOP: ... NS = default: NS = RX_IDLE; endcase end
always@(CS) begin case(CS) RX_IDLE: monitor_reg = 4'b0000; RX_START:monitor_reg = 4'b0001; RX_BIT0: monitor_reg = 4'b0010; RX_BIT1: monitor_reg = 4'b0010; RX_BIT2: monitor_reg = 4'b0010; RX_BIT3: monitor_reg = 4'b0010; RX_BIT4: monitor_reg = 4'b0010; RX_BIT5: monitor_reg = 4'b0010; RX_BIT6: monitor_reg = 4'b0010; RX_BIT7: monitor_reg = 4'b0010; RX_STOP: monitor_reg = 4'b0100; default: monitor_reg = 4'b1000; (把编译好的代码下载到FPGA后,monitor_reg输出1000; endcase
// monitor_reg = CS; (去掉上面的case部分,保留这句,则UART正常运行) end
assign ledout = ~RxBuffer; ...
endmodule
|