Welcome to the Parallax Discussion Forums, sign-up to participate.

# If Wishes Were Horses (Question on P2 Counters)

Posts: 5,891
edited April 2017
...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?
Jon McPhalen
Hollywood, CA
It's Jon or JonnyMac -- please do not call me Jonny.

• Posts: 8,372
I remember asking nicely for a one-shot mode and Chip put it in.
But that was a few years ago...
Prop Info and Apps: http://www.rayslogic.com/
• Posts: 8,372
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...
Prop Info and Apps: http://www.rayslogic.com/
• Posts: 5,891
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.
Jon McPhalen
Hollywood, CA
It's Jon or JonnyMac -- please do not call me Jonny.
• Posts: 8,372
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...
Prop Info and Apps: http://www.rayslogic.com/
• Posts: 9,005
:D Yeah.

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

Do not taunt Happy Fun Ball! @opengeekorg ---> Be Excellent To One Another SKYPE = acuity_doug