Changing selected outputs ?
Harley
Posts: 997
I want to change three selected output states (A24..A26). Some time back I was told the code below would alter the desired bits in the least time.
xor temp,OUTA ' combine with desired pin states xor OUTA,temp ' set/clear for desired pin statesHowever, checking it w/ pencil and paper, it seems the output is not right (that is, all the remaining bits become zeros.) What am I doing wrong? Here is an example:
OUTA = 0...01_011_10...0 xor temp = 0...00_101_00...0 -------------------------------- temp = 0...01_110_10...0 1st result xor OUTA = 0...01_011_10...0 -------------------------------- OUTA = 0...00_101_00...0 2nd resultThis is what I get when I work it out on paper! I'm confused. When I first got the '2 xor's' suggestion, it was difficult to work it out, for some reason. Think I'm in that rut again.
Comments
To change output states, you need 3 instructions and one constant:
Or, if the bits to change correspond exactly to the one bits in dira,
-Phil
Mike G's scheme changes the Ones two instructions before Zeros are output; which would produce a 111 state. Phil's changes the three outputs of interest, however the change is 150-200 nsec, @ 80 MHz clock, after reading the output states. That might be a problem as other cogs could change an output during that time and it be clobbered.
As it is, presently the cog's loop is taking too long to complete vs. the external cycle it has to deal with, so I need minimal instructions to implement the control over these three bits (affecting A24..A26). (Oooh!, would Prop 2 ever be helpful here.(
Your latest solution is correct.
It's only a problem if your cog's dira has bits set to one that those other cogs are outputting on. Otherwise, your cog will not alter those outputs, even if they change during your three-instruction mod of outa.
-Phil