6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Apr 28, 2024 11:59 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Sat Mar 04, 2017 10:32 am 
Offline

Joined: Wed Mar 02, 2016 12:00 pm
Posts: 343
Hi

I have this project in which I want to interface a 6502 to a lattice CPLD and while is sounds quite straight-forward, its not quite so simple.

I have tested different ways of doing it, and as the CPLD wants to have a common clock (which I set as its internal FPGA clock at 133MHz), there is some twists in order to get it smoothly compiled into a real device.

The simulator (Lattice Diamond) seems to be able to do most things, while the real world is somewhat different (but you all know how that is).

What I WANT to do is to make an internal clock that is set at about the same frequency as the external 6502, then reset the internal Clock with basis of the external CLK2 signal (the Clock is constructed by a counter from the FPGA clock edge). This seems to work fine in the simulator, but not so within the CPLD. I am unable to get the two clocks syncronized, which is probably not so surprising given my short experience with CPLDs.

What I am able to do is by using the WR signal from the 6502 and write to the CPLD memory. I can also use the address lines to trigger the writing/reading, but using the external CLK2 is not working.

Basically, the logic to synchronize an internal clock with an external is what I would like to get going. So my question to you is how you would go about this to get clock synchronization. Or maybe I am just thinking of this the wrong way, so what solution would you use to get an internal clock and external clock to work together? I want to keep the 133MHz clock for fast internal logic (basically I trigger memory read/write with it, so I can have the memory interface to other things most of the time).

I know I can just skip the clock thing and go directly with the address signals and it would work, but this is one of those problems that is just too irritating to put on a shelf. I would really like to see if there is a good solution to it. :roll:


Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 04, 2017 11:01 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
Rather than trying to synchronise two clocks, as you have a master clock which is a great deal faster than the 6502 clock, may you can just sample the 6502 clock the same way you sample the RnW and address lines.

For a 6502 write, CPLD read, when your state machine sees the clock going from high to low, you know that the previous sample was the final sample during that Phi2.

For a 6502 read, CPLD write, you need to sample the address lines and start driving the bus some little time before the end of Phi2. Either you can count from the last falling edge, knowing the frequencies, or again you can sample Phi2 and choose to drive only in the second half of the cycle.


Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 04, 2017 12:10 pm 
Offline
User avatar

Joined: Tue Nov 16, 2010 8:00 am
Posts: 2353
Location: Gouda, The Netherlands
Easy solution to keep the clocks synchronized is to have the CPLD generate the 6502 clock by a divider. But that only works if you can control the 6502's clock. If you're trying to attach to existing hardware, I would follow BigEd's advise. Make sure you use a synchronizer (two registers in a row) to capture the clock.


Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 04, 2017 2:27 pm 
Offline

Joined: Wed Mar 02, 2016 12:00 pm
Posts: 343
BigEd wrote:
Rather than trying to synchronise two clocks, as you have a master clock which is a great deal faster than the 6502 clock, may you can just sample the 6502 clock the same way you sample the RnW and address lines.

For a 6502 write, CPLD read, when your state machine sees the clock going from high to low, you know that the previous sample was the final sample during that Phi2.

For a 6502 read, CPLD write, you need to sample the address lines and start driving the bus some little time before the end of Phi2. Either you can count from the last falling edge, knowing the frequencies, or again you can sample Phi2 and choose to drive only in the second half of the cycle.

That would probably work. Just disregard the CLK2 as a clock and check its state instead. Why didn't I think of that! :shock:

Arlet wrote:
Easy solution to keep the clocks synchronized is to have the CPLD generate the 6502 clock by a divider. But that only works if you can control the 6502's clock. If you're trying to attach to existing hardware, I would follow BigEd's advise. Make sure you use a synchronizer (two registers in a row) to capture the clock.

The 6502 is uncontrolled, so I have to follow it somehow. But I have been so narrowminded with respect of treating the CLK2 as a clock that I ended up making an internal CLK2-clock just to keep it that way. :oops:


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 06, 2017 7:50 pm 
Offline
User avatar

Joined: Sun Nov 27, 2011 12:03 pm
Posts: 229
Location: Amsterdam, Netherlands
You can synchronize the external clock to the internal one by a series of synchronisation registers (as mentioned by others), but check your CPLD documentation for the metastability figures so you know how many registers is 'officially' enough. And take the syncrhonisation delay into account when doing things that involve both clocks.

If you have PLLs in there (but in most CPLDs you don't), another solution would be to use the external clock as the reference clock going into the PLL. Given some thoughtful parameterisation of the PLL, that would effectively synchronize the clocks as well.


Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 18, 2017 6:06 am 
Offline

Joined: Wed Mar 02, 2016 12:00 pm
Posts: 343
I finally managed to get it going with an internal clock and using the address lines for syncronization:

Attachment:
image.png
image.png [ 719.22 KiB | Viewed 3033 times ]


The Vic-20 shown above is the digitized output from a real one:

Attachment:
image.jpeg
image.jpeg [ 2.57 MiB | Viewed 3033 times ]


Currently it only acts as a memory expansion using the internal EBR Ram of the CPLD. My next step is to add a 6502 core of some kind. ;)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: