Stop a running timer
Moderator: Moderators
Stop a running timer
I'd like to stop the VIA timers from running. What's the easiest way to do that? It looks like I would have to configure the timer to single interval mode, put zero in the timer register and acknowledge the IRQ. Is there an easier way to do it?
- Mike
- Herr VC
- Posts: 4845
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
Re: Stop a running timer
I am sorry to tell you, but ...
Unlike the 6526 CIA, there are no enable bits for the two timers in the 6522 VIA. Timer 1 can be operated in continuous or one-shot mode (the latter, which you call 'single interval mode'). Timer 2 only works in one-shot mode.
When in one-shot mode, both timers issue an interrupt when underflowing from 0 to $FFFF - provided the corresponding bit in the IER is set - and then continue counting down from $FFFF, but won't issue any further interrupts unless they are reloaded.
In continuous mode, timer 1 is reloaded from the latch value when it has underflowed. With a latch value of 0, the timer value alternates between 0 and $FFFF. A latch value of $FFFF will result in the timer value being $FFFF on two successive cycles and then counting down from there, for a period of 65537 cycles.
That being said, what application did you have in mind that led you want to stop the timers? Wasn't it sufficient to merely stop interrupts from occuring?
... you probably should have phrased that question more in line of "Is there any way to do that?".bjonte wrote:I'd like to stop the VIA timers from running. What's the easiest way to do that?
Unlike the 6526 CIA, there are no enable bits for the two timers in the 6522 VIA. Timer 1 can be operated in continuous or one-shot mode (the latter, which you call 'single interval mode'). Timer 2 only works in one-shot mode.
When in one-shot mode, both timers issue an interrupt when underflowing from 0 to $FFFF - provided the corresponding bit in the IER is set - and then continue counting down from $FFFF, but won't issue any further interrupts unless they are reloaded.
In continuous mode, timer 1 is reloaded from the latch value when it has underflowed. With a latch value of 0, the timer value alternates between 0 and $FFFF. A latch value of $FFFF will result in the timer value being $FFFF on two successive cycles and then counting down from there, for a period of 65537 cycles.
That being said, what application did you have in mind that led you want to stop the timers? Wasn't it sufficient to merely stop interrupts from occuring?
Re: Stop a running timer
In order to make my program start to be deterministic I start by shutting off the IRQ and NMI interrupts. I'm thinking if there's a timer that continues to count it will set the interrupt flag sometime in the future and potentially trigger an intended interrupt later.
I'm now setting the timer to one-shot and acknowledge the IRQ when it has triggered to avoid this.
Re: Stop a running timer
If the IER bit is disabled no IRQ/NMI is generated, all that happens in the appropriate bit in the IFR register get set. This will be cleared when you next write to the timer latch.bjonte wrote: ↑Sat Mar 13, 2021 11:52 am In order to make my program start to be deterministic I start by shutting off the IRQ and NMI interrupts. I'm thinking if there's a timer that continues to count it will set the interrupt flag sometime in the future and potentially trigger an intended interrupt later.
Re: Stop a running timer
I would state SEI as first opcode at all.
BR
BR
Valid rule today as earlier: 1 Byte = 8 Bits
-._/classes instead of masses\_.-
-._/classes instead of masses\_.-
Re: Stop a running timer
Mmhm, true. If I clear the IRQ enable bits that should be enough because any attempts to enable them would also mean setting the timer value and reset the acknowledge bit.
- Mike
- Herr VC
- Posts: 4845
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
Re: Stop a running timer
As long as solely your program runs, you're pretty much in control regarding this. When 3rd party code is executed from your program, all bets are off as that other code can reinit the VIA registers to its liking without any chance for your program to inhibit this or regain control.bjonte wrote:If I clear the IRQ enable bits that should be enough because any attempts to enable them would also mean setting the timer value and reset the acknowledge bit.
Note, bits in the IER are not defined by writing them as zeroes or ones, rather when writing, bit 7 gives the required status (0 = clear, 1 = set) and the other bits indicate which enables should be changed. For example, writing %01111111 = $7F clears all IER flags, writing %10000001 = $81 explicitly enables timer 1 IRQs and leaves the enable status of all other sources unchanged.
That still doesn't quite answer what you're up to. Is your program supposed to autostart from cartridge?In order to make my program start to be deterministic I start by shutting off the IRQ and NMI interrupts.
Re: Stop a running timer
It's surprising how much code doesn't do this properly, I've disassembled several programs/ROMs (including stuff written by CBM) that does the wrong thing.Mike wrote: ↑Sun Mar 14, 2021 3:58 am Note bits in the IER are not defined by writing them as zeroes or ones, rather when writing, bit 7 gives the required status (0 = clear, 1 = set) and the other bits indicate which enables should be changed. For example, writing %01111111 = $7F clears all IER flags, writing %10000001 = $81 explicitly enables timer 1 IRQs and leaves the enable status of all other sources unchanged.
Re: Stop a running timer
cant you "stop" at least timer2 by setting it to count pb6 pulses (which never happen)?
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.
Re: Stop a running timer
Ah, sorry for the delay. I seem to be missing notifications. I made an invitation intro for a Commodore club so it's a standalone PRG file started from BASIC.
Re: Stop a running timer
I went with clearing the IRQ enable bits and acknowledging everything.