Propeller timing
Newzed
Posts: 2,503
I have the following little routine in my program:
repeat· until z == 162_000
····· z := z + 1
It takes precisely 10 seconds for z to reach 162_000.· This translates to 16_200 counts per second, which further translates to 61.7us per count.
Does this sound about right when the Prop clock is running at 80_000_000 cycles per second?
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
repeat· until z == 162_000
····· z := z + 1
It takes precisely 10 seconds for z to reach 162_000.· This translates to 16_200 counts per second, which further translates to 61.7us per count.
Does this sound about right when the Prop clock is running at 80_000_000 cycles per second?
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
Comments
There are many options to speed up SPIN, e.g. try this loop:
··· z:= 0
··· repeat· until z == 162_000 '5 = 78_000· 10 = 162_000·· 30 = 500000
····· z := z + 1
···· if key.gotkey
······· cmds
In addtion to augmenting z, the program has to check the status of key.got key.· If z = 162_000 then it returns to menu, where the·DS1307 has to be read, then displayed.· All this takes time so your estimate of 30us is probably pretty close.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
deSilva,
I love the way you optimized a delay routine for speed [noparse]:)[/noparse]
z--
And don't fuss at me about the key.gotkey loop.· Without it, it would have just set there and cycled endlessly.· Besides, at my age I am very sensitive.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Post Edited (Paul Baker (Parallax)) : 10/11/2007 10:13:00 PM GMT
The deSilva, these people have a bad habit of spoiling efficient code with functionality don't they [noparse]:)[/noparse]
Graham
repeat 162_000
How long does that take?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
Your idea (and question) was obviosly how to wait best for 1 second!
I remember you did it with WAITCNT formerly, which did not help acting quickly on keys...
So IF this was the question, than you should do it by:
Note that it has to be exactly CNT-z< CLKFREQ to care for the overflow!
deS, you are correct. I want to establish delays of precisely 5 seconds, 10 seconds and 30 seconds. If I use CNT and clkfreq, I can make the timing loop exact. However, the overhead of reading readadc, readclk2, etc., increases the overall delay. That is why I wrote "if z == 162_000". I can adjust the value of z to give the precisely, or very close to it, the delay that I want . Another thing that will affect the delay is how close is the clock to rolling over to the next second when you read it. If it has just rolled over, then your delay will be accurate for quite a while. If the clock is just about to roll over to the next second, and your timing loop is a few ms off, the it will gain 1 second in a short time. Right now the program gains 1 second about every 105 cycles, but there is nothing I can do about that so I accept it. The accuracy of your delay is really dependent on what point in time you read the clock.
And there is one other thing – in case I should ever want to increase the delay to 60 seconds for long-term data logging, it would be easy enough to do by setting the value of z. I could never do it with clkfreq because the max value you can get is clkfreq*53. Above that the value exceeds 32 bits.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
When having to work with >40 seconds there is little support, something I should have expected from the SPIN interpreter in the first place; e.g. it would not have considerably disturbed the performance checking internally CNT during each loop and updating a milisecond clock or such...
Post Edited (deSilva) : 10/12/2007 7:08:31 PM GMT
You can use his MarkSync and WaitSync routines as examples of how to set things up to wait for some future point in time no matter how long the stuff you are doing takes.
When you run all of your overhead routines and then delay for 30 seconds, the delay is more than 30.· What you want to do it remember the time (cnt) before you start your overhead stuff and predict what the cnt will be in 30 seconds, and then do your overhead stuff.· When·that is done, wait for cnt to catch up to where you predicted the 30 seconds would be.· This way, your cycles are always 30 seconds, no matter how long your overhead took.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Stan Dobrowski
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
Graham
cnto := cnt
(code,etc.)
repeat until cnt == cnto + clkfreq*5
····· if key.gotkey
······· cmds
The display never cycled.· Am I writing it wrong?
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
Yes. Firstly you are looking for one exact value of CNT and secondly you are not taking into account overflow and wrap-round.
deSilva already addressed this above ...
··· z := cnt
··· repeat while cnt-z < clkfreq
····· if key.gotKey
····· cmds
The program will respond to a keypress but it never cycles.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
When you add the suggested
z := cnt
inside the IF this will be "re-triggered" after each key press....
But without such action it will leave the loop within 1 sec.
What did you have in mind for that situation?
··· z := cnt
··· repeat while cnt-z< clkfreq*5
····· if key.gotKey
······· cmds
The screen refreshes sometime every 5 seconds, sometimes every 6 seconds.· If I press a key to select an option, it takes varying times for the screen to redisplay.· One time it was about 3 seconds, one time it took 22 seconds.· With my
··· repeat· until z == 78_000
····· z := z + 1·············· '20 = 328_000
····· if key.gotkey
······· cmds
······· z := 31_000······· '2 second delay
I will gain a second about every 10 minutes and the wait after a keypress is always consistent.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
Graham
That should refresh the display every 10 seconds and handle any keys as they occur.
Post Edited (hippy) : 10/13/2007 5:37:21 PM GMT
In YOUR program you set
z:= 32_000
after command processing, in my snippet you have added nothing of that kind, so the counters will go astray when your menu activities take longer than 40 seconds e.g....
So please add a
QUIT
in the IF part after your cmd processing, or a
z:= CNT - 4*CLKFREQ
or whetever you WANT..... This in fact is still a little bit unclear, what you WANT.
To your first remark: It is not caused by this loop when your screen refresh takes sometimes 5 and sometimes 6 seconds. When it takes 6 seconds this has a reason from code you did not show us.
timeout := clkfreq + cnto
··· repeat 5
····· repeat while ( timeout - cnt ) > 0
······· if key.gotkey
········· cmds
····· timeout := clkfreq + cnt
It is cycling every 5 seconds right now.· I'm letting it run to see if it holds the 5 second delay.· I'll hold up checking a keypress for a while.
Graham, I have attached my original code.· Beginning with Line 180, the program refreshes depending on what value I set z to - 5, 10, 20 or 30 seconds.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
hippy, the displayed time increased 1· second after about 380 refreshes and then continued at 5 second intervals.· That is the best I have been able to do so far.· I think it depends a lot on exactly at what time you start reading the DS1307.· Now I'll try it out at a 10-second delay.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
If it does not work post the full code you are testing. You obviously need to give sensible values for timeout and refresh.
If the count goes greater than cnt+timeout then it leaves the second repeat you can add a warning function or whatever.
Otherwise within that loop as well as checking the keyboard it will also refresh the screen at an appropriate interval, the second variable cnt1 keeps the too timing processes seperate despite the fact they use the same timer.
Graham
deS and Graham, thank you very much for your assistance.· I think I'll go with hippy's suggestion - it is quite·simple to implement and to change the delay interval.· In fact I could go to a 1-minute delay if I wanted, or even a 5-minute delay, just by changing the repeat value.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
Graham