Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

What is the difference between two code?

Status
Not open for further replies.

lupineye

Junior Member level 3
Joined
Oct 30, 2006
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,522
When I make the counter with DLL, I used the below two code, but when clock goes higher, the second code didn't work. Can anyone tell me why?
thank you

first ,

process (clk, rst)
begin
if rst ='1' then
counter <= (others => '0);
elsif clk'event and clk='1' then
counter <= counter +1;
end if;
end process;

second,

process (clk, rst)
begin
if rising_edge(clk) then
if rst ='1' then
counter <= (others =>'0');
else
counter <= counter +1;
end if;
end process;
 

bansalr

Full Member level 2
Joined
Dec 22, 2005
Messages
145
Helped
17
Reputation
34
Reaction score
4
Trophy points
1,298
Activity points
2,117
The second code is fundametally worng. Remove the rst from the senstivity list.
 

ankit12345

Banned
Joined
Dec 27, 2005
Messages
181
Helped
10
Reputation
20
Reaction score
4
Trophy points
1,298
Location
bangalore,India
Activity points
0
first code has asyncronous reset................
second has synchronous reset..................

what type of reset u need????
 

Aastik

Member level 1
Joined
Oct 8, 2005
Messages
33
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Activity points
1,476
Yes, as ankit said, first code has Asynchronous reset whereas the second one has Synchronous reset. Both the schemes are ok and both are supposed to work. When you say the second code didn't work, does it mean it didn't work in simulation or it didn't work on board?
Well, one small thing...... the reset pulse width should be more than the clock period for the second code.

Regards.
 

shiv_emf

Advanced Member level 2
Joined
Aug 31, 2005
Messages
605
Helped
22
Reputation
44
Reaction score
6
Trophy points
1,298
Activity points
4,106
well for synchronous design ! v need not bother about rst .. so v can remove it frm sensitivity list ;)
 

bis_

Member level 2
Joined
Jun 21, 2006
Messages
50
Helped
14
Reputation
28
Reaction score
0
Trophy points
1,286
Activity points
1,573
add missing "end if" in second code
Code:
process (clk, rst)
begin
   if rising_edge(clk) then
      if rst ='1' then
         counter <= (others =>'0');
      else
         counter <= counter +1;
      end if;
   end if;  --<---- added line
end process;
and remember that it uses synchronous reset. it will be better if you keep "rst" in the sensitivity list.

bis
 

keano

Member level 1
Joined
Dec 24, 2004
Messages
36
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Location
TUNISIA
Activity points
251
The second code will only work if the rst is up on a rising edge of the clock.

Since it's a synchronous reset, it shouldn't be present in the sensibility list of the process.
 

xuzaiwang

Newbie level 4
Joined
Jan 2, 2007
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,300
if clock is higher, the second case will not be reset!

i.e. reset high pulse is shorter than clock period!
 

xuzaiwang

Newbie level 4
Joined
Jan 2, 2007
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,300
i.e. reset high pulse is shorter than clock period!

when clock rising, reset may be low level, so the reg signal is in unknow state forever!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top