Shop OBEX P1 Docs P2 Docs Learn Events
assignment problem - am I stroked with blindness? — Parallax Forums

assignment problem - am I stroked with blindness?

virtuPICvirtuPIC Posts: 193
edited 2009-05-15 19:08 in Propeller 1
I want to measure period times of an input pin signal. To test the code I want to run debug output on the same cog. To reduce the data load to a reasonable amount I try to run the output only ten times per second. The code fails: Debug output is sent every loop cycle. Find the stripped down code below. It should print the values of cnt and variables cntdisplay and cnt0 ten times per second. I see many more writings - but cntdisplay always has value 0. That am I missing here?

Any help appreciated!

CON
  _clkmode = xtal1+pll16x
  _clkfreq = 80_000_000

OBJ
  pc :  "PC_Text"
   
PUB theremin | cnt0, cntdisplay
  pc.start(pc#TXPIN)
  cntdisplay := cnt
  repeat
    cnt0 := cnt  
    'delay will go here
    cnt0 := cnt - cnt0
    if cnt - cntdisplay >= clkfreq / 10
      pc.dec(cnt)
      pc.str(string(" "))
      pc.dec(cntdisplay)
      pc.str(string(" "))
      cntdisplay := cnt
      pc.dec(cnt0)
      pc.str(string($0d))

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Airspace V - international hangar flying!
www.airspace-v.com/ggadgets for tools & toys

Post Edited (virtuPIC) : 5/15/2009 11:58:15 AM GMT

Comments

  • James LongJames Long Posts: 1,181
    edited 2009-05-15 09:48
    virtuPIC said...
    I want to measure period times of an input pin signal. To test the code I want to run debug output on the same cog. To reduce the data load to a reasonable amount I try to run the output only ten times per second. The code fails: Debug output is sent every loop cycle. Find the stripped down code below. It should print the values of cnt and variables cntdisplay and cnt0 ten times per second. I see many more writings - but cntdisplay always has value 0. That am I missing here?

    Any help appreciated!

    CON
      _clkmode = xtal1+pll16x
      _clkfreq = 80_000_000
    
    OBJ
      pc :  "PC_Text"
       
    PUB theremin | cnt0, cntdisplay
      pc.start(pc#TXPIN)
      cntdisplay := cnt
      repeat
        cnt0 := cnt  
        'delay will go here
        cnt0 := cnt - cnt0
        if cnt - cntdisplay >= clkfreq / 10
          pc.dec(cnt)
          pc.str(string(" "))
          pc.dec(cntdisplay)
          pc.str(string(" "))
          cntdisplay := cnt
          pc.dec(cnt0)
          pc.str(string($0d))
    


    I would probably rearrange some of this to be easier to read like this:

    CON
      _clkmode = xtal1+pll16x
      [s]_clkfreq = 80_000_000[/s]
      _xinfreq = 5_000_000
     
    OBJ
      pc :  "PC_Text"
       
    PUB theremin | cnt0, cntdisplay, Time_delay
    
      Time_delay = clkfreq/10
      pc.start(pc#TXPIN)
      cntdisplay := cnt
      cnt0 := cnt
      cnt0 += Time_delay  
      repeat  
        'delay will go here
        'cnt0 := cnt - cnt0 <----- I would comment out this line but I'm not sure what you are trying to see.
        if cnt >= cnt0
          pc.dec(cnt)
          pc.str(string(" "))
          pc.dec(cntdisplay)
          pc.str(string(" "))
          cntdisplay := cnt
          pc.dec(cnt0)
          pc.str(string($0d))
          cnt0 += Time_delay
    
    
    



    James L

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    James L
    Partner/Designer

    Lil Brother SMT Assembly Services

    Post Edited (James Long) : 5/15/2009 10:03:30 AM GMT
  • Chris MicroChris Micro Posts: 160
    edited 2009-05-15 09:50
    _clkfreq = 80_000_000
    if cnt - cntdisplay >= clkfreq / 10

    underline?

    In my programms the headline looks like this:
    CON

    _clkmode = xtal1 + pll16x ' sysclk setup

    _xinfreq = 5_000_000

    OneSecond = 80_000_000 ' number of sysclk cycles during one second
  • James LongJames Long Posts: 1,181
    edited 2009-05-15 09:56
    Chris Micro said...
    _clkfreq = 80_000_000
    if cnt - cntdisplay >= clkfreq / 10

    underline?

    In my programms the headline looks like this:
    CON

    _clkmode = xtal1 + pll16x ' sysclk setup

    _xinfreq = 5_000_000

    OneSecond = 80_000_000 ' number of sysclk cycles during one second

    Ha, didn't catch that.

    James L

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    James L
    Partner/Designer

    Lil Brother SMT Assembly Services
  • virtuPICvirtuPIC Posts: 193
    edited 2009-05-15 10:30
    Chris Micro said...
    _clkfreq = 80_000_000
    if cnt - cntdisplay >= clkfreq / 10

    underline?

    In my programms the headline looks like this:
    CON

    _clkmode = xtal1 + pll16x ' sysclk setup

    _xinfreq = 5_000_000

    OneSecond = 80_000_000 ' number of sysclk cycles during one second

    What do you mean with 'underline'? Writing '_clkfreq' and reading 'clkfreq' is perfectly correct according to the propeller manual. The other way round is wrong.

    I just looked up '_clkfreq' vs. '_xinfreq' in the manual. Both are possible. You can read the number of sysclk cycles per second from 'clkfreq' - no matter which of the two you define.

    I tried your proposal. Doesn't help. Anyway, I hadn't expect it would since the problem doesn't seem to be in the counter.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Airspace V - international hangar flying!
    www.airspace-v.com/ggadgets for tools & toys
  • mparkmpark Posts: 1,305
    edited 2009-05-15 10:57
        if cnt - cntdisplay >= clkfreq / 10
    
    


    ">=" does not mean "less than or equal"; it is an assignment operator. "a >= b" is the same as "a := a > b". Use "=>" instead.
  • virtuPICvirtuPIC Posts: 193
    edited 2009-05-15 11:54
    mpark said...
    ">=" does not mean "less than or equal"; it is an assignment operator. "a >= b" is the same as "a := a > b". Use "=>" instead.

    shocked.gifshocked.gifshocked.gif AAAaaarrrggghhh!!!!!! I was stroked with blindness. I know why I prefer to program in PASM instead of SPIN. shakehead.gif

    This little correction helped a lot.

    Thank you very much!!!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Airspace V - international hangar flying!
    www.airspace-v.com/ggadgets for tools & toys
  • mparkmpark Posts: 1,305
    edited 2009-05-15 16:50
    Of course I meant to write "greater than or equal".
  • RaymanRayman Posts: 14,827
    edited 2009-05-15 17:36
    This is another thing pushing me towards the C compiler... It's hard programming in C++ and SPIN at the same time!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My Prop Info&Apps: ·http://www.rayslogic.com/propeller/propeller.htm
  • agodwinagodwin Posts: 72
    edited 2009-05-15 18:22
    I keep writing ':=' in my C code .. :-(
  • virtuPICvirtuPIC Posts: 193
    edited 2009-05-15 19:08
    Yeah... Regarding operators SPIN has some great features. Some additional operators that directly map to propeller instructions (e.g. ||, **, ~>, <----). Some more or less usable features that abbreviate the code a little (e.g. ~, ~~, |<...). But some operators that are different from the equivalent operators in C, Java et al. (e.g. :=, @, >=, ?...)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Airspace V - international hangar flying!
    www.airspace-v.com/ggadgets for tools & toys
Sign In or Register to comment.