IF ....THEN.... problems


Closed Thread
Results 1 to 17 of 17

Hybrid View

  1. #1
    Join Date
    Feb 2011
    Posts
    9

    Smile IF ....THEN.... problems

    Hi, I`ve got a simple problem I can`t solve. Maybe someone can help me .
    There is a part of code:

    begin:
    pause 100
    IF timer = 1 AND relay = 1 THEN
    pause 500
    timer = 0 'turn off timer'
    PAUSE 1000
    portb.1 = 0
    timer = 1 'turn on timer'

    IF timer = 1 AND relay = 1 THEN

    pause 500
    timer = 0 'turn off timer'
    pause 1000
    portb.1 = 1
    pause 1000
    timer = 1 'turn on timer'
    ENDIF
    ENDIF
    .
    .
    .
    The problem is with second IF....THEN...., whole cycle goes without examining the second IF ...AND...THEN. But I need following:

    When first IF...AND ....THEN "show", go to commands after THEN. After that, examine second(the same as first) IF...AND...THEN and go to commands after its THEN. How can I fix this to do what I want?
    Thanks in advance .

  2. #2
    Join Date
    May 2010
    Location
    Chile
    Posts
    25


    Did you find this post helpful? Yes | No

    Default Re: IF ....THEN.... problems

    You've got a redundancy in your code (maybe on purpose),

    First you activate the timer = 1 flag, and in the next line of code you put an " IF timer = 1..."

    Also the second IF THEN ELSE is inside the first IF THEN, try separating them.

    Try using indent in your coding to see in a better way your routine operation

    this is your code...commented
    Code:
    begin:
    pause 100
    IF timer = 1 AND relay = 1 THEN
        pause 500
        timer = 0 'turn off timer'
        PAUSE 1000
        portb.1 = 0
        timer = 1 'turn on timer'               '--turned timer = 1 
    
        IF timer = 1 AND relay = 1 THEN   '--inside first loop? move it out.  Timer already turned 1 on previous line, so is always true for that part
            pause 500
            timer = 0 'turn off timer'
            pause 1000
            portb.1 = 1
            pause 1000
            timer = 1 'turn on timer'
        ENDIF
    ENDIF
    Last edited by El_AMPo; - 21st February 2011 at 15:31.
    "If at first doesn't work, kicking it wont help either"

  3. #3
    Join Date
    Feb 2011
    Posts
    9


    Did you find this post helpful? Yes | No

    Lightbulb Re: IF ....THEN.... problems

    Ok, first of all thanks .

    This was part of code.... there is more. First is BUTTON command which activate timer. Then comes the rest of code.... then timer = 0 and again just turn the timer on without pressing button. Here is complete code with button command and corrections:

    TRISA = $FF
    TRISB = $00
    B0 var byte
    symbol t1 = porta.1
    symbol timer = portb.0
    symbol relay = porta.0


    begin:
    pause 100
    IF timer = 1 AND relay = 1 THEN
    pause 500
    timer = 0 'turn off timer'
    PAUSE 1000
    portb.1 = 0
    timer = 1 'turn on timer'
    ENDIF

    IF timer = 1 AND relay = 1 THEN

    pause 500
    timer = 0 'turn off timer'
    pause 1000
    portb.1 = 1
    pause 1000
    timer = 1 'turn on timer'
    ENDIF

    B0 = 0
    button t1,0,255,0,B0,1,step 'if button is pressed, go to step'
    pause 50
    goto begin

    step:
    timer = 1

    goto begin

    End


    This still do the same. Any help now?

  4. #4
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: IF ....THEN.... problems

    try coding like this:
    Code:
    IF (timer = 1) and (relay = 1) then
    I am not sure if this will work, it seems maybe relay never = 1?
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  5. #5
    Join Date
    Feb 2011
    Posts
    9


    Did you find this post helpful? Yes | No

    Unhappy Re: IF ....THEN.... problems

    yes relay will be =1 . I will explain. The timer is hardware piece with ne 555 and it has a relay on board. The portb.0 turning on timer(with transistor), and timer relay is on(relay = 0) for some time depending of potentiometer position. After timer turn off(ne555 ), the portb.0 is still on, but timer is not on becouse ne555 turn it off.The relay is off but it is connected to a porta.1 like button. So if relay is off, the pin porta.1 is on high (1) (pull up resistor). That is why the relay = 1 (it should be off and portb.0 is on, but timer is off).
    I hope you have understand me .

    All I need is to do this, example:
    begin:
    IF step1 AND step2 THEN
    step3

    IF step1 AND step2 THEN
    step4

    IF step1 AND step2 THEN
    step5

    goto begin
    end



    with this order.

  6. #6
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: IF ....THEN.... problems

    so can you do this:
    Code:
    IF (step 1) and (step 2) then : ' notice the : it lets you have multiple steps
     step 3
     step 4
     step 5
    endif
    did you try it with () around the conditions?
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: IF ....THEN.... problems

    Dumb question, what pic are you using and have you set PORTA.0 and 1 to digital?

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts