IF ....THEN.... problems


Closed Thread
Results 1 to 17 of 17

Hybrid View

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


    Did you find this post helpful? Yes | No

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

    OK, Maybe I see the problem. AND MAYBE I can explain it. Here goes. This is your program from a few posts back with some added comments:
    Code:
    TRISA = $FF 'Postavi sve pinove porta A kao ulazne 
    TRISB = $00 'Postavi sve pinove porta B kao izlazne 
    B0 var byte
    i var byte
    symbol t1 = porta.1
    symbol tajmer = portb.0
    symbol rele = porta.0
    
    
    begin:
    pause 100 'vrlo bitna pauza'
    while tajmer = 1 and rele = 1 ' when both are 1, we do this while loop
    goto petlja 
    petlja:
    i = 0
    for i = 1 to 2
    If i = 1 then
    pause 300
    goto petlja1'     EVERY time timer and relay are 1, we go to petlja1
    endif
    
    if i = 2 then
    pause 300
    goto petlja2 
    endif
    
    next i 
    
    petlja1: '                        We are here because timer and relay are = 1
    PAUSE 500
    tajmer = 0 'iskljuci tajmer' '          now timer = 0?
    portRETb.1 = 0 'ukljuci crvenu diodu veliku'
    pause 3000 'pauza 3 sekunde'
    RETURN ' I think you need to add this here
    
    petlja2: '                         We are here because we fall in here from petlja1
    tajmer = 1 '                     now timer = 1 again
    portb.2 = 0 'ukljuci diodu zelenu'
    portb.1 = 1 'iskljuci crvenu diodu'
    pause 200
    RETURN'    and here
    wend 'vrlo bitna pauza'           ' go back and check while again. right now timer = 1, relay = ??
    '                                            If relay also = 1, you will never get out of the loop.
    
    IF tajmer = 1 AND rele = 1 ' I think you will never get to this check, stuck in the while loop.
    portb.3 = 0
    portb.1 = 1
    portb.2 = 1
    ENDIF
    
    B0 = 0
    button t1,0,255,0,B0,1,ukljucenje 'ako je taster pritisnut idi na ukljucenje'
    
    goto begin
    
    ukljucenje:
    tajmer = 1
    
    
    goto begin
    
    End
    If you change the RED goto to gosub,add the returns, and move the petlja1 and petlja2 routines to the end of the program. It may act as you expect.
    -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!

  2. #2
    Join Date
    Feb 2011
    Posts
    9


    Did you find this post helpful? Yes | No

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

    This with gosub, return.... not work well. The same again. What about putting in While loop another loop who checking the same condition and if it is not, go to this loop again until real state shows, and then go to another operation. All this inside this begin while....wend loop.
    I tried to put petlja1 and petlja2, after wend... and also after buttons goto begin, and after second timer on, it goes off and on immediately, and again from the begining.

    I`ll try another couple of combinations, and let you know tommorow about it.

    Thanks for helping me .

    Best regards.

  3. #3
    Join Date
    Feb 2011
    Posts
    9


    Did you find this post helpful? Yes | No

    Wink Re: IF ....THEN.... problems

    In this changed code you wrote, the sentence in line with wend, you said: 'go back and check while again. right now timer = 1 and rele = ? 'if releay also = 1, you will never get out of the loop'.

    Yes, you are right. The rele is = 1 but after some of time depends of ne 555 chip and potentiometer, otherwise it is = 0 when timer working. When relay is = 1 timer is still ON! but not working until turn the transistor on and off again (+12V for timer). That is big problem, I have to go out from that loop and do testing again in while, and then go back into previous loop. But without colision of theese two loops.

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


    Did you find this post helpful? Yes | No

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

    Quote Originally Posted by bursach View Post
    'go back and check while again. right now timer = 1 and rele = ? 'if releay also = 1, you will never get out of the loop'.
    I am sorry for not being clear. I did not mean for you to go and check, I ment this is what the program is doing. and the conditions when it gets there.
    -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

    Ok, I understand.
    Check this new code. There is very strange things happening in pic work. THis code was compiled and after pushing button and timer iz on, after relay is 1, the portb.2 is on?! and then nothing happens. Second compiling the same code in chip, results different cycle. I was wondering if something is wrong with power or chip ? What is difference betwen 16F84A and 16F628, can I use 628 with same code but compile with this type? Maybe that is the problem.

    TRISA = $FF 'Postavi sve pinove porta A kao ulazne
    TRISB = $00 'Postavi sve pinove porta B kao izlazne
    B0 var byte
    i var byte
    symbol t1 = porta.1
    symbol tajmer = portb.0
    symbol rele = porta.0

    begin:

    gosub petlja
    pause 1000
    gosub petlja1
    pause 1000
    gosub petlja2
    goto begin

    petlja:
    pause 100 'vrlo bitna pauza'
    while tajmer = 1 and rele = 1
    PAUSE 500
    tajmer = 0 'iskljuci tajmer'
    portb.1 = 0 'ukljuci crvenu diodu veliku'
    pause 3000
    tajmer = 1

    return
    wend
    petlja1:
    pause 100 'vrlo bitna pauza'
    while tajmer = 1 and rele = 1
    PAUSE 100
    tajmer = 0 'iskljuci tajmer'
    portb.1 = 1 'ukljuci crvenu diodu veliku'
    pause 3000
    portb.2 = 0
    tajmer = 1
    return
    wend 'vrlo bitna pauza'
    petlja2:
    pause 100 'vrlo bitna pauza'
    while tajmer = 1 and rele = 1
    PAUSE 100
    tajmer = 0 'iskljuci tajmer'
    portb.1 = 1 'ukljuci crvenu diodu veliku'
    pause 3000
    portb.2 = 1
    portb.3 = 0
    return
    wend

    B0 = 0
    button t1,0,255,0,B0,1,ukljucenje 'ako je taster pritisnut idi na ukljucenje'
    goto begin

    ukljucenje:
    tajmer = 1


    goto begin

    End

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