6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Mon Jul 01, 2024 6:52 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: External Timer
PostPosted: Thu Jan 12, 2017 11:56 pm 
Offline
User avatar

Joined: Sun Sep 08, 2013 10:24 am
Posts: 740
Location: A missile silo somewhere under southern England
Hi guys

I need some opinions on what to use as a Timer source for my 6502 projects as my experience with porgrammable timers is next to zero.

Looking at my needs, mostly it's going to be for writing to I2C ICs at 400KHz and also to a 44780 LCD module. I'd use the timer to prompt when the next bit/command is to be sent or received.

I know I can do this with the timer in a 65C22, but as I plan to change the PHI2 oscillator speeds at times I need an external timer and not one based off of PHI2.

Looking around I have found a programmable timer by TI: the CD4541B (datasheet).

Obviously, as the CD4541B only goes up to 100KHz with the internal oscillator, I'd need to attach something like a 1MHz external oscillator on pin 3 and then hook pin 8 (Q) to one of CA1, CA2, CB1, or CB2 on a VIA and use that to generate interrupts. Pins for A, B, Master Reset, Auto Reset, Mode and Q /Q Select (pins 12, 13, 6, 5, 10, 9 respectively) would need to be hooked up to port A or B of the 65C22.

What do you think? Is this a good IC & implementation or is there a better way or IC?


Top
 Profile  
Reply with quote  
 Post subject: Re: External Timer
PostPosted: Fri Jan 13, 2017 1:16 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8460
Location: Southern California
If the Φ2 frequency is not known at the time of the program being written, but there will be another, unrelated but known time base, you could use the VIA's T2 in pulse-counting mode on PB6. Feed the signal from an external source to PB6 and give the T2 counter a number and let it count down, and program it to generate an interrupt when it reaches 0. However, I think it will be easy enough to do bit-banging on the I²C without overrunning the device. Also, most things that need time to process a command can be polled; for example, the I²C EEPROMs need time to do their programming, and you can poll it until it acknowledges the poll, indicating that it's ready for another command. On the LCD, you can read the busy bit. There's hardly a reason to time it. Without polling, there's often something else for the computer to do anyway, like form the next byte to feed, and by the time it can feed it to the device, the device is ready and waiting anyway.

_________________
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  
 Post subject: Re: External Timer
PostPosted: Fri Jan 13, 2017 3:26 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8236
Location: Midwestern USA
banedon wrote:
I need some opinions on what to use as a Timer source for my 6502 projects as my experience with porgrammable timers is next to zero...I know I can do this with the timer in a 65C22, but as I plan to change the PHI2 oscillator speeds at times I need an external timer and not one based off of PHI2.

Attachment:
File comment: 82C54 Programmable Timer
82c54_PIT.pdf [387.73 KiB]
Downloaded 97 times

It might be a little overkill.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
 Post subject: Re: External Timer
PostPosted: Sat Jan 14, 2017 5:44 pm 
Offline
User avatar

Joined: Sun Sep 08, 2013 10:24 am
Posts: 740
Location: A missile silo somewhere under southern England
Thanks for the responses. That looks promising BigDD. I'll have a look through and see if I can integrate it. Even if I can't or don't I'll still get one to have a play around with it.
Garth, you make a good point with regard to nto needing a timer for LCD and I2C - been a long while since I was looking at my 6502 projects and I clearly wasn't thinking.
I'll post in the appropriate section of the forum with my efforts at trying to impement both, although so far I'm tearing my hair out over it the LCD bust flag implementation lol.


Top
 Profile  
Reply with quote  
 Post subject: Re: External Timer
PostPosted: Sat Jan 14, 2017 8:43 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8460
Location: Southern California
I replied about the LCD in the other topic. For this one, I'll comment that I have a sample I²C-interfacing circuit at http://wilsonminesco.com/6502primer/pot ... ITBANG_I2C, and sample code, in several forms, at http://wilsonminesco.com/6502primer/GENRLI2C.ASM .

A nice thing you can do is to leave a 0 in the VIA port's output bit (particularly for I²C data) full time, and just change the bit in the data-direction register. Even for output, since I²C uses a passive pull-up, outputting a 1 just involves making the VIA pin an input by way of the data-direction register, even though the output register has a 0 in that bit.

Again it works nicely to put the data on bit 6 or 7 of the port so you can test it with the BIT instruction. Regardless of what's in the accumulator, BIT will put the port's bit 7 in N (to test with BMI or BPL) and bit 6 in V (to test with BVS/BVC). Putting the clock on bit 0 works nicely to toggle it with a single instruction, INC or DEC, assuming you knew the starting value so you don't make a carry or a borrow ripple into other bits.

_________________
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  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 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: