Small Program Problem
Newzed
Posts: 2,503
I have a program for the DS1307 and the MCP3004 which is working fine.· When I start the program, the VGA displays the current time and then the Menu.· It then goes to my Getchoice method where it waits for me to select an option by pressing one of 7 keys.· Each time I select an option, the time is again displayed when the selected instruction has been completed.
I would like to insert an instruction at the beginning of the Getchoice routine that says:
"if no key is pressed within 30 seconds go to menu"
The problem is I don't know how to write that in SPIN.
Any suggestions?
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
·
I would like to insert an instruction at the beginning of the Getchoice routine that says:
"if no key is pressed within 30 seconds go to menu"
The problem is I don't know how to write that in SPIN.
Any suggestions?
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
Graham
As I've said before "you can do it!"
Graham
I·can make the VGA redisplay with the new current time every 5, or 10, or 30 or whatever.· What I can not do is "interrupt" the waitcnt statement with a keypress that will execute the desired option.· I even used a
"if key.gotkey" statement after the waitcnt but the program did not execute it.· So that is my problem.· Now.....any new suggestions?
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
·
Just loop until the CNT you are waiting for goes by....
And call key.gotkey in that loop.
Note: Don't use something as " > CNT" or so to end the loop ... This is the tricky part
·· key.clearkeys
·· repeat
···· waitcnt(clkfreq*10 + cnto)
···· if key.gotkey
······ cmds
···· menu
·······
PUB cmds
·· cmd := key.gotkey··
·· if cmd == "a"
···· alarm
···· (and so on)
The VGA redisplays every 10 seconds - that's fine - but, if I press a key during the waitcnt, the program ignores the "if key.gotkey".· What I want to happen is that the VGA will redisplay every 10 seconds, but if I press a key - and it may be 30 minutes later - I want the program to interrupt the waitcnt statement, or, failing that, wait until the waitcnt statement is completed, then go to the option I want.· I don;'t seem to be able to do that.
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
·
·· cnto := cnt
·· key.clearkeys
·· repeat
···· repeat 1
······ waitcnt(clkfreq*5 + cnto)
···· if key.gotkey
······ cmds
···· repeat 1
······ waitcnt(clkfreq*10 + cnto)
···· if key.gotkey
······ cmds
···· menu
·······
PUB cmds
·· cmd := key.getkey··
·· if cmd == "a"
···· alarm
·· if cmd == "s"
···· setclock
Works just fine.· When I press a key I have to wait for the active waitcnt to complete but that is not a problem.· If necessary, I can change the waitcnt statement toi a smaller value, then just increase the number of iterations until I get the time I want.
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
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
·
I had written:
·· repeat
···· if cnt·== cnto + clkfreq*5
······ menu
···· if key.gotkey
······ cmds
The program would respond to a keypress but it would never go to menu.· I finally realized that "if cnt·== cnto + clkfreq*5·" was the problem.· The chnces of cnt precisely equalling cnto + clkfreq*5 were extremely remote, so I gave it a windown and wrote:
· repeat
···· if cnt·=> cnto + clkfreq*5·amd cnt<clkfreq*6
······ menu
···· if key.gotkey
······ cmds
Now it works, but this creates another problem.· After about 45 or 46 iterations the screen starts garbling a bit - I get rows of dots and the letters become distorted, then the screen goes to a multicolored display and locks up.· I have to reset to continue.· I think the stack that holds the return· markers is overflowing and locking up the program.· Any idea how to fix that?· It occurred to me that if I could have the program automatically reset itself every 35 or so iterations that would solve the problem, sort of.··I think the state and direction of Pin 10 - Resn - is input high.· Suppose I connect Pin X to Pin 10 and set it to:
dira[noparse][[/noparse]X] := 0
outa[noparse][[/noparse]X] := 1
Then I write:
if y == 35······ (y is my counter)
· dira[noparse][[/noparse]X] := 1
· outa[noparse][[/noparse]X] := 0
· waitcnt(clkfreq/1000 + cnt)
· dira[noparse][[/noparse]X := 0
· outa[noparse][[/noparse]X] := 1
Would that not reset the Propeller?
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
·
cnto := cnt
dt:=0
key.clearkeys
repeat until (dt>clkfreq*5)
dt:=cnt-cnt0
if (key.gotkey)
quit
if (key.gotkey)
cmds
menu
(a) This here makes little sense
even when i substitute AND for "amd". The main problem is, when you do not post an exact copy of your code, the tiny mistake responsible for your problems can never be spotted!
(b) Consider that CNT wil run up to POSX and then from NEGX downto zero again. That is why I called it "the tricky thing"... The < and > Operations however work in "signed" mode. But is is feasible after a little bit thinking...
(c) Never - I repeat NEVER - accept a not understood program behavior and "work around". You can "work around" when ypou have understood the problem. So there is no reason why a stack should overflow or whatever. LOOK FOR the real cause!!
(d) There is a special instruction to reset the Prop from program code (REBOOT)
I am not an expert programmer.· In fact, I'm not even a very good programmer.· I wouldn't have a clue where look to find the problem that occurs after 45 or so iterations.· In case you have the time to look, I have attached a copy of my program.
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
Have a look into a somewhat obscure feature of SPIN called "aborting"....
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
·
(1) initialize
(2) start
(3) iI2cScan -- returns
(3) menu
(4) readclock2
(5) menu1
etc. etc.
Post Edited (deSilva) : 10/6/2007 9:22:00 PM GMT
you reset the timer. You test the character for validity. If it's bad, you throw it away. If it's a menu call, you execute the appropriate item.
Seems like a straightforward case construct to me, where exceeding the timer is one of the cases.
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
·
Now......can anyone explain why this happens when the screen said I have 3080 free longs?
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
·
For example, The MENU·method calls READCLOCK2 which calls MENU1 when in turn calls MENU again.· Or READCLOCK2 calls CMDS which calls MENU again.· You have a child·method calling it's own parent.· This creates a circular reference that never ends - until the Prop crashes because it runs out of stack space.
Make a chart·with all of your methods listed.· Now draw arrows from each method to all of the other methods it executes.· It should become clear from the arrows that you have certain situations where execution will travel around in a circle back to a method that is already running.
Fixing this is not a case of adding a few RETURN commands.· You need to rethink the structure and hierarchy of your methods so that there are no circles.· You cannot end all of your child methods by calling MENU.· You have to let the child method finish and return back to its parent.
It is not a memory size (free space) problem.· The amount of free space just determines how long you can go before crashing.· You have to stop the circular references that are eating the memory.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Stan Dobrowski
Post Edited (Stan671) : 10/7/2007 8:00:58 PM GMT
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
·
One suggestion, not particularly material but saves space:
Post Edited (Fred Hawkins) : 10/7/2007 11:15:38 PM GMT
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
·