Alex wrote:
> So I wrote this vhdl program with the use of the Design below .
I don't see the faintest relation between the picture and your code.
The picture does not show any shift register, but instead an
asynchronous ripple counter! Try "jk ripple counter" with google and to
find some information.
> Is what I'm writing correct or not ?
What does the syntax checker tell about your code? What does the
simulation show with your code? What about the clr signal? Where does it
come from? What should happen to d with each clock? Why is there an "end
case" midst in th code?
1 | process(CLK)
|
2 | if (clr='1') then -- WARNING incomplete sensitivity list!!
|
3 | -- ERROR what the heck is "clr"?
|
4 | temp <= "0000";
|
5 | O <= "0000";
|
6 | end if ;
|
7 | else if (clk ='1' and clk'event) then -- ERROR due to previous end if!!
|
8 | --Right shift -- INFO: the synthesizer does not interpret comments
|
9 | -- It simply transfers the rest of the code to hardware!
|
10 | temp <= d;
|
11 | temp(2 downto 0) <= temp(3 downto 1);
|
12 | temp (3) <= '0';
|
13 | O <= temp;
|
14 | end case; -- ERROR end of what case??
|
15 | end if;
|
16 | end process;
|
And when I look at this code snippet I urge you to read more about the
behaviour of signals in processes:
1 | temp <= d;
|
2 | temp(2 downto 0) <= temp(3 downto 1);
|
3 | temp (3) <= '0';
|
4 | O <= temp;
|
That behaviour may look strange to a top-down-softeware-programmer:
signals do NOT change their "start-values" throughout the whole process.
And at the end of the process "the last assignment wins". So this code
could be rearranged this way withou any chage in the result:
1 | O <= temp; -- the one and only assignment to O, so it could be placed anywhere
|
2 | -- temp <= d; -- simply delete this line. It doesn't change anything.
|
3 | temp(2 downto 0) <= temp(3 downto 1); -- becaue all of temp is overwritten afterwards
|
4 | temp(3) <= '0';
|
And now the question: is that what you wanted?
> And I have a question about temp(3) . Should it be 0 ?
Maybe. Depends on the requirements.