Using the 65C22 VIA's timers
The VIA interface chip offers more than GPIOs. It can also keep time.
The 65C22 Versatile Interface Adapter (VIA) chip is popular primarily for the way it gives you 16 general-purpose input/output (GPIO) pins. But it has many more tricks up its sleeve, and these include the presence of two timers.
A timer is the kind of functionality you might normally associate with a microcontroller. And you can use it in a number of ways.
The basic method of a timer is to set a value and have it decrease with every tick of the system clock. On the 65C22, the counters are 16-bit values, so they can start as high as 65,535 ($FFFF). Then you either check in occasionally to see what value it has reached or configure it so that it generates an interrupt when it reaches zero. You also have the option to have the timer restart automatically at the value you first gave it (free run mode) or do nothing after reaching zero (one-shot mode).
One classic use of a timer is to create a delay function. If you’ve programmed in the Arduino IDE, you’ll be familiar with delay(), and AVR coders will know _delay_ms() and _delay_us(). I use Timer 1 in the main VIA board of my 6502-based Zolatron homebrew computer to provide a similar functionality — useful when you want to, say, send strobe signals or give peripherals time to respond.
The 65C22’s timers — T1 and T2 — are not identical and so we’ll be focusing on T1 for the purposes of this article, as it’s the more versatile of the two.


