Controller port clocking

Discuss hardware-related topics, such as development cartridges, CopyNES, PowerPak, EPROMs, or whatever.

Moderator: Moderators

Post Reply
johey
Posts: 8
Joined: Fri Aug 26, 2016 3:42 am

Controller port clocking

Post by johey »

Trying to build a custom uC based controller adapter for the NES (American model). Though I'm surprised over the clock pulse I get from the NES. First, it looks to be active low in contrast to reference diagrams, but most strangely the clock pulse is very short. About 1 us.
20160903_223738.jpg
Channel 1 is the latch and channel 2 is the clock pulse. What is this about? Should it be like this? When is the data read? On rising edge? I'm in trouble with this timing.
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Controller port clocking

Post by lidnariq »

The clock pulse is only true (= low) for the (usually) 1/(1.789MHz) that the address bus is exactly $4016 (Player 1) or $4017 (Player 2).

The system uses transparent latches instead of edge-triggered registers; transparency closes on the falling edge of M2 (which should be approximately the same time as the rising edge of JOYn/OE, maybe a little earlier)

It's worth noting that the NES's joypad inputs are isolated from the CPU data bus; you have all the time from the rising edge until shortly after the next falling edge to drive the correct new value, and you don't need to only emit while JOYn/OE is low (this what the 74'368 on the mainboard is for)

You might find the following pages on the wiki useful:
nesdevwiki:CPU pin out and signal description
nesdevwiki:Standard controller
as well as the 6502 datasheet. ( http://6502.org/documents/datasheets/mos/ )
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Controller port clocking

Post by rainwarrior »

Also might be worth noting that the clocks themselves come from software, so the timing is highly variable from game to game. Some won't read them all at once, some won't even read all of them, some will read extra bits. It's also very common for games to re-read the whole thing (i.e. latch and start again) three or four times in a single frame.
johey
Posts: 8
Joined: Fri Aug 26, 2016 3:42 am

Re: Controller port clocking

Post by johey »

Thanks for the informative replies!

When I try sending data on the data pin, it looks like the NES is pulling it low. Is that an expected behavior?
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Controller port clocking

Post by lidnariq »

There should only be a weak pullup resistor on the input side of the 74'368 on the mainboard.

If you're seeing otherwise ... uh, are you connected to the right place?
johey
Posts: 8
Joined: Fri Aug 26, 2016 3:42 am

Re: Controller port clocking

Post by johey »

Indeed I wasn't connecting it correctly. :oops:
johey
Posts: 8
Joined: Fri Aug 26, 2016 3:42 am

Re: Controller port clocking

Post by johey »

Just want to say thank you for all valuable input. I successfully made it working after some trial n error.
Post Reply