Altera_Forum
Honored Contributor
16 years agoHow to make sure nios send a single cycle control signal to peripheral?
hye everyone..this is a very basic question
i was testing how to control custom HW using nios. The custom HW in my case is just a simple counter. ive attach my counter to avalon bus and manage to give signal and read output from it. however a single control signal from nios triggered a few counts on my counter. e.g : if i do this in c
printf("count=%d",IORD_8DIRECT(COUNTER_0_BASE,1));
IOWR_8DIRECT(COUNTER_0_BASE,0,1);
printf("count=%d",IORD_8DIRECT(COUNTER_0_BASE,1));
the output is: 0
3but i actually want it to count up a single value each time the nios tell it to. this is my current interface for counter<->avalonbus: module avalon_counter(
//avalon signal
clk,
reset_n,
read,
write,
readdata,
writedata,
address,
chipselect,
//conduit
outCNT
);
input clk,
read,
write,
chipselect,
reset_n;
input address;
input writedata;
output reg readdata;
//component signal
reg cnt_up;
reg cnt_dwn;
wire oCNT;
//conduit signal
output outCNT;
assign outCNT = oCNT;
always@(posedge clk)
begin
if(!reset_n)
readdata <= 8'b0;
else
begin
if (chipselect == 1'b1)
begin
case(address)
1'b0:
begin
if(writedata)
begin
cnt_up<=1'b1;
cnt_dwn<=1'b0;
end
else
begin
cnt_up<=1'b0;
cnt_dwn<=1'b1;
end
end
1'b1:
readdata<={2'b00,oCNT};
endcase
end
else
begin
cnt_up <= 1'b0;
cnt_dwn<= 1'b0;
end
end
end
counter u1(
.clk(clk),
.resetn(reset_n),
.cnt_up(cnt_up),
.cnt_dwn(cnt_dwn),
.oCNT(oCNT)
);
endmodulei suspect that avalon only deassert chipselect after few cycle.so as long as the chipselect==1 cnt_up or cnt_dwn is always assert with value=1. How can i make sure that a single command from nios only trigger a single count on my counter?