Re: touble with a time calculation
ok well EL0 is counting up , EL1 and EL3 are copys of EL0
EL4 is the time left in the event
Event1_OT = time duration of event
Event2_OT = Time when to display the timeleft clock
i
f EVent1_OT all 0 then disable time left clock
if Event2_OT all 0 then no timeleft clock
Event2_OT can not be > Event1_OT set time
Code:
if Event1_OT_Day = 0 and Event1_OT_hour = 0 and Event1_OT_Min = 0 and _ ' if all values are 0 , then dont enable the overrun timer
Event1_OT_sec = 0 and Event1_OT_100th = 0 then
EL2_Enable = 0 ' Disable El2 Counter
EL2_Allow = 0 ' clear Flag so EL4 wont start
else
EL2_Allow = 1 ' Event1 setting Higher than 0 so allow EL4 to be enabled if Event2 settings are higher than 0
endif
' ---------------------
if Event2_OT_Day = 0 and Event2_OT_hour = 0 and Event2_OT_Min = 0 and _
Event2_OT_sec = 0 and Event2_OT_100th = 0 then
EL4_Allow = 0 ' disable Event End Timer - EL4
else
EL4_Allow = 1 ' Allow Event End Timer - EL4
endif
if EL2_Allow = 1 and EL4_Allow = 1 then ' if Event1 times set and Event2 times set then allow EL4_enable to start Event End timer
if EL1_Days <= Event2_OT_Day and EL1_Hours <= Event2_OT_Hour and _
EL1_Minutes <= Event2_OT_Min and EL1_Seconds <= Event2_OT_Sec and _
EL1_100th <= Event2_OT_100th then EL4_Enable = 1 ' show clock when time left in event
all i have so far
Re: touble with a time calculation
Have you got any further?
Re: touble with a time calculation
STEVE , I would like to say yes , but i have not had the time to think it through further , other coding issues have taken time away from this problem.
I do need to get it to work , i am thinking something along the lines what you applied before for the count up event is a good start.
Re: touble with a time calculation
you like to have a go at it steve ?
Re: touble with a time calculation
Re: touble with a time calculation
sent you a pm
cheers
sheldon
Re: touble with a time calculation
Re: touble with a time calculation
Sheldon,
I have had a look at your code but some work has come in and distracted me. I will give it some thought over the weekend and get back to you.
Re: touble with a time calculation
that cool steve , let me know if i can give any further details
Re: touble with a time calculation
No problem Sheldon apart from me being a perfectionist of course. There are some parts of the code that are hard for me to follow, which has set me thinking.
This
Code:
if Event1_OT_Day = 0 and Event1_OT_hour = 0 and Event1_OT_Min = 0 and _ ' if all values are 0 , then dont enable the overrun timer
Event1_OT_sec = 0 and Event1_OT_100th = 0 then
EL2_Enable = 0 ' Disable El2 Counter
EL2_Allow = 0 ' clear Flag so EL4 wont start
else
EL2_Allow = 1 ' Event1 setting Higher than 0 so allow EL4 to be enabled if Event2 settings are higher than 0
endif
is easier to read like this
Code:
if Event1_OT_Day = 0 and _
Event1_OT_hour = 0 and _
Event1_OT_Min = 0 and _ ' if all values are 0 , then dont enable the overrun timer
Event1_OT_sec = 0 and _
Event1_OT_100th = 0 then
EL2_Enable = 0 ' Disable El2 Counter
EL2_Allow = 0 ' clear Flag so EL4 wont start
else
EL2_Allow = 1 ' Event1 setting Higher than 0 so allow EL4 to be enabled if Event2 settings are higher than 0
endif
you could also do something like
Code:
EL2_Allow = Event1_OT_Day + _
Event1_OT_hour + _
Event1_OT_Min + _ ' if all values are 0 , then don't enable the overrun timer
Event1_OT_sec + _
Event1_OT_100th
if EL2_Allow = 0 then EL2_Enable = 0 ' Disable El2 Counter
Just thoughts that need testing out. I am wondering if bitwise comparators could be used in the last version. Could also possibly have
Code:
EL2_Enable = Event1_OT_Day + _
Event1_OT_hour + _
Event1_OT_Min + _ ' if all values are 0 , then don't enable the overrun timer
Event1_OT_sec + _
Event1_OT_100th
Would that work?
Re: touble with a time calculation
yes it should as its look for 0 only value , also removing the "and" will reduced compile size as well a little , good idea
Re: touble with a time calculation
EL2_Allow is a Var bit , atm , and that code would require it to become VAR byte , i am getting very full on this chip and every byte less in mem is a good move ,
i am thinking since the value i am looking for is either 0 or 1 , can i leave the variable as a BIT , even though values higher than 1 are going to occur ?
Re: touble with a time calculation
Quote:
Originally Posted by
longpole001
EL2_Allow is a Var bit , atm , and that code would require it to become VAR byte , i am getting very full on this chip and every byte less in mem is a good move
Tight for space is a very good reason to make the code more efficient.
Obviously you have a routine that sets the time could you set the EL2_Allow and other "flags" within that code. I am thinking that at present the same comparisons are made multiple times in different places.
I am also led to believe that compound statements are inefficient.
Code:
EL2_Allow = 0
EL2_Allow = EL2_Allow + Event1_OT_Day
EL2_Allow + Event1_OT_hour
EL2_Allow + Event1_OT_Min ' if all values are 0 , then don't enable the overrun timer
EL2_Allow + Event1_OT_sec
EL2_Allow + Event1_OT_100th
is more efficient than
Code:
EL2_Allow = Event1_OT_Day + _
Event1_OT_hour + _
Event1_OT_Min + _ ' if all values are 0 , then don't enable the overrun timer
Event1_OT_sec + _
Event1_OT_100th
can you explore this idea by trying both ways. This is food for thought for both of us which is very interesting.
Re: touble with a time calculation
steve ,
so far this is the only place the comparison is made , the flag is used from that point for the other routines
I am down to he last 5k of code space on 128k chip and a fair way to go , i have sd card / code running so i now have to some how make the menu's , some fonts etc all run from the fat16 card , which will need to be somehow index to the menu data, fonts etc , which i not done before ,
so after this clock bit is done, and some oher issues , this will be the next task and i am sure another thread
but examples if anyone has any where the sd card code can
a. a routine that copies the selected lookup table into the created indexed file on the SD , which is accumulative , and returns the indexed start point + data length , the next free point of file for next entry , value back to the program where the routine was called.
c. after output file has been made by the routine above , it is removed from the compile
d. the code that gets the stored data from the start point + length references , fills the required lookup table, as used
i am not sure if SDFS can have more than 1 open file at a time for reading and writing on the fly,but i can see it may need to for other data file creation
regards
Sheldon
the code can make an indexed output hex file of the selected data of the varable sized lookup tables that need to be placed into that hex file
c data with an indexing system for the hex file to find the data which will be on the sd card
d. method and code to assemble the data back into the required lookup table using the index.
i am sure its been done but i could not find an example so far in pbp
Re: touble with a time calculation
I have done the routine you intend using an SD card for but I used on board EEPROM (18F452).
The data in the EEPROM could be changed within the program using keypad and serial LCD display.
However to place the initial data into the EEPROM I created a program just to do that thereby saving code space. But you are thinking in terms of "code"?
Re: touble with a time calculation
After same more thinking on my part I have come to the conclusion that I have not appreciated the scale of what you are doing. I agree lets fix the time issue then start another SD car thread.
Re: touble with a time calculation
yes ill start on the space problem thread later this week ,
can you PM me an example bit of code for the sd card , mainly how you append data to existing open file , indexed data reads example if you have it
Re: touble with a time calculation
Simple here is and example from wiki
http://www.picbasic.co.uk/forum/cont...USB-SD-LOGGING
or is it simple?
Re: touble with a time calculation
time problem sorted , thanks steve for your help on that , cheers m8
next part flash / data transfer from program mem to flash - problems never seems to stand still for long