Shop OBEX P1 Docs P2 Docs Learn Events
Reading and writing PHSA in NCO mode — Parallax Forums

Reading and writing PHSA in NCO mode

Have a situation where I need to create phase discontinuities in the output of CTRA while the counter is running in NCO mode. This suggests I would need to do some sort of Read-Modify-Write to PHSA. A warning in the manual goes something like this: "Beware that doing a read-modify-write instruction on PHS, like "ADD PHSA, #1", will cause the last-written value to be used as the destination operand input, rather than the current accumulation."

My brain is too scrambled ATM to decipher that sentence, but it doesn't sound good... Doesn't sound like the right way to accomplish phase modulation.

What _is_ the right way to step PHSA with some regularity?

Comments

  • Read PHSA into a variable, modify the variable, then write it back to PHSA. The amount you modify it by will have to account for the extra instructions required.

    -Phil
  • K2K2 Posts: 691
    Read PHSA into a variable, modify the variable, then write it back to PHSA. The amount you modify it by will have to account for the extra instructions required.

    Kool. Maybe that accounting can be determined empirically by arranging for one read/add/write sequence for each cycle of the counter, to be done immediately after each negative excursion of the counter output. The addition would add zero. You could then measure the new frequency, invert the result, and subtract the old period.

    (The synchronized one-update-per-cycle is to avoid the situation where the MSB in PHSA changes while you're doing the read, null addition, and write.)

Sign In or Register to comment.