Both the 8253 and the 8254 are very similar chips. They both share the same pin-outs but the 8254 has the upper hand in terms of faster counting speeds and a slightly better set of commands, but in essence the two are the same.
So what can I do with one of these chips?
The uses of a timer / counter chip are quite varied. You may need to time an event very accuratly, check the speed of somenthing, create a square wave or pulses at a particular rate, or even control the speed of a DC motor.
With many programmable modes, these chips can answer almost any timing or counting problem you can conceive. As will be explained in more detail later, the 8253/54 data sheet provides details on how to implement each mode, but before that, you will need to understand some of the basics.
To use this card some knowledge of programming will be required, the simple examples below use Microsoft's QuickBasic. This language is fairly easy to obtain and was supplied with DOS 6.22. By no means is the use of these cards limited to programming with any particular language, but the language does need to be able to input and output to ports.
And how do I make it do things?
To get the chip to do anything the CPU must tell it what to do... Ok that seems sensible, but how does the CPU know what to send and where to send it?, well.... that's the job of the program and guess who writes the program?... You do!.
If you're new to programming then maybe try something like basic, but different people prefer different languages, ask around, you may have some friends who know a bit about programming and may be able to help, or you may just like the look, i.e. cost, of a particular package. But most of all don't be put off, we all like a bit of a challenge and love the sense of achievement when it all works. But do be warned, programming can become addictive, you could end up like thousands of other programmers, sitting at the computer, bleary eyed, 3am in the morning, thinking "just a few more minutes".
Our range of cards plug into any available 8 or 16-bit slot (also known as an AT or ISA slot) on your PC's motherboard, just like a sound or video card does. Your Central Processing Unit, i.e your Pentium etc., communicates with cards by knowing the card's address and sending data to it. By physically using jumpers on the card, we can assign a set of addresses to the card, then in software, we can tell the CPU what these addresses are (more about this in the Programming section).
Ports vs. Memory
Addressing ports is different to addressing memory. Ports have port addresses and memory has memory addresses, port address 1234 is different to memory address 1234. Our range of cards use port addresses and cannot be set to use memory addresses. Sorry to go on about this but there is a lot of confusion surrounding this subject.
Reading?, writing??, bytes???, oh dear!. Don't worry, simply put reading is getting stuff from outside and copying inside your Pentium, writing is getting stuff from your Pentium and copying it outside somewhere. Reading and writing does not destroy the original but merely creates a copy. Bytes.. well this is a unit of data, it is effectively a block of eight bits, where each bit can either on or off. To help remember this, the word Byte was derived from the term "By Eight", get it?.
But, you may say, I've got a 32bit computer!. Don't worry there are still instructions on 32 bit machines, that can address just 8 bit chunks. Anyway, all ports on your PC are only 8 bits wide so everything is very straightforward.
You can use any computer programming language you like (e.g. Turbo C, Quick Basic, Pascal, Visual Basic, C or C++. Any programming language that is, that allows the writing and reading of bytes to a port address. For example in Quick Basic you use:
OUT(portAddress, byteValue)
byteValue = IN(portAddress)
OUT writes byteValue (0 to 255 decimal) to the address defined in portAddress and IN reads the value from portAddress and stores it in the variable byteValue.
Different languages will use similar commands but will tend to look very similar, for instance in C you would use:
outportb(portAddress, byteValue);
byteValue = inportb(portAddress);
to accomplish the same thing. The instructions outportb and inportb do the same thing as with the basic OUT and IN statements.
Ok so we've run through how to send things to your computer's ports and how to read stuff from your computer's ports. Next step, sending stuff to your 8253/54.
Before we can do this we first need to know a little about what these chips can do and more importantly, how we make them do what we want them to do!. This is where things start to get a bit technical.
The Timer Registers
Each of the three counters has a thing called a register, yes this is a port, you send it a value that is used to load the counter with. It's a bit like a microwave oven, you set it to so many seconds or minutes, wait, and evetually DING your pie has burst open and you're loking for some kitchen roll. Well unfortunatly these 8253/54's can't do anything that spectacular.
Anyway, like with your microwave, if all is ok the counter will count the number you have set down to zero and then do something. What it does depends on the control mode you've set.
Control mode?, well this is the good bit that allows this little chip to be all things to all men, or women. One mode lets you switch something on for a period, like the microwave, while another mode will just give the Ding at the end. To understand what mode to use for your project you will need to know a bit about the Control Register, and if you havn't guessed it already, it's a port and it's where you send the control mode to.
Feeling a bit sore in the head?, well it's about time for a break before we get onto the next section.