Shop OBEX P1 Docs P2 Docs Learn Events
Counter use in PASM — Parallax Forums

Counter use in PASM

ypapelisypapelis Posts: 99
edited 2011-09-09 15:36 in Propeller 1
Just as I was getting comfortable with PASM and counters, I am stuck in what appears as a trivial problem. I am sure once somebody points out the solution, I will bump my head on the wall, but here it goes.

I am trying to setup a COG to use a counter to count rising edges on an input pin and write the count on a variable in main memory where SPIN code can access it. (the actual application is much more complicated, but this is the minimum program that demonstrates my problem).

The code I am using is below.

CntrTest.spin

The pin I am trying to 'count' is Pin 21. I have confirmed that connectivity is correct, because if I write SPIN code to count, it works fine (shown in the main cog). I have copied the value of the control register (I replaced the 'wrlong phsa, countAAddr' with 'wrlong ctra, countAAddr' and confirmed it is correct. I also updated the value of phsa within the second COG so I am sure that the 'copy back' to main memory works. Yet, I don't get the count to work in PASM.

Any idea of what I am doing wrong?

Comments

  • tonyp12tonyp12 Posts: 1,951
    edited 2011-09-09 15:16
    Reading from phsa that is on the destination side, you are sending its shadow version.
    So you need to make a copy of phsa.


    startLoop
    mov mycopy,phsa ' make a copy
    wrlong mycopy,par 'write to hub address pointed to by par.
    jmp #startLoop


    copy phsa to itself would set the shadow version, but not safe?
    I think it would reset itself to a 1 or 2 tick older version and could revert a accumulator event that happend at the same time.

    So if the left side has a read-only register (or in this case a pseudo read-only/write register)
    you are not sending the actual (aka expected) value but the value stored at the shadow register.

    As it's more about the source/dest side rules for special registers that are read-only than read/write rules.


    Cmp/Test can not use read-only registers on it's destination side either.
    Just think of them as of what they really are, Sub/And opcodes with r flag cleared

    You could also say that Wrlong is Rdlong with nr, or that Waitcnt is a just an Add that freezes until counter matches dest.

    Manual quotes:
    Note that in Propeller Assembly, the PHSA and PHSB registers cannot be used in a read-modify-write operation in the destination field of an instruction.
    Instead, separate read, modify, and write operations (instructions) must be performed.

    PHSA and PHSB are read/write pseudo-registers. In the SrcOperand they read the counter’s accumulator value.
    In the DestOperand they read the shadow register whose address PHSA or PHSB occupies, but modifications affect both the shadow and accumulator registers.
  • ypapelisypapelis Posts: 99
    edited 2011-09-09 15:36
    Darn, that's it. Shadow version, i remember reading about it but it didn't "register".

    Thanks!
Sign In or Register to comment.