6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 15, 2024 5:20 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: 6522 VIA timer
PostPosted: Mon Sep 05, 2005 12:36 am 
Offline

Joined: Wed Jul 20, 2005 11:08 pm
Posts: 53
Location: Hawaii
I am thinking of building a 6502-based digital clock. For the timing, I would like the timing to be done by a 6522 VIA. How do I program Timer 1 of the 6522 to tick once a second? Oh, and I don't want to use any approaches that modify PA or PB, since I'd like to hook up those to a BCD decoder.

_________________
Sam

---
"OK, let's see, A0 on the 6502 goes to the ROM. Now where was that reset vector?"


Top
 Profile  
Reply with quote  
 Post subject: Re: 6522 VIA timer
PostPosted: Mon Sep 05, 2005 2:25 am 
Offline
User avatar

Joined: Wed Sep 03, 2003 6:53 pm
Posts: 153
Location: Long Island, NY
asmlang_6 wrote:
I am thinking of building a 6502-based digital clock. For the timing, I would like the timing to be done by a 6522 VIA. How do I program Timer 1 of the 6522 to tick once a second? Oh, and I don't want to use any approaches that modify PA or PB, since I'd like to hook up those to a BCD decoder.


Start by determining the 16-bit value that will give you a 1Hz timeout. This is dependent on the clock frequency, which if it's a stock 6522 would be 1MHz. Disable Timer 1 interrupts in the IER unless you want/need to respond to a timeout interrupt. Set the ACR for the proper mode (probably $C0 for free-running, PB7 output enabled). Then, store the count value in register address +4 and +5 (low byte and high byte latches). Writing to the high-order latch starts the counter. PB7 is the output pin which may need conditioning/buffering depending on the circuit loading.

Although I haven't pulled the 6522 data sheet, as I recall it had some good information on this (no code unfortunately), but it's pretty straightforward.

_________________
Rich Cini
Build Master and maintainer of the Altair32 Emulation project
http://cini.classiccmp.org
http://altair32.classiccmp.org


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Sep 05, 2005 5:33 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8541
Location: Southern California
Quote:
How do I program Timer 1 of the 6522 to tick once a second?

You'd have to use a very low clock speed (about 65kHz max!) to get it up to a 1-second timeout.  Otherwise, use a much faster time-out rate and count up in software, changing the display only when the count reaches a high enough value to increment the seconds' byte.

The 6522 VIA's T1 can be used in different ways, including free-running with the time-out frequency being determined by the phase-2 frequency and the T1 latch value you store.  (The time-out frequency is actually ph2/(n+2), where ph2 is the phase-2 frequency, and n is the latch value.  The latch (and counter) however, being only 16-bit, cannot count nearly high enough to go a whole second unless the clock frequency is really low.  On my 5MHz workbench computer, I have VIA1 cause an interrupt every 10ms (.01 second) for keeping time, since the VIA can't even count up to the next round number of 20ms at 5MHz, or even to 1/60th of a second.  Every time T1 times out, an interrupt is generated, and software updates the memory locations that keep the time from the hundredths-of-seconds place to the years' place.  This is covered in the 6502 interrupts primer, which also covers the code for how to set up the 6522.  The "Tip of the Day" column at http://www.6502.org/forum/viewtopic.php?t=342 may also be helpful, particularly tips numbers 9 and 21.  (The purpose of the "Tip of the Day" was to give ideas of what can be done, not to give all the details of how.)



Quote:
since I'd like to hook up those to a BCD decoder.

Why would you use a BCD decoder?  Just use the software to figure out the decimal output and which LED segments to light up to get the right display.  Use the software also to strobe the LED matrix so you don't need so many connections.  Then a single 6522 will have enough I/O lines to take care of the display, the buttons, and the beeper or speaker (also connected directly, with no other hardware).

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: