Generating a 60Hz Interrupt

Everything about programming, including VDP and Sound programming.
Post Reply
User avatar
thewiz
Posts: 137
Joined: 12 Aug 2012 16:08

Generating a 60Hz Interrupt

Post by thewiz »

Ok I've been looking into generating a 60Hz interrupt using the CTC as a large number of VGM's have been captured at this rate.

I am using channel 1 for this to avoid the VDP interrupt on channel 0.

So my first attempt got a 61Hz interrupt by programming the CTC in Timer mode, with a prescaler of 256 and a const of 256:

4000000 / 256 = 15625
15625 / 256 = 61

So I am now looking at using the CTC in counter mode, with a prescaler of 256 and a const of 20:

4000000 / 13 = 307692
307692 / 256 = 1201
1201 / 20 = 60

Have I got that right?
THIS is what Memotech is doing now.
Martin A
Posts: 799
Joined: 09 Nov 2013 21:03

Re: Generating a 60Hz Interrupt

Post by Martin A »

I can see one issue, if you look on page 232 of the new manual, it says there's no pre-scaler when the CTC is in counter mode.

However you could still use timer mode a large count value to avoid triggering too often, and then do a sub count in the interrupt handler.

Possible values
4000000 / 256 = 15625
Count of 130 =120.2
software count 1 in 2 gives 60.1

Slightly closer
4000000 /16 = 250000
count of 245 = 1020.4
software count 1 in 17 gives 60.02
User avatar
thewiz
Posts: 137
Joined: 12 Aug 2012 16:08

Re: Generating a 60Hz Interrupt

Post by thewiz »

Thanks Martin,

Hadn't thought of counting interrupts in the ISR routine too.

Your first idea would be a simple flip/flop affair.

LD A, (ISR_FF)
INC A
AND 1
LD (ISR_FF), A
JR ????
THIS is what Memotech is doing now.
Martin A
Posts: 799
Joined: 09 Nov 2013 21:03

Re: Generating a 60Hz Interrupt

Post by Martin A »

I needed to do something similar for the 6502 board, I was using the BBC basic 3 rom, and the BBC used a 100hz ticker.

There wasn't a way to get exactly that from the 4mhz main clock and the /256 pre-scaler setting. (/256 and 156 count =100.2 and /256 and 157 count =99.5 )

So I used /16 and a count of 250 to get a 1khz interrupt, and only passed 1 in ten to the 6502 board.
Post Reply