This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Timing in NES, other than waiting for VBLANK

Timing in NES, other than waiting for VBLANK
by on (#41461)
Hi, is it possible to meassure time in the NES other than waiting for VBLANK?
This gives a precision of a 60th of a second, in NTSC, but what if you want more precision? is it possible?

by on (#41462)
There's APU frame IRQs (which is nearly the same rate as NMIs -- about 60 Hz).

There's also DMC IRQs which have an adjustable timer and can happen pretty quick (by my math... once about every 432 cycles.. which works out to about 4143 Hz). The problem with these though is they use the DMC which means if you're using the DMC for timing, you can't use it for audio. Plus using the DMC can interfere with joypad reads, which means you need to repeatedly read joypad data until you get two nonconflicting returns.

Some mappers also have a much simpler CPU cycle counter. But then you have to use that mapper, of course.

Other than that, I can't think of any. Only other way really is to count cycles (which you can't do from C).
Re: Timing in NES, other than waiting for VBLANK
by on (#41465)
Petruza wrote:
Hi, is it possible to meassure time in the NES other than waiting for VBLANK?

The best answer depends on your answer to the following: Of what event are you trying to measure the time?

by on (#41468)
Altough the VBlank may not happen exactly 60 times per second (50 respectively for PAL consoles), I guess it's still the most accurate method.
Re: Timing in NES, other than waiting for VBLANK
by on (#41471)
tepples wrote:
Petruza wrote:
Hi, is it possible to meassure time in the NES other than waiting for VBLANK?

The best answer depends on your answer to the following: Of what event are you trying to measure the time?


I want to make a metronome. But maybe 60 hz are enough.

PS: Tepples, don't take it personal, but your avatar annoys me a lot :? can I make one for you? maybe with some NES character...

by on (#41472)
Hmmh, your avatar is much weirder too (altough it doesn't annoy me). A face viewed by front and face at the same time is really weird.

by on (#41478)
The easy way to get flexible timing at 60hz is to use sub-frame counting with 16-bit adds. Just make it so the lower byte is never reset (always carries over).

To your timer (16-bit variable), you'd add values like these every frame to get these rates:
$0100 = 60Hz.
$0001 = 1/256Hz
$0180 = 90Hz

I guess you actually could just ditch the high byte and trigger a beat whenever the low byte wraps around (check carry flag).

by on (#41479)
Bregalad wrote:
Hmmh, your avatar is much weirder too (altough it doesn't annoy me). A face viewed by front and face at the same time is really weird.

Looks like a texture map to me.

But then, if you just want to make a metronome for tempos between 40 and 240 beats per minute, here's how you could do it:
Code:
while not done:
    wait for vblank
    update display
    counter = counter + selected_beats_per_minute
    if counter >= frames_per_minute:
        counter -= frames_per_minute
        beep

The value of frames_per_minute depends on whether you're on NTSC (use 3606) or PAL (use 3000).

by on (#41481)
In this post, Bregalad wrote:
Hmmh, your avatar is much weirder too (altough it doesn't annoy me). A face viewed by front and face at the same time is really weird.


Tepples' avatar is not weird at all, it just annoys me, I'm not sure why.

by on (#41482)
A strange thing to talk about, but it does make him seem constantly annoyed. If he's comfortable with it then I don't know why he'd change it though, I know I'm hesitant to give up stuff like that when I've used it for ages.

What's that kid from?

by on (#41483)
UncleSporky wrote:
What's that kid from?

Pinocchio 2

by on (#41487)
Whoa... :) and made by Filmation!

by on (#41490)
tepples wrote:
UncleSporky wrote:
What's that kid from?

Pinocchio 2


Does the name "Pin Eight" have to do with that?
Because in spanish Pin 8 would be "Pin ocho" the same as Pinocchio.

by on (#41491)
UncleSporky wrote:
it does make him seem constantly annoyed.

You're right, that's maybe what annoys me.
Maybe in my subconscious I think tepples is always bothered by something, like Pinnochio seems to be :D

by on (#41495)
Petruza wrote:
Does the name "Pin Eight" have to do with that?
Because in spanish Pin 8 would be "Pin ocho" the same as Pinocchio.

Whoa. That's deep.

by on (#41496)
BMF54123 wrote:
Whoa. That's deep.


Haha, couldn't have said it better :lol: .