CTRMODE Confusion
Jim C
Posts: 76
I've been struggling for 'bout a day with CTRA and CTRMODE's. So far, NCO and PLL modes have yielded to dedicated work. And so have the edge-detection modes, when using Spin. However, I would like to speed the edge detection up a bit and would like to use assembly.
If any of the guru's on the forum could look at the attached code and figure out why it does not count number of edges detected, I would appreciated it.
Thanks,
Jim C
If any of the guru's on the forum could look at the attached code and figure out why it does not count number of edges detected, I would appreciated it.
Thanks,
Jim C
spin
3K
Comments
I believe your principal problem is the way you do the comparison. To read a phsx register, it MUST be done as a "source", you have it as a "destination".
Try the modified code:
Cheers,
Peter (pjv)
Thanks for the help. The bit about phsa/b needing to be the source with the CMP command was the key. On that note, I reviewed what documentation I could find, and was unable to locate a reference. Can you direct me to info on such like?
You also pointed out an easier way to count and loop, as well as some errors in the documentation. I have included a cleaned up version of the code that incorporates these fixes, and demonstrates operation with LED's on pin 16 and 17 of the demo board. The LED's prove it's working, and an 'scope isn't needed.
Also in the code are 32-bit constant/variables, written all the way out. I keep getting tangled up by bit numbers, and binary, and literals not being full words: writing it all the way out simplifies it for the simple-minded (like me).
Gradually making progress,
Jim C
Glad you got it working!
After a bunch of searching, I located the pertinent documentation. It was by Chip Gracey in the Private Propeller Forum. I don't know how to make a link to that, so all I can do is post it here, and hope not to lose the formatting.
Cheers,
Peter (pjv)
In the attached document, there seemed to be one pertinent section about phsa:
>>PHSA / PHSB
The PHS register is the oddest of all COG registers. Not only can it be written
and read via COG instructions, but it also functions as a free-running
accumulator, summing the FRQ register into itself on potentially every clock
cycle. Any instruction writing to PHS will override any accumulation for that
clock cycle. PHS can only be read through the source operand (same as PAR, CNT,
INA, and INB). Doing a read-modify-write instruction on PHS (ie ADD PHSA,#1)
will cause the last-written value to be used as the destination operand input,
rather than the current accumulation.<<
I understand how a 'read-modify-write' instruction using phsx as the destination would result in a modified phsx. But, using the CMP instruction, which leaves the destination unchanged, shouldn't have modified the destination. So, why didn't the CMP work with phsx as the destination?
Thanks,
Jim C
As I'm not schooled in the inner workings of the Propeller, we'll have to leave that to Chip to answer when he has time. There are several registers that behave this way.
Cheers,
Peter (pjv)
If you could pass this question along, such that it winds up in a FAQ or assembly language manual, that would be great.
Thanks for your help.
Jim C
Like yourself, I have no "inside track" to the folks at Parallax, so the passing along is just as well done by yourself. That said, hopefully this interchange will be read by them, and nothing further needs to be done.
You could try a PM to Jeff Martin...... busy guy though!
Cheers,
Peter (pjv)