如何对外部脉冲进行记数?好象timer core不能对外部的脉冲进行记数的
请高手解答下 ,谢谢了!
做一个记数模块完成记数,并做成Avalon总线从设备,nios ii通过Avalon访问记数值
可以用中断,来一个脉冲就+1
用中断的方式不太好,如果计数很频繁会影响系统的稳定性.最好用硬件逻辑来计数,传送给nios.
写了个模块 ,调试时总是读不出来值,请大家知道下,鉴别下哪里出错了.
module counter(
reset_n,
clk_av,
io,
s_address,
s_chipselect,
s_read_n,
s_write_n,
s_writedata,
s_readdata
);
input reset_n;
input clk_av;
input io;
input [15:0] s_address;
input s_chipselect;
input s_read_n;
input s_write_n;
input [15:0] s_writedata;
output [15:0] s_readdata;
reg [15:0] s_readdata;
reg [15:0] counter_reg;
reg [15:0] counter;
reg [15:0] start_reg;
reg [15:0] end_reg;
always@(posedge clk_av or negedge reset_n)
begin
counter_reg <= counter;
if(~reset_n)
counter_reg <= 16'd0;
else if(s_chipselect &(~s_write_n)&(s_address == 16'd0))
counter_reg <= s_writedata;
end
always@(posedge clk_av or negedge reset_n)
begin
if(~reset_n)
start_reg <= 16'd0;
else if(s_chipselect &(~s_write_n)&(s_address == 16'd1))
start_reg <= s_writedata;
end
always@(posedge clk_av or negedge reset_n)
begin
if(~reset_n)
s_readdata <= 16'd0;
else if(s_chipselect &(~s_read_n))
begin
case(s_address)
16'd0:
s_readdata <= counter_reg; //16'h00ff;//
16'd1:
s_readdata <= start_reg;
default:
s_readdata <= 16'dz;
endcase
end
end
always@(io)
begin
if(start_reg==16'd1)
counter <= counter + 1;
end
endmodule
always@(io)
begin
if(start_reg==16'd1)
counter <= counter + 1;
end
这段话你的计数器不用时钟驱动,那怎么计数呢??
改成
always@(posedge io)
begin
if(start_reg==16'd1)
counter <= counter + 1;
end
来一个脉冲增加一个值可以不?
这个io是外部脉冲的输入阿 ,我要记下的就是这个外部脉冲的输入数
nios要读取这个计数值还是要clk_av来操作地址的吧
我是这样理解的。
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |