?? speed_select.v.bak
字號:
module speed_select(clk,rst_n,bps_start,clk_bps);
input clk; // 50MHz主時鐘
input rst_n; //低電平復位信號
input bps_start; //接收到數據后,波特率時鐘啟動信號置位
output clk_bps; // clk_bps的高電平為接收或者發送數據位的中間采樣點
parameter bps9600 = 5207, //波特率為9600bps
bps19200 = 2603, //波特率為19200bps
bps38400 = 1301, //波特率為38400bps
bps57600 = 867, //波特率為57600bps
bps115200 = 433; //波特率為115200bps
parameter bps9600_2 = 2603,
bps19200_2 = 1301,
bps38400_2 = 650,
bps57600_2 = 433,
bps115200_2 = 216;
reg[12:0] bps_para; //分頻計數最大值
reg[12:0] bps_para_2; //分頻計數的一半
reg[12:0] cnt; //分頻計數
reg clk_bps_r; //波特率時鐘寄存器
//----------------------------------------------------------
reg[2:0] uart_ctrl; // uart波特率選擇寄存器
//----------------------------------------------------------
always @ (posedge clk or negedge rst_n) begin
if(!rst_n) begin
uart_ctrl <= 3'd0; //默認波特率為9600bps
end
else begin
case (uart_ctrl) //波特率設置
3'd0: begin
bps_para <= bps9600;
bps_para_2 <= bps9600_2;
end
3'd1: begin
bps_para <= bps19200;
bps_para_2 <= bps19200_2;
end
3'd2: begin
bps_para <= bps38400;
bps_para_2 <= bps38400_2;
end
3'd3: begin
bps_para <= bps57600;
bps_para_2 <= bps57600_2;
end
3'd4: begin
bps_para <= bps115200;
bps_para_2 <= bps115200_2;
end
default: ;
endcase
end
end
always @ (posedge clk or negedge rst_n)
if(!rst_n) cnt <= 13'd0;
else if(cnt<bps_para && bps_start) cnt <= cnt+1'b1; //波特率時鐘計數啟動
else cnt <= 13'd0;
always @ (posedge clk or negedge rst_n)
if(!rst_n) clk_bps_r <= 1'b0;
else if(cnt==bps_para_2 && bps_start) clk_bps_r <= 1'b1; // clk_bps_r高電平為接收或者發送數據位的中間采樣點
else clk_bps_r <= 1'b0;
assign clk_bps = clk_bps_r;
endmodule
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -