Shop OBEX P1 Docs P2 Docs Learn Events
If Wishes Were Horses (Question on P2 Counters) — Parallax Forums

If Wishes Were Horses (Question on P2 Counters)

JonnyMacJonnyMac Posts: 9,102
edited 2017-04-02 14:38 in Propeller 2
...we'd all be eating steak. (Jayne Cobb, "Firefly")

Admittedly, I've had no time to dive into the raging waters of the P2 design, only popping in from time-to-time to see what others are doing. Please forgive my ignorant question.

One of the things I like about the P1 counters is the ability to generate a precise pulse using NCO (%00100). What I'd really love is an NCO "one shot" mode. In my [fantasy] world, when the phsx hit 0 the accumulation of frqx into phsx would stop -- giving me a set-and-forget pulse output.

Is this possible in the P2, or am I showing my love of fantasy by quoting a fictional character misquoting a well-known phrase?

Comments

  • RaymanRayman Posts: 14,643
    I remember asking nicely for a one-shot mode and Chip put it in.
    But that was a few years ago...
  • RaymanRayman Posts: 14,643
    I think this is the pulse mode from the P2 docs:
    %00100 = pulse/cycle output
    
    This mode overrides OUT to control the pin output state.
    
    X[15:0] establishes a base period in clock cycles which forms the empirical cycle time.
    
    X[31:16] establishes a value to which the base period counter will be compared to on each clock cycle, as it counts from X[15:0] down to 1, before starting over at X[15:0] if decremented Y > 0. On each clock, if the base period counter > X[31:16] and Y > 0, the output will be high (else low).
    
    Whenever Y[31:0] is written with a non-zero value, the pin will begin outputting a high pulse or cycles, starting at the next base period.
    
    Some examples:
    
    If X[31:16] is set to 0, the output will be high for the duration of Y > 0.
    
    If X[15:0] is set to 3 and X[31:16] is set to 2, the output will be 0-0-1 (repeat)  for the duration of Y > 0.
    
    IN will be raised when the pulse or cycles complete, with the pin reverting to low output.
    
    During reset (DIR=0), IN is low, the output is low, and Y is set to zero.
    

    These smart pins may be too smart for me to figure out though...
  • If nothing else, it looks like there's a set-and-forget PWM mode with fixed frequency (the SX had this and it was disappointed it didn't make it into the P1).

    Sometime soon I'm going to have to download the P2 files and start to play.
  • RaymanRayman Posts: 14,643
    If I'm reading it like I hope, then you can set Y=1 to get a single pulse.

    Funny if it turns out to be the same code (%00100) as P1...
  • :D Yeah.

    That time is rapidly approaching. Soon, SPIN 2 and C will be operational. Optimal Playtime.

  • evanhevanh Posts: 15,915
    edited 2017-04-03 11:39
    Smartpins are packing a lot of function and the flexibility makes the mode descriptions real eyes glazed over material. Here's an interesting, but now out-of-date, diagram Ariba skilfully made back when Smartpins was really taking shape - http://forums.parallax.com/discussion/comment/1366024/#Comment_1366024

    EDIT: Changed the link to the slightly later improved version.
Sign In or Register to comment.