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.

Help > counter stopping

Status
Not open for further replies.

sameem_shabbir

Advanced Member level 4
Joined
Jan 5, 2008
Messages
104
Helped
5
Reputation
10
Reaction score
2
Trophy points
1,298
Location
Pakistan
Activity points
1,946
Will this code stop the counter at 12?


always @ (posedge clk)
begin
if (counter >= 12)
counter <= 12;
else
counter <= counter+1;
end


If not how should i stop it on a certain value.
 

btminzon

Full Member level 2
Joined
Jun 12, 2006
Messages
122
Helped
9
Reputation
18
Reaction score
1
Trophy points
1,298
Location
Brazil
Activity points
2,144
well, analyzing the logic, yes, when reach 12, the counter assumes always 12. but, you could do as follows

if (counter < 12)
counter <= counter + 1;

unless you need to update the counter, you don´t need to keep in 12... this code above must work also. I´m not considering the fact that you are using Else, in other words, you are discarding all other solution, including negative numbers, tri-state and don´t care. good luck!!

regards

Breno
 

echo47

Advanced Member level 5
Joined
Apr 7, 2002
Messages
3,942
Helped
638
Reputation
1,274
Reaction score
89
Trophy points
1,328
Location
USA
Activity points
33,176
Both of those examples will stop at 12 when counting from a lower number, however both behave differently if 'counter' is initialized to a higher value such as 14.

If your application needs to support those higher counter values, a simple change will stop it at 12 irregardless of initial value:
if (counter != 12)
counter <= counter + 1;


Or if you like one-liners:
counter <= counter + (counter != 12);
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top