Strange Waitcnt Problem
crgwbr
Posts: 614
This problem has stumped me for about a week, I finally decided to post it here to see if you can figure it out.· I'm in the middle of implementing a PINK module with the Propeller.· My program reads an encoder, does some calculations with the reading, then assigns it to a variable in the PINK.· This is the Display Loop protion of my code:
PUB Display_Loop····································· ······ ······· ''Display_Loop
waitcnt(80_000_000 + cnt)···························· ········· 'Wait 1 Second
Work_Var[noparse][[/noparse]5] := FM.FDiv(Enc1, 108)··························· 'Divide Encoder Reading by 108
Work_Var[noparse][[/noparse]6] := FS.FloatToString(Work_Var[noparse][[/noparse]5])· ·········· 'Convert Answer to String
·
if Enc1 < 0····························································· 'If Encoder Reading is less than Zero
· Serial.Str(string("!NB0W01:Tool Above Zero Plane"))···· 'Assign Pink Variable 01: Tool Above Zero Plane
· Serial.tx(CLS)······················································ ·'Finalize Variable Change
··
else······································································ 'If Encoder Reading is 0 or Greater
· Serial.Str(string("!NB0W01:"))·································· 'Assign Pink Variable 01: Work_Var[noparse][[/noparse]6]
· Serial.Str(Work_Var[noparse][[/noparse]6])····························
· Serial.tx(CLS)······················································· 'Finalize Variable Change
Display_Loop···························································'Loop Back to Beginning
This Code should wait 1 second, do some math, make a desision, assign a variable, then repeat.· But for some reason, it isn't waiting at waitcnt like it should be.· This is causeing the pink to be blasted with serial information so fast that it can not make sense of it.· Anyone have An Idea of why it's doing this?
Thanks,
crgwbr
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NerdMaster
For
Life
PUB Display_Loop····································· ······ ······· ''Display_Loop
waitcnt(80_000_000 + cnt)···························· ········· 'Wait 1 Second
Work_Var[noparse][[/noparse]5] := FM.FDiv(Enc1, 108)··························· 'Divide Encoder Reading by 108
Work_Var[noparse][[/noparse]6] := FS.FloatToString(Work_Var[noparse][[/noparse]5])· ·········· 'Convert Answer to String
·
if Enc1 < 0····························································· 'If Encoder Reading is less than Zero
· Serial.Str(string("!NB0W01:Tool Above Zero Plane"))···· 'Assign Pink Variable 01: Tool Above Zero Plane
· Serial.tx(CLS)······················································ ·'Finalize Variable Change
··
else······································································ 'If Encoder Reading is 0 or Greater
· Serial.Str(string("!NB0W01:"))·································· 'Assign Pink Variable 01: Work_Var[noparse][[/noparse]6]
· Serial.Str(Work_Var[noparse][[/noparse]6])····························
· Serial.tx(CLS)······················································· 'Finalize Variable Change
Display_Loop···························································'Loop Back to Beginning
This Code should wait 1 second, do some math, make a desision, assign a variable, then repeat.· But for some reason, it isn't waiting at waitcnt like it should be.· This is causeing the pink to be blasted with serial information so fast that it can not make sense of it.· Anyone have An Idea of why it's doing this?
Thanks,
crgwbr
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NerdMaster
For
Life
Comments
I don't see a repeat command anywhere to initiate a loop!
I have never tried calling a routine from within the routine I'm calling, I don't know if there is a trick here that will work.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NerdMaster
For
Life
Last night I was having a go at a terminal program in VB. I was haveing the prop send a 4096 byte array to the pc and was getting clobbered data. I keep incrementing the wait between reads and was getting 4 or 5 bytes. It was not until I gave up and decreased the wait that I got any data through. It was trial and mostly error that finally got it to working. Don't give up!!!
I tried that (with the demo board) and it is working well. The led is blinking with 1 sec timing. The problem is probably bound to the Serial think.
I can not try more because i cannot simulate more.
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
PUB Display_Loop
waitcnt(80_000_000 + cnt) 'Wait 1 Second
dira[noparse][[/noparse]16]~~
!outa[noparse][[/noparse]16]
' your code as comment
...
...
...
Display_Loop
Best regards,
dro
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
in medio virtus
Post Edited (inservi) : 1/29/2007 2:56:36 PM GMT
Does this work properly?
I would change the 108 to 108.0 (A floating Point Value)
Regards,
Eric
After some more thinking, I advice you to use good programing style and to avoid the call of a routine by itself. This is usable when a compiler support recursivity and if you need this effect.
I not read that spin is !
use a more clean structure as this:
Take careful to your programing style because spin is a 'structured' language and Basic is not. Banish all that look like a 'goto'.
Best regards,
dro
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
in medio virtus
Post Edited (inservi) : 1/29/2007 3:29:56 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NerdMaster
For
Life
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Stan Dobrowski