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

VHDL code to a logic circuit

Status
Not open for further replies.

daisyzari

Junior Member level 3
Joined
Feb 8, 2011
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,907
I'm having difficulty understanding this part of code that I've been using in my I2C project.

Code:
gen_clken: process(clk, nReset)
begin
if (nReset = '0') then
cnt <= (others => '0');
clk_en <= '1'; --'0';
elsif (clk'event and clk = '1') then
if (cnt = 0) then
clk_en <= '1';
cnt <= clk_cnt; -- loading of clk_cnt when clk_en is disabled
else
if (slave_wait = '0') then
cnt <= cnt -1;
end if;
clk_en <= '0';
end if;
end if;

end process gen_clken;
I actually need to translate this code into a logical circuit. And so it is important that I understand this code.
Can anyone pls help me understand and translate this code into a logical circuit?

Thank you :grin:
 

Alexium

Full Member level 2
Joined
Jan 6, 2011
Messages
148
Helped
39
Reputation
78
Reaction score
39
Trophy points
1,308
Location
Ukraine
Activity points
2,163
Why don't you synthesise the code and study the RTL scheme?
Besides, the code is pretty simple and straightforward. Is there some specific aspect you don't understand, or you need a full explanation?
 
  • Like
Reactions: FvM

    FvM

    points: 2
    Helpful Answer Positive Rating

daisyzari

Junior Member level 3
Joined
Feb 8, 2011
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,907
Why don't you synthesise the code and study the RTL scheme?
Besides, the code is pretty simple and straightforward. Is there some specific aspect you don't understand, or you need a full explanation?
I did checkk the RTL of the code but I can't seem to understand it along with the code. It seems to be some sort of clock divider to another code but I don't how it works as a clock divider for that code. Can you please explain to us how the code works thank you very much.
 

atulaxc

Member level 1
Joined
Jan 25, 2010
Messages
39
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,288
Activity points
1,467
Here is some explanation in blue, I have divided the code in three parts
Part 1 ----
if (nReset = '0') then
cnt <= (others => '0');
clk_en <= '1'; --'0';
----------------------
At reset cnt = 0 and clk_en =1 is
----------------------
Part 2 -----
elsif (clk'event and clk = '1') then
if (cnt = 0) then
clk_en <= '1';
cnt <= clk_cnt; -- loading of clk_cnt when clk_en is disabled
else
-----------------
When not in reset then with every rising edge of clock load cnt with clk_cnt and keep clk_en 1
-----------------
Part 3 ---
if (slave_wait = '0') then
cnt <= cnt -1;
end if;
clk_en <= '0';
end if;
end if;
-------------------------
If not in reset and no rising edge on clock then decrement the cnt and clear clk_en = 0
--------------------------
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,967
Helped
14,147
Reputation
28,553
Reaction score
12,834
Trophy points
1,393
Location
Bochum, Germany
Activity points
278,259
-------------------------
If not in reset and no rising edge on clock then decrement the cnt and clear clk_en = 0
--------------------------
Please reconsider!

Although the code can be analyzed as such, I don't think it's reasonable to cut a small snippet from a project (an I2C controller from opencores.org) and ask for an explanation. If you know the meaning of the involved signals, it can be understood better. You also omitted comments around the code snippet. Finally, a project link should be given.
 

Alexium

Full Member level 2
Joined
Jan 6, 2011
Messages
148
Helped
39
Reputation
78
Reaction score
39
Trophy points
1,308
Location
Ukraine
Activity points
2,163
-------------------------
If not in reset and no rising edge on clock then decrement the cnt and clear clk_en = 0
--------------------------
The explanation is wrong. You can't do something when there is "no rising edge", it doesn't make sense.
 

atulaxc

Member level 1
Joined
Jan 25, 2010
Messages
39
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,288
Activity points
1,467
You can still decrement on negative edge of clock or have a counter which is pure combinatorial .. We need to first know the entire code to know it in details. Its quite possible that the printed code is not correct.
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,967
Helped
14,147
Reputation
28,553
Reaction score
12,834
Trophy points
1,393
Location
Bochum, Germany
Activity points
278,259
You can still decrement on negative edge of clock or have a counter which is pure combinatorial ..
..
Its quite possible that the printed code is not correct
The present code, which is a correct excerpt from a opencores project, is actually counting on rising edge. As already mentioned, I agree to your comment about posting more code.

I don't see however, how a "pure combinational counter" in synthesized hardware should work. I know, that asynchronous logic design exists as an alternative method to usual synchronous design. But it needs at least an enable signal with handshake to signal events.

A logic implementing your description
If not in reset and no rising edge on clock then decrement the cnt and clear clk_en = 0
won't be synthesizable and bring up an error message like "state of signal cnt[x] isn't preserved outside clock edges".
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top