VHDL code for 4 x 4 register file (replacement fopr 74LS670 logic)

Pagina 2/2
1 |

Van Gregory

Champion (295)

afbeelding van Gregory

23-04-2023, 08:40

Maybe this is of interest to you:

vhdl

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity SN74XX670 is
generic (
DELAY : time
);

port (
we : in std_logic;
waddr : in std_logic_vector(1 downto 0);
d : in std_logic_vector (3 downto 0);
re : in std_logic;
raddr : in std_logic_vector(1 downto 0);
q : out std_logic_vector(3 downto 0)
);

end SN74XX670;

architecture rtl of SN74XX670 is
constant SIZE : natural := 4;

subtype nibble is std_logic_vector(3 downto 0);
type nibble_array is array(0 to SIZE-1) of nibble;

function init return nibble_array is
variable result : nibble_array;
begin
for i in nibble_array'range loop
result(i) := "0000";
end loop;
return result;
end function;

function to_string(b : std_logic_vector) return string is
begin
return integer'image(to_integer(unsigned(b)));
end function;

signal regs : nibble_array := init;
begin

-- Set high impedance state by default.
q <= "ZZZZ";

-- Read interface.
process(re, raddr, we) -- NOTE Outputs should change on changing raddr & when
-- NOTE overwritten by a write cycle.
variable n : nibble;
begin
if re = '0' then
n := regs(to_integer(unsigned(raddr)));
q <= n after DELAY;
report "read " & to_string(n) & " at " & to_string(raddr);
else
q <= "ZZZZ";
end if;
end process;

-- Write interface.
process(we)
begin
if we = '0' then
regs(to_integer(unsigned(waddr))) <= d after DELAY;
report "wrote " & to_string(d) & " at " & to_string(waddr);
end if;
end process;

end rtl;

Van Gregory

Champion (295)

afbeelding van Gregory

30-04-2023, 21:42

WORP3 wrote:

Programming FPGA's has nothing to do with actual programming, it's describing a digital design, so think like this:

What type of flipflops are being used in this logic diagram?

Van cjs

Master (143)

afbeelding van cjs

01-05-2023, 02:40

Gregory wrote:

What type of flipflops are being used in this logic diagram?

They are standard [url=https://en.wikipedia.org/wiki/Flip-flop_(electronics)#D_flip-flop]D flip-flops[/url]. The G input, probably meaning "gate," is more usually called the clock input.

(I've no idea why the forum won't properly render my link above.)

Van Gregory

Champion (295)

afbeelding van Gregory

01-05-2023, 17:37

.

Van Gregory

Champion (295)

afbeelding van Gregory

01-05-2023, 17:38

cjs wrote:
Gregory wrote:

What type of flipflops are being used in this logic diagram?

They are standard [url=https://en.wikipedia.org/wiki/Flip-flop_(electronics)#D_flip-flop]D flip-flops[/url]. The G input, probably meaning "gate," is more usually called the clock input.

(I've no idea why the forum won't properly render my link above.)

So it can store 4 words of 4-bits.

Van cjs

Master (143)

afbeelding van cjs

01-05-2023, 18:14

Gregory wrote:

So it can store 4 words of 4-bits.

Right. You'll notice that if E̅W̅ is not asserted (is high, because negative logic) none of the flip-flops have G enabled, so none will read their D inputs. When E̅W̅ is asserted, only one of the four rows of flip-flops, determined by WA and WB will have G asserted, and thus will store whatever's on their D inputs.

Van Gregory

Champion (295)

afbeelding van Gregory

02-05-2023, 14:35

I'll see if I can get this to work in a CPLD. Just wondering about the high-impedance output, don't know if all clpd devices support this. Just thinking.

Van Gregory

Champion (295)

afbeelding van Gregory

02-05-2023, 17:16

Pencioner wrote:

Well, version 13 seems to support that (i tried it once with version 9.1 or so and it was not available)

What i found: https://www.intel.com/content/www/us/en/programmable/quartus...
so it seems like the code you found is not really synthezable (it might be only for emulation in tools but not for real chips). I guess you'd need to read coding styles mentioned in this link etc and change the code. Or maybe write your own

Btw with some googling i have found the implementations which implements 4x4 register file though they are not 3-state (so this should be modified to be fully equivalent to LS670) - http://quitoart.blogspot.com/2017/09/fpga-vhdl-verilog-4-bit-register-file.html

Can you give some guidance on how to implement the 3-state?

Van lkpalwa

Expert (118)

afbeelding van lkpalwa

03-05-2023, 12:53

I think the Altera 7000s support that as I can see in the manual

https://edg.uchicago.edu/~bogdan/l1aux/doc/parts/m7000.pdf

Pagina 2/2
1 |