help with PIC16F628 conditional program


Closed Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    Apr 2009
    Posts
    24

    Question help with PIC16F628 conditional program

    i'm having problem working with a conditional program,

    Code:
    @ DEVICE PIC16F628A, INTRC_OSC_NOCLKOUT, WDT_OFF, PWRT_OFF, MCLR_OFF,PROTECT_ON,CPD_ON, BOD_OFF, LVP_OFF
    
    DEFINE OSC 4
    
    CMCON = 7
    VRCON = 0
    
    
    TRISA = 95
    TRISB = 0
    PORTB = 0
    
    GS1  var PORTA.0
    GS2  var PORTA.1
    TEMP var PORTA.2
    FWD  VAR PORTA.3
    REvs VAR PORTA.4
    Neut var PORTA.7
    
    forward  var PORTB.0
    revers   var PORTB.1
    one      var PORTB.2
    two      var PORTB.3
    three    var PORTB.4
    starterd var PORTB.5
    
    
    start: IF Neut = 1 then
            low forward
            low revers
           else
            if (FWD = 1) and (REvs = 0) then
            low revers
            high forward
           else
            low revers
            low forward
            if (FWD = 0) AND (REvs = 1) then
            low forward
            high revers
            endif
            endif
    endif
    goto start 
    end
    i need to monitor all the possible conditions in my input then ouput the right combination following this table.

    ------ INPUTS-------|-----OUTPUTS-----
    FWD---Neut--REvs-|---forward---revers
    --0-------0------1---|------0-----------1
    --1-------0------0---|------1-----------0
    --0-------1------0---|------0-----------0
    --0-------1------1---|------0-----------0
    --1-------1------0---|------0-----------0

    also i have problem on making PORTA.7 work as an input

    i plan to add more functions when this part worked

    TIA.
    Last edited by joseph; - 4th July 2010 at 15:26.

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by joseph View Post
    i'm having problem working with a conditional program,

    ------ INPUTS-------|-----OUTPUTS-----
    FWD---Neut--REvs-|---forward---revers
    --0-------0------1---|------0-----------1
    --1-------0------0---|------1-----------0
    --0-------1------0---|------0-----------0
    --0-------1------1---|------0-----------0
    --1-------1------0---|------0-----------0

    also i have problem on making PORTA.7 work as an input


    TIA.
    Hi, joseph

    @ first ...

    your motor must be powered only if ( FWD ^ REVS = 1 ) AND ( NEUT = 0 ) ... ELSE outputs OFF

    after that

    forward = FWD and reverse = NOT forward ...

    what gives us ...

    Code:
     
    IF ( FWD ^ REVS ) AND NOT NEUT THEN
      forward = FWD : reverse = NOT forward
    ELSE
      forward = 0 : reverse = 0
    ENDIF
    Instead of writing :

    Code:
    TRISA = 95
    Write
    Code:
    TRISA = %  01011111 ' 95 in binary
    And you see instantly ... you've set Porta.7 as an output ...


    Alain
    Last edited by Acetronics2; - 4th July 2010 at 16:49.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Apr 2009
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    sir i tried to compile this

    Code:
    @ DEVICE PIC16F628A, INTRC_OSC_NOCLKOUT, WDT_OFF, PWRT_OFF, MCLR_OFF,PROTECT_ON,CPD_ON, BOD_OFF, LVP_OFF
    
    DEFINE OSC 4
    
    CMCON = 7
    VRCON = 0
    
    
    TRISA = %01011111
    TRISB = 0
    PORTB = 0
    
    GS1  var PORTA.0
    GS2  var PORTA.1
    TEMP var PORTA.2
    FWD  VAR PORTA.3
    REvs VAR PORTA.4
    Neut var PORTA.7
    
    forward  var PORTB.0
    revers   var PORTB.1
    one      var PORTB.2
    two      var PORTB.3
    three    var PORTB.4
    starterd var PORTB.5
    
    
    
    
    start: IF ( FWD ^ REVS ) AND NOT NEUT THEN
            forward = FWD : revers = NOT forward
           ELSE
            forward = 0 : revers = 0
           ENDIF
    goto start
    end
    it compiles but does not work

    this part is not clear to me:
    Code:
    IF ( FWD ^ REVS ) AND NOT NEUT THEN
            forward = FWD : revers = NOT forward
           ELSE
            forward = 0 : revers = 0
           ENDIF
    thanks for the reply

  4. #4
    Join Date
    Apr 2009
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    Code:
     IF ( FWD ^ REVS ) AND NOT NEUT THEN   
            forward = FWD : revers = NOT forward
           ELSE
            forward = 0 : revers = 0
           ENDIF
    IF ( FWD ^ REVS ) AND NOT NEUT THEN <---- do this mean, if FWD and REVS are opposite and NEUT is low then

    forward = FWD : revers = NOT forward <---- forward is equal to what is FWD and revers is equal to opposite of forward else

    forward = 0 : revers = 0 <---- turn the outputs low

  5. #5
    Join Date
    Apr 2009
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    RA7 won't be an input until i independently configured it as an input so i placed this line
    Code:
    INPUT neut


    Code:
    @ DEVICE PIC16F628A, INTRC_OSC_NOCLKOUT, WDT_OFF, PWRT_OFF, MCLR_OFF,PROTECT_ON,CPD_ON, BOD_OFF, LVP_OFF
    
    DEFINE OSC 4
    
    CMCON = 7
    pause 1
    VRCON = 0
    pause 1
    
    TRISA = 95
    TRISB = 0
    PORTB = 0
    
    GS1  var PORTA.0
    GS2  var PORTA.1
    TEMP var PORTA.2
    FWD  VAR PORTA.3
    REvs VAR PORTA.4
    Neut var PORTA.7
    
    forward  var PORTB.0
    revers   var PORTB.1
    one      var PORTB.2
    two      var PORTB.3
    three    var PORTB.4
    starterd var PORTB.5
    
    input neut
    
    
    start: IF ( FWD ^ REVS ) and not neut THEN
            forward = FWD : revers = NOT forward
           ELSE
            forward = 0 : revers = 0
           ENDIF
    goto start
    end
    this works, but for some reason instead of revers/portb.0 going steady high when the input condition rules i got some oscillations, the led connected on this on my simulation blinks

    thanks

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by joseph View Post
    RA7 won't be an input until i independently configured it as an input so i placed this line
    Code:
    INPUT neut
    Did you notice IF you want Porta.7 as an input ... the TRIS value must be > 127 ???

    here you have 95 ... tadaaaa ...

    this works, but for some reason instead of revers/portb.0 going steady high when the input condition rules i got some oscillations, the led connected on this on my simulation blinks
    no reason for that ... simulators are just toys , so do not believe what they say ...
    may be you could add some debouncing to your inputs ... but simulation won't show anything.

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    Join Date
    Apr 2009
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    i didn't notice that

    here's a screenshot:


    this happens to all ports on portb except rb0 where i get a straight line


    thanks
    Last edited by joseph; - 4th July 2010 at 19:01. Reason: changed image link

  8. #8
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default

    Could you post your ISIS file here ??? ( xxx.DSN )

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  9. #9
    Join Date
    Apr 2009
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    here
    direct link:
    http://dc187.2shared.com/download/D7...42736-ef003566

    if the direct link doesn't work, here:
    http://www.2shared.com/file/D7VAeRiX/ecu.html


    thanks
    Last edited by joseph; - 4th July 2010 at 19:32.

  10. #10
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default

    Hi, Joseph

    Definitly a simulator issue ... ( one MORE for Proteus ... )

    Just run your program in MPSIM ( MPLAB Simulator ) in step by step mode, and you won't see any change for the output ...

    I did told you Sims are toys ... , forget about them !!!

    BTW, Correct code is:

    Code:
     IF ( FWD ^^ REVS ) AND NOT NEUT THEN   
            forward = FWD : revers = NOT forward
           ELSE
            forward = 0 : revers = 0
           ENDIF
    Doesn't change anything ... but brain satisfying !!! ( it's a logical EXOR, and not a bitwise one )

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  11. #11
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Joseph,

    Add some resistors in series with the LED's that are being overdriven.
    It will stop blinking.

    Proteus Rules.
    MPSIM is Lame.
    DT

  12. #12
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Talking

    Quote Originally Posted by Darrel Taylor View Post
    Joseph,

    Add some resistors in series with the LED's that are being overdriven.
    It will stop blinking.

    Proteus Rules.
    MPSIM is Lame.
    Hi, Darrel ...

    did you try to close Forward, then the two other switches ( or/and ) ...

    you said " lame " ??? ... funny ...

    Alain

    Judge of peace: my EasyPic5 ... Proteus is OUT !!!
    Last edited by Acetronics2; - 5th July 2010 at 13:13.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  13. #13
    Join Date
    Apr 2009
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Joseph,

    Add some resistors in series with the LED's that are being overdriven.
    It will stop blinking.

    Proteus Rules.
    MPSIM is Lame.
    whoa it seems that proteus simulates the overload protection, it worked

    thanks Darrel, thanks Alain

    i will try to complete the code. i'l update this thread soon

Members who have read this thread : 1

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