Setting output pin state via PASM
Chris_D
Posts: 305
I need some help on this one.
I am controlling an output from two different cogs using PASM.
I setup the mask with this...
Z_Dir_pinmask := |< Zd
I set the pin to an output with this...
or dira,Z_Dir_pinmask
I set the pin to high with this...
andn outa,Z_Dir_pinmask
and I set the pin to low with this....
or outa,Z_Dir_pinmask
This works fine when I exclusively work in one COG or the other. Once I set the state of the output, I can't seem to change it back from the other COG. Niether COG runs code at the same time except perhaps during startup. Both COGs contain the code to set the pin as output and setsup the pinmask.
If I were to guess, it looks to me like using "andn outa,Z_Dir_pinmask" behaves differently depending on which state the pin is currently in.
Thanks in advance
Chris
I am controlling an output from two different cogs using PASM.
I setup the mask with this...
Z_Dir_pinmask := |< Zd
I set the pin to an output with this...
or dira,Z_Dir_pinmask
I set the pin to high with this...
andn outa,Z_Dir_pinmask
and I set the pin to low with this....
or outa,Z_Dir_pinmask
This works fine when I exclusively work in one COG or the other. Once I set the state of the output, I can't seem to change it back from the other COG. Niether COG runs code at the same time except perhaps during startup. Both COGs contain the code to set the pin as output and setsup the pinmask.
If I were to guess, it looks to me like using "andn outa,Z_Dir_pinmask" behaves differently depending on which state the pin is currently in.
Thanks in advance
Chris
Comments
The side benefit to this behavior is that you can use on cog to gate another when using an active-low output.
I think I understand what you are saying. Do you know any way to work around this?
Chris
That won't work for me in this case. The output pin needs to be controlled by both COGS. However, I might be able to overcome this by having COG #1 communicate to COG #2 to change the state of the pin. This isn't a high-speed activity so I should have plenty of time availble to communicate this through the hub. Having the pin state changed by only one COG should get me around this problem if I understand it correctly.
Chris
I have COG #1 set a variable in the core via the hub which specifies the state of the pin. COG #2, which is running in a tight loop polls that variable via the hub and sets the state of the pin based on that variables value. This gets around the problem with two COGs controlling the same output pin and them being OR'd together.
THe downside is that it uses up a few long for the variables, isn't all that elegant, and I had to add a delay in COG #1 to wait for COG #2 to change the state of the pin which used up some program space. It does work though!
Thanks again guys,
Chris
I am not sure I understand your question but will try to explain why I needed to do what I did...
The project is a motion control project (CNC) the creates the Step and Direction signals for the axes drives. All motion is performed by first setting a the direction signal (output pin) followed with a timed series of pulses on the step signal (output pin).
The logic involved to create the types of motions (linear, circular, helical, jog, home routines) exceeded the memory of one COG so I had to split up these motion routines into two cogs. Because of the OR'd issue with the outputs across all COGs, I could not have positive control over the direction pin's state. The step pin isn't a problem as it is always pulsed so it's state is always known (only high during a motion). The direction signal though would be set depending on the motion from either COG, this caused the problem where I didn't have positive or absolute control of direction.
Hope that answers your question.
Chris