Shop OBEX P1 Docs P2 Docs Learn Events
Strange results when using objects in SPIN — Parallax Forums

Strange results when using objects in SPIN

EliEli Posts: 3
edited 2007-12-12 19:45 in Propeller 1
Hello all,


I am a fairly new user of the propeller processor technology, and I am having a problem with some of my SPINcode that I was hoping someone could help me out with.

I·created some code in a routine that resets an input pin and then tests it to see if that pin is still low:

····· PUB Scanner

1)···ina[noparse][[/noparse]4] := 0
2)· ·IF ina[noparse][[/noparse]4] == 0
3)···· Beep

(where Beep is·a call to a routine that activates a beeper)

When I run this code directly, the processor beeps as·expected. However, when I run·a·separate object that calls this method, the circuit does not beep.

If I change line 2 of the code to read:

IFNOT ina[noparse][[/noparse]4] == 0

Then the circuit beeps. If I change the·line to read

IFNOT ina[noparse][[/noparse]4] == 1

The circuit still beeps. In other words, the circuit is telling me that pin 4 is neither a 1 nor a 0. However, if I change the line to read

IF ina[noparse][[/noparse]4] == 0 OR ina[noparse][[/noparse]4] == 1

The circuit beeps, telling me that pin 4 is either a 1 or 0 (or both?).

Does anyone know why this is happening? Why does the·system·operate correctly when I run the method directly, but then give confilcting results when I·run the method by calling it through a different object? Any help would be grealtly appreciated. Thanks.

--Eli


··

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-12-12 19:34
    The thing that stands out to me is that you are writing data to a read only register (ina), this will not perform as you expect it to. If you want to write to a pin you must use outa instead (also dira must be set to one for each pin set as output for the pin to to be an actual output).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-12-12 19:38
    First off, ina is read-only; you can't "reset" its bits. Probably what's happening in your code is that pin A4 is toggling rapidly, so if your code doesn't catch it in one state, it catches it in another. As to why the beeper doesn't beep when used in another object, you'd have to show us all your code to help figure that one out.

    -Phil
  • CardboardGuruCardboardGuru Posts: 443
    edited 2007-12-12 19:45
    Perhaps in the cog when you are running it directly you have pin 4 set to an input
    dira:=0
    and in the other cog, it's set to an output.
    dira:=1
    By default they are inputs.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Help to build the Propeller wiki - propeller.wikispaces.com
    Play Defender - Propeller version of the classic game
    Prop Room Robotics - my web store for Roomba spare parts in the UK

Sign In or Register to comment.