LONG TIME TIMER

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

Moderator: Benj

Post Reply
SILVESTROS9
Posts: 115
Joined: Wed Aug 03, 2016 10:45 pm
Has thanked: 24 times
Been thanked: 11 times
Contact:

LONG TIME TIMER

Post 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 ...

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: LONG TIME TIMER

Post 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.
Attachments
Very long delays.fcfx
(10.81 KiB) Downloaded 212 times
Martin

SILVESTROS9
Posts: 115
Joined: Wed Aug 03, 2016 10:45 pm
Has thanked: 24 times
Been thanked: 11 times
Contact:

Re: LONG TIME TIMER

Post 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 ).

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: LONG TIME TIMER

Post 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?
Martin

SILVESTROS9
Posts: 115
Joined: Wed Aug 03, 2016 10:45 pm
Has thanked: 24 times
Been thanked: 11 times
Contact:

Re: LONG TIME TIMER

Post 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 ?

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: LONG TIME TIMER

Post 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.
Martin

SILVESTROS9
Posts: 115
Joined: Wed Aug 03, 2016 10:45 pm
Has thanked: 24 times
Been thanked: 11 times
Contact:

Re: LONG TIME TIMER

Post 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 ?
Last edited by SILVESTROS9 on Tue Aug 20, 2019 5:58 pm, edited 1 time in total.

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: LONG TIME TIMER

Post 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
Martin

SILVESTROS9
Posts: 115
Joined: Wed Aug 03, 2016 10:45 pm
Has thanked: 24 times
Been thanked: 11 times
Contact:

Re: LONG TIME TIMER

Post 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...
Attachments
HSC-S200-05-D-PW2L-demo.fcfx
(94.67 KiB) Downloaded 182 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: LONG TIME TIMER

Post 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.
Martin

SILVESTROS9
Posts: 115
Joined: Wed Aug 03, 2016 10:45 pm
Has thanked: 24 times
Been thanked: 11 times
Contact:

Re: LONG TIME TIMER

Post 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 ?

SILVESTROS9
Posts: 115
Joined: Wed Aug 03, 2016 10:45 pm
Has thanked: 24 times
Been thanked: 11 times
Contact:

Re: LONG TIME TIMER

Post 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....

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: LONG TIME TIMER

Post 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?
Martin

SILVESTROS9
Posts: 115
Joined: Wed Aug 03, 2016 10:45 pm
Has thanked: 24 times
Been thanked: 11 times
Contact:

Re: LONG TIME TIMER

Post 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 ?

SILVESTROS9
Posts: 115
Joined: Wed Aug 03, 2016 10:45 pm
Has thanked: 24 times
Been thanked: 11 times
Contact:

Re: LONG TIME TIMER

Post 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 ?

Post Reply