PDA

View Full Version : touble with a time calculation



longpole001
- 13th May 2014, 00:12
Hi guys , having a mind block on a time calculation

what i need is to set a time and show the amount of time that has occurred past (OVERTIME ) that set time

the hours mins , sec is working ok as a count up clock

the calculation fails when overtime goes to 1min is sec 0 etc

eg if the set value is say 0 hours , 0 mins 10sec

the overtime clock will start counting past 10sec






OT_Hours = Hours - set_hour
OT_Minutes = Minutes - set_Min
OT_Seconds = Seconds -set_sec

richard
- 13th May 2014, 01:08
OT_Hours = 0 OT_Minutes = 0 OT_Seconds = 0
#stop clock here for the test otherwise sec/min rollovers during if tests will give incorrect results
if Hours > set_hour then OT_Hours = Hours - set_hour
if Minutes > set_Min then OT_Minutes = Minutes - set_Min
if Seconds > set_sec then OT_Seconds = Seconds -set_sec
#resume clock

note hour rollover to next day is not taken into account

longpole001
- 13th May 2014, 03:15
hi richard , the main clock cant be stopped and needs to be a running test

the rollover from sec to mins is the issue as well as mins to hours

with the Set_Day= 0, Set_Hour= 0 ,Set_min= 0, Set_sec = 10

this code has that issue of when the clock roles over

the OT variables are used to display the OT clock
Days, Hours, Mins,Secs variables are the main clock
"Set_" varables are the time allowed

the OT clock is only enabled after the Set time is = > than the main clock



if OT_Days => Set_Day and OT_Hours => Set_Hour and OT_Minutes => Set_Min and OT_Seconds => Set_OT_Sec then OT_Enable = 1


if OT_Enable = 1 THEN
if Days > Set_Day then OT_Days = Days - Set_Day
if Hours > Set_Hour then OT_Hours = Hours - Set_Hour
if Minutes > Set_Min then OT_Minutes = Minutes - Set_Min
if Seconds > Set_Sec then OT_Seconds = Seconds - Set_Sec

endif

longpole001
- 13th May 2014, 03:26
corrected code to be, so only OT is enabled and shown when Set time matched or exceeded , but roll over is still the problem




if Days => Set_Day and Hours => Set_Hour and Minutes => Set_Min and Seconds => Set_OT_Sec then OT_Enable = 1


if OT_Enable = 1 THEN
OT_Days = Days - Set_Day
OT_Hours = Hours - Set_Hour
OT_Minutes = Minutes - Set_Min
OT_Seconds = Seconds - Set_Sec

endif

richard
- 13th May 2014, 05:26
I have the same sort of problems comparing multibyte values that increment in isr routines , the only solutions I can find are to
1. stop the clock then compare vars (disable interrupts)
2. compare the vars in the "clock" isr where they wont change as you compare them
3. maybe have a special case for seconds=59, minutes=59 and seconds=59 , seconds= 59 and minutes=59 and hour=23 (if seconds and minutes and hours are all single byte vars )
option 3 seems flaky

Jerson
- 13th May 2014, 05:30
Why not try something straight forward as this?



' run this every second along with your clock code
if (Hours >= Set_Hours AND Minutes >= Set_Min AND Seconds >= Set_Sec)
OT_Seconds = OT_Seconds+1
if (OT_Seconds > 59)
OT_Seconds = 0
OT_Minutes = OT_Minutes+1
if (OT_Minutes > 59)
OT_Minutes = 0
OT_Hours = OT_Hours+1
' you may want to restrict / rollover the hours to 24 hours format here.
endif
endif
endif

longpole001
- 13th May 2014, 06:57
I have a main clock in place

the overtime clock = main clock - set time

the problem occures when the clock value roles over and the clockvalue - set_time < 0
during that time the value of the OT clock is incorrect

eg set time = 10 sec , when main clock counts to 1min , the over time clock would show 0.50 instead of 0.51 etc, for the duration of main clock moving 1.00 - 1.10 , then it be fine


this approch seems to be correct but i am not sure if it needs to be nested




if Days => Set_Day and Hours => Set_Hour and _
Minutes => Set_Min and Seconds => Set_Sec and _
100th => Set_100th then OT_Enable = 1


if OT_Enable = 1 THEN
OT_Days = Days - Set_Day
OT_Hours = Hours - Set_Hour
OT_Minutes = Minutes - Set_Min
OT_Seconds =Seconds - Set_sec
OT_100th = 100TH - Set_100th
endif


if Hours - Set_Hour <0 then
OT_Days = Days - 1
OT_Hours = 24 - Set_Day + Hours
endif

if Minutes - Set_Min <0 then
OT_Hours = OT_Hours - 1
OT_Minutes = 60 - Set_Min + Minutes
endif

if Seconds - Set_Sec <0 then
OT_Minutes = OT_Minutes - 1
OT_Seconds = 60 - Set_Sec + Seconds
endif

if 100TH - Set_100th <0 then
OT_Seconds = OT_Seconds - 1
Ot_100TH = 100 - Set_100th + 100TH
endif

longpole001
- 13th May 2014, 07:02
if Hours - Set_Hour <0 then
OT_Days = Days - 1
OT_Hours = 24 - Set_Hour + Hours
endif


typo fixed

richard
- 13th May 2014, 07:34
hows this going to work
if Days => Set_Day and Hours => Set_Hour and _
Minutes => Set_Min and Seconds => Set_Sec and _
100th => Set_100th then OT_Enable = 1

imagine set day=0 set hour=1 set min=30
if hour = 2 and min=29 then it will test false when it should be true

u need to think in terms of timestamp
timestamp= sec+min*60 +hour*3600 etc day * whatever. (unix does it from some arcane date in 1980 in microseconds)
then compare timestamp
this will not solve rollovers however

from wiki
unix timestamp 00:00:00 UTC on January 1, 1970

richard
- 13th May 2014, 08:09
just for the sake of an argument on a raspberry pi
you could just go datetime.datetime(now)-settime and you wold get a RESULT in years,months,days,hours,minutes,seconds and microseconds
a pi costs about 40 bucks has 512m of ram usb and Ethernet built in . makes life easy

EarlyBird2
- 13th May 2014, 08:26
A clock does not have values of

24 hours
60 min
60 sec
100 100th

for example a clock showing 59 seconds will change to 0 on the next second.

the calculation

if Seconds - Set_Sec <0 then
OT_Minutes = OT_Minutes - 1
OT_Seconds = 60 - Set_Sec + Seconds
endif

should be

if Seconds - Set_Sec <0 then
OT_Minutes = OT_Minutes - 1
OT_Seconds = 59 - Set_Sec + Seconds
endif

and the same for the other < comparisons.

EarlyBird2
- 13th May 2014, 08:29
just for the sake of an argument on a raspberry pi
you could just go datetime.datetime(now)-settime and you wold get a RESULT in years,months,days,hours,minutes,seconds and microseconds
a pi costs about 40 bucks has 512m of ram usb and Ethernet built in . makes life easy

Are you advising us all to use Raspbbery Pi?

richard
- 13th May 2014, 08:43
not at all however it depends on the size of the task ,think of moving bricks with a Toyota corolla if you only need to move a few its fine, to move 10000 would be an ordeal better suited to a tray truck with hydraulic loader.
pbp is a great product but if you want to do a lot with floats, longs , singed math , datetime objects colour gui's etc then other platforms and languages make life a lot easier.

EarlyBird2
- 13th May 2014, 08:57
Easy does not increase understanding.

Unfortunately we live in a plug and play world. The Pi was created to address the issue of children not understanding how computers work and introduce them to programming so it is made easy to produce quick results and grab their imagination. What it does not do is teach electronics. But as I have never had one my opinion is not a first hand informed one.

Anyway this thread is about time calculation not Pi and have we just hijacked a thread which is against the rules?

richard
- 13th May 2014, 09:15
do I understand the problem correctly
I'm assuming we have a set time day-h:m:s.xx ie day 0 hour 2 minute 30 sec 28.34 and that we then subsequently read a clock and calculate the elapsed time between now and the set time if and only if the now time is greater than the set time .
is this right ?

EarlyBird2
- 13th May 2014, 09:33
Richard No.

longpole001's program counts down to set time then counts up after set time.

longpole001
- 13th May 2014, 10:10
in fact i have several clock timers running for this project , most are based on the master timer with other value settings to change the displayed results

for this task the time counter counts up from 0 , the set _time value is the length of time before trigging the overtime clock , which counts up to show the total amount of time exceeding the set_time values

when the main timer exceeds the set_time then a secondary timer ( overtime clock ) is enabled and then shows and continues to run until the main timer stops

as seen if the overtime clock values = main clock - set time , when a sec , min , hour roles over , a < 0 value will occur untill the time value = set_time value again

EarlyBird2
- 13th May 2014, 10:38
as seen if the overtime clock values = main clock - set time , when a sec , min , hour roles over , a < 0 value will occur untill the time value = set_time value again

Yes that is exactly what your code does. I did wonder if that was what you wanted to do.

I was also thinking if this is necessary

if Days => Set_Day and Hours => Set_Hour and _
Minutes => Set_Min and Seconds => Set_Sec and _
100th => Set_100th then OT_Enable = 1

and what would be the implications of just having this

OT_Days = Days - Set_Day
OT_Hours = Hours - Set_Hour
OT_Minutes = Minutes - Set_Min
OT_Seconds =Seconds - Set_sec
OT_100th = 100TH - Set_100th



if Hours - Set_Hour <0 then
OT_Days = Days - 1
OT_Hours = 23 - Set_Day + Hours
endif

if Minutes - Set_Min <0 then
OT_Hours = OT_Hours - 1
OT_Minutes = 59 - Set_Min + Minutes
endif

if Seconds - Set_Sec <0 then
OT_Minutes = OT_Minutes - 1
OT_Seconds = 59 - Set_Sec + Seconds
endif

if 100TH - Set_100th <0 then
OT_Seconds = OT_Seconds - 1
Ot_100TH = 99 - Set_100th + 100TH
endif

Just a thought :)

longpole001
- 13th May 2014, 12:02
the reason for the enable is that until the time = > the setting , the output is not displayed , also the enable flag is used for other routines , hardware options and other timers., also if the values of the Set time all are 0 then that disables the flag for this timer for display on the Glcd's and other outputs

there are several timer clock options that need to show - time in secs only , mins+ sec only , hours,min, sec only ,currently these options turn off / on flags inside the main up/ down timer counter code to enable hours, mins ,sec changes

by changing the values to 59 from 60 for say the secs this results in the following

if set_hour= 0 set_min = 0, Set_sec = 10

if main elapsed time now shows = 0 hour, 1 min , 0 sec

If OT_sec = 60 - Set_sec + Seconds(main elapsed ) then

OT display = 50 (60 - 10 + 0)

if OT_sec = 59 - Set_sec + Seconds(main elapsed ) then

OT display = 49 (59 - 10 + 0)

if the event time was set for 10 sec and the main time is now 1 min then the overtime should read 50secs , not 49 sec

I think i have this correct , but i am still testing
cheers

Sheldon

richard
- 13th May 2014, 14:00
if you have a clock running
try this
h m s var bytes (current time )
x y z var byte (old time )
a b c var byte ( time difference)
carry var bit

time_difference: (assumes current time > old time)
carry=0
c=s-z
if c>127 then
c=c+60
carry=1
endif
b=m-(y+carry)
if b>127 then
b=b+60
carry=1
else
carry=0
endif
a=h-(x+carry)
if a>127 then
a=a+24
carry=1 ;extra day needed to be added
else
carry=0
endif
return

longpole001
- 13th May 2014, 19:43
that should work as well richard , cheers
the mind block orginally came from not sure why i was seeing the output i was , and finding that the <0 resulted in the displayed variables being incorrect during that time

longpole001
- 15th May 2014, 05:58
well after a few more tests that did not work well , yes , when you enter a event period of 10sec for the event time or 1 min or 1 hour , 1day then code answers earlier will allow for the <0 error when it roles over , but its does not when you combine Event set time for say 1 m 10 sec

so lets start again
sounds simple but its giving me a problem
GOAL
------
the count up elapsed base timer is counting up from 0 , when the set time values are => then time set for the event the Overtime clock is enabled starts counting up to show the time past the set time

code references
---------------
Base Elapsed timer is set to count up = EL1
Overtime Clock = EL2
Event1_OT_xxx = Time set duration for event


EL1 has the standard time duration if statements enabled so that sec = 60 then sec = 0 , min = min +1 , same for hour , day 0 then 1 min , etc etc for counting up





'------- Event overrun timer 1--------
if EL1_Days => Event1_OT_Day and EL1_hOURS => Event1_OT_Hour and _
EL1_Minutes => Event1_OT_Min and EL1_Seconds => Event1_OT_Sec and _
EL1_100th => Event1_OT_100th then EL2_Enable = 1

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

if EL2_Enable = 1 THEN ; EL2 = EL1 current values - set overrun value
EL2_Days = EL1_Days - Event1_OT_Day
EL2_Hours = EL1_Hours - Event1_OT_hour
EL2_Minutes = EL1_Minutes - Event1_OT_Min
EL2_Seconds = EL1_Seconds - Event1_OT_sec
EL2_100th = EL1_100TH - Event1_OT_100th
endif




addings code to allow for <0 error ( EL1_Seconds - Event1_OT_sec) - this occurs when secs role over 1min but the work arround is not working when combined with sat set times of 1min 10 sec


any further sugestions

richard
- 15th May 2014, 07:29
its never going to work if you don't allow for the negative carry (borrow) , subtracting time is no different to subtracting base (16 12 10 8 2 ) numbers except that hours are base 24 , minutes and seconds are base 60 . have a look again at my example note the order of calculation also

richard
- 15th May 2014, 07:36
i'll say it again if the el1 time data vars update in real time via an isr (as I suspect they may) the whole process is flawed unless you can fix (stop the clock) the el1 time vars for the duration of the subtraction .

longpole001
- 15th May 2014, 07:42
i thought about just starting another clock by using the base ticks but i cant cos

EL0 is the master clock elasped clock , which counts up or down and when started is not stoped untill reset
EL1 is copy of EL0 - used to display the time and has enable /disable to stop the count on EL1 on display , then enable EL1 copies the current values from the master clock to EL1
EL2 is the overtime clock based on the values of EL1 - set event times

this why i really need to correct the errors in EL2 values by using EL1 - set times as far as i can see

longpole001
- 15th May 2014, 07:57
hi richard yes sent you a pm on this

cheers

Sheldon

EarlyBird2
- 15th May 2014, 08:37
if EL2_Enable = 1 THEN ; EL2 = EL1 current values - set overrun value

EL2_100th = EL1_100TH - Event1_OT_100th+100
if EL2_100th<100 then
EL1_Seconds=EL1_Seconds-1
Else
EL2_100th=EL2_100th-100
endif

EL2_Seconds = EL1_Seconds - Event1_OT_sec+60
if EL2_Seconds<60 then
EL1_Minutes=EL1_Minutes-1
else
EL2_Seconds =EL2_Seconds -60
endif

EL2_Minutes = EL1_Minutes - Event1_OT_Min +60
if EL2_Minutes<60 then
EL1_Hours=EL1_Hours-1
else
EL2_Minutes =EL2_Minutes -60
endif

EL2_Hours = EL1_Hours - Event1_OT_hour+24
if EL2_Hours<24 then
EL1_Days=EL1_Days-1
else
EL2_Hours =EL2_Hours -24
endif

EL2_Days = EL1_Days - Event1_OT_Day

endif



Just something to try

richard
- 15th May 2014, 09:22
steve has the right idea for the math but since el1/el2 vars can be updated via the isr at any time during the calcs the results will vary.

statisticly it will fail about 4-5 times per hundred calcs based on :-
I think chances of failure are 1/60+1/60+1/100+1/24 I might be wrong about the stats

EarlyBird2
- 15th May 2014, 09:36
If isr affects EL1 vars create Temp_EL1 vars at the start of the routine and use these for the calculation.

richard
- 15th May 2014, 09:48
won't work . the isr can change the values as u copy them to the temp vars ,been there done that

EarlyBird2
- 15th May 2014, 09:57
Ok some problems do not have an answer.

Bye

richard
- 15th May 2014, 10:15
only solution I know is to disable isr and copy vars to a buffer then enable isr and then perform calcs on the buffered data.
it may mean the odd lost interrupt / whats worse incorrect calcs or missed ints
only the designer can make that call .

longpole001
- 15th May 2014, 10:23
the isr updates EL0,EL1 , EL2 during the call

the isr reloads timer1 every 10ms , then updates EL0-2 variables during that call and displaying them take time ,

a long as the running display is clearly correct for EL2 =EL1 - set_times for sec,min, hour ,day , then i think it be ok.

at the moment its just show the totaly wrong values for duration of the set time

longpole001
- 15th May 2014, 10:54
thanks guys

ill try both ways i rather not have wrong calculations but i also know this interupt is serviced every 10ms , and the E0-2 varables should be correct for that amount of time ??

richard
- 15th May 2014, 11:07
that's the wrong way to think about it , you can never know when the 10ms period will start or finish , this way is better.
the interrupt latency with a 32mHZ clk will be about 10uS anyway , time to copy 4 bytes to a buffer say 4 uS , the interrupt will only be deferred 4uS plus another couple for the int disable enable worst case you'll hardly notice

longpole001
- 15th May 2014, 16:25
hI GUYS , using the code by steve seems to work , a small change cos i use EL1 values to show the current time value , so any changes that change the EL1 values in the calculating the EL2 , is not possible so i need to copy the values of EL1 to EL3 , then use EL3 as a temp group

I am trying to disable the interupt whilest in the ISR subroutine , before the copy of EL0 to EL1-3 , then re -enable interrupt after ,

but i get a interrupt priority state not found error when compile atm

richard
- 16th May 2014, 03:38
it serves no purpose to stop the isr from within the isr , its a waste of time copying the el vars to a buffered copy inside the isr .
time in your case is in essence a multi byte var , the value is volatile and cannot be guaranteed outside the isr when the isr is running.
the correct procedure is
disable isr
copy bytes to buffer
enable isr
do your subtraction

longpole001
- 18th May 2014, 01:01
ok done that , cheers

longpole001
- 18th May 2014, 08:33
steve was wodering what the code may be if i was to use the el1 values plus event1 setting to the overrun point , and use say event 2 seting to show the amount time left before overrun , eg EL0 is counting up , copied to EL1 for display , Event 1 setts time for the overrun , Event2 sets time to show time before reching the overrun time , EL3 displays the time counting down to reach time set by Event1 time.

EarlyBird2
- 18th May 2014, 09:18
Probably easy to do. Post some code from the relevant section for me to look at.

longpole001
- 19th May 2014, 06:12
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




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

EarlyBird2
- 1st June 2014, 11:49
Have you got any further?

longpole001
- 2nd June 2014, 08:58
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.

longpole001
- 4th June 2014, 23:28
you like to have a go at it steve ?

EarlyBird2
- 5th June 2014, 07:31
Yes please.

longpole001
- 5th June 2014, 08:46
sent you a pm

cheers

sheldon

EarlyBird2
- 5th June 2014, 08:53
Thanks

For the code.

EarlyBird2
- 6th June 2014, 06:31
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.

longpole001
- 6th June 2014, 07:44
that cool steve , let me know if i can give any further details

EarlyBird2
- 6th June 2014, 08:18
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



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



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



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



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?

longpole001
- 6th June 2014, 10:20
yes it should as its look for 0 only value , also removing the "and" will reduced compile size as well a little , good idea

longpole001
- 6th June 2014, 23:19
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 ?

EarlyBird2
- 7th June 2014, 05:55
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.



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



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.

longpole001
- 8th June 2014, 02:02
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

EarlyBird2
- 8th June 2014, 08:34
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"?

EarlyBird2
- 8th June 2014, 09:55
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.

longpole001
- 9th June 2014, 02:26
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

EarlyBird2
- 9th June 2014, 10:23
Simple here is and example from wiki

http://www.picbasic.co.uk/forum/content.php?r=272-USB-SD-LOGGING

or is it simple?

longpole001
- 11th June 2014, 07:39
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