How can you check a specific pin number inside of a cogs ina register in PASM?
turbosupra
Posts: 1,088
Hello,
With spin, I would write temp := ina[6]
With PASM, I'm able to view all of the pins with "mov pinsState, ina" and then writing pinsState but I'm not sure how to do a cmp to 1010111100000000000000000[size=+2]1[/size]000000 ?
I'd like to do:
cmp pinsState, #1 or cmp pinsState, #0
Is this possible?
With spin, I would write temp := ina[6]
With PASM, I'm able to view all of the pins with "mov pinsState, ina" and then writing pinsState but I'm not sure how to do a cmp to 1010111100000000000000000[size=+2]1[/size]000000 ?
I'd like to do:
cmp pinsState, #1 or cmp pinsState, #0
Is this possible?
Comments
try this:
mov ina,ina 'copy to shadow
and ina,_mypin wz
if_z ...
-Phil
And if I wanted to check for that pin being low, then
I've never used test before and am trying to wrap my head around it
in this case is the same as
How would this work with testing the pin being low?
-Phil
I'm sure I'm not the only one with many bit operation examples translated into binary.
Sorry, Brad and others for the OT (but not too much so) rant.
Explanation
TEST is similar to AND except it doesnt write a result to Value1; it performs a bitwise AND of the values in Value1 and Value2 and optionally stores the zero-result and parity of the result in the Z and C flags.
If the WZ effect is specified, the Z flag is set (1) if Value1 AND Value2 equals zero. If the WC effect is specified, the C flag is set (1) if the result contains an odd number of high (1) bits.
test against a low to then move high cycles
test 00000000000000000000000001000000, 10101111000000000000000000000000 WZ, WC
if_z mov highCycles, phsa ' if they AND to 0, Z is set to 1
I understand how this AND works, because the only one that is high in the pin mask is pin 6 and I guess test sets Z to 1 because no 1's are returned from the AND operation?
test against a high to then move low cycles
test 00000000000000000000000001000000, 10101111000000000000000001000000 WZ
if_nz mov lowCycles, phsb ' if they AND to 1, Z is set to 0
And with this one, if it is ANDed together, there is a single 1 from the AND operation, so test sets the Z flag to 0?
Do I have it?
odd bits/C=1
even bits/C=0
So if a bit from ina is high, all the bits below are ANDed together and 1 of them results in an odd number of bits (1)
0000000000000000000000000[size=+2]1[/size]000000 (pin mask)
ANDed
1010111100000000000000000[size=+2]1[/size]000000
=
0000000000000000000000000[size=+2]1[/size]000000
C=1
and if a bit is low, all the bits are ANDed together and 0 of them result in an odd number of bits (0)
0000000000000000000000000[size=+2]1[/size]000000 (pin mask)
ANDed
1010111100000000000000000[size=+2]0[/size]000000
=
0000000000000000000000000[size=+2]0[/size]000000
C=0
I take it this is best used when testing a single pin?
-Phil
I can't figure out what I'm doing wrong here?
The binary value of pinReadMask is 00000000000000000000001000000000
I can see pstPtr16 oscillating between 1 and 0 and I've set the counters up as shown below.
highCycles is always 0 and lowCycles is at least doing something, does the format at least look correct?
highCycles should read ~66500
lowCycles should read ~200000
pinRead is 22, pinReadMask is 00000000010000000000000000000000
pin is 26, pinMask is 00000100000000000000000000000000
POS_DETECT long %01000 << 26
NEG_DETECT long %01100 << 26
I would like to read the high cycles when the pin goes low, and the low cycles when the pin goes high, but without a wait command as well as then clear the high cycles when the pin is low and clear the low cycles when the pin is high, again without any wait commands.
I've reread what everyone has written a bunch of times and to me, the code below should work based on my understanding, and it is not.
Thanks for the reply and pointing out that I'm clearing on the wrong 1/2 of the cycle, I've changed that to what is reflected below but it still isn't working? I've also changed the initialize code to reflect the following.
I have my full object with lots of pasm and lots of debugging/commenting. Would you rather me create something simple?
What I would like to do is:
when pin == 1, copy phsb to lowCycles, then clear phsb
when pin == 0, copy phsa to highCycles, then clear phsa
Does my code look close if I switch to
Let me know if you'd like me to try to build some simple object. Thanks!
Here is the object itself, if you need the entire project, please let me know.
Thank you again.
Here is what the pst is seeing (as a general example, the numbers are changing with each refresh)
I was able to get this to work a few minutes ago, but it was discovered through attrition. I'll be using your code to learn more about this, as I obviously have a huge gaping hole in my PASM knowledge when it comes to checking a pins input state. I want to make sure my head is completely wrapped around this, before moving to the next code that I have to write. Believe it or not, I'm pretty much an ADC/DAC away from testing this out in the car!
I was told that you could not do a conditional condition, such as
cmp x, y
if_e cmp, x, z
Is that incorrect? I see that you've done that with cmp/test, is it special with the test operation or can you do as I've written above?
Thank you again for the help.
What's the branch condition in this case?
Ok, so in PASM you can do if && if, or if || if? I did not know that, but that will be handy.
I like puzzles! I believe it would be if x=y but x!=z, jump to #label? My question is, if x!=y, does it satisfy the if_ne also? If that is true, how would you handle that, with a jump, or is there something a little cleaner/universal like a break?
You mean x == y AND x <> z? If so, not quite (one out of three). Just take it one step at a time. You have 4 input conditions (x <> y, x == y, x <> z, x == z) what happens for each pairing?
Ok, I'm not sure yet if I'm looking at this correctly, because I'm still unclear if these are always evaluated conditionally/together, or they can be evaluated separately line by line? If the second comparison is always evaluated only if the first comparison is equal, then I believe I have the below correct. It's like a 2 digit binary equation : )
x==y / x!=z := true
x==y / x==z := false
x!=y / x!=z := false
x!=y / x==z := false