output's on as power is supplied


Closed Thread
Results 1 to 13 of 13
  1. #1

    Default output's on as power is supplied

    First I would like to thank those of you who helped me last week with the serial I/O expander that I was experimenting with last Friday. I now have everything working momentary now but at times when I apply power some if not all relays activate. Below is my code to activate the serial relays using a PIC16f84A:

    INCLUDE "bs2defs.bas"
    keydata VAR b3
    serpin VAR porta.4
    trisa = %00010000
    trisb = %00000000

    loop:
    gosub loop1
    goto keyed
    keyed:
    IF keydata = 1 THEN outr1
    IF keydata = 2 THEN outr2
    IF keydata = 3 THEN outr3
    IF keydata = 4 THEN outr4
    IF keydata = 5 THEN outr5
    IF keydata = 6 THEN outr6
    IF keydata = 7 THEN outr7
    IF keydata = 8 THEN outr8
    IF keydata = 9 THEN outr9
    IF keydata = 10 THEN outr10
    IF keydata = 11 THEN outr11
    IF keydata = 12 THEN outr12
    GOTO loop
    outr1:
    HIGH 0
    gosub loop1
    low 0
    GOTO loop

    outr2:
    HIGH 1
    gosub loop1
    low 1
    GOTO loop

    outr3:
    HIGH 2
    gosub loop1
    low 2
    GOTO loop

    outr4:
    HIGH 3
    gosub loop1
    low 3
    GOTO loop

    outr5:
    TOGGLE 4
    PAUSE 250
    GOTO loop

    outr6:
    TOGGLE 5
    PAUSE 250
    GOTO loop

    outr7:
    HIGH 6
    gosub loop1
    low 6
    GOTO loop

    outr8:
    HIGH 7
    gosub loop1
    low 7
    GOTO loop

    outr9:
    porta.0 = 1
    gosub loop1
    porta.0 = 0
    GOTO loop

    outr10:
    porta.1 = 1
    gosub loop1
    porta.1 = 0
    GOTO loop

    outr11:
    porta.2 = 1
    gosub loop1
    porta.2 = 0
    GOTO loop

    outr12:
    porta.3 = 1
    gosub loop1
    porta.3 = 0
    GOTO loop

    loop1:
    SERIN serpin,N2400,[254],keydata
    IF keydata => 1 AND keydata <= 12 THEN GOTO keyed
    return

    Thanks again for your help

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by tazntex View Post
    keydata var b3
    What is 'b3' supposed to be?


    Your logic is messed up...
    Code:
    INCLUDE "bs2defs.bas"
    keydata VAR b3 <----- what is this again?
    serpin VAR porta.4 
    trisa = %00010000 : trisb = %00000000
    
    loop:
    gosub loop1
    goto keyed    <------Why GOTO the next line below?
    Let the program go to it, after all, it's right there
    keyed:
    IF keydata = 1 THEN outr1........IF keydata = 12 THEN outr12
    and again, from the last thread you posted this in, it's fairly
    bad form using all these IF/THEN statements,
    look at using BRANCH in the manual instead
    .....................
    loop1: 
    SERIN serpin,N2400,[254],keydata
    IF keydata => 1 AND keydata <= 12 THEN GOTO keyed
     You GOSUB'd into this loop1: but you GOTO to get out of it if need be.
    You can't do that, at least not for very long, depending on the program.
    That's a stack overflow waiting to happen which leads to a PIC reset,
    or at least a big mess.
    return
    Last edited by skimask; - 21st May 2007 at 21:32.

  3. #3


    Did you find this post helpful? Yes | No

    Default serial relays

    thanks Skimask for the reply here is my code again:

    INCLUDE "bs2defs.bas"
    keydata VAR b3 'relay number storage variable
    serpin VAR porta.4 'serial input pin
    trisa = %00010000
    trisb = %00000000

    loop:
    gosub loop1 ' I am going to loop one to receive data on the serial pin then I am going to "keyed" to instruct the pic which relay to turn on.

    goto keyed


    loop1:
    SERIN serpin,N2400,[254],keydata
    IF keydata => 1 AND keydata <= 12 THEN GOTO keyed 'goto keyed if key is 'pressed
    return

  4. #4


    Did you find this post helpful? Yes | No

    Default using the branch

    I read in the PicBasicPro manual about using the branch as you suggested,
    branch b3, [outr1,outr2,outr3,outr4,outr5,outr6,outr7,outr8,ou tr9,outr10,outr11,outr12]
    I just compiled and tried the circuit seems to work fine. I am curious about why using many "If, Then" statements is not a good way of doing things.

    Thanks again, as you may have guess I new into this and still learning .

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by tazntex View Post
    keydata VAR b3 'relay number storage variable

    IF keydata => 1 AND keydata <= 12 THEN GOTO keyed 'goto keyed if key is 'pressed
    And again...b3 does not make any sense.
    When you define a variable, you define it as a type; a bit, a byte, a word, a bucket, a scoop of ice cream, a car, whatever...

    What exactly is a b3?

    And again...in the If/Then, you GOSUB into the LOOP1, and then you GOTO out of LOOP1 back to the main loop. When you GOSUB, you push a return address onto the stack (i.e. a place to remember where I was before, look up GOSUB and RETURN in the manual), and from there, you must RETURN out of it. If you GOTO out of a GOSUB, you keep remembering where you were, but you'll never forget. A PIC only has so many empty spaces to remember, and by RETURNing, you free up one of those spaces. If you never RETURN, eventually, you won't remember either.

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by tazntex View Post
    I just compiled and tried the circuit seems to work fine. I am curious about why using many "If, Then" statements is not a good way of doing things.
    A lot of If/Then statements, all back-to-back, just kinda looks ugly, and makes it a bit harder to read. You have to scroll up, scroll down, move all around. With the BRANCH, it's all on one line. It doesn't neccessarily save memory, code, or whatever, it just looks better.

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Never trust a PIC at boot, it's output level is hard to predict. you should set it yourself at the top of your code and add a little delay
    Code:
        PORTA = 0
        PORTB = 0    
        trisa = %00010000
        trisb = %00000000
        PAUSE 50 ' settle time 
    
    loop:
    It's not a bad idea to enable the Power Up timer in your Configuration fuses as well.
    Code:
    @       __CONFIG _XT_OSC & _PWRTE_ON & _WDT_OFF & _CP_OFF
    http://www.picbasic.co.uk/forum/showthread.php?t=543
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    And again...b3 does not make any sense.
    When you define a variable, you define it as a type; a bit, a byte, a word, a bucket, a scoop of ice cream, a car, whatever...

    What exactly is a b3?
    B3 is defined in the "bs2defs.bas" INCLUDE file.

    It's an alias to W1.HIGHBYTE. W1 is also defined there as a WORD.
    <br>
    DT

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    B3 is defined in the "bs2defs.bas" INCLUDE file.
    It's an alias to W1.HIGHBYTE. W1 is also defined there as a WORD.
    <br>
    Ahhh...that covers why it compiles with errors...

  10. #10
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    2nd round
    IT COMPILE WITHOUT ERROR, IT'S DEFINED IN THE BS2DEFS.BAS file.

    unless you removed the INLCUDE "BS2DEFS.BAS" linet, IT WILL COMPILE WITHOUT ERROR.

    Once again ?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    It's not a bad idea to enable the Power Up timer in your Configuration fuses as well.
    Code:
    @       __CONFIG _XT_OSC & _PWRTE_ON & _WDT_OFF & _CP_OFF
    I've never really had problems with outputs coming on at power-up. They always seem to be in INPUT mode.

    But assuming you did need to set them manually, wouldn't the Power-ON timer just make it that much longer till they actually got set to output.

    Just a thought.
    <br>
    DT

  12. #12
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    If the hardware don't care about the 'Tri-State' or 'High impedance' level, yes...about 72mSec longer.

    Unfortunately there's no Brown-Out detect on this one, we have no schematic and we can't measure the PSU behaviours and rise time from where we are.. hard to have the ultimate solution.

    Maybe i misunderstood the original problem...
    Quote Originally Posted by tazntex
    I now have everything working momentary now but at times when I apply power some if not all relays activate.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    If the hardware don't care about the 'Tri-State' or 'High impedance' level ....
    Right, and that could be a problem.

    Here's an idea for Taz.
    Try running this program ...
    Code:
    STOP
    Yes, that's the whole program.

    It'll leave the pins in Hi-Z mode.

    Then see if any relays come on?
    <br>
    DT

Similar Threads

  1. Battery powered applications
    By NavMicroSystems in forum Off Topic
    Replies: 7
    Last Post: - 22nd June 2009, 07:12
  2. Pic getting part power from Analog Port
    By ShaneMichael in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 22nd April 2009, 10:34
  3. Outputs high to power
    By volcane in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd February 2008, 18:29
  4. 12 Servo's together does not seem to work, Power problem
    By macx75 in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th December 2006, 19:30
  5. Power up problem
    By Ken McDonald in forum General
    Replies: 1
    Last Post: - 28th December 2004, 17:06

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