Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem in verilog code for timer

Status
Not open for further replies.

arishsu

Member level 3
Member level 3
Joined
Sep 10, 2013
Messages
66
Helped
6
Reputation
12
Reaction score
6
Trophy points
8
Location
India
Visit site
Activity points
422
Hi,
I tried to simulate a code for a timer and I got an error when I tried to synthesize on ISE. The error is as below.
"ERROR:Xst:1312 - Loop has iterated 64 times. Use "set -loop_iteration_limit XX" to iterate more."
"ERROR:Xst:1312 - Loop has iterated 64 times. Use "set -loop_iteration_limit XX" to iterate more."

my code is pasted below.


module timer_unit(LDTIM0,LDTIM1,LDTIM2,STRTIM0,STRTIM1,STRTIM2,clk,data,TIM0,TIM1,TIM2
);
input [15:0]data;
input clk,LDTIM0,LDTIM1,LDTIM2,STRTIM0,STRTIM1,STRTIM2;
output TIM0,TIM1,TIM2;
timer T0(LDTMR0,STRTIM0,clk,TIM0,data);
timer T1(LDTMR1,STRTIM1,clk,TIM1,data);
timer T2(LDTMR2,STRTIM2,clk,TIM2,data);
endmodule

module timer(LDTIM,STRTIM,clk,TIM,data);
input LDTIM,STRTIM,clk;
input [15:0] data;
output reg TIM;
reg [15:0]tmr_count;
initial tmr_count=16'b0;
always@(posedge clk)
begin
if (!LDTIM)
tmr_count=16'b0;
else
tmr_count=data;
/* end
always@(posedge clk)
begin
if (STRTIM)
begin*/
while((tmr_count>0)&&STRTIM)
begin
tmr_count=tmr_count-1;
end
while(tmr_count<=0)
begin
TIM=1;
end
end
//end
endmodule
 

You are misunderstanding the nature of iteration constructs in HDL. They are useless to implement a timer.

You'll have a reg variable tmr_count that's initially loaded and decremented each clock cycle (or initially zeroed, incremented and compared with end time) and some supplementing logic.

There are also violations of Verilog semantic, e.g. tmr_count is assigned in multiple always blocks.
 
Hi FvM,
actually i used only one always loop. 2nd one is commented out.
So you are saying there is no possibility of making such a timer using verilog? Actually our professor gave this logic and asked me to write a code for that.
Any alternative solutions for this?
 

actually i used only one always loop. 2nd one is commented out.
Yes, I overlooked this.

I just realized, that you probably only have to write if instead of while to make the code work.
 
  • Like
Reactions: zel and arishsu

    arishsu

    Points: 2
    Helpful Answer Positive Rating

    zel

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top