Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers

delay

Altera_Forum
Honored Contributor II
1,230 Views

hello, 

 

i have a little question for you, guys....how can i put a delay between two if instructions (the second if to be executed after a few seconds)..........the code is in verilog. 

 

thx, tastax
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
508 Views

 

--- Quote Start ---  

hello, 

 

i have a little question for you, guys....how can i put a delay between two if instructions (the second if to be executed after a few seconds)..........the code is in verilog. 

 

thx, tastax 

--- Quote End ---  

 

Use counter.  

// very simpy without reset.  

reg [7:0] cnt; 

always @ (posedge clk) begin 

 

cnt <= cnt + 1'b1; 

 

if(condition1 && (cnt == 7'h0))begin ..... end 

if(condition2 && (cnt == 7'h3))begin ..... end 

if(condition3 && (cnt == 7'h13))begin ..... end 

 

end
0 Kudos
Altera_Forum
Honored Contributor II
508 Views

we have reset, also. The code is: 

 

always@(posedge iCLK or negedge iRST_n) 

begin 

 

if (!iRST_n) begin 

pattern_data <= 8'h00; 

cnt <= 0; 

r1<=0; 

r2<=0; 

r3<=0; 

r4<=0; 

r5<=0; 

r6<=0; 

r7<=0; 

r8<=0; 

r9<=0; 

nr1<=0; 

nr2<=0; 

nr3<=0; 

nr4<=0; 

nr5<=0; 

nr6<=0; 

nr7<=0; 

nr8<=0; 

nr9<=0; 

culoare<=1; 

once1<=0; 

once2<=0; 

once3<=0; 

once4<=0; 

once5<=0; 

once6<=0; 

once7<=0; 

once8<=0; 

once9<=0;  

cul1<=0; 

cul2<=0; 

c1<=0; 

c2<=0; 

c3<=0; 

c4<=0; 

c5<=0; 

c6<=0; 

c7<=0; 

c8<=0; 

c9<=0; 

 

end 

else if((x_cnt>(Hsync_Blank-1))&&(x_cnt<(H_LINE-Hsync_Front_Porch))) 

begin 

 

pattern_data <= graycnt; 

red_1 <= pattern_data; 

green_1 <= 0; 

blue_1 <= 0; 

cnt <= cnt + 1'b1; 

if ((iY_COORD>100)&&(iY_COORD<1370)&&(iX_COORD>100)&&(iX_COORD<1353)&&(x_cnt>750)&&(x_cnt<1010)&&(y_cnt>358)&&(y_cnt<511)) begin 

r1<=1; 

r2<=1; 

 

if ((once1 == 1'b0)&&(culoare<=9)) begin 

 

culoare<=culoare+1; 

nr1<=culoare; 

once1=1'b1; 

nr2<=culoare+1; 

if (culoare%2==1) begin 

cul1<=cul1+1; 

c1<=1; 

 

end 

else if(culoare%2==0) begin 

cul2<=cul2+1; 

c1<=2; 

end  

 

end 

 

end 

 

if ((r1)&&(x_cnt>750 )&&(x_cnt<1010)&&(y_cnt>358)&&(y_cnt<511)) // r1 "if"  

begin  

if ((nr1%2==1)) begin 

 

pattern_data <= 200; 

blue_1 <= pattern_data; 

 

 

 

end 

else if ((nr1%2==0)&&(nr1!=0)) begin  

 

pattern_data <= 200; 

green_1 <= pattern_data; 

 

end 

 

end 

if ((iY_COORD>1371)&&(iY_COORD<2677)&&(iX_COORD>100)&&(iX_COORD<1353)&&(x_cnt>485)&&(x_cnt<742)&&(y_cnt>358)&&(y_cnt<511)) begin 

 

r2<=1; 

if ((once2 == 1'b0)&&(culoare<=9)) begin 

culoare<=culoare+1; 

nr2<=culoare; 

once2=1'b1; 

if (culoare%2==1) begin 

cul1<=cul1+1; 

c2<=1; 

 

end 

else if(culoare%2==0) begin 

cul2<=cul2+1; 

c2<=2; 

end  

end 

end 

if ((r2)&&(x_cnt>485)&&(x_cnt<742)&&(y_cnt>358)&&(y_cnt<511)) // r2 "if"  

begin 

if (nr2%2==1) begin  

pattern_data <= 200; 

blue_1 <= pattern_data; 

end 

else if ((nr2%2==0)&&(nr2!=0)) begin  

pattern_data <= 200; 

green_1 <= pattern_data; 

 

end 

 

end 

end  

 

 

 

between the r1 "if" and r2 "if" we have to produce a delay. 

thx
0 Kudos
Reply