1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
Hi there, anyone can explain the whole coding above for me? I need each explanation for each line. Thanks alot.
VHDL coding explanation.
Hi there, anyone can explain the whole coding above for me? I need each explanation for each line. Thanks alot.
Guest
#2188555
Is the code snipped above in a clocked process ? Maybe you are able to post the whole code, so we can see it in connection. best regards Tobias
This is the full coding. You want me to post the test bench too? Kelly N. wrote: > Hi there, anyone can explain the whole coding above for me? > I need each explanation for each line. I don't think that makes any sense, because each line itself describes, what it does... :-o Much more useful is a description, what the whole thing does... It is a synchronous counter: http://faculty.kfupm.edu.sa/COE/ashraf/RichFilesTeaching/COE022_200/Chapter%205.htm http://tams-www.informatik.uni-hamburg.de/applets/hades/webdemos/30-counters/30-sync/sync-dff_print.html Like I still don't understand how it works. Why is the coding like this. & why we need to c(0) <= not c(0); in the first place.
Guest
#2188645
if you count up, the LSB is always alternating. this is what this
particular line does. all other lines represent adders.
carry(x) holds the carry of the addition 'before' the bit.
c(1)<= c(1) xor carry(0);
carry(1) := c(1) and carry(0);
0+0 = 00
1+0 = 01
0+1 = 01
1+1 = 10
the XOR calculates the LSB, the AND the MSB of each addition.
Alright. This applies to all the lines after that right? But why in the first place they need c(0) <= not c(0); the initial of c(0) is 00000000 am I right? Kelly N. wrote: > the initial of c(0) is 00000000 am I right? Ist is only one bit and therefore just '0'... :-/ > Like I still don't understand how it works. > Why is the coding like this. > & why we need to > c(0) <= not c(0); > > in the first place. Did you have a look for http://tams-www.informatik.uni-hamburg.de/applets/hades/webdemos/30-counters/30-sync/sync-dff.html Did you see the most left XOR? With the enable signal permanently '1' this is just an inverter. And that results in a simple NOT. If you want to describe the schematic there http://tams-www.informatik.uni-hamburg.de/applets/hades/webdemos/30-counters/30-sync/sync-dff.html you must do it that way (referring to your posted code):
BTW: You will not find this component on any FPGA (hardly anywhere on earth):
It seems to me thats Verilog thinking: always @(posedge reset)... But you will not find a flipflop, thats sensitive to two (different) clock signals!!! Instead the Reset is level sensitive:
Sorry. My understand might be low. I don't get you. Whats your question? What do you not understand? > But why in the first place they need > c(0) <= not c(0); If you pick any stage in the middle of the code and do a slightliy reformatting, then you see
Each stage refers to the previous stage. So for a 212 bit witdh the last entries will be
Its easy, isn't it? And now: what to do with stage 0?
And because we don't have a stage '-1' we substitute it with a logic '1':
And now a little bit boolean equation magic: What is XX AND '1'? Correct answer: XX What is YY XOR '1'? Correct answer: NOT YY And if you take this knowledge into your code it results in:
I think somehow I understand. But I want to ask one very stupid question. <= & := what's the different & means? > <= & := what's the different & means?
Take ANY VHDL book and have a look for the different behaviuor of
signals and variables.
And after that: as a VHDL beginner forget_variables for (at least) the
next half year!
Hi, I could get the waveform from 00000000, 00000001, 000000010, 00000011. But I don't understand how it get with the coding above. I understand the first 2 lines. But from 3rd lines onwards, I couldn't understand. When i work out, I get c(1) = '1' - 00000010 carry(1) = '1' - 00000010 c(2) = '1' - 00000100 carry(2) = '1' 00000100 Is this the correct way of doing? > I understand the first 2 lines.
I'm not sure with that...
Lets say we start with values like this:
s is a std_logic signal
v is a std_logic variable
Lets define:
Both of them start with a value '0', so we have s = '0' and v = '0'
And now we add a clock and enter a process like this:
So tell me: whats the value of s and v after one rising edge of clk? And now the same here:
Again: telle me whats the value of s and v after one rising edge of clk?
> c(2) = '1' - 00000100
This is nonsense: you cannot subtract a vector from one bit!
But I understand what you mean... ;-)
signal s : std_logic := '0';
process (clk)
variable v : std_logic := '0';
begin
if rising_edge(clk) then
s <= '1';
v := s;
end if;
end process;
So tell me: whats the value of s and v after one rising edge of clk?
s = 1
v = 1 ?
signal s : std_logic := '0';
process (clk)
variable v : std_logic := '0';
begin
if rising_edge(clk) then
v := '1';
s <= v;
end if;
end process;
Again: telle me whats the value of s and v after one rising edge of clk?
s = 1
v = 1 ?
> c(2) = '1' - 00000100
This is nonsense: you cannot subtract a vector from one bit!
But I understand what you mean... ;-)
I mean c(2) = 00000100 not 1-00000100. :D
But is it correcT?
> Again: telle me whats ... s = 1 v = 1 ? The second one you got correct. > So tell me: whats the value .... s = 1 v = 1 ? Wrong! In the first sample we have s = '1' and v = '0'. Thats the behaviour of signals!!! (And your problem at the moment!) The value of each signal remains throughout the whole process. The assignment of the signals "new" value is done at "end process". So check this:
Whats the result?
Guest
#2191487
Kelly N. wrote: > s = 1 > v = 1 ? > ... > s = 1 > v = 1 ? This is your guess. What is the result from your simulator? Duke > What is the result from your simulator?
One should not need a simulator for this...
But it could be a tool to come behind the (different) behaviour of
signals and variables in a process ;-)
a = 1 b = 1 x = 0 y = 0 c = 1 z = 0 Correct? > Correct? Whats your simulators opinion? > Correct? No... :-( This is the result: a = 1 b = 0 !! x = 0 y = 1 !! c = 1 z = 0 The short way: Variables take over the new value immediately. Signals take over the last assigned value at the end of the process. I'm confuse now. We should look at the operator (<= / :=) or ? > We should look at the operator (<= / :=) or ?
Not particular!
The assignment token is just a indication for a signal or a variable.
The := is the assignment symbol necessary for variables, the <= is the
one for the signals.
You must know the difference of the behaviour between signals and
variables, not the difference of the assignment tokens. If you ause the
:= instead of the <= then your simulator/synthesizer generates a error.
But if you use a variable where you should use a signal, then no error
is generated, but you get a different behaviour...
I don't know the behaviour of signals and variables. Can explain a bit to me? > I don't know the behaviour of signals and variables. > Can explain a bit to me? I did already... :-/ But here once more: a signal keeps its entry value throughout the whole process. At the end of the process it takes over the last assigned value. A variable takes immediately over the assigned value. See this:
So at the end of this process we have s = 777, v = 777 And now you must take any book about VHDL and a simulator and check it out for yourself. Alright! thanks so much! i get it now. :) Sorry, I got question on my coding. Let's say
c(1) = '0'
carry(0) = '1'
I need find out carry (1)
c(1) <= c(1) xor carry(0);
0 xor 1 = 1
So c(1) <= next = 1, current = 0 ? am I right?
Then when I need to find the carry (1) := c(1) and carry(0);
the c(1) which value should I use?
> the c(1) which value should I use? c is a signal and therefore it does not change its value until the end of the process. Then it will get the last assigned value. > c(1) = '0' > carry(0) = '1' > I need find out carry (1)
Hi, I got question. [code] C(0) <= NOT c(0); Carry(0) := c(0); C(1) <= c(1) XOR carry (0) Carry(1) := c(1) AND c(0) If I were to keep contiune process. I would need to run again and again. I got mix up. The coding start with 00 00 01 10 11 I should get this result I try to work it out but I got confuse. C(0) <= NOT c(0); -- c(0) = current: 0. Next: 1 Carry(0) := c(0); -- carry(0)= 0 C(1) <= c(1) XOR carry (0). -- c(1) = current: 0. Next: 0 Carry(1) := c(1) AND c(0) -- carry(1)= 0 Am I right? Which value should I use when I execute again? I got confuse by this. ReplyPlease log in before posting. |