Shop OBEX P1 Docs P2 Docs Learn Events
Any reason why this IF statement would not work? — Parallax Forums

Any reason why this IF statement would not work?

ElectricAyeElectricAye Posts: 4,561
edited 2013-11-12 01:39 in Propeller 1
I've got a code problem which appears to involve this IF statement. It compiles but it doesn't seem to be functioning the way I would expect.
Maybe it's not a legal way to use outa???

IF (outa[PumpEnablePin] == %1)
....do amazing things....

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2013-11-11 19:13
    wouldn't you want to use ina instead of outa ?
  • KyeKye Posts: 2,200
    edited 2013-11-11 19:14
    I would look at the value of ina instead...
  • tonyp12tonyp12 Posts: 1,951
    edited 2013-11-11 19:19
    INA would work, but would also depend if other cogs/counters are using the pin.
    Maybe he setting the pin and using the set pin state as a flag for later? (maybe should use a bit flag in a variable instead)

    Quote:
    Normally OUTA is only written to but it can also be read from to retrieve the current I/O pin output latch states.
    This is ONLY the cog’s output latch states, not necessarily the actual output states of the Propeller chip’s I/O pins,
    as they can be further affected by other cogs or even this cog’s other I/O hardware (Video Generator, Count A, etc.).
    The following assumes Temp is a variable created elsewhere:
    Temp := OUTA[15..13] 'Get output latch state of P15 to P13

    The above sets Temp equal to OUTA bits 15, 14, and 13; i.e.: the lower 3 bits of Temp are now equal to
    OUTA15:13 and the other bits of Temp are cleared to zero
  • ElectricAyeElectricAye Posts: 4,561
    edited 2013-11-11 19:32
    wouldn't you want to use ina instead of outa ?

    In another part of the code and in another cog, I'm setting outa[PumpEnablePin] := %1 which seems to get the pump moving.
    Later, in another cog, I just want my VGA to display that the pump is moving, so I'm using that IF statement followed by a simple VGA display command. No matter what, however, the display always tells me the pump is not moving, even when the pump is actually moving. So I thought maybe I was using the outa wrong. If my outa is okay, then I know to look elsewhere for the bug. It's a long, hairy program, so there's a lot to look at - I'm just trying to eliminate possibilities.

    Of course an easy fix is just to create a new variable that tracks movement, but I was just baffled by this.

    Thanks everyone.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2013-11-11 19:36
    tonyp12 wrote: »
    ...Normally OUTA is only written to but it can also be read from to retrieve the current I/O pin output latch states.
    This is ONLY the cog’s output latch states, not necessarily the actual output states of the Propeller chip’s I/O pins,
    as they can be further affected by other cogs or even this cog’s other I/O hardware....

    Oh, Smile, maybe that's the problem. The cog I'm using for display is blind to what the other cog, which is commanding the movement, is doing.

    Many thanks. That looks like a good thing to check on.
  • Heater.Heater. Posts: 21,230
    edited 2013-11-12 01:39
    ElectricAye,
    The cog I'm using for display is blind to what the other cog, which is commanding the movement, is doing.
    That would be it.

    It's amazing how often problems in snippets of code that people have been fighting with for hours and eventually posted here turn out to be problems elsewhere in their program.

    Simple fix is just to use INA, as Beau said.
Sign In or Register to comment.