I'm ashamed to ask - pointer dereferening question
ags
Posts: 386
This is embarrasing. I think in terms of C/C++, and I have already RTFM many times. I can't figure out why I'm unable to start with a SPIN local variable containing a hub RAM address and increment the value of the register pointed to by that address. I just want to march a single bit from LSB to MSB. Here's what I started out with:
and here's how I surrendered after 30 minutes of trying unsuccessfully to make it work:
What am I missing? The long[registerContainingAnAddress] and variable.short syntax is not natural for me, but I do think I understand it? I parenthesized until I was exhausted, wondering if it was an issue with operator precedence. No luck.
Thanks for any help.
PUB Test(cmdAddr, mSecInterval) | clockTics clockTics := 80000 * mSecInterval long[cmdAddr] := $00000001 'works repeat waitcnt(clockTics + cnt) if (long[cmdAddr] == $80000000) long[cmdAddr] := $00000001 else long[cmdAddr]<<=1 ' does not work 'also tried (and failed): 'long[cmdAddr] := ((long[cmdAddr])<<1)
and here's how I surrendered after 30 minutes of trying unsuccessfully to make it work:
PUB Test(cmdAddr, mSecInterval) | clockTics, cmdVal clockTics := 80000 * mSecInterval '80MHz clock cmdVal := $00010000 repeat long[cmdAddrr] := cmdVal if (cmdVal == $80000000) cmdVal := $00010000 else cmdVal <<= 1 waitcnt(clockTics + cnt)
What am I missing? The long[registerContainingAnAddress] and variable.short syntax is not natural for me, but I do think I understand it? I parenthesized until I was exhausted, wondering if it was an issue with operator precedence. No luck.
Thanks for any help.
Comments
How do you validate that assigning $00000001 works but shifting doesn't?
I believe you're call should be: NOT
Does that make any difference?
This is just a test harness for the PASM code I wrote to drive a shift register. That code runs in another cog, and watches for a value in the hub RAM address (passed in to cognew(..) for the PASM code) and then sends it out to the shift register. I breadboarded a simple circuit (with the shift registers) that drives LEDs. With Test16Bits() the LEDs chase as expected; with Test16Bits_2() the first LED lights and then that's all.
Ironically, the PASM code (the goal of this phase of the project, which the Test*() code is merely to test) was correct the first time; however, I spent an hour trying to figure out what was wrong, only to realize it was my test bench...
Thanks for any thoughts on this. (I suppose there might be something else going on in the PASM code (or elsewhere), but it does work as expected with the Test16Bits() test driver.
What I didn't post was my PASM code in a different cog. It just loops, waiting to see a non-zero value in the memory location that is written by the test harness (Test16Bit(...)). When it sees any non-zero value, it copies it to cog RAM, clears the hub RAM location, processes that value and then loops looking for the next non-zero value.
Of course, with Test16Bit(...), after each waitcnt period, a new non-zero value is written to that hub RAM location, and all works as planned. With Test16Bit_2(...), the first value is written ($00010000), it is seen by the PASM code in the other cog, copied, and then processed. The next waitcnt time, the main (SPIN) cog does what I told it to do: read the hub RAM location, shift left one bit, and write it back out. The only problem is, it was cleared by the PASM cog so shifting all zeros left one bit doesn't do much.
Good Grief! More coffee, less stupid. My sincere apologies to those that wasted pesonal cycles helping to diagnose. If it's worth anything, the confirmation that the SPIN code I wrote and posted worked for others did help me eventully focus my attention to the right place.