Page 1 of 1

LONG TIME TIMER

Posted: Sun Aug 18, 2019 2:42 pm
by SILVESTROS9
Dear sirs,
i would like to run a part of FC8 code for a long time ( some days to 1 month )...is it possible to do that and how ? when the code goes to that part ( a macro ) starts a timer that runs in the background...at the end of preset time, the code leave the macro and goes to a connection point...a code example that can add in the macro , will be very useful ...

Re: LONG TIME TIMER

Posted: Sun Aug 18, 2019 8:46 pm
by medelec35
Hi SILVESTROS9,
attached is a flowchart that sets a variable called

Code: Select all

TimeUpFlag 
to a value of 1 after 5 Days, 2 Hours, 3 minutes has elapsed.
The variable can be used in conjunction with a decision branch.
The time duration is set within TimerISR Macro.
For this to work, the timer interrupt has to be set up correctly which is determined by the clock speed of the target device.

Re: LONG TIME TIMER

Posted: Mon Aug 19, 2019 1:21 pm
by SILVESTROS9
Medelec35,
thanks for your answer...is there a way to test the timer without waiting days ? how to calculate and set up the clock speed of the target ? ( I'll use a PIC16F1939 ).

Re: LONG TIME TIMER

Posted: Mon Aug 19, 2019 1:37 pm
by medelec35
I have created the flowchart so you can change the time delay to what ever time you want.
All you need to do is drag the

Code: Select all

TimeUpFlag = 1
calculation box from within the TimerISR call macro and place it within the Yes branch of

Code: Select all

If Seconds = 60
Then you only need to wait 1 minute.
You will need to place an output icon in the yes Decision branch of

Code: Select all

If TimeUpFlag
within Main.
Also, within main you will require variables to reset all the values, so that counting can start from scratch
SILVESTROS9 wrote:how to calculate and set up the clock speed of the target ? ( I'll use a PIC16F1939 ).
Are you using Internal or external osc?

Re: LONG TIME TIMER

Posted: Mon Aug 19, 2019 9:13 pm
by SILVESTROS9
medelec35,
I use external oscillator ( a crystal 16 MHz ).
about verylongdelays code ( at main ) in decision branch there is " if TimeUpFlag? "..... is this correct , or " if TimeUpFlag=1 ?

Re: LONG TIME TIMER

Posted: Mon Aug 19, 2019 10:23 pm
by medelec35
Hi SILVESTROS9.
SILVESTROS9 wrote:I use external oscillator ( a crystal 16 MHz ).
In that case:
New setting for 16MHz.png
(57.25 KiB) Downloaded 1685 times
SILVESTROS9 wrote:about verylongdelays code ( at main ) in decision branch there is " if TimeUpFlag? "..... is this correct , or " if TimeUpFlag=1 ?
Both are correct.
If the value is left off, then it would be true (Yes branch) if the variable was any value except 0.

Re: LONG TIME TIMER

Posted: Tue Aug 20, 2019 4:11 pm
by SILVESTROS9
medelec35,
is it possible to calculate the accuracy of timer at 1 month period ? what are the factors that have effect in that ?

Re: LONG TIME TIMER

Posted: Tue Aug 20, 2019 5:19 pm
by medelec35
SILVESTROS9 wrote:medelec35,
I tested at simulator
You cant use flowcode simulator using a stopwatch as simulation is way quicker than real time.
Can you post your flowchart, and I will see if I can tell what the issue is.
What we can do is have another small delay, Reset values and start timing all over again

Re: LONG TIME TIMER

Posted: Tue Aug 20, 2019 10:25 pm
by SILVESTROS9
medelec35,
I think that there is no reset at variables after timer disable....below is the flowchart for your opinion... most important for me is the accuracy of timer at 1 month, and the max theoretical deviation at that period...

Re: LONG TIME TIMER

Posted: Wed Aug 21, 2019 7:47 am
by medelec35
I can't see anything that will make the time shorter, except for clearing variables prior to timer interrupt being enabled.
I would recommend this:
Resetting timer.png
(8.4 KiB) Downloaded 1636 times
You will need to run on hardware to check timing.
SILVESTROS9 wrote:most important for me is the accuracy of timer at 1 month, and the max theoretical deviation at that period...
That will be dependent on the crystal oscillator accuracy.
Crystals accuracy also depends on the ambient temperature.
To see how much theoretical time difference, you need to know the ppm of the crystal circuit.
Supposing the maximum is 20PPM (Parts Per million).
As there are 86400 seconds per day, in one day the maximum seconds difference could be:

Code: Select all

20 / 1000000 × 86400 = 1.728

Code: Select all

Per Month = 365.25 / 12 × 1.728 = 52.596

Code: Select all

Per Year =  1.728 × 365.25 = 631.152 
Just make sure you have the correct matching capacitors stated within the crystal datasheet.

Re: LONG TIME TIMER

Posted: Wed Aug 21, 2019 11:59 am
by SILVESTROS9
medelec35,
I set the calculation box to clearing variables before timer interrupt enable...the timer works ok only the first time of password set after hardware reset ...the second time that I set the password without hardware reset , the timer works for 3 seconds...it seems that there is no variables clearing...is it possible to check the variables on simulator ?

Re: LONG TIME TIMER

Posted: Wed Aug 21, 2019 8:55 pm
by SILVESTROS9
medelec35,
the 5 variables was cleared....but we forget to add also in calculation box the TimeUpFlag=0...after that the timer works fine....

Re: LONG TIME TIMER

Posted: Thu Aug 22, 2019 7:20 am
by medelec35
Good spot!
Yes I should have also included TimeUpFlag=0 with all the other variables being cleared.
So the timing is correct on hardware?

Re: LONG TIME TIMER

Posted: Thu Aug 22, 2019 2:02 pm
by SILVESTROS9
medelec35,
the timing is correct on hardware ...with a typical crystal the deviation is 2 seconds at 1 hour...its ok ... another issue...sometimes the security code not inserted correct ...it needs 2 or 3 times to get the message "security code ok "....its about accuracy or keyboard resistors ? what can I do to solve this ? a way I think is to display the security code at LCD ...how can do that ?

Re: LONG TIME TIMER

Posted: Fri Aug 23, 2019 12:12 am
by SILVESTROS9
medelec35,
ok, I found the way to display the numbers of security code...also I would like to reduce the number of buttons....a way is to use 3 buttons ...UP and DN to select the number 0-9 , and SET to input at circular buffer...is there a component for that , or a code example with numbers displayed on 4x20 LCD ?