Any reason why this IF statement would not work?
ElectricAye
Posts: 4,561
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....
Maybe it's not a legal way to use outa???
IF (outa[PumpEnablePin] == %1)
....do amazing things....
Comments
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 cogs output latch states, not necessarily the actual output states of the Propeller chips I/O pins,
as they can be further affected by other cogs or even this cogs 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
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.
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.
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.