Chess Clock Project

This is the place for any magazine-related discussions that don't fit in any of the column discussion boards below.
Post Reply
chessman
Posts: 292
Joined: Tue Jan 14, 2003 1:01 am
Location: Issaquah, WA
Contact:

Chess Clock Project

Post by chessman »

NOTE: This is a long post.
To sum it up, I need some help with PIC code. If you can't help in that area, you don't need to read it all (but you still can!) Just warning you in advance so you don't get aggrevated with the length...<p>I am currently starting a new project, a Chess Clock for, well, chess of course. The basis of a chess clock is a dual timer that counts down from a starting value, and when a move is made, a button is pressed, holding the current timer value and starting the other timer.<p>Control will be from a PIC and display will be done by 8 7-segment LEDs, common anode, because those are the only type I have laying around. 4 digits on each side will display the time remaining, and a decimal point will be used to divide minutes and seconds.
Obviously, multiplexing the 7-seg. LEDs is the way to go, which leaves me with a couple questions:
1) Which PIC should I use for the project? Samples I currently have on hand are the 16F84 and 16F877, so I will be using one of those. I was thinking the 16F877 will be the only way to go, because there are 4 inputs + 7 outputs for digits and 8 digit select BJTs. That's 19 I/O lines.
2) Would it be a good idea to keep each group of 4 digits on seperate lines? I was thinking it would ease required code, as only 4 digits would have to be multiplexed on each group of 11 lines instead of 8 digits on 15 lines. Maybe my thinking is wrong here....<p>Some more specs of the project are:
- 4MHz or 20MHz clock MUST be used. Unfortunately, I cannot spend the money on a 32.whatever kHz watch crystal.
- 1 button for each player (momentary). This button is pressed when the move is made. It stops the current timer from counting down, holds the value, and starts the other timer.
- 1 time set button (momentary). Hold it and the countdown time increases from 0 to 90 minutes, then overflows and starts over.
- 1 reset button (momentary). Push it and clock value resets to zero on both displays.
- 1 Time Out LED. Flashes when either clock reaches zero.<p>I am having trouble figuring out the code that I need for the PIC. I am relatively new to PIC programming so I'm not sure how to do some basic things.
It would be great if some of you could help me out with my project, as this is a very ambitious goal. Specific routines I need help with are:
- generating the ten millisecond delay required to accurately keep the time without resetting a one second counter during a button interrupt.
- handling the multiplexing of the LEDs and running it in the background so time can be accurately kept.
- being able to handle an interrupt from either the play clock buttons or the time reset button.<p>I'm thinking for time reset it might work to just make the reset button on the _MCLR line on the PIC. If the code starts the clock displaying:
00.00 00.00
then this would work. Doing that would solve the problem of handling multiple-button interrupts.<p>Another problem:
It takes 10 milliseconds to write to EEPROM....so in the button interrupt handler, storing the current clock time would interfere with counting the clock time from TMR0....
Could this be solved by writing all variables to RAM? I'm new to interrupt handlers, so I don't know how it's normally done.<p>Any help any of you can provide me with is greatly appreciated!!<p>~Kyle
bodgy
Posts: 1044
Joined: Tue Dec 04, 2001 1:01 am
Location: Australia
Contact:

Re: Chess Clock Project

Post by bodgy »

Kyle,<p>I can give you a hand! <p>Now I would chooses the 877 as it has 3 timers. Of which Timer 1 can be made to count by an external pulse/switch.<p>I have a routine that is in 'C' I've got an ASM version somewhere that will give you rock solid 1 second timing without using a separate crystal.<p>Now as far as the 7 segment display is concerned, it could be made easier if you are allowed or can afford to purchase the MAX 7219 or similar chip, as this does all the multiplexing for you, you just have to send the code then.<p>Bog standard multiplexing really doesn't matter how many displays are attached because it's just a simple counter required to update which anode needs to be switched.<p>If you use the _MCLR as the reset, don't forget this will reset the whole program - is that what you want?<p>Is this to be in assembler or basic or c?<p>Do you have a breadboard or development board for the PIC?<p>feel free to email me
On a clear disk you can seek forever.
hlreed
Posts: 349
Joined: Wed Jan 09, 2002 1:01 am
Location: Richmond, TX
Contact:

Re: Chess Clock Project

Post by hlreed »

To help clarify this for yourself treat the system as an input, output device.
Now, list your inputs and input widths and outputs and width. Then the program is to simply read the inputs and do something and write the outputs.
Put this on paper. Do not try to remember everything, even though you see the project in your head.
The processor mentioned above is fine, but you should think about that last, not first.<p>Good luck,
Harold L. Reed
Microbes got brains
chessman
Posts: 292
Joined: Tue Jan 14, 2003 1:01 am
Location: Issaquah, WA
Contact:

Re: Chess Clock Project

Post by chessman »

I do have plenty of prototyping resources, power supplies, and a fairly good DMM.<p> Code will be done in assembler, because I like the interface as opposed to basic or C.<p>Unfortunately, ordering the multiplexing IC is not an option for me. My parents won't allow me to spend any more money, because I just spent a lot on basic equipment needed.<p>If it is possible, I'd like to do this all-software.<p>Yes, I am aware that using the _MCLR line will reset the whole program. The "Reset Time" button is used to:
1. stop the time counter
2. reset both clock displays to zero
3. wait for user input from "Time Set" button.<p>the code can be programmed to enter this state on power-up, so it would be fine to reset the whole PIC.
bodgy
Posts: 1044
Joined: Tue Dec 04, 2001 1:01 am
Location: Australia
Contact:

Re: Chess Clock Project

Post by bodgy »

OK<p>So the first thing to do is to write your algorithm or if you prefer Program Descriptive Language amounts in the end to the same thing.<p>Your display will require 15 data lines. This could be cut down but might be a project to do after you have the first one working if you wanted to you could use your idea of addressing in two sets of 4 in which case you need 7 lines for the segments, 4 for the anodes and 1 to switch between the two banks of displays 12 data lines.<p>First Draft - note this is not complete and it will need amending.
SETUP<p>Begin:
setup PORTS
_ Switch off ADC
_ initial state
_ direction
_ set up Option register
_ Set up INTCON register
End setup<p>INITIAL STATE
Begin:
_ clear digit counter
_ set display to display zero

etc.<p>there is some 7 segment code available for download from Tony Nixons site - www.bubblesoftonline.com.au under projects.<p>As I said feel free to email me if you need to.<p>colin
On a clear disk you can seek forever.
bodgy
Posts: 1044
Joined: Tue Dec 04, 2001 1:01 am
Location: Australia
Contact:

Re: Chess Clock Project

Post by bodgy »

Ahem, part of what I said was um how shall I put it ? Ah yes rubbish.<p>Ignore the bit about one bit for bank switching the displays - this wouldn't work in this particular setup!<p>colin
On a clear disk you can seek forever.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests