Shop OBEX P1 Docs P2 Docs Learn Events
Strange Waitcnt Problem — Parallax Forums

Strange Waitcnt Problem

crgwbrcrgwbr Posts: 614
edited 2007-01-29 21:35 in Propeller 1
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

Comments

  • bambinobambino Posts: 789
    edited 2007-01-29 13:54
    crgwbr,

    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.
  • crgwbrcrgwbr Posts: 614
    edited 2007-01-29 14:25
    I've tried it with a repeat command instead routine call; it does the same thing.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    NerdMaster
    For
    Life
  • bambinobambino Posts: 789
    edited 2007-01-29 14:35
    After a week I suppose you have tried moving the waitcnt around in the loop a bit so that it is called at different times!

    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!!!
  • Luis DigitalLuis Digital Posts: 371
    edited 2007-01-29 14:43
    Above all I recommend to use Waitcnt(clkfreq + cnt)
  • inserviinservi Posts: 113
    edited 2007-01-29 14:51
    Hello,

    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
  • SailerManSailerMan Posts: 337
    edited 2007-01-29 15:14
    I noticed this line

    Work_Var[noparse][[/noparse]5] := FM.FDiv(Enc1, 108)
    


    Does this work properly?

    I would change the 108 to 108.0 (A floating Point Value)

    Regards,

    Eric
  • inserviinservi Posts: 113
    edited 2007-01-29 15:16
    Hello,

    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:
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    PUB main
      repeat
        waitcnt(80_000_000 + cnt)                                           'Wait 1 Second
        Display_Loop
    
    
    PUB Display_Loop
      Work_Var :=  FM.FDiv(Enc1, 108)                            'Divide Encoder Reading by 108 
      Work_Var[noparse][[/noparse]6] :=  FS.FloatToString(Work_Var)       '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
    
    
    



    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
  • crgwbrcrgwbr Posts: 614
    edited 2007-01-29 16:09
    Thanks Guys, I'll try this. Hopefully I'll get by the end of today, if it doesn't I'm going to abandone the pink, and just go with a USB interface.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    NerdMaster
    For
    Life
  • Stan671Stan671 Posts: 103
    edited 2007-01-29 21:35
    I cannot see why the waitcnt is not working either, unless it may be because you don't have the two clock setting CONstants in the front of the program?· Maybe because it is not indented under the PUB line?· I also feel that it is poor form and possibly a real problem having a method call itself as a way of repeating forever.· Anyway, there is always many ways to do something, here is another example.
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    PUB Display_Loop
      repeat
        waitcnt(80_000_000 + cnt)                        'Wait 1 Second
        Work_Var :=  FM.FDiv(Enc1, 108.0)                'Divide Encoder Reading by 108 
      
        Serial.Str(string( "!NB0W01:" )                  'Begin to Assign Pink Variable 01:
    
     
        if Enc1 < 0                                         'If Encoder Reading is less than Zero
          Serial.Str( string( "Tool Above Zero Plane" ) )     'then Assign to Tool Above Zero Plane
        else                                                'else Encoder Reading is 0 or Greater
          Serial.Str( FS.FloatToString(Work_Var) )            'assign Answer converted to String
    
     
        Serial.tx(CLS)                                   'Finalize Variable Change
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Stan Dobrowski

Sign In or Register to comment.