Hi all,
I would like to be able to interface a WDC65C02 to an FPGA, specifically write to the FPGA block ram from the 6502.
The FPGA is presented to the 6502 as an IO device at address $FF80 (for example). One chip select line, 3 address lines, the 8 data lines, the PHI2 line and the RWB line are all inputs to the FPGA.
I am trying to make the FPGA save the data received in it's block ram when I am writing to it from the 6502. I have tried at least 5 different ways, and I always get unreliable data. I have looked at many timing diagrams for the 6502 write cycles and it seems that my verilog code conforms to that. The address is latched on a clock positive edge, and the data on the clock negative edge.
The 6502 test code is very simple:
Code:
ldx #0
loop:
stx $FF80
inx
ldy #$10
jsr delay
bra loop
or something to that effect.
I have tried delays between 0 and about 2000 cycles, but I don't think that should affect anything.
One of the possible issues is with the level converters. I have tried both TXS0108 and 74LVC4245 with the same results.
Here is some of the current verilog code:
Code:
// CLK_100M is a 100Mhz clock generated by the on chip PLL
always @(posedge CLK_100M) begin
// This sets the command registerfrom the address lines when the chip is enabled and the 6502 is writing
// (the enabled and write signals are inverted ENB and RWB)
if ((PHI2 == 1'b1) && (enabled == 1'b1) && (write == 1'b1)) begin
command_reg <= REG;
end
end
always @(posedge CLK_100M) begin
// this saves the data from the 6502 during the whole of PHI2 high and stops when it goes low
if ((PHI2 == 1'b1) && (enabled == 1'b1) && (write == 1'b1) && (save_data == 1'b0)) begin
command_data <= DATA;
end
else if (PHI2 == 1'b0) begin
// Here I do something like this :
bram[command_reg] <= command_data;
end
end
I have tried many different ways, including something like this :
Code:
always @(posedge PHI2)
command_reg <= REG;
always @(negedge PHI2)
command_data <= DATA;
but always with mostly garbage results.
I have tried with the 6502 running at 12, 10, and 1.8 Mhz (only 3 oscillator values I have).
Does anybody have any idea what I'm doing wrong ? I'm a complete newb with FPGA (I'm using an ice40 by the way) so any pointers will be more than welcome.
Thanks