VHDL project : 5 bit shift reg

Guest #4983684
Rate this post
useful
not useful
Hello everyone .

I have a project on VHDL . I have to create a 5 bit shift reg , with the 
following options :

000 : Reset /
001 : Parallel loading /
002 : Right shift /
003 : Left shift /
004 : Circular right shift /
005 : Circular left shift /
006 : 1s' complement /
007 : 2s' complement

I have every module , but i can't create the final module , i don't know 
it's structure . Any help ?

D flip flop : https://pastebin.com/Myj69R0L
Half adder : https://pastebin.com/AAYpA4br
Mux 8X1 : https://pastebin.com/w6r14wee
prescaler : https://pastebin.com/XH9Mtzyq

Code is attached too .
Attached files:
Guest #4985363
Rate this post
useful
not useful
Could you describe what each of those do?

000 : Reset /
001 : Parallel loading /
002 : Right shift /
003 : Left shift /
004 : Circular right shift /
005 : Circular left shift /
006 : 1s' complement /
007 : 2s' complement

Reset is load with all zero?
Parallel load ok
Right,left shift ok but where is input and output?
Circular shift, ok, input = output?
1s and 2s complement?! Does this matter? Is is just a series of bits ...

Try to describe each "function" in HDL and then pack it in a case 
structure.
#4985715
Rate this post
useful
not useful
> Reset is load with all zero?

Yes

> Right,left shift ok but where is input and output?

You get a 5 bit input an a standard output, and every time you select 
what you want to do with input .

> Circular shift, ok, input = output?

yes

> Try to describe each "function" in HDL and then pack it in a case
> structure.

I have to do it using different modules

- - - - - -

BTW , i think i made it working !

You give a 5 bit input and the number of the selection (what to do) and 
it gives output based on them of course .

I have uploaded the file . Of course this one doesn't use the prescaler 
, it's just for simulation .
Attached files:
#4985874
Rate this post
useful
not useful
Sorry for the late reply .

I don't get any errors , only 2 warnings if i remember corectly.

Sel='010' shifts left every clock , circular .

Here are the final's programms options (sel) , sorry .


000 : Parallel loading /
001 : Right shift /
010 : Left shift /
011 : Circular right shift /
100 : Circular left shift /
101 : 1s' complement /
110: 2s' complement

Can you help me fix the errors you found ?


Thamnks a lot
#4985910
Rate this post
useful
not useful
Thank you very much for your help .

It works OK from what i see in the simulation .

I will have to get the fpga (spartan 3) this coming week to test it , so 
i'll probably need to figure out how to upload it to the fpga too (will 
update here too) .

Thanks a lot Gustl and everyone else that helped with their answer !
#4985917
Rate this post
useful
not useful
Thank you! And yes, it is a hard long way :-)

So ... i think it is not working. Here pass many clockcycles while 
nothing changes, no shifts or so.

HDLs like VHDL can be used even on a more abstract level. Ne need to 
describe singe FlipFlops. A shift register with 5 bits can be written 
as:

signal register: std_logic_vector(4 downto 0); --5 bits total
...
begin
...
register <= register(0) & register(4 downto 1); --circular right shift
register <= register(3 downto 0) & register(4); --circular left shift

And the MUX can be written as

if .... then
elsif ... then
endif;

or with the case statement.
#4985932
Rate this post
useful
not useful
Really? I understand shift registers a bit different:

When it is in the state "shift right" the contend is shifted right one 
step with every clock cycle. So in the waveform sel is 1 ("001") and 
there are many clock cycles but is does not shift with each cycle.

It should look like 
http://www.cse.psu.edu/~kxc104/class/cmpen297B/08f/hw/hw7/serialShift2.png
or the contend:

sel = "001"
it gehts loaded with "11000" and then it should shift:
"11000"
"01100"
"00110"
"00011"
...

But maybe we have different understanding and it is all right.
#4985953
Rate this post
useful
not useful
Hm, the way you started is very educating, but not easy. Yes, you can 
describe every single FlipFlop and MUX and half-adder, but you could use 
the language constructs from VHDL instead. I don't know your constraints 
if you must describe each element on its own.

I attached a waveform which shows what i guess it should show :-)

The register contains "11000"
Then res goes high for one clock
The register contains "00000"
Then sel goes to "001" and the registers loads the input "11000" again.

Then 3 clocks right shift:
"0110"
"00110"
"00011"

Then 3 clocks left shift:
"00110"
"01100"
"11000"

Then 6 clocks Circular right shift
"0110"
"00110"
"00011"
"10001"
"11000"
"01100"


Then 6 clocks Circular left shift
"11000"
"10001"
"00011"
"00110"
"01100"
"11000"

But i don't know what is meant by
1s' complement and 2s' complement. They are representation of numbers. 
Should the shift register count or somethig like that? Or should the 
contend be converted?

Edit:
I attatched the schematic view from xilinx ise (the software you use) 
and from the newer vivado (which does not support spartan FPGAs). Looks 
like your hand-drawn schematic is very close to the schematic ise made 
from my hdl code which is working. but on more intensive look not sooo 
close. i recommend to write it in a more abstract way, not describing 
instantiating single FFs and MUXes. Let the toolchain do that for you.
Attached files:
#4986485
Rate this post
useful
not useful
OK, so ... i attatched the Testbench and a startingpoint for the 
fivebit.vhd description.

The only data which is stored in this description are the bits in the 
register:
1
signal data: std_logic_vector(4 downto 0):=(others => '0');

The output is directly connected to the content of the register:
1
EKS <= data;

then we use a clocked process, so everything is triggered with the 
rising edge of clock:
1
process begin
2
  wait until rising_edge(clock);
3
.
4
.
5
.
6
end process;

The reset "res" is synchron with the clock, read as "if res = '1' and a 
rising edge of clk happens" then the reset is executed. asynchron reset 
should not be used in modern FPGAs.

After the reset there is the MUX which can be written as many
1
if SEL =  "001" then data <= whatever_you_like;
2
elsif SEL =  "010" then data <= whatever_you_like;
3
else data <= whatever_you_like;
4
end if;

it can also be written like
1
case SEL is
2
  when "001" => data <= whatever_you_like;
3
  when "010" => data <= whatever_you_like;
4
  when others => data <= whatever_you_like;
5
end case;
The "when others" case is mandatory. in the fivebit.vhd i used if .. 
else description.

I wrote the first 4 entrys:
1
    if    SEL = "000" then data <= (others => '0'); --Reset
2
    elsif SEL = "001" then data <= INP; --Parallel loading
3
    elsif SEL = "010" then data <= '0' & data(4 downto 1); --Right shift
4
    elsif SEL = "011" then data <= data(3 downto 0) & '0'; --Left shift

the rest is left for you. circular right/left shift is like normal 
right/left shift but with the bit falling out at one end shifted in the 
other end again.
I still don't really understand what should happen to the bits in the 
register with 1s or 2s complement selected. And with normal right/left 
shift this
1
elsif SEL = "010" then data <= '0' & data(4 downto 1);
shifts right, and the leftmost bit is filled with '0'. Is this how it 
shold be or should the leftmost bit be for example a new bit from the 
input?
like data <= INP(0) & data(4 downto 1) or so ...
Attached files:
Moderator (Company: Titel) #4986499
Rate this post
useful
not useful
Gustl B. wrote:
> OK, so ... i attatched the Testbench and a startingpoint for the
> fivebit.vhd description.
Nice job, but I think it must be cleared whether those components from 
the initial post MUST or CAN be used.
When they MUST be used then it is a fairly stupid exercise for 
structural description from an old fashioned teacher (because in real 
life nobody will instantiate a flipflop or a adder by using components 
explicitly).
If they CAN be used, then i would kick then beside and do it like your 
simple examples in less then 30 lines VHDL code.

Up to now for a pity it looks more like they MUST be used... :-/
#4986579
Rate this post
useful
not useful
Because of cluelessness and lazyness i still would go the easy way. 
Describe the logic in simple vhdl, look at the RTL view of your 
toolchain (i posted a picture above somewhere) and then implement this 
picture (= a working schematic) with the components you have to use.
#4986981
Rate this post
useful
not useful
Wohoooo! It works (in simulation)! But ... it was tricky. Use the VIVADO 
schematic because VIVADO uses the right MUXes. And then you have to dive 
deep in vivado and get the details for all connections.

000 : Reset /
001 : Parallel loading /
002 : Right shift /
003 : Left shift /
004 : Circular right shift /
005 : Circular left shift /

can be implemented this way with 5 MUXes and 5 FFs and one inverter (for 
res) because reset in your FlipFlop HDL has an active low clear.

I also attatched the mux.png it shows how the mux is connected in the 
schematic_vivado.png it can be implemented as 5 independed muxes with 
the mux HDL description you provided.

what i could not implement was the thing with 1s and 2s complement. i 
understand what 2s complement is, but not how it should behave in the 
shift register. the question is:

contend of the shift register is data(4 downto 0)
now SEL = "110" (6).
what should happen with every rising clock?
data <= ?
And what should happen if SEL = "111" (7)?
Attached files:
#4987042
Rate this post
useful
not useful
Michael K. wrote:
>> And what should happen if SEL = "111" (7)?
>
> nothing .

Souldn't this be the 2s complement thing?
1s complement is easy but for 2s complement you need an adder or more 
complex logic.
My guess is that with SEL = 110 with every clock the content in the 
register should be converted like 1s complement. and so with SEL = 111, 
with every clock it should be converted in 2s complement.

Michael K. wrote:
> Can i do the process you mentioned in ISE ? Because i have to

I don't know. i might be hard because ISE does not use 8-input MUXes in 
the RTL schematic. the HDL is independent from ISE or VIVADO, so if you 
once wrote the HDL files in vhdl you can use an simulate them with ISE 
or VIVADO.
Here i only needed VIVADO to get the information about what is connected 
to what.

Edit:
I just added the SEL = 110 and SEL = 111 cases as:
[vhdl]    when "110" => data <= not data; --1s' complement
    when others => data <= std_logic_vector(unsigned(not data) +1); 
--2s' complement (SEL = "111")[vhdl]

and ... now ISE uses 8-input MUXes in the RTL schematic. Just like 
VIVADO. In the waveform you can see that with SEL = 110 all bits in the 
register are inverted with every clock and with SEL = 111 all bits are 
inverted and 1 is added with every clock. But i don't know if this is 
intended.
If this is ok, then you may use ISE, it looks good.
Attached files:
#4987052
Rate this post
useful
not useful
Gustl B. wrote:
> Michael K. wrote:
>>> And what should happen if SEL = "111" (7)?
>>
>> nothing .
>
> Souldn't this be the 2s complement thing?
> 1s complement is easy but for 2s complement you need an adder or more
> complex logic.
> My guess is that with SEL = 110 with every clock the content in the
> register should be converted like 1s complement. and so with SEL = 111,
> with every clock it should be converted in 2s complement.

I was confused because in my project i had 7 options , and reset was 
connected straight to tue flip flops . Yes if you use 000 option as 
reset , 111 will be 2s complement .

I'll ask my teacher and/or an older student tomorrow if they have any 
idea if it's possible to do it from my current project . I'll also have 
to check the the last testbench file you uploaded earlier today .

Thanks again
#4987064
Rate this post
useful
not useful
No Problem, i learn something too, good Night!

Edit:
And it works. Schematics attatched. But it was not easy to dig through 
the very strange signal names in ISE. And it's very sag that neither 
vivado nor ise show signal names in the schematic, you have to klick on 
the lines. you also can't show busses as individual wires.
Attached files:
#4987463
Rate this post
useful
not useful
I think i finally made it !

My Diagram in post #6 has the solution ... In 000 option (parallel 
transfer) you transfer the input to the output . Then EVERY time , you 
give as input to the mux's from the output of option 000 (parallel 
transfer) , and so every time it gets the output without the user doing 
something . Basically to change input you have to give a new 5 bit input 
and re-run 000 option .
Attached files:

Reply

Please log in before posting.

or

Log in with Google account

Registration is free and takes only a minute.

Register now