Shop OBEX P1 Docs P2 Docs Learn Events
COGS & I/O register confusion — Parallax Forums

COGS & I/O register confusion

DavidMDavidM Posts: 630
edited 2008-08-25 01:41 in Propeller 1
HI,

I need to set 4 pins P0-to P3 as outputs and set them hi/lo as needed.

I have my main method which runs another method ( in a separate OBJECT) that initializes the pins and sets them hi to a particular pattern. This works OK.

I have another method which can set the same 4 I/O pins as needed but in needs to run in its own COG for timing reasons. this cog is created new each time the method is called. This works OK.

for some reason the method that runs in the new COG does not effect the I/O pins at all IF it is run after the first method!

I think this has something to do with each COG having its own DIRA / OUTA registers? I have looked at the manual but there are no examples of this.

SO..

How do I get 2 different methods ( 1 runs in the main COG) and the other method (runs in a new COG) , but never at the same time! to both control the same set of I/O pins effectively.

Thanks

Dave M

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-08-25 00:05
    The DIRA bits of all the cogs are logically OR'd together. If any of the cogs make a pin an output (setting the bit to 1), then the I/O pin is an output. Both cogs should set the DIRA bits (P0-P3) to 1 when they initialize themselves.

    The OUTA bits of all the cogs are logically OR'd together if the cog sets them to outputs. If you have two cogs potentially using the same pins for outputs, but not at the same time, you can do two things: 1) Make sure only one cog sets its OUTA register bits for the pins to 1. When one cog is finished with the I/O pins, it should set its OUTA register bits for those pins to zeros 2) Alternatively, when a cog is finished with the pins, it should set its DIRA bits to zero making the pins inputs as far as it is concerned. Depending on how you're using the pins, you may need pullups (if both cogs set the pins to inputs for a short time).
  • DavidMDavidM Posts: 630
    edited 2008-08-25 01:41
    HI Mike

    I tried the 2nd option of making the OUTPUT to an INPUT at the end of its method as this does not effect the device I am talking too. I do have pull-ups on my circuit so thats OK.


    YOUR IDEA WORKED PERFECTLY!

    The first option you had I had already done in my code, so that did not work.

    Thanks heaps Mike!

    I owe you another beer!

    Dave M
Sign In or Register to comment.