Shop OBEX P1 Docs P2 Docs Learn Events
BS2 help with program — Parallax Forums

BS2 help with program

edited 2010-02-16 15:32 in BASIC Stamp
Hello,

I can't determine why this program doesn't work the way I'm thinking it should. I need to turn on four relays with a 15 second delay in between each turn on. I've also got it set up where you need to push a button to start the program. It appears that the BS2 "times out" or resets before all relays light. Is this something into the BS2?

'What's a Microcontroller - International Power delayed Relay Switching.bs2
'Activate circuit with reset switch, timed delay of four relays then hold them in on state
'till reset or power is switched off.

' {$STAMP BS2}
' {$PBASIC 2.5}


DEBUG "Delayed turn on of four relays after pressing start button!"
DO
DEBUG ? IN3
IF (IN3 = 1) THEN

GOTO Routine1


Routine1:
DEBUG "Wait 1 second to turn on R1"
PAUSE 1000
DEBUG "Turn on R1"
HIGH 14
DEBUG "Wait 15 Seconds to turn on R2"
PAUSE 15000
DEBUG "Turn on R2"
HIGH 13
DEBUG "Wait 15 Seconds to turn on R3"
PAUSE 15000
DEBUG "Turn on R3"
HIGH 12
DEBUG "Wait 15 Second to turn on R4"
PAUSE 15000
DEBUG "Turn on R4"
HIGH 11

ELSE

PAUSE 100

ENDIF

LOOP

STOP

Thanks!
John

Comments

  • Spiral_72Spiral_72 Posts: 791
    edited 2010-02-11 22:28
    I've had symptoms like that when trying to switch a high current device with the same power supply that runs the stamp. "Dead batteries"

    A quick check with a volt meter on your supply will check this. It's possible your relay coils are pulling enough to overload the supply, or overload the Stamp bus.

    You could also temporarily replace each relay with a 1k resistor in series with an LED, just to iron out your problems. Then connect the relays one by one to see what happens?



    Also, make your program super simple just to lay a foundation, no buttons, no loops, just cut and dry code. I do this A LOT when I'm having problems. For example:

    Relay #1 ON
    pause 15000

    Relay #2 ON
    pause 15000

    Relay #3 ON
    pause 15000

    Relay #4 ON
    pause 15000

    end program
  • Spiral_72Spiral_72 Posts: 791
    edited 2010-02-11 22:30
    Also, before you go any further, are you using diodes to protect your stamp from the inductive "kicK" of the relays??
  • edited 2010-02-12 14:29
    Spiral,

    Thanks for the feedback. I am using a diode across the relay to prevent kickback.
    I've reduced the code to this and am still having problems. I've gone down to a simple 470 ohm resistor and an LED on P15 thru P12. LED P15 turns on, LED P14 turns on, LED P13 flashes but doesn't stay on, P12 never comes on. I believe this is a "time-out" or name reset problem caused by a USB communication error. I am uncertain how to get around this? Any help would be greatly appreciated.
    Thanks!

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}



    HIGH 15
    PAUSE 1500

    HIGH 14
    PAUSE 1500

    HIGH 13
    PAUSE 1500

    HIGH 12
    PAUSE 1500

    HIGH 11
    PAUSE 1500

    END
  • edited 2010-02-12 14:46
    Spiral,

    I changed the END command to a STOP command...no help?
  • Spiral_72Spiral_72 Posts: 791
    edited 2010-02-12 14:59
    Wow, no kidding. As frustrating as this is, at least you've eliminated you program. It should work no problem with LED's so if you are confident with your circuit, that's not it either.

    I wouldn't suspect a communications problem because once you burn the program, you can unhook the com cable and the Stamp run independently.


    Ah, you know what? Put this command before the code:

    DIRH %11111111

    That will make all the pins outputs.... I bet that's it. DUH! [noparse]:)[/noparse]
  • edited 2010-02-12 15:17
    Here's what the code looks like, I added the "=" sign after the DIRH no help. I still get a reset about every 2 seconds!

    Makes sense, once I RUN/download the program USB is out of the picture.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    DIRH= %11111111

    HIGH 15
    PAUSE 1500

    HIGH 14
    PAUSE 1500

    HIGH 13
    PAUSE 1500

    HIGH 12
    PAUSE 1500

    STOP
  • FranklinFranklin Posts: 4,747
    edited 2010-02-12 15:51
    Try running the program in a loop.
    
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    DIRH= %11111111
    
    DO
    HIGH 15
    PAUSE 1500
    
    HIGH 14
    PAUSE 1500
    
    HIGH 13
    PAUSE 1500
    
    HIGH 12
    PAUSE 1500
    
    LOW 12
    LOW 13
    LOW 14
    LOW 15
    PAUSE 1500
    LOOP
    



    This probably isn't valid code but you should get the idea.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • edited 2010-02-12 16:58
    This program runs perfect:

    DO

    HIGH 15
    PAUSE 1500
    LOW 15

    HIGH 14
    PAUSE 1500
    LOW 14

    HIGH 13
    PAUSE 1500
    LOW 13

    HIGH 12
    PAUSE 1500
    LOW 12

    LOOP

    STOP


    This program does not run correctly: I get a reset after the the second/third LED lights. All I did was remove the LOW 15 command, why should this cause problems?

    DO

    HIGH 15
    PAUSE 1500


    HIGH 14
    PAUSE 1500
    LOW 14

    HIGH 13
    PAUSE 1500
    LOW 13

    HIGH 12
    PAUSE 1500
    LOW 12

    LOOP

    STOP
  • MoskogMoskog Posts: 554
    edited 2010-02-12 17:18
    Your relays are probably using too much current. Are you using transistors between the stamp and the relays? If not, then do that and try also to·run the relays from another power supply, just remember to share ground.
  • edited 2010-02-12 17:35
    Moskog,

    I'm not running any relays at this time. Just 470 Ohm resistors in series with each LED on outputs P15-P12. Should be no problem with current.
    I plan to use a TIP transistor to drive each relay.
  • MoskogMoskog Posts: 554
    edited 2010-02-12 17:53
    How much current will those LEDs use when all of them are lit? Remember the BS2 can't source or sink more then 40-50 mA totally. I still cant stop suspect the problem is current overflow. Are you using the Board of education?

    Something else connected to your Stamp?

    Post Edited (Moskog) : 2/12/2010 5:58:33 PM GMT
  • allanlane5allanlane5 Posts: 3,815
    edited 2010-02-12 18:53
    If you can light one at a time, but can't light two, that's usually a power-supply problem. Are you using a 9-volt battery? Because they max-out (and start dropping voltage) at 40 mA or so. Also, is it a NEW battery?

    This is why people use the 7805, and 4 AA cells (or a wall-wart) to get around current limitations.

    Oh, and the classic check for this is to put:

    SEROUT 16, 16468, [noparse][[/noparse]"Reset!",CR]
    at the start of your program, then monitor the debug terminal window on the IDE for "Reset!" messages.
  • Spiral_72Spiral_72 Posts: 791
    edited 2010-02-12 19:49
    I'd change the 470 resistors with 1k resistors on the LED's. That should pull 5mA each X 4 = 20mA @5V

    so what ARE you using as a power supply? I asked early on: Did you check the supply with a voltmeter while the circuit was on?




    I'm guessing bad solder joints/poor connection with your protoboard or poor supply

    Post Edited (Spiral_72) : 2/12/2010 7:54:10 PM GMT
  • edited 2010-02-12 19:52
    Allan,

    I'm using a plug in 1 amp 9 volt wall transformer plugged in the 6-9 volt DC circular jack.
    Can the BS2 source or sink 4 LED's at one time?

    Could the BS2 be sending a "timeout" about every two seconds?
  • edited 2010-02-12 20:07
    If I run this program the first LED stays on with no apparent blinking:
    HIGH 15
    'HIGH 14
    'HIGH 13
    'HIGH 12

    STOP

    When I run this program the first and second LED's start blinking:
    HIGH 15
    HIGH 14
    'HIGH 13
    'HIGH 12

    STOP

    When I run this program the first, second, and third LED's are blinking even faster:
    HIGH 15
    HIGH 14
    HIGH 13
    'HIGH 12

    STOP

    Every time I allow another LED to come on the blink rate goes up!
  • Spiral_72Spiral_72 Posts: 791
    edited 2010-02-12 20:53
    The Stamp should not be resetting every two seconds or ever.

    You could try tying the reset pin to +5V Vcc through a 10k resistor (which is a good idea anyways, for all your stamp projects)

    You could try unplugging the stamp programming cable after you've sent you program. I can't imagine this helping, but it's worth a shot.

    You need to tell us the supply voltage with the stamp powered up and the program running. Also if you have a scope, I'd be interested to see how close to DC the power supply is ESPECIALLY if the wall-wart is intended to be a battery charger. You might be able to check this by measuring the supply with your voltmeter on the AC setting. The closer to DC the level is, the less AC voltage there will be (closer to 0VAC). Also the power supply could be defective.

    And yes the stamp should have no problems sourcing four LED's at 5mA each.

    That's all I have. Good luck.

    Post Edited (Spiral_72) : 2/12/2010 9:07:14 PM GMT
  • allanlane5allanlane5 Posts: 3,815
    edited 2010-02-12 21:55
    Note that 5 mA will work for special "low-current" LED's. "Normal" LED's will work from 10 mA to 20 mA -- 5 mA will leave them dark.

    What have you plugged the BS2 into? Is it a BOE (Board Of Education)?

    If you're using the on-BS2 regulator module, driving more than one LED is a bad idea -- unless they are "low-current" LED's.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2010-02-12 22:55
    What happen when you run this

    DO
    HIGH 15
    'HIGH 14
    'HIGH 13
    'HIGH 12
    LOOP

    If·LEDs still blinking then you are having a current·overflow problem

    Also try a 2.2k resister and see if makes any different

    If you are still having this problems I·do not know what else it could be

    I hope this helps

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam
  • edited 2010-02-15 14:04
    Good news!

    Right on with the current overflow problem. I bumped up the resistor values and wala, no more blinking LED's. I did notice the Board of Education on-board regulator was running hot.

    Thanks everyone! It's great to be able to find help when your in a pickle!
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2010-02-15 22:48
    What resister·value did you use for your LEDs

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam
  • Spiral_72Spiral_72 Posts: 791
    edited 2010-02-16 15:32
    sam_sam_sam said...
    What resister value did you use for your LEDs

    Use Ohm's law: V=I*R
    Where V is voltage in VOLTS, I is current in AMPS, R is resistance in OHMS


    I use 5ma to drive the standard sized LED's I have. Yes it's dim, but still easy to see. I bought some small 3mm green ones that are very bright at 3mA.


    So if you are running them off Vcc (5V) bus voltage you use V/I=R or 5V / 0.005A = R or 1k ohm

    10mA would be 5V / 0.010A = 500 ohm

    Most standard 6mm size LED's have a max current of 20 or 30mA. The small ones are 10mA, 15mA maybe even 5mA so you'll need to take that into account too.

    And that's it! Make sure you don't exceed the maximum bus current listed in the manual. I thought it was 80mA, but others have said only 40mA.... You'll have to look it up (and I do too)



    "MY" rule of thumb is never exceed 5mA off a pin and I try to keep it under that. More than 5mA and I use a transistor or small relay.

    Post Edited (Spiral_72) : 2/16/2010 3:38:38 PM GMT
Sign In or Register to comment.