P
Prime
Guest
Hi,
I am trying to teach myself verilog, and have run into the following problem.
I have a Xilinx XC9536 linked up to the expansion connector of an old
(6809 based) micro, so that I can use it as an IO buffer. I have connected
the relevant bus signals to the CPLD, and have two sets of pins configured
as porta output and portb input.
I have the output port working fine, when I write a value to the port, it is
appears on the output port pins (I have some leds connected to these), however
reading from the input port I cannot get to work.
I have included the code below, I'm sure it's something simple,
but my beginner's eyes can't spot it
// Test module for reading and writing ports within a CPLD.
// Host system is a motorola 6809 based machine.
module DragonTest(halt,addr,rw,reset,e,p2,
porta,portb,data,
firq,nmi);
input [0:4]addr; // Bottom 5 address lines
input rw; // R/W line
input reset; // Reset line
input e; // E Clock
input p2; // P2 active low at addresses $FF40-$FF5F
inout [0:7]porta; // Port A
inout [0:5]portb; // Port B (only 6 bits wide)
inout [0:7]data; // CPU data bus
output firq; // FIRQ inturrupt line
output nmi; // NMI Inturrupt line
output halt; // Processor HALT line
reg [0:7] porta_latch; // Port A output latch
reg [0:5] portb_latch; // Port B input latch
reg [0:7] data_out; // Data bus output latch
assign porta = porta_latch; // Always output latched value on port A
// Force inturrupts & halt into hi-z as we currently don't use them
assign nmi = 1'bz;
assign firq = 1'bz;
assign halt = 1'bz;
// Enable signal,
wire enable1;
// Enable ourselves between $FF50-$FF5F
assign enable1 = !p2 & addr[4] & e;
assign out_enable = enable1 & rw;
// Only output data on bus, if we are selected, and processor is reading
// (R/W=high).
assign data = out_enable ? data_out : 8'bzzzzzzzz;
always @(posedge enable1 or negedge reset)
begin
// Reset latches to known sensible values.
if(reset==0)
begin
porta_latch = 8'b00000000;
portb_latch = 8'b100100;
data_out = 8'bzzzzzzzz;
end
else
begin
if(rw==1) // RW=1, so processot reading
begin
portb_latch=portb; // Latch data in *****
data_out={0,0,portb_latch}; // Latch onto data bus.
end
else // RW=0, so processor writing.
begin
porta_latch=data; // latch data out to port A
end
end
end
endmodule
**** If I comment out this line, and read the port I get back the value, of
portb_latch setup by the reset clause, however I never seem to be able to
read the values from the chip pins.
Cheers.
Phill.
I am trying to teach myself verilog, and have run into the following problem.
I have a Xilinx XC9536 linked up to the expansion connector of an old
(6809 based) micro, so that I can use it as an IO buffer. I have connected
the relevant bus signals to the CPLD, and have two sets of pins configured
as porta output and portb input.
I have the output port working fine, when I write a value to the port, it is
appears on the output port pins (I have some leds connected to these), however
reading from the input port I cannot get to work.
I have included the code below, I'm sure it's something simple,
but my beginner's eyes can't spot it
// Test module for reading and writing ports within a CPLD.
// Host system is a motorola 6809 based machine.
module DragonTest(halt,addr,rw,reset,e,p2,
porta,portb,data,
firq,nmi);
input [0:4]addr; // Bottom 5 address lines
input rw; // R/W line
input reset; // Reset line
input e; // E Clock
input p2; // P2 active low at addresses $FF40-$FF5F
inout [0:7]porta; // Port A
inout [0:5]portb; // Port B (only 6 bits wide)
inout [0:7]data; // CPU data bus
output firq; // FIRQ inturrupt line
output nmi; // NMI Inturrupt line
output halt; // Processor HALT line
reg [0:7] porta_latch; // Port A output latch
reg [0:5] portb_latch; // Port B input latch
reg [0:7] data_out; // Data bus output latch
assign porta = porta_latch; // Always output latched value on port A
// Force inturrupts & halt into hi-z as we currently don't use them
assign nmi = 1'bz;
assign firq = 1'bz;
assign halt = 1'bz;
// Enable signal,
wire enable1;
// Enable ourselves between $FF50-$FF5F
assign enable1 = !p2 & addr[4] & e;
assign out_enable = enable1 & rw;
// Only output data on bus, if we are selected, and processor is reading
// (R/W=high).
assign data = out_enable ? data_out : 8'bzzzzzzzz;
always @(posedge enable1 or negedge reset)
begin
// Reset latches to known sensible values.
if(reset==0)
begin
porta_latch = 8'b00000000;
portb_latch = 8'b100100;
data_out = 8'bzzzzzzzz;
end
else
begin
if(rw==1) // RW=1, so processot reading
begin
portb_latch=portb; // Latch data in *****
data_out={0,0,portb_latch}; // Latch onto data bus.
end
else // RW=0, so processor writing.
begin
porta_latch=data; // latch data out to port A
end
end
end
endmodule
**** If I comment out this line, and read the port I get back the value, of
portb_latch setup by the reset clause, however I never seem to be able to
read the values from the chip pins.
Cheers.
Phill.