Shop OBEX P1 Docs P2 Docs Learn Events
Timing Quirk — Parallax Forums

Timing Quirk

lockadoclockadoc Posts: 115
edited 2010-01-19 01:57 in Propeller 1
I made a small method to light some leds for an amount of time after a button push than they turn off.
the quirk is that when I change the variableto a larger number the on time goes down instead of up.

I can come up with the number I need for the two different delays I want.But would like to know the why of quirk

Bill S

Comments

  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-01-19 01:37
    At some point you're going to roll-over the limit of a 32-bit value and your delays will get smaller. You can save yourself a lot of grief by using a standard timing unit. If you ever used a BASIC Stamp then you're accustomed to PAUSE -- here's how to duplicate that in your programs.

    First, create a constant for one millisecond:

    con
      MS_001 = 80_000_000 / 1_000
    


    This assumes that you have an 80MHz system (typical). Next create a simple public method:

    pub pause(ms) | t
    
      t := cnt
      repeat ms
        waitcnt(t += MS_001)
    


    BAM! You're done, and no more guessing or calculating values for waitcnt. If you want to wait 0.1 seconds, you use pause(100). Want to wait 2.5 seconds, use pause(2_500). Honestly, it doesn't get much easier than that, and your programs will be much easier to follow.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA

    Post Edited (JonnyMac) : 1/19/2010 1:54:33 AM GMT
  • RaymanRayman Posts: 14,876
    edited 2010-01-19 01:45
    I'm tired, but doesn't that code show 1 second waits?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My Prop Info&Apps: ·http://www.rayslogic.com/propeller/propeller.htm
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-01-19 01:52
    I'm tired, too -- you're right and I fixed the listing. Thanks for the catch, Ray.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
  • AJMAJM Posts: 171
    edited 2010-01-19 01:57
    Phew, I thought I was going to have to start re-learning everything.

    Nice code snippet
Sign In or Register to comment.