Sobakava
Full Member level 6
simple verilog question
I implemented a pattern generator using Verilog and XC9500 CPLD.
Pattern generated with a clock input.
There is a counter, it counts and there is a Case//endcase block which process counter value and generates pulses...
When counter reaches to 21048, I set it to 0 and next frame starts...
While running my pattern generator freely, there is no problem...
But now I need to control generator with an external trigger...
If a negative or positive edge detected from START pin, it
generator should run for ONCE... Only one turn should be done,
then when it reaches to 21048, it should stop until next START trigger...
input main_clock;
reg counter[14:0];
reg can_read=0;
always @(posedge main_clock)
begin
if (counter==21048)
begin
counter=0;
can_read=0;
end
if (can_read)
begin // begin can read it
counter=counter+1;
case (counter)
1: begin ... end
2: begin ... end
endcase
end
end
I added a reg called as CAN_READ to the design...
input readit;
always @(posedge readit)
begin
can_read=1;
end
As I mentioned, when a positive edge detected at pin READIT, can_read bit will set and main_clk will generate pattern until can_read remains set. When counter reaches to 21048, can_read will be resetted and pattern generator will stop...
Xilinx ISE can implement this design and I load it to chip, but it seems it does not work... Generator always runs and I can not stop it using READIT pin....
Isn't it possible to set/reset a register (can_read) in two different always@(posedge....) blocks?
Any opinion?
I implemented a pattern generator using Verilog and XC9500 CPLD.
Pattern generated with a clock input.
There is a counter, it counts and there is a Case//endcase block which process counter value and generates pulses...
When counter reaches to 21048, I set it to 0 and next frame starts...
While running my pattern generator freely, there is no problem...
But now I need to control generator with an external trigger...
If a negative or positive edge detected from START pin, it
generator should run for ONCE... Only one turn should be done,
then when it reaches to 21048, it should stop until next START trigger...
input main_clock;
reg counter[14:0];
reg can_read=0;
always @(posedge main_clock)
begin
if (counter==21048)
begin
counter=0;
can_read=0;
end
if (can_read)
begin // begin can read it
counter=counter+1;
case (counter)
1: begin ... end
2: begin ... end
endcase
end
end
I added a reg called as CAN_READ to the design...
input readit;
always @(posedge readit)
begin
can_read=1;
end
As I mentioned, when a positive edge detected at pin READIT, can_read bit will set and main_clk will generate pattern until can_read remains set. When counter reaches to 21048, can_read will be resetted and pattern generator will stop...
Xilinx ISE can implement this design and I load it to chip, but it seems it does not work... Generator always runs and I can not stop it using READIT pin....
Isn't it possible to set/reset a register (can_read) in two different always@(posedge....) blocks?
Any opinion?