EDAboard.com | EDAboard.de | EDAboard.co.uk | WTWH Media

Bidirectional bus : how to in Verilog

Ask a question - edaboard.com

elektroda.net NewsGroups Forum Index - Verilog Language - Bidirectional bus : how to in Verilog

Goto page 1, 2  Next


Guest

Tue Apr 28, 2020 7:45 pm   



Hi all,
I'm new to Verilog (although I've been designing and repairing electronics since many years).Not being yet familiar with coding I'm porting to Quartus schematics block some designs of mine using the examples (primitives) in the library.There are a couple of designs with bidirectional bus (made by the 74LS245 transceiver) hence I was wondering how to accomplish this in Verilog.Here are snippets of schematics:

https://i.postimg.cc/HLDFnmFZ/bidir.jpg

https://i.postimg.cc/XvfMVrs7/bidir-2.jpg

Any help or suggestion is appreciated.Thanks in advance.

Rick C
Guest

Tue Apr 28, 2020 8:45 pm   



On Tuesday, April 28, 2020 at 2:24:58 PM UTC-4, bri...@gmail.com wrote:
Quote:
Hi all,
I'm new to Verilog (although I've been designing and repairing electronics since many years).Not being yet familiar with coding I'm porting to Quartus schematics block some designs of mine using the examples (primitives) in the library.There are a couple of designs with bidirectional bus (made by the 74LS245 transceiver) hence I was wondering how to accomplish this in Verilog.Here are snippets of schematics:

https://i.postimg.cc/HLDFnmFZ/bidir.jpg

https://i.postimg.cc/XvfMVrs7/bidir-2.jpg

Any help or suggestion is appreciated.Thanks in advance.


I'm not as conversant in Verilog as VHDL, but in VHDL signals have a value 'Z' which is essentially the high impedance state of a tri-state output. When you want a driver to output the high-impedance state you drive it with a 'Z'.

However, there are few ways to implement such designs. FPGAs no longer contain internal tri-state drivers. They are only in the I/O pins. So an FPGA can hang on an external bus as a tri-state driver, but not internally. I think you won't find many ASIC devices that aren't the same way.

Is this for an external bus?

--

Rick C.

- Get 1,000 miles of free Supercharging
- Tesla referral code - https://ts.la/richard11209


Guest

Tue Apr 28, 2020 8:45 pm   



On Tuesday, 28 April 2020 20:52:23 UTC+2, Rick C wrote:
Quote:
On Tuesday, April 28, 2020 at 2:24:58 PM UTC-4, bri...@gmail.com wrote:
Hi all,
I'm new to Verilog (although I've been designing and repairing electronics since many years).Not being yet familiar with coding I'm porting to Quartus schematics block some designs of mine using the examples (primitives) in the library.There are a couple of designs with bidirectional bus (made by the 74LS245 transceiver) hence I was wondering how to accomplish this in Verilog.Here are snippets of schematics:

https://i.postimg.cc/HLDFnmFZ/bidir.jpg

https://i.postimg.cc/XvfMVrs7/bidir-2.jpg

Any help or suggestion is appreciated.Thanks in advance.

I'm not as conversant in Verilog as VHDL, but in VHDL signals have a value 'Z' which is essentially the high impedance state of a tri-state output. When you want a driver to output the high-impedance state you drive it with a 'Z'.

However, there are few ways to implement such designs. FPGAs no longer contain internal tri-state drivers. They are only in the I/O pins. So an FPGA can hang on an external bus as a tri-state driver, but not internally. I think you won't find many ASIC devices that aren't the same way.

Is this for an external bus?

--

Rick C.

- Get 1,000 miles of free Supercharging
- Tesla referral code - https://ts.la/richard11209


Thanks for reply.I forgot to say that I want to implement the logics in old CPLD (+5V tolerant Altera or Atmel).The bus is external and, since there is no 74245 in the Quartus library, I made my own but I think it's not working good as I get crash in the system.Hence, I'm also considering to use external 74245 devices and embed the rest of the logics in the CPLD.

Richard Damon
Guest

Tue Apr 28, 2020 9:45 pm   



On 4/28/20 3:40 PM, briccus_at_gmail.com wrote:
Quote:
On Tuesday, 28 April 2020 20:52:23 UTC+2, Rick C wrote:
On Tuesday, April 28, 2020 at 2:24:58 PM UTC-4, bri...@gmail.com wrote:
Hi all,
I'm new to Verilog (although I've been designing and repairing electronics since many years).Not being yet familiar with coding I'm porting to Quartus schematics block some designs of mine using the examples (primitives) in the library.There are a couple of designs with bidirectional bus (made by the 74LS245 transceiver) hence I was wondering how to accomplish this in Verilog.Here are snippets of schematics:

https://i.postimg.cc/HLDFnmFZ/bidir.jpg

https://i.postimg.cc/XvfMVrs7/bidir-2.jpg

Any help or suggestion is appreciated.Thanks in advance.

I'm not as conversant in Verilog as VHDL, but in VHDL signals have a value 'Z' which is essentially the high impedance state of a tri-state output. When you want a driver to output the high-impedance state you drive it with a 'Z'.

However, there are few ways to implement such designs. FPGAs no longer contain internal tri-state drivers. They are only in the I/O pins. So an FPGA can hang on an external bus as a tri-state driver, but not internally. I think you won't find many ASIC devices that aren't the same way.

Is this for an external bus?

--

Rick C.

- Get 1,000 miles of free Supercharging
- Tesla referral code - https://ts.la/richard11209

Thanks for reply.I forgot to say that I want to implement the logics in old CPLD (+5V tolerant Altera or Atmel).The bus is external and, since there is no 74245 in the Quartus library, I made my own but I think it's not working good as I get crash in the system.Hence, I'm also considering to use external 74245 devices and embed the rest of the logics in the CPLD.


Verilog driving with logic state 'z' should synthesize into a tri-state
driver, or there should be a Tristate macro function you can explicitly
instantiate for the output pin.

Rick C
Guest

Tue Apr 28, 2020 9:45 pm   



On Tuesday, April 28, 2020 at 3:40:40 PM UTC-4, bri...@gmail.com wrote:
Quote:
On Tuesday, 28 April 2020 20:52:23 UTC+2, Rick C wrote:
On Tuesday, April 28, 2020 at 2:24:58 PM UTC-4, bri...@gmail.com wrote:
Hi all,
I'm new to Verilog (although I've been designing and repairing electronics since many years).Not being yet familiar with coding I'm porting to Quartus schematics block some designs of mine using the examples (primitives) in the library.There are a couple of designs with bidirectional bus (made by the 74LS245 transceiver) hence I was wondering how to accomplish this in Verilog.Here are snippets of schematics:

https://i.postimg.cc/HLDFnmFZ/bidir.jpg

https://i.postimg.cc/XvfMVrs7/bidir-2.jpg

Any help or suggestion is appreciated.Thanks in advance.

I'm not as conversant in Verilog as VHDL, but in VHDL signals have a value 'Z' which is essentially the high impedance state of a tri-state output.. When you want a driver to output the high-impedance state you drive it with a 'Z'.

However, there are few ways to implement such designs. FPGAs no longer contain internal tri-state drivers. They are only in the I/O pins. So an FPGA can hang on an external bus as a tri-state driver, but not internally.. I think you won't find many ASIC devices that aren't the same way.

Is this for an external bus?

--

Rick C.

- Get 1,000 miles of free Supercharging
- Tesla referral code - https://ts.la/richard11209

Thanks for reply.I forgot to say that I want to implement the logics in old CPLD (+5V tolerant Altera or Atmel).The bus is external and, since there is no 74245 in the Quartus library, I made my own but I think it's not working good as I get crash in the system.Hence, I'm also considering to use external 74245 devices and embed the rest of the logics in the CPLD.


A crash in what system, the tools or your hardware?

Why don't you paste your '245 model code? It can't be very much code. It should be less than half a dozen lines. In VHDL this would be one line of code depending on the length of your signal names.

IO_bus <= (others => 'Z') when Tristate_En = '0' else Internal_bus;

I imagine the Verilog is very similar.

--

Rick C.

+ Get 1,000 miles of free Supercharging
+ Tesla referral code - https://ts.la/richard11209


Guest

Tue Apr 28, 2020 10:45 pm   



On Tuesday, 28 April 2020 22:31:55 UTC+2, Rick C wrote:
Quote:
On Tuesday, April 28, 2020 at 3:40:40 PM UTC-4, bri...@gmail.com wrote:
On Tuesday, 28 April 2020 20:52:23 UTC+2, Rick C wrote:
On Tuesday, April 28, 2020 at 2:24:58 PM UTC-4, bri...@gmail.com wrote:
Hi all,
I'm new to Verilog (although I've been designing and repairing electronics since many years).Not being yet familiar with coding I'm porting to Quartus schematics block some designs of mine using the examples (primitives) in the library.There are a couple of designs with bidirectional bus (made by the 74LS245 transceiver) hence I was wondering how to accomplish this in Verilog.Here are snippets of schematics:

https://i.postimg.cc/HLDFnmFZ/bidir.jpg

https://i.postimg.cc/XvfMVrs7/bidir-2.jpg

Any help or suggestion is appreciated.Thanks in advance.

I'm not as conversant in Verilog as VHDL, but in VHDL signals have a value 'Z' which is essentially the high impedance state of a tri-state output. When you want a driver to output the high-impedance state you drive it with a 'Z'.

However, there are few ways to implement such designs. FPGAs no longer contain internal tri-state drivers. They are only in the I/O pins. So an FPGA can hang on an external bus as a tri-state driver, but not internally. I think you won't find many ASIC devices that aren't the same way.

Is this for an external bus?

--

Rick C.

- Get 1,000 miles of free Supercharging
- Tesla referral code - https://ts.la/richard11209

Thanks for reply.I forgot to say that I want to implement the logics in old CPLD (+5V tolerant Altera or Atmel).The bus is external and, since there is no 74245 in the Quartus library, I made my own but I think it's not working good as I get crash in the system.Hence, I'm also considering to use external 74245 devices and embed the rest of the logics in the CPLD.

A crash in what system, the tools or your hardware?

Why don't you paste your '245 model code? It can't be very much code. It should be less than half a dozen lines. In VHDL this would be one line of code depending on the length of your signal names.

IO_bus <= (others => 'Z') when Tristate_En = '0' else Internal_bus;

I imagine the Verilog is very similar.

--

Rick C.

+ Get 1,000 miles of free Supercharging
+ Tesla referral code - https://ts.la/richard11209


Well, as i said I'm not yer familiar with writing code so I ported to Quartus the logic diagram of the 74245 (from whatever datasheet) and made a BDF file (and a BSF too for the symbol) :

http://www.mediafire.com/file/5evap6f2lmq7mq5/IC74245.bdf/file


I also found a couple of Verilog implementation of the 74245 :

Library ieee;
Use ieee.std_logic_1164.all;

Entity VHDL_74245 is
Port(G_L,DIR: in std_logic;
A,B: inout std_logic_vector(7 downto 0);
Y: out std_logic_vector(7 downto 0));
End VHDL_74245;

Architecture behav of VHDL_74245 is
Begin
Process (G_L, DIR, A,B)
Begin
If(G_L='0' and DIR='1') then
B<=A;
Elsif (G_L='0' and DIR='0') then
A<=B;
End if;
End process;
End behav;


library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;


entity CPLD_74LS245 is
Port ( nE : in STD_LOGIC;
dir : in STD_LOGIC;
B : inout STD_LOGIC_VECTOR (7 downto 0);
A : inout STD_LOGIC_VECTOR (7 downto 0));
end CPLD_74LS245;

architecture Behavioral of CPLD_74LS245 is
begin

-- Wenn nE = 1 oder dir = '1' dann HighZ
-- Sonst B
A <= (7 downto 0 => 'Z') when nE = '1' OR dir = '1' else B;

-- Wenn nE = 1 oder dir = '1' dann HighZ
-- Sonst A
B <= (7 downto 0 => 'Z') when nE = '1' OR dir = '0' else A;

end Behavioral;

Rick C
Guest

Wed Apr 29, 2020 1:45 am   



On Tuesday, April 28, 2020 at 5:39:47 PM UTC-4, bri...@gmail.com wrote:
Quote:
On Tuesday, 28 April 2020 22:31:55 UTC+2, Rick C wrote:
On Tuesday, April 28, 2020 at 3:40:40 PM UTC-4, bri...@gmail.com wrote:
On Tuesday, 28 April 2020 20:52:23 UTC+2, Rick C wrote:
On Tuesday, April 28, 2020 at 2:24:58 PM UTC-4, bri...@gmail.com wrote:
Hi all,
I'm new to Verilog (although I've been designing and repairing electronics since many years).Not being yet familiar with coding I'm porting to Quartus schematics block some designs of mine using the examples (primitives) in the library.There are a couple of designs with bidirectional bus (made by the 74LS245 transceiver) hence I was wondering how to accomplish this in Verilog.Here are snippets of schematics:

https://i.postimg.cc/HLDFnmFZ/bidir.jpg

https://i.postimg.cc/XvfMVrs7/bidir-2.jpg

Any help or suggestion is appreciated.Thanks in advance.

I'm not as conversant in Verilog as VHDL, but in VHDL signals have a value 'Z' which is essentially the high impedance state of a tri-state output. When you want a driver to output the high-impedance state you drive it with a 'Z'.

However, there are few ways to implement such designs. FPGAs no longer contain internal tri-state drivers. They are only in the I/O pins. So an FPGA can hang on an external bus as a tri-state driver, but not internally. I think you won't find many ASIC devices that aren't the same way.

Is this for an external bus?

--

Rick C.

- Get 1,000 miles of free Supercharging
- Tesla referral code - https://ts.la/richard11209

Thanks for reply.I forgot to say that I want to implement the logics in old CPLD (+5V tolerant Altera or Atmel).The bus is external and, since there is no 74245 in the Quartus library, I made my own but I think it's not working good as I get crash in the system.Hence, I'm also considering to use external 74245 devices and embed the rest of the logics in the CPLD.

A crash in what system, the tools or your hardware?

Why don't you paste your '245 model code? It can't be very much code. It should be less than half a dozen lines. In VHDL this would be one line of code depending on the length of your signal names.

IO_bus <= (others => 'Z') when Tristate_En = '0' else Internal_bus;

I imagine the Verilog is very similar.

--

Rick C.

+ Get 1,000 miles of free Supercharging
+ Tesla referral code - https://ts.la/richard11209

Well, as i said I'm not yer familiar with writing code so I ported to Quartus the logic diagram of the 74245 (from whatever datasheet) and made a BDF file (and a BSF too for the symbol) :

http://www.mediafire.com/file/5evap6f2lmq7mq5/IC74245.bdf/file


I also found a couple of Verilog implementation of the 74245 :

Library ieee;
Use ieee.std_logic_1164.all;

Entity VHDL_74245 is
Port(G_L,DIR: in std_logic;
A,B: inout std_logic_vector(7 downto 0);
Y: out std_logic_vector(7 downto 0));
End VHDL_74245;

Architecture behav of VHDL_74245 is
Begin
Process (G_L, DIR, A,B)
Begin
If(G_L='0' and DIR='1') then
B<=A;
Elsif (G_L='0' and DIR='0') then
A<=B;
End if;
End process;
End behav;


library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;


entity CPLD_74LS245 is
Port ( nE : in STD_LOGIC;
dir : in STD_LOGIC;
B : inout STD_LOGIC_VECTOR (7 downto 0);
A : inout STD_LOGIC_VECTOR (7 downto 0));
end CPLD_74LS245;

architecture Behavioral of CPLD_74LS245 is
begin

-- Wenn nE = 1 oder dir = '1' dann HighZ
-- Sonst B
A <= (7 downto 0 => 'Z') when nE = '1' OR dir = '1' else B;

-- Wenn nE = 1 oder dir = '1' dann HighZ
-- Sonst A
B <= (7 downto 0 => 'Z') when nE = '1' OR dir = '0' else A;

end Behavioral;


Your .BDF file is a schematic file format and I don't have a viewer for it. Can you generate an image file or PDF file of your schematic?

The other two implementations are VHDL, not Verilog.

The first looks like it is intended to be used at a chip interface, but is not complete and in fact would generate a latch.

The second is complete but will need to use tristate drivers on both sides of the unit. Are you trying to make a '245 device in a CPLD or are you putting logic in the CPLD and you need to interface the design to a bi-dir tristate bus?

Can you point me to the source of the design you want to implement?

The I/Os of a CPLD or FPGA have to split the bus in two like this.

+------< OE
|
External /|
Tri-state +-----< |-----< A
| \|
Y <<>>-----+ CPLD
| |\
Bus +-----| >-----> B
|/

I don't know of any TTL devices that do this. If you can use VHDL code I can give you a VHDL module that will do this. I need to see your full design to tell if this is what you need or how to adapt it.

--

Rick C.

-- Get 1,000 miles of free Supercharging
-- Tesla referral code - https://ts.la/richard11209

Rick C
Guest

Wed Apr 29, 2020 5:45 am   



Just so you know. If the ascii art drawing looks like gibberish you need to view it in a mono-spaced font.

Here is some (untested) VHDL to implement the buffer you need for the outside world. I'm sitting here bored, so thought I'd do something useful.

-- A is an input from the FPGA/CPLD innards
-- B is output to the FPGA/CPLD innards,
-- Y is external bidir
-- OE is a high true output enable
signal A, B, Y std_logic_vector (7 downto 0);

io_buf: process(A,Y,OE) begin
if (OE = '1') then
Y = A;
else
Y = 'Z';
end if;

B = Y;
end process io_buf;

io_buf is just a label which is optional. Even if you give it a label adding the label at the end is always optional.

A process is not a subroutine. The list of inputs are not like the inputs/outputs of a subroutine. They are always inputs that will cause the process to "run". In VHDL2008 you can replace that list with an asterisk. If you want something modular to be used in multiple places you can make it a procedure or an entity. A procedure IS a subroutine. An entity is a module that is instantiated (connected to the rest of the circuit through a port map, i.e. a wire list).

io_buf: procedure (
signal A : in std_logic_vector(7 downto 0);
signal B : out std_logic_vector(7 downto 0);
signal Y : inout std_logic_vector(7 downto 0);
signal OE : in std_logic ) is
begin
if (OE = '1') then
Y = A;
else
Y = 'Z';
end if;

B = Y;
end procedure io_buf;


The simplest way to do this is to just use concurrent statements (the simplest type of VHDL. You don't really need the B bus at all since it is just the Y bus from the outside. So the only assignment you need is to drive the output bus to a high-Z state when you aren't driving data.

Y <= 'Z' when (OE = '0') else A;

You can add this if it is more clear

B <= Y;

Sorry if this doesn't help you. I was bored and it was useful for me to review.

--

Rick C.

-+ Get 1,000 miles of free Supercharging
-+ Tesla referral code - https://ts.la/richard11209


Guest

Wed Apr 29, 2020 10:45 am   



On Wednesday, 29 April 2020 06:43:32 UTC+2, Rick C wrote:
Quote:
Just so you know. If the ascii art drawing looks like gibberish you need to view it in a mono-spaced font.

Here is some (untested) VHDL to implement the buffer you need for the outside world. I'm sitting here bored, so thought I'd do something useful.

-- A is an input from the FPGA/CPLD innards
-- B is output to the FPGA/CPLD innards,
-- Y is external bidir
-- OE is a high true output enable
signal A, B, Y std_logic_vector (7 downto 0);

io_buf: process(A,Y,OE) begin
if (OE = '1') then
Y = A;
else
Y = 'Z';
end if;

B = Y;
end process io_buf;

io_buf is just a label which is optional. Even if you give it a label adding the label at the end is always optional.

A process is not a subroutine. The list of inputs are not like the inputs/outputs of a subroutine. They are always inputs that will cause the process to "run". In VHDL2008 you can replace that list with an asterisk. If you want something modular to be used in multiple places you can make it a procedure or an entity. A procedure IS a subroutine. An entity is a module that is instantiated (connected to the rest of the circuit through a port map, i.e. a wire list).

io_buf: procedure (
signal A : in std_logic_vector(7 downto 0);
signal B : out std_logic_vector(7 downto 0);
signal Y : inout std_logic_vector(7 downto 0);
signal OE : in std_logic ) is
begin
if (OE = '1') then
Y = A;
else
Y = 'Z';
end if;

B = Y;
end procedure io_buf;


The simplest way to do this is to just use concurrent statements (the simplest type of VHDL. You don't really need the B bus at all since it is just the Y bus from the outside. So the only assignment you need is to drive the output bus to a high-Z state when you aren't driving data.

Y <= 'Z' when (OE = '0') else A;

You can add this if it is more clear

B <= Y;

Sorry if this doesn't help you. I was bored and it was useful for me to review.

--

Rick C.

-+ Get 1,000 miles of free Supercharging
-+ Tesla referral code - https://ts.la/richard11209


Thanks for spending your time on this.
Yes, I know the two examples of the 74245 I posted are in VHDL and not in Verilog, anyway I think I can use both languages in my Quartus design.
Here is the logic diagram of my 74245 implementation (yes, I want to make this device in my CPLD design) :

http://www.mediafire.com/file/q8qspgz60nfpqum/IC74245.pdf/file

Here's the whole design, it's a simple circuit made of few TTLs gates (with a socket that plugs into the hosting hardware)

http://www.mediafire.com/file/arry2cio0l2g3aw/design.pdf/file

Rick C
Guest

Wed Apr 29, 2020 11:45 am   



On Wednesday, April 29, 2020 at 5:11:25 AM UTC-4, bri...@gmail.com wrote:
Quote:
On Wednesday, 29 April 2020 06:43:32 UTC+2, Rick C wrote:
Just so you know. If the ascii art drawing looks like gibberish you need to view it in a mono-spaced font.

Here is some (untested) VHDL to implement the buffer you need for the outside world. I'm sitting here bored, so thought I'd do something useful.

-- A is an input from the FPGA/CPLD innards
-- B is output to the FPGA/CPLD innards,
-- Y is external bidir
-- OE is a high true output enable
signal A, B, Y std_logic_vector (7 downto 0);

io_buf: process(A,Y,OE) begin
if (OE = '1') then
Y = A;
else
Y = 'Z';
end if;

B = Y;
end process io_buf;

io_buf is just a label which is optional. Even if you give it a label adding the label at the end is always optional.

A process is not a subroutine. The list of inputs are not like the inputs/outputs of a subroutine. They are always inputs that will cause the process to "run". In VHDL2008 you can replace that list with an asterisk. If you want something modular to be used in multiple places you can make it a procedure or an entity. A procedure IS a subroutine. An entity is a module that is instantiated (connected to the rest of the circuit through a port map, i.e. a wire list).

io_buf: procedure (
signal A : in std_logic_vector(7 downto 0);
signal B : out std_logic_vector(7 downto 0);
signal Y : inout std_logic_vector(7 downto 0);
signal OE : in std_logic ) is
begin
if (OE = '1') then
Y = A;
else
Y = 'Z';
end if;

B = Y;
end procedure io_buf;


The simplest way to do this is to just use concurrent statements (the simplest type of VHDL. You don't really need the B bus at all since it is just the Y bus from the outside. So the only assignment you need is to drive the output bus to a high-Z state when you aren't driving data.

Y <= 'Z' when (OE = '0') else A;

You can add this if it is more clear

B <= Y;

Sorry if this doesn't help you. I was bored and it was useful for me to review.

--

Rick C.

-+ Get 1,000 miles of free Supercharging
-+ Tesla referral code - https://ts.la/richard11209

Thanks for spending your time on this.
Yes, I know the two examples of the 74245 I posted are in VHDL and not in Verilog, anyway I think I can use both languages in my Quartus design.
Here is the logic diagram of my 74245 implementation (yes, I want to make this device in my CPLD design) :

http://www.mediafire.com/file/q8qspgz60nfpqum/IC74245.pdf/file

Here's the whole design, it's a simple circuit made of few TTLs gates (with a socket that plugs into the hosting hardware)

http://www.mediafire.com/file/arry2cio0l2g3aw/design.pdf/file


I don't know if you can duplicate a '245 device in a 20 pin CPLD. That will require 16 outputs and I don't think they make 20 CPLDs with 20 outputs.

Why can't you just use a 74LS245 device? They are still made. Mouser has them in stock for less than a dollar.

--

Rick C.

+- Get 1,000 miles of free Supercharging
+- Tesla referral code - https://ts.la/richard11209

Rick C
Guest

Wed Apr 29, 2020 11:45 am   



On Wednesday, April 29, 2020 at 6:33:29 AM UTC-4, Rick C wrote:
Quote:
On Wednesday, April 29, 2020 at 5:11:25 AM UTC-4, bri...@gmail.com wrote:
On Wednesday, 29 April 2020 06:43:32 UTC+2, Rick C wrote:
Just so you know. If the ascii art drawing looks like gibberish you need to view it in a mono-spaced font.

Here is some (untested) VHDL to implement the buffer you need for the outside world. I'm sitting here bored, so thought I'd do something useful..

-- A is an input from the FPGA/CPLD innards
-- B is output to the FPGA/CPLD innards,
-- Y is external bidir
-- OE is a high true output enable
signal A, B, Y std_logic_vector (7 downto 0);

io_buf: process(A,Y,OE) begin
if (OE = '1') then
Y = A;
else
Y = 'Z';
end if;

B = Y;
end process io_buf;

io_buf is just a label which is optional. Even if you give it a label adding the label at the end is always optional.

A process is not a subroutine. The list of inputs are not like the inputs/outputs of a subroutine. They are always inputs that will cause the process to "run". In VHDL2008 you can replace that list with an asterisk. If you want something modular to be used in multiple places you can make it a procedure or an entity. A procedure IS a subroutine. An entity is a module that is instantiated (connected to the rest of the circuit through a port map, i.e. a wire list).

io_buf: procedure (
signal A : in std_logic_vector(7 downto 0);
signal B : out std_logic_vector(7 downto 0);
signal Y : inout std_logic_vector(7 downto 0);
signal OE : in std_logic ) is
begin
if (OE = '1') then
Y = A;
else
Y = 'Z';
end if;

B = Y;
end procedure io_buf;


The simplest way to do this is to just use concurrent statements (the simplest type of VHDL. You don't really need the B bus at all since it is just the Y bus from the outside. So the only assignment you need is to drive the output bus to a high-Z state when you aren't driving data.

Y <= 'Z' when (OE = '0') else A;

You can add this if it is more clear

B <= Y;

Sorry if this doesn't help you. I was bored and it was useful for me to review.

--

Rick C.

-+ Get 1,000 miles of free Supercharging
-+ Tesla referral code - https://ts.la/richard11209

Thanks for spending your time on this.
Yes, I know the two examples of the 74245 I posted are in VHDL and not in Verilog, anyway I think I can use both languages in my Quartus design.
Here is the logic diagram of my 74245 implementation (yes, I want to make this device in my CPLD design) :

http://www.mediafire.com/file/q8qspgz60nfpqum/IC74245.pdf/file

Here's the whole design, it's a simple circuit made of few TTLs gates (with a socket that plugs into the hosting hardware)

http://www.mediafire.com/file/arry2cio0l2g3aw/design.pdf/file

I don't know if you can duplicate a '245 device in a 20 pin CPLD. That will require 16 outputs and I don't think they make 20 CPLDs with 20 outputs..


Sorry, I meant I don't think they make 20 pin CPLDs with 16 outputs.


Guest

Wed Apr 29, 2020 11:45 am   



On Wednesday, 29 April 2020 12:33:29 UTC+2, Rick C wrote:
Quote:
On Wednesday, April 29, 2020 at 5:11:25 AM UTC-4, bri...@gmail.com wrote:
On Wednesday, 29 April 2020 06:43:32 UTC+2, Rick C wrote:
Just so you know. If the ascii art drawing looks like gibberish you need to view it in a mono-spaced font.

Here is some (untested) VHDL to implement the buffer you need for the outside world. I'm sitting here bored, so thought I'd do something useful..

-- A is an input from the FPGA/CPLD innards
-- B is output to the FPGA/CPLD innards,
-- Y is external bidir
-- OE is a high true output enable
signal A, B, Y std_logic_vector (7 downto 0);

io_buf: process(A,Y,OE) begin
if (OE = '1') then
Y = A;
else
Y = 'Z';
end if;

B = Y;
end process io_buf;

io_buf is just a label which is optional. Even if you give it a label adding the label at the end is always optional.

A process is not a subroutine. The list of inputs are not like the inputs/outputs of a subroutine. They are always inputs that will cause the process to "run". In VHDL2008 you can replace that list with an asterisk. If you want something modular to be used in multiple places you can make it a procedure or an entity. A procedure IS a subroutine. An entity is a module that is instantiated (connected to the rest of the circuit through a port map, i.e. a wire list).

io_buf: procedure (
signal A : in std_logic_vector(7 downto 0);
signal B : out std_logic_vector(7 downto 0);
signal Y : inout std_logic_vector(7 downto 0);
signal OE : in std_logic ) is
begin
if (OE = '1') then
Y = A;
else
Y = 'Z';
end if;

B = Y;
end procedure io_buf;


The simplest way to do this is to just use concurrent statements (the simplest type of VHDL. You don't really need the B bus at all since it is just the Y bus from the outside. So the only assignment you need is to drive the output bus to a high-Z state when you aren't driving data.

Y <= 'Z' when (OE = '0') else A;

You can add this if it is more clear

B <= Y;

Sorry if this doesn't help you. I was bored and it was useful for me to review.

--

Rick C.

-+ Get 1,000 miles of free Supercharging
-+ Tesla referral code - https://ts.la/richard11209

Thanks for spending your time on this.
Yes, I know the two examples of the 74245 I posted are in VHDL and not in Verilog, anyway I think I can use both languages in my Quartus design.
Here is the logic diagram of my 74245 implementation (yes, I want to make this device in my CPLD design) :

http://www.mediafire.com/file/q8qspgz60nfpqum/IC74245.pdf/file

Here's the whole design, it's a simple circuit made of few TTLs gates (with a socket that plugs into the hosting hardware)

http://www.mediafire.com/file/arry2cio0l2g3aw/design.pdf/file

I don't know if you can duplicate a '245 device in a 20 pin CPLD. That will require 16 outputs and I don't think they make 20 CPLDs with 20 outputs..

Why can't you just use a 74LS245 device? They are still made. Mouser has them in stock for less than a dollar.

--

Rick C.

+- Get 1,000 miles of free Supercharging
+- Tesla referral code - https://ts.la/richard11209


I explained myself bad, sorry.I want to port into a CPLD the schematics I attached in which there is a 74245, not doing a CPLD version of the 74245.And yes, I have considered to use an external 74245 instead of implenting it in the Quartus CPLD design whereas all the remaining logics you can see in the attached schematics will be implemented in the CPLD.


Guest

Wed Apr 29, 2020 11:45 am   



On Wednesday, 29 April 2020 12:42:05 UTC+2, bri...@gmail.com wrote:
Quote:
On Wednesday, 29 April 2020 12:33:29 UTC+2, Rick C wrote:
On Wednesday, April 29, 2020 at 5:11:25 AM UTC-4, bri...@gmail.com wrote:
On Wednesday, 29 April 2020 06:43:32 UTC+2, Rick C wrote:
Just so you know. If the ascii art drawing looks like gibberish you need to view it in a mono-spaced font.

Here is some (untested) VHDL to implement the buffer you need for the outside world. I'm sitting here bored, so thought I'd do something useful.

-- A is an input from the FPGA/CPLD innards
-- B is output to the FPGA/CPLD innards,
-- Y is external bidir
-- OE is a high true output enable
signal A, B, Y std_logic_vector (7 downto 0);

io_buf: process(A,Y,OE) begin
if (OE = '1') then
Y = A;
else
Y = 'Z';
end if;

B = Y;
end process io_buf;

io_buf is just a label which is optional. Even if you give it a label adding the label at the end is always optional.

A process is not a subroutine. The list of inputs are not like the inputs/outputs of a subroutine. They are always inputs that will cause the process to "run". In VHDL2008 you can replace that list with an asterisk.. If you want something modular to be used in multiple places you can make it a procedure or an entity. A procedure IS a subroutine. An entity is a module that is instantiated (connected to the rest of the circuit through a port map, i.e. a wire list).

io_buf: procedure (
signal A : in std_logic_vector(7 downto 0);
signal B : out std_logic_vector(7 downto 0);
signal Y : inout std_logic_vector(7 downto 0);
signal OE : in std_logic ) is
begin
if (OE = '1') then
Y = A;
else
Y = 'Z';
end if;

B = Y;
end procedure io_buf;


The simplest way to do this is to just use concurrent statements (the simplest type of VHDL. You don't really need the B bus at all since it is just the Y bus from the outside. So the only assignment you need is to drive the output bus to a high-Z state when you aren't driving data.

Y <= 'Z' when (OE = '0') else A;

You can add this if it is more clear

B <= Y;

Sorry if this doesn't help you. I was bored and it was useful for me to review.

--

Rick C.

-+ Get 1,000 miles of free Supercharging
-+ Tesla referral code - https://ts.la/richard11209

Thanks for spending your time on this.
Yes, I know the two examples of the 74245 I posted are in VHDL and not in Verilog, anyway I think I can use both languages in my Quartus design.
Here is the logic diagram of my 74245 implementation (yes, I want to make this device in my CPLD design) :

http://www.mediafire.com/file/q8qspgz60nfpqum/IC74245.pdf/file

Here's the whole design, it's a simple circuit made of few TTLs gates (with a socket that plugs into the hosting hardware)

http://www.mediafire.com/file/arry2cio0l2g3aw/design.pdf/file

I don't know if you can duplicate a '245 device in a 20 pin CPLD. That will require 16 outputs and I don't think they make 20 CPLDs with 20 outputs.

Why can't you just use a 74LS245 device? They are still made. Mouser has them in stock for less than a dollar.

--

Rick C.

+- Get 1,000 miles of free Supercharging
+- Tesla referral code - https://ts.la/richard11209

I explained myself bad, sorry.I want to port into a CPLD the schematics I attached in which there is a 74245, not doing a CPLD version of the 74245..And yes, I have considered to use an external 74245 instead of implenting it in the Quartus CPLD design whereas all the remaining logics you can see in the attached schematics will be implemented in the CPLD.


I forgot.As CPLD I will use a +5V Altera EPM7128 (TQFP100) with 84 I/O and 128 macrocells.I already successfully used it in other my projects.

Kevin Neilson
Guest

Wed Apr 29, 2020 7:45 pm   



On Tuesday, April 28, 2020 at 12:24:58 PM UTC-6, bri...@gmail.com wrote:
Quote:
Hi all,
I'm new to Verilog (although I've been designing and repairing electronics since many years).Not being yet familiar with coding I'm porting to Quartus schematics block some designs of mine using the examples (primitives) in the library.There are a couple of designs with bidirectional bus (made by the 74LS245 transceiver) hence I was wondering how to accomplish this in Verilog.


I haven't used tristates in quite a while, but as I recall, it goes something like this:

inout [7:0] tristate_bus, // declare tristates as inout ports
...

reg [7:0] data_out; // data to be driven onto tristate_bus
reg output_en; // 1=>drive data_out onto tristate_bus
assign tristate_bus = output_en ? data_out : 'bz; // high-Z when output_en=0
wire [7:0] read_data = tristate_bus; // data read from tristate bus

Rick C
Guest

Wed Apr 29, 2020 9:45 pm   



On Wednesday, April 29, 2020 at 6:44:37 AM UTC-4, bri...@gmail.com wrote:
Quote:
On Wednesday, 29 April 2020 12:42:05 UTC+2, bri...@gmail.com wrote:
On Wednesday, 29 April 2020 12:33:29 UTC+2, Rick C wrote:
On Wednesday, April 29, 2020 at 5:11:25 AM UTC-4, bri...@gmail.com wrote:
On Wednesday, 29 April 2020 06:43:32 UTC+2, Rick C wrote:
Just so you know. If the ascii art drawing looks like gibberish you need to view it in a mono-spaced font.

Here is some (untested) VHDL to implement the buffer you need for the outside world. I'm sitting here bored, so thought I'd do something useful.

-- A is an input from the FPGA/CPLD innards
-- B is output to the FPGA/CPLD innards,
-- Y is external bidir
-- OE is a high true output enable
signal A, B, Y std_logic_vector (7 downto 0);

io_buf: process(A,Y,OE) begin
if (OE = '1') then
Y = A;
else
Y = 'Z';
end if;

B = Y;
end process io_buf;

io_buf is just a label which is optional. Even if you give it a label adding the label at the end is always optional.

A process is not a subroutine. The list of inputs are not like the inputs/outputs of a subroutine. They are always inputs that will cause the process to "run". In VHDL2008 you can replace that list with an asterisk. If you want something modular to be used in multiple places you can make it a procedure or an entity. A procedure IS a subroutine. An entity is a module that is instantiated (connected to the rest of the circuit through a port map, i.e. a wire list).

io_buf: procedure (
signal A : in std_logic_vector(7 downto 0);
signal B : out std_logic_vector(7 downto 0);
signal Y : inout std_logic_vector(7 downto 0);
signal OE : in std_logic ) is
begin
if (OE = '1') then
Y = A;
else
Y = 'Z';
end if;

B = Y;
end procedure io_buf;


The simplest way to do this is to just use concurrent statements (the simplest type of VHDL. You don't really need the B bus at all since it is just the Y bus from the outside. So the only assignment you need is to drive the output bus to a high-Z state when you aren't driving data.

Y <= 'Z' when (OE = '0') else A;

You can add this if it is more clear

B <= Y;

Sorry if this doesn't help you. I was bored and it was useful for me to review.

--

Rick C.

-+ Get 1,000 miles of free Supercharging
-+ Tesla referral code - https://ts.la/richard11209

Thanks for spending your time on this.
Yes, I know the two examples of the 74245 I posted are in VHDL and not in Verilog, anyway I think I can use both languages in my Quartus design.
Here is the logic diagram of my 74245 implementation (yes, I want to make this device in my CPLD design) :

http://www.mediafire.com/file/q8qspgz60nfpqum/IC74245.pdf/file

Here's the whole design, it's a simple circuit made of few TTLs gates (with a socket that plugs into the hosting hardware)

http://www.mediafire.com/file/arry2cio0l2g3aw/design.pdf/file

I don't know if you can duplicate a '245 device in a 20 pin CPLD. That will require 16 outputs and I don't think they make 20 CPLDs with 20 outputs.

Why can't you just use a 74LS245 device? They are still made. Mouser has them in stock for less than a dollar.

--

Rick C.

+- Get 1,000 miles of free Supercharging
+- Tesla referral code - https://ts.la/richard11209

I explained myself bad, sorry.I want to port into a CPLD the schematics I attached in which there is a 74245, not doing a CPLD version of the 74245.And yes, I have considered to use an external 74245 instead of implenting it in the Quartus CPLD design whereas all the remaining logics you can see in the attached schematics will be implemented in the CPLD.

I forgot.As CPLD I will use a +5V Altera EPM7128 (TQFP100) with 84 I/O and 128 macrocells.I already successfully used it in other my projects.


Ok, that is more clear. I will say the EPM7128 is very much overkill for this design, but that's ok. Better too large than too small. So the code I gave you should do the job here is an example that does the full in and out of the '245. One I/O is A and the other B as in your schematic.


signal DA, DB : std_logic_vector (7 downto 0);
signal s402_2H, s401_fi, other_ck, s601 : std_logic;
signal RD_n, s603, s602, wait_n, FF1, FF2 : std_logic;

DA <= 'Z' when (s602 or RD_n = '1') else DB;
DB <= 'Z' when (s602 or not RD_n = '1') else DA;

wait_n <= not 402_2H or s601;
s602 <= FF1 and FF2 or s601;
s603 <= s602 or not RD_n;

process (other_ck, 402_2H_n) begin
if (402_2H = '1') then
FF1 <= '1';
elsif (rising_edge(other_ck))
FF1 <= s401_fi;
end if;

if (falling_edge(other_ck))
FF2 <= FF1;
end if;
end process;

This is the logic as shown on the page. It still needs the entity boilerplate to define the I/Os for the device which are the signals on the 28 pin connector.

Can you tell me what the design does? The '245 device seems to simple connect pins on the 28 pin socket back to itself, either in one direction or the other. What plugs into the socket??? It would appear to be an MCU which makes little sense to tie 8 lines back to themselves. Or maybe you are trying to replace one of the higher complexity bus interface devices that aren't made anymore?

There are a couple of parts of the schematic that are troubling. One is the use of the PREset pin on the FF. PREset and CLR are asynchronous logic (combinational) and have very particular timing constraints which will be very different inside the CPLD and a TTL device. Without a thorough understanding of the design it is hard to know if this will work well. It is better to use the synchronous logic with separate combinational logic. That can only be done with detailed info on the intended operation of the device.

The same thing applies to the use of two inverters to create the enable on the '245 device. This is a logic noop which will only create an ill defined delay. This is hard to do in a CPLD since the tools will optimize it out.. It has the same timing concerns as the PREset on the FF.

The more info you can provide, the more help you can get.

--

Rick C.

++ Get 1,000 miles of free Supercharging
++ Tesla referral code - https://ts.la/richard11209

Goto page 1, 2  Next

elektroda.net NewsGroups Forum Index - Verilog Language - Bidirectional bus : how to in Verilog

Ask a question - edaboard.com

Arabic version Bulgarian version Catalan version Czech version Danish version German version Greek version English version Spanish version Finnish version French version Hindi version Croatian version Indonesian version Italian version Hebrew version Japanese version Korean version Lithuanian version Latvian version Dutch version Norwegian version Polish version Portuguese version Romanian version Russian version Slovak version Slovenian version Serbian version Swedish version Tagalog version Ukrainian version Vietnamese version Chinese version Turkish version
EDAboard.com map