Shop OBEX P1 Docs P2 Docs Learn Events
Solved - Best way to set/reset a pin from multiple cogs? — Parallax Forums

Solved - Best way to set/reset a pin from multiple cogs?

Christof Eb.Christof Eb. Posts: 1,241
edited 2025-01-02 11:11 in Propeller 2

Hi,
I need to use a pin as digital output and set it to high or low from different cogs. I have not yet found a description, what happens if I set the pin to high from one cog and set it to low from another one. There has been a description in P1 documents. So at the moment I believe that the cogs OR their outputs. A low cannot overwrite a high ( drvh ) from another cog. Is this true for P2 also?

Is there a Smartmode, which I could use instead of simple drvh drvl to achieve my goal?

Many thanks! Christof

Comments

  • evanhevanh Posts: 16,129
    edited 2025-01-02 10:03

    Yes, OUT in the cogs is same as Prop1 behaviour.

    Yes, Smartpins could be used to override pinout state. OUT is ignored then. P_TRANSITION (%00101) mode would do it. Each WYPIN #1, #<pin number> will toggle the pin. You kind of have to separately keep track of whether the pin is high or low since the smartpin doesn't tell you.

    Another way is just use the pin config fields to invert the pin output. Set both and OUT and DIR high then set P_INVERT_OUTPUT for a low and clear it for a high.

    Another way is use DAC levels 255 for high and 0 for low.

  • @evanh said:
    Yes, OUT in the cogs is same as Prop1 behaviour.

    Yes, Smartpins could be used to override pinout state. OUT is ignored then. P_TRANSITION (%00101) mode would do it. Each WYPIN #1, #<pin number> will toggle the pin. You kind of have to separately keep track of whether the pin is high or low since the smartpin doesn't tell you.

    Another way is just use the pin config fields to invert the pin output. Set both and OUT and DIR high then set P_INVERT_OUTPUT for a low and clear it for a high.

    Another way is use DAC levels 255 for high and 0 for low.

    Thanks a lot! - I will try to use P_INVERT_OUTPUT then.

  • Yes, this TAQOZ snippet works:

    : pinSet ( flag pin -- ) \ set pin via smart mode, usable from multiple cogs
       PIN \ select pin
       H \ set high
       \ %AAAA_BBBB_FFF_MMMMMMMMMMMMM_TT_SSSSS_0 M6=invert
       0= if                 %1000000_00_00000_0 else 0 then WRPIN
    ;
    
  • evanhevanh Posts: 16,129

    Not actually the Smartpin doing that. A Smartpin uses the X/Y/Z registers.

  • Christof Eb.Christof Eb. Posts: 1,241
    edited 2025-01-02 11:36

    @evanh said:
    Not actually the Smartpin doing that. A Smartpin uses the X/Y/Z registers.

    Well, if something can only be understood, if you read the Smartpin documentation, than this seems to be part of "Smartpin"?

    To do the opposite of a given command seems to be something like artificial intelligence or own mind?

  • RaymanRayman Posts: 14,865

    @evanh have to find that smartpin diagram…

  • roglohrogloh Posts: 5,865

    @Rayman said:
    @evanh have to find that smartpin diagram…

    Might be this one?
    https://forums.parallax.com/discussion/comment/1545265/#Comment_1545265

  • evanhevanh Posts: 16,129

    Yes, that's the diagram.

    I am being picky. And Chip has been unclear in the docs, yes. He doesn't appear to have a particular mind on pin vs smartpin.

  • RaymanRayman Posts: 14,865

    Maybe dac level is most straightforward?

    Guess would try that…

Sign In or Register to comment.