- Avalon是一个总线协议,设计的必须符合接口协议。具体协议上传到资源中,自行下载。
信号定义: - 示例pwm设计ip并调用
module pwm_logic(
input clk ,
input rst_n ,
input en ,
input [31:0] counter_arr ,
input [31:0] counter_ccr ,
output reg pwm
);
reg [31:0] cnt;
wire add_cnt;
wire end_cnt;
reg [31:0] counter_ccr_r;
always @(posedge clk or negedge rst_n)begin
if(!rst_n)begin
cnt <= 0;
end
else if(add_cnt)begin
if(end_cnt)begin
cnt <= 0;
end
else begin
cnt <= cnt + 1;
end
end
end
assign add_cnt = en;
assign end_cnt = add_cnt && cnt == counter_arr - 1;
always @(posedge clk)begin
if(!cnt)begin
counter_ccr_r <= counter_ccr;
end
else begin
counter_ccr_r <= counter_ccr_r;
end
end
always @(posedge clk or negedge rst_n)begin
if(!rst_n)begin
pwm <= 1'b0;
end
else if(cnt >= counter_ccr_r)begin
pwm <= 1'b1;
end
else if(cnt < counter_ccr_r )begin
pwm <= 1'b0;
end
else begin
pwm <= pwm ;
end
end
endmodule
avalone接口协议
module pwm_avalon_port(
input clk ,
input rst_n ,
input as_chipselect,
input [1:0] as_address ,
input as_write ,
input [31:0] as_writedata ,
output reg [31:0] as_readdata ,
output wire pwm_dout
);
reg control;
reg [31:0] counter_arr;
reg [31:0] counter_ccr;
always @(posedge clk or negedge rst_n)begin
if(!rst_n)begin
counter_arr <= 32'b0;
end
else if(as_chipselect && as_write && (as_address == 0))begin
counter_arr <= as_writedata;
end
else begin
counter_arr <= counter_arr;
end
end
always @(posedge clk or negedge rst_n)begin
if(!rst_n)begin
counter_ccr <= 32'b0;
end
else if(as_chipselect && as_write && (as_address == 1))begin
counter_ccr <= as_writedata;
end
else begin
counter_ccr <= counter_ccr;
end
end
always @(posedge clk or negedge rst_n)begin
if(!rst_n)begin
control <= 1'b0;
end
else if(as_chipselect && as_write && (as_address == 2))begin
control <= as_writedata[0];
end
else begin
control <= control;
end
end
always @(posedge clk or negedge rst_n)begin
if(!rst_n)begin
as_readdata <= 32'b0;
end
else if(as_chipselect)begin
case (as_address)
0: as_readdata <= counter_arr ;
1: as_readdata <= counter_ccr ;
2: as_readdata <= control ;
default: as_readdata <= 32'b0;
endcase
end
end
pwm_logic inst_pwm_logic(
.clk (clk ),
.rst_n (rst_n ),
.en (control ),
.counter_arr (counter_arr),
.counter_ccr (counter_ccr),
.pwm (pwm_dout )
);
endmodule
- 具体操作流程
|