Help with a stop watch.

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
Edshere
Posts: 4
Joined: Tue Jan 17, 2006 3:27 am
Location: McPherson, KS USA
Contact:

Help with a stop watch.

Post by Edshere »

I'm wanting to build a stop watch with a relolution of .001. I was planning on useing a 16f88. Can anybody point me in the right direction to start this thing? Should I use a different chip? Is .001 accuracy realistic? etc.

edit- a little more detail about the project. I have a piston with two normally open switches, one on the top and one on the bottom. When the piston is depressed it will make an input or close a switch(#1) at which time it resets or zeros the stop watch. when the piston is release and starts to travel the switch(#1) opens and the stopwatch starts. When the pistion is extended i want to close another switch(#2) and stop the clock. then I need to display the results on a lcd. Keep in mind I don't need the lcd to count, i just need it to show the final time value. By the way the longest this will ever take is 1.5 seconds so I don't need minute or hour logic.

Pretty simple, I just need to figure out how to make the 1/1000th clock accurate.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Post by Benj »

Hi Edshere I can help a bit but I think Steve who will be on moday will be able to shed more light on the situation for you.

I would recommend using the internal timer0 or timer1 if the 88 has this to do the timing for you. I would recommend that every time the timer rolls over from its max value to its min value eg 255 to 0 you allow an interrupt to occur.

To work out the time it takes for an interrupt to occur you simply use this simple formula.

Program freq = Xtal freq / 4
Program time = 1 / Program freq
max delay time = counter max value * program time * prescalar

eg

Program freq = 4MHz / 4 = 1Mhz
Program time = 1 / 1Mhz = 0.000001 seconds
prescalar = 1
max delay = timer0 (256) * 0.000001 = 0.000256 seconds
max delay = timer1 (65536) * 0.000001 = 0.065536 seconds

an example program using the timer0 and interrupts is available here
http://www.ben-rowland.co.uk/Proteus_Pic_Simulation.htm
under interrupt demos.

You could then start counting timeouts from when the first switch is pressed to when the second switch is pressed. Then calculate and show the result in seconds on an LCD.

User avatar
Steve
Matrix Staff
Posts: 3418
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Post by Steve »

I suggest looking at the frequencies of crystals available. Many years ago, we opted for a 3.2768MHz crystal because this would divide down into milliseconds. We currently use the 19.6608MHz crystal as standard because this is ok at dividing to milliseconds, but also divides down well to provide common BAUD rates.

You will find that crystals that are not an exact number of MHz will typically be used to generate BAUD rates or divide for timing applications.

Post Reply