Stop Watch (MM:SS:DD),

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
armagon29
Posts: 56
Joined: Thu May 07, 2009 4:40 pm
Been thanked: 2 times
Contact:

Stop Watch (MM:SS:DD),

Post by armagon29 »

Dear All:

I made a modification from FC example “Digital clock” to become a STOPWATCH (MM:SS:DD), but I tested this FC Stopwatch with a real Casio Stopwatch and they have about 10% different between 2 times, could you help me to check time interruption options or clock speed

Thanks

5. Digital stopwatch.FCF
D Stopwatch
(15.81 KiB) Downloaded 470 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: STOP WATCH (MM:SS:DD),

Post by medelec35 »

Hi armagon29.
You can try the following two thing to make your stop watch more accurate.

1) In your INITIALISE macro, Change prescaler in your timer interrupt from 1:1 to 1:256

2) In your INTERRUPT_TMR0 macro add a C Code box with

Code: Select all

tmr0=+64;
at the beginning.


Let me know if that works please, and if it does I will explain what the problem was.
Your flowchart counts in 100th secs, secs and minutes now.

Martin
Martin

armagon29
Posts: 56
Joined: Thu May 07, 2009 4:40 pm
Been thanked: 2 times
Contact:

Re: STOP WATCH (MM:SS:DD),

Post by armagon29 »

FC stopwatch works OK now

Thanks

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: STOP WATCH (MM:SS:DD),

Post by medelec35 »

Your welcome, Thanks for letting us know.
I will explain what was happening for anyone wishing to learn how the timer0 side works. Then it would be easier to create/alter flowcharts that involve timer0

For a brief explernaion of timer0 interrupt including why I added

Code: Select all

tmr0=+64;
See:
http://www.matrixmultimedia.com/mmforum ... =26&t=8660

With the original digital clock example which I have attached, if you look at the timer0 properties In INITIALISE macro (double click or right click timer0 icon and select properties), the prescaler is set for 1:128 and below it shows interrupt frequency at 150Hz.
This means that the timer0 macro is accessed once every 1/150 = (6.667ms to 3 decimal places) = 150 times a second hence 150Hz
That is why in the SECONDS macro there is a decision branch

Code: Select all

SECOND_COUNTER >= 150
, since 6.667ms x 150 = 1 second
So each time the SECONDS macro is accessed the SECOND_COUNTER is increased by 1, and when the value reaches 150, exactly a second has passed. The name SECOND_COUNTER is a bit missleading since when this value is increased by 1 its only 6.66ms has elapsed and not 1 second!

Going to the example armagon29 posted,

Code: Select all

SECOND_COUNTER >= 150
is changed to

Code: Select all

SECOND_COUNTER >= 1
.
Since this there is a calculation within the Yes part:

Code: Select all

SECONDS = SECONDS + 1
then after timer0 interrupt is been accessed ONCE!this decision will then be true, both

Code: Select all

SECONDS
and

Code: Select all

SECONDS_UNITS
will increase by +1. Looking at the timer0 properties interrupt frequency is 19200Hz this will happen every 1/19200 = 52us. Thats why the timing is out.

Here's what I did. I decided that the timer0 interrupt should trigger every 100ms since flowchart is created so 10 x

Code: Select all

SECONDS_UNITS
increases
SECONDS_TENS
by 1, and 10 x

Code: Select all

SECONDS_TENS
increases Seconds by 1. Therefore since to get 1 scecond, the interrupt has to trigger 100 times. Since you want to LCD to display every 10ms like a stop watch, I have changed interrupt to the nearest lower value to 100Hz = 75Hz, and used my program posted here:
http://www.matrixmultimedia.com/mmforum ... =26&t=8660
To obtain desired value for

Code: Select all

tmr0=+64;
.

Martin
Attachments
5. Digital clock.FCF
Original Flowchart from examples page found here: http://www.matrixmultimedia.com/flowcode.php
(15.78 KiB) Downloaded 382 times
Martin

Post Reply