Shop OBEX P1 Docs P2 Docs Learn Events
Invalid number of parameters error — Parallax Forums

Invalid number of parameters error

DJFXDJFX Posts: 15
edited 2005-12-06 23:29 in General Discussion
Here is the code that I am working with.· Every time I try to compile it I get an error "Invalid number of parameters" because of the 3 conditions in the IF statement.· Any help in correcting this problem would be greatly appreciated.


'
' Device Settings
'

DEVICE········· SX28, OSCXT2, TURBO, STACKX, OPTIONX
FREQ··········· 4_000_000

'
' IO Pins
'


Gas········ VAR·RB.6
Flow······· VAR·RB.5
Temp······· VAR·RB.4

Solenoid··· VAR·RC.0
Fan········ VAR·RC.1
Alarm······ VAR·RC.2

'
' Main
'

PROGRAM Start
Start:
IF·Gas = 1 AND Flow·= 0 AND Temp = 0 THEN Check

·LOW·RC.0·· 'Solenoid
·HIGH·RC.1· 'Fan
·HIGH·RC.2· 'Alarm
·GOTO Start
Check:
·HIGH·RC.0· 'Solenoid
·LOW· RC.1· 'Fan
·LOW· RC.2· 'Alarm
·GOTO Start

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-12-05 19:05
    SX/B only allows one operator per line -- remember, we keep things very simple so you can see what's going on underneath.· Here's another way to solve that problem:

    Start:
    · LOW Solenoid
    · LOW Fan
    · LOW Alarm

    Main:
    · temp1 = RB & %01110000
    · IF temp1 = 0 THEN
    ··· Solenoid = 1
    ··· Fan = 0
    ··· Alarm = 0
    · ELSE
    ··· Solenoid = 0
    ··· Fan = 1
    ··· Alarm = 1
    · ENDIF
    · GOTO Main


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • DJFXDJFX Posts: 15
    edited 2005-12-05 20:43
    For this code we are running LED's that represent our Solenoid, Fan and Alarm.· The output I·get is when I push any of the button's our Alarm and Fan LED's turn on.· What I need is·that only when gas, RB.6 is high the Alarm and Fan LED's turn on.· If RB.6 is high·and RB.5 or RB.4 are high, my Alarm and Fan LED's should turn off.
  • nick bernardnick bernard Posts: 329
    edited 2005-12-05 21:01
    do one binary operation per line and store the value in a temporary variable; in this case i used tempBit.

    tempBit = flow OR temp
    tempBit = tempBit AND gas

    if tempBit = 1 then...
    else...
    endif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    engineer, fireman, bowler, father, WoW addict [noparse];)[/noparse]
  • DJFXDJFX Posts: 15
    edited 2005-12-05 21:23
    When I do this I get an error message: "BYTE Parameter Expected "Flow" and the same for Temp and Gas.
  • DJFXDJFX Posts: 15
    edited 2005-12-05 22:26
    Hi anyone I need help again!!! This time my error displays UNKNOWN COMMAND "LED". I think this time I have the logic correct. Pleas if anyone can help me I will realy acpreciate it Here is my code. It activates when and only if (gas = 1 and flow =0 and temp = 0.


    '
    ' Program Description
    '

    '
    ' Device Settings
    '

    DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
    FREQ 4_000_000


    '
    ' IO Pins
    '
    Gas VAR RC.1
    Flow VAR RC.2
    Temp VAR RC.3

    Solenoid VAR RB.0
    Fan VAR RB.1
    Alarm VAR RB.2

    tempbit VAR bit
    temp2 VAR bit
    temp1 VAR BYTE
    '
    ' Main
    '
    Start:
    LOW Solenoid
    LOW Fan
    LOW Alarm

    Main:
    tempbit = Flow OR Temp
    if tempbit = 0 THEN
    temp2 = tempbit OR Gas
    else
    end if

    IF temp2 = 1 THEN
    Solenoid = 0
    Fan = 1
    Alarm = 1
    ELSE
    Solenoid = 1
    Fan = 0
    Alarm = 0
    ENDIF
    GOTO Main
  • BeanBean Posts: 8,129
    edited 2005-12-05 22:51
    SX/B does not allow AND or OR with bit variables. Mainly because the SX assembly language doesn't either.

    Your making it too hard on yourself. Try this:
    ' -------------------------------------------------------------------------
    ' Program Description
    ' -------------------------------------------------------------------------
    ' -------------------------------------------------------------------------
    ' Device Settings
    ' -------------------------------------------------------------------------
    DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
    FREQ 4_000_000
    
    ' -------------------------------------------------------------------------
    ' IO Pins
    ' -------------------------------------------------------------------------
    Gas VAR RC.1 
    Flow VAR RC.2
    Temp VAR RC.3
    Solenoid VAR RB.0
    Fan VAR RB.1
    Alarm VAR RB.2
     
    temp0 VAR Byte
     
    ' -------------------------------------------------------------------------
    ' Main
    ' -------------------------------------------------------------------------
    Start:
      LOW Solenoid
      LOW Fan
      LOW Alarm
     
    Main:
      temp0 = Flow + Temp
      temp0 = temp0 + ~Gas
      ' temp0 can ONLY be 0 if Flow=0, Temp=0, and Gas=1
      IF temp0 = 0 THEN
        Solenoid = 0
        Fan = 1
        Alarm = 1
      ELSE
        Solenoid = 1
        Fan = 0
        Alarm = 0
      ENDIF
      GOTO Main
    



    Bean.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module" Now available from Parallax for only·$49.95
    http://www.parallax.com/detail.asp?product_id=30015

    Product web site: www.sxvm.com

    Those that would give up freedom for security will have neither.


    Post Edited (Bean (Hitt Consulting)) : 12/5/2005 10:55:29 PM GMT
  • DJFXDJFX Posts: 15
    edited 2005-12-05 23:21
    Well I tried it and it works!!!!· I want to thank all you guys for the help.· You don't know how much I appreciate it.· Thank you again.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-12-06 04:17
    And sorry I lead you astray momentarily, DJ -- I was in the California office this morning and it a rush to get to my plane.... I'm safely back in Big D now.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • DJFXDJFX Posts: 15
    edited 2005-12-06 21:14
    Now that worked but now I modified it and it doesn't work.· Here is the new code: The problem lies by in line whre i use temp3.· It does not like it.· It says expected Flow and then the bottom line says expected Gas.· Pl

    '
    ' Program Description
    '
    '
    ' Device Settings
    '
    DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
    FREQ 4_000_000
    '
    ' IO Pins
    '
    Gas VAR RC.1
    Flow VAR RC.2
    Temp VAR RC.3
    Solenoid VAR RB.0
    Fan VAR RB.1
    Alarm1 VAR RB.2
    Alarm2 VAR RB.3

    temp0 VAR Byte
    temp3 VAR Byte

    '
    ' Main
    '
    Start:
    · LOW Solenoid
    · LOW Fan
    · LOW Alarm1
    · LOW Alarm2

    Main:
    · temp0 = Flow + Temp
    · temp0 = temp0 + ~Gas
    ·' temp0 can ONLY be 0 if Flow=0, Temp=0, and Gas=1 alarm dange level
    · temp3 = Flow & Temp
    · temp3 = temp3 &· Gas
    ·' temp1 can ONLY be 1 if Flow=1, Temp=1, and Gas=1 alarm dang level rising
    ·
    ·
    · IF temp0 = 0 THEN
    ··· Solenoid = 0
    ··· Fan = 1
    ··· Alarm1 = 1
    ··· Alarm2 = 0
    ·IF temp3 = 1 THEN
    ···· Solenoid = 1
    ···· Fan = 0
    ···· Alarm1 = 0
    ···· Alarm2 = 1
    ··ENDIF
    ··· Solenoid = 1
    ··· Fan = 0
    ··· Alarm1 = 0
    ··· Alarm2 = 0
    · ENDIF

    ·
    · GOTO Main

    Any Help is greatly appreciated.

    Post Edited (DJFX) : 12/6/2005 9:29:50 PM GMT
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-12-06 21:51
    You might consider this:

    · temp3 = RC & %00001110··· ' mask unused bits
    · temp3 = temp3 >> 1······· ' remove unused zero-bit

    · IF temp3 = %000 THEN
    ··· ' do something
    · ENDIF

    · IF temp3 = %001 THEN
    ··· ' do something else
    · ENDIF

    · IF temp3 = %010 THEN
    ··· ' do yet something else
    · ENDIF

    · ' more IF-THEN structures (like above) as required

    It may seem a little verbose but I think it's cleaner and less error-prone that what you're currently attempting.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • BeanBean Posts: 8,129
    edited 2005-12-06 23:29
    Dude,
    You CANNOT use AND or OR with bit variables. That means "&" and "|" too.
    You also have your IF...ENDIF boogered up.

    Just add the bit together like this:

    temp3 = Flow + Temp
    temp3 = temp3 + Gas
    ' temp3 can ONLY be 3 if Flow=1, Temp=1, and Gas=1 alarm dang level rising

    IF temp3 = 3 THEN
    ' whatever

    ENDIF

    Keep working on it, and keep posting. We'll steer you in the right direction.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module" Now available from Parallax for only·$49.95
    http://www.parallax.com/detail.asp?product_id=30015

    Product web site: www.sxvm.com

    Those that would give up freedom for security will have neither.
    ·
Sign In or Register to comment.